Initial work on API for mute/unmute.

This commit is contained in:
Mark Anderson 2016-08-23 22:42:27 +01:00
parent b0a5090221
commit efbda57deb
5 changed files with 60 additions and 0 deletions

View file

@ -96,8 +96,15 @@ public class BlurDatabaseHelper {
}
public Set<String> getAllFeeds() {
return getAllFeeds(false);
}
private Set<String> getAllFeeds(boolean activeOnly) {
String q1 = "SELECT " + DatabaseConstants.FEED_ID +
" FROM " + DatabaseConstants.FEED_TABLE;
if (activeOnly) {
q1 = q1 + " WHERE " + DatabaseConstants.FEED_ACTIVE + " = 1";
}
Cursor c = dbRO.rawQuery(q1, null);
LinkedHashSet<String> feedIds = new LinkedHashSet<String>(c.getCount());
while (c.moveToNext()) {
@ -107,6 +114,10 @@ public class BlurDatabaseHelper {
return feedIds;
}
public Set<String> getAllActiveFeeds() {
return getAllFeeds(true);
}
private List<String> getAllSocialFeeds() {
String q1 = "SELECT " + DatabaseConstants.SOCIAL_FEED_ID +
" FROM " + DatabaseConstants.SOCIALFEED_TABLE;
@ -496,6 +507,12 @@ public class BlurDatabaseHelper {
}
}
public void setFeedActive(String feedId, boolean active) {
ContentValues values = new ContentValues();
values.put(DatabaseConstants.FEED_ACTIVE, active);
synchronized (RW_MUTEX) {dbRW.update(DatabaseConstants.FEED_TABLE, values, DatabaseConstants.FEED_ID + " = ?", new String[]{feedId});}
}
/**
* Marks a story (un)read but does not adjust counts. Must stay idempotent an time-insensitive.
*/

View file

@ -288,6 +288,10 @@ public class FolderListFragment extends NbFragment implements OnCreateContextMen
} else if (item.getItemId() == R.id.menu_choose_folders) {
DialogFragment chooseFoldersFragment = ChooseFoldersFragment.newInstance(adapter.getFeed(groupPosition, childPosition));
chooseFoldersFragment.show(getFragmentManager(), "dialog");
} else if (item.getItemId() == R.id.menu_mute_feed) {
FeedUtils.muteFeed(getActivity(), adapter.getFeed(groupPosition, childPosition));
} else if (item.getItemId() == R.id.menu_unmute_feed) {
FeedUtils.unmuteFeed(getActivity(), adapter.getFeed(groupPosition, childPosition));
}
return super.onContextItemSelected(item);

View file

@ -48,6 +48,7 @@ public class APIConstants {
public static final String URL_UNREAD_HASHES = NEWSBLUR_URL + "/reader/unread_story_hashes";
public static final String URL_READ_STORIES = NEWSBLUR_URL + "/reader/read_stories";
public static final String URL_MOVE_FEED_TO_FOLDERS = NEWSBLUR_URL + "/reader/move_feed_to_folders";
public static final String URL_SAVE_FEED_CHOOSER = NEWSBLUR_URL + "/reader/save_feed_chooser";
public static final String PARAMETER_FEEDS = "f";
public static final String PARAMETER_H = "h";
@ -86,6 +87,7 @@ public class APIConstants {
public static final String PARAMETER_IN_FOLDERS = "in_folders";
public static final String PARAMETER_QUERY = "query";
public static final String PARAMETER_TAG = "tag";
public static final String PARAMETER_APPROVED_FEEDS = "approved_feeds";
public static final String VALUE_PREFIX_SOCIAL = "social:";
public static final String VALUE_ALLSOCIAL = "river:blurblogs"; // the magic value passed to the mark-read API for all social feeds

View file

@ -571,6 +571,15 @@ public class APIManager {
return response.getResponse(gson, NewsBlurResponse.class);
}
public NewsBlurResponse saveFeedChooser(Set<String> feeds) {
ValueMultimap values = new ValueMultimap();
for (String feed : feeds) {
values.put(APIConstants.PARAMETER_APPROVED_FEEDS, feed);
}
APIResponse response = post(APIConstants.URL_SAVE_FEED_CHOOSER, values);
return response.getResponse(gson, NewsBlurResponse.class);
}
/* HTTP METHODS */
private APIResponse get(final String urlString) {

View file

@ -263,6 +263,34 @@ public class FeedUtils {
}.execute();
}
public static void muteFeed(final Context context, final Feed feed) {
updateFeedActiveState(context, feed, false);
}
public static void unmuteFeed(final Context context, final Feed feed) {
updateFeedActiveState(context, feed, true);
}
private static void updateFeedActiveState(final Context context, final Feed feed, final boolean active) {
new AsyncTask<Void, Void, NewsBlurResponse>() {
@Override
protected NewsBlurResponse doInBackground(Void... arg) {
APIManager apiManager = new APIManager(context);
Set<String> activeFeeds = dbHelper.getAllActiveFeeds();
if (active) {
activeFeeds.add(feed.feedId);
}
return apiManager.saveFeedChooser(activeFeeds);
}
@Override
protected void onPostExecute(NewsBlurResponse result) {
feed.active = active;
dbHelper.setFeedActive(feed.feedId, active);
triggerSync(context);
}
}.execute();
}
public static FeedSet feedSetFromFolderName(String folderName) {
return FeedSet.folder(folderName, getFeedIdsRecursive(folderName));
}