mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Add mark all as read call to APIManager for use from menu item in all stories list
This commit is contained in:
parent
2992d72085
commit
5cecfcabd2
4 changed files with 29 additions and 48 deletions
|
@ -6,6 +6,7 @@ import android.content.ContentResolver;
|
|||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.widget.Toast;
|
||||
|
@ -15,13 +16,10 @@ import com.actionbarsherlock.view.MenuInflater;
|
|||
import com.newsblur.R;
|
||||
import com.newsblur.database.DatabaseConstants;
|
||||
import com.newsblur.database.FeedProvider;
|
||||
import com.newsblur.domain.Story;
|
||||
import com.newsblur.domain.ValueMultimap;
|
||||
import com.newsblur.fragment.AllStoriesItemListFragment;
|
||||
import com.newsblur.fragment.FeedItemListFragment;
|
||||
import com.newsblur.fragment.SyncUpdateFragment;
|
||||
import com.newsblur.network.APIManager;
|
||||
import com.newsblur.network.MarkAllStoriesAsReadTask;
|
||||
import com.newsblur.service.SyncService;
|
||||
|
||||
public class AllStoriesItemsList extends ItemsList {
|
||||
|
@ -90,15 +88,17 @@ public class AllStoriesItemsList extends ItemsList {
|
|||
|
||||
@Override
|
||||
public void markItemListAsRead() {
|
||||
Cursor stories = getContentResolver().query(FeedProvider.ALL_STORIES_URI, null, FeedProvider.getStorySelectionFromState(currentState), null, null);
|
||||
ValueMultimap storiesToMarkAsRead = new ValueMultimap();
|
||||
for (int i = 0; i < stories.getCount(); i++) {
|
||||
stories.moveToNext();
|
||||
Story story = Story.fromCursor(stories);
|
||||
storiesToMarkAsRead.put(story.feedId, story.id);
|
||||
}
|
||||
|
||||
new MarkAllStoriesAsReadTask(apiManager) {
|
||||
new AsyncTask<Void, Void, Boolean>() {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... arg) {
|
||||
if (apiManager.markAllAsRead()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (result) {
|
||||
|
@ -116,8 +116,8 @@ public class AllStoriesItemsList extends ItemsList {
|
|||
} else {
|
||||
Toast.makeText(AllStoriesItemsList.this, R.string.toast_error_marking_feed_as_read, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}.execute(storiesToMarkAsRead);
|
||||
};
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,7 @@ public class APIConstants {
|
|||
public static final String URL_SIGNUP = "http://newsblur.com/api/signup";
|
||||
public static final String URL_FEED_COUNTS = "http://newsblur.com/reader/refresh_feeds/";
|
||||
public static final String URL_MARK_FEED_AS_READ = "http://newsblur.com/reader/mark_feed_as_read/";
|
||||
public static final String URL_MARK_ALL_AS_READ = "http://newsblur.com/reader/mark_all_as_read/";
|
||||
public static final String URL_MARK_STORY_AS_READ = "http://newsblur.com/reader/mark_story_as_read/";
|
||||
public static final String URL_MARK_FEED_STORIES_AS_READ = "http://newsblur.com/reader/mark_feed_stories_as_read/";
|
||||
public static final String URL_MARK_SOCIALSTORY_AS_READ = "http://newsblur.com/reader/mark_social_stories_as_read/";
|
||||
|
@ -58,6 +59,7 @@ public class APIConstants {
|
|||
public static final String PARAMETER_SHARE_SOURCEID = "source_user_id";
|
||||
public static final String PARAMETER_MARKSOCIAL_JSON = "users_feeds_stories";
|
||||
public static final String PARAMETER_URL = "url";
|
||||
public static final String PARAMETER_DAYS = "days";
|
||||
|
||||
public static final String PARAMETER_PAGE_NUMBER = "page";
|
||||
|
||||
|
|
|
@ -105,6 +105,18 @@ public class APIManager {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean markAllAsRead() {
|
||||
final APIClient client = new APIClient(context);
|
||||
final ValueMultimap values = new ValueMultimap();
|
||||
values.put(APIConstants.PARAMETER_DAYS, "0");
|
||||
final APIResponse response = client.post(APIConstants.URL_MARK_ALL_AS_READ, values, false);
|
||||
if (!response.isOffline && response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean markStoryAsRead(final String feedId, final ArrayList<String> storyIds) {
|
||||
final APIClient client = new APIClient(context);
|
||||
|
@ -661,6 +673,7 @@ public class APIManager {
|
|||
final APIResponse response = client.get(APIConstants.URL_FEED_AUTOCOMPLETE, values);
|
||||
|
||||
if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
|
||||
// TODO doesn't handle auto complete not supporting premium users only causing force close ?
|
||||
return gson.fromJson(response.responseString, FeedResult[].class);
|
||||
} else {
|
||||
return null;
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package com.newsblur.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.newsblur.domain.ValueMultimap;
|
||||
|
||||
public abstract class MarkAllStoriesAsReadTask extends AsyncTask<ValueMultimap, Void, Boolean> {
|
||||
List<String> feedIds = new ArrayList<String>();
|
||||
private APIManager apiManager;
|
||||
|
||||
public MarkAllStoriesAsReadTask(final APIManager apiManager) {
|
||||
this.apiManager = apiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(ValueMultimap... params) {
|
||||
ValueMultimap stories = params[0];
|
||||
if (stories.size() == 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(APIConstants.PARAMETER_FEEDS_STORIES, stories.getJsonString());
|
||||
return apiManager.markMultipleStoriesAsRead(values);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected abstract void onPostExecute(Boolean result);
|
||||
}
|
Loading…
Add table
Reference in a new issue