mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Added callbacks and Content Provider hack to effectively handle feed counts.
This commit is contained in:
parent
5114fa6422
commit
482b316501
10 changed files with 66 additions and 28 deletions
|
@ -36,6 +36,8 @@ public class ItemsList extends SherlockFragmentActivity implements SyncUpdateFra
|
|||
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||
super.onCreate(bundle);
|
||||
setResult(RESULT_OK);
|
||||
|
||||
setContentView(R.layout.activity_itemslist);
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
feedId = getIntent().getStringExtra(EXTRA_FEED);
|
||||
|
@ -71,7 +73,7 @@ public class ItemsList extends SherlockFragmentActivity implements SyncUpdateFra
|
|||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Log.d(TAG, "Returned okay.");
|
||||
if (resultCode == RESULT_OK) {
|
||||
itemListFragment.updated();
|
||||
itemListFragment.hasUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +100,7 @@ public class ItemsList extends SherlockFragmentActivity implements SyncUpdateFra
|
|||
@Override
|
||||
public void updateAfterSync() {
|
||||
Log.d(TAG , "Redrawing UI");
|
||||
itemListFragment.updated();
|
||||
itemListFragment.hasUpdated();
|
||||
setSupportProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,13 @@ public class Main extends SherlockFragmentActivity implements StateChangedListen
|
|||
Log.d(TAG, "State changed");
|
||||
folderFeedList.changeState(state);
|
||||
}
|
||||
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Log.d(TAG, "Returned okay.");
|
||||
if (resultCode == RESULT_OK) {
|
||||
folderFeedList.hasUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAfterSync() {
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.actionbarsherlock.view.MenuInflater;
|
|||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.actionbarsherlock.view.Window;
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.database.DatabaseConstants;
|
||||
import com.newsblur.database.FeedProvider;
|
||||
import com.newsblur.database.ReadingAdapter;
|
||||
import com.newsblur.domain.Feed;
|
||||
|
@ -36,7 +37,7 @@ public class Reading extends SherlockFragmentActivity implements OnPageChangeLis
|
|||
public static final String EXTRA_FEED = "feed_selected";
|
||||
public static final String TAG = "ReadingActivity";
|
||||
public static final String EXTRA_POSITION = "feed_position";
|
||||
|
||||
|
||||
private int passedPosition;
|
||||
private int currentState;
|
||||
private String feedId;
|
||||
|
@ -48,7 +49,7 @@ public class Reading extends SherlockFragmentActivity implements OnPageChangeLis
|
|||
private ReadingAdapter readingAdapter;
|
||||
private ContentResolver contentResolver;
|
||||
private SyncUpdateFragment syncFragment;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceBundle) {
|
||||
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||
|
@ -73,13 +74,13 @@ public class Reading extends SherlockFragmentActivity implements OnPageChangeLis
|
|||
setTitle(feed.title);
|
||||
|
||||
createFloatingHeader();
|
||||
|
||||
|
||||
syncFragment = (SyncUpdateFragment) fragmentManager.findFragmentByTag(SyncUpdateFragment.TAG);
|
||||
if (syncFragment == null) {
|
||||
syncFragment = new SyncUpdateFragment();
|
||||
fragmentManager.beginTransaction().add(syncFragment, SyncUpdateFragment.TAG).commit();
|
||||
}
|
||||
|
||||
|
||||
pager = (ViewPager) findViewById(R.id.reading_pager);
|
||||
pager.setPageMargin(UIUtils.convertDPsToPixels(getApplicationContext(), 1));
|
||||
pager.setPageMarginDrawable(R.drawable.divider_light);
|
||||
|
@ -89,9 +90,11 @@ public class Reading extends SherlockFragmentActivity implements OnPageChangeLis
|
|||
pager.setCurrentItem(passedPosition);
|
||||
|
||||
new MarkStoryAsReadTask(this, contentResolver, syncFragment).execute(readingAdapter.getStory(passedPosition));
|
||||
|
||||
setResult(RESULT_OK);
|
||||
}
|
||||
|
||||
|
||||
private void createFloatingHeader() {
|
||||
View view = findViewById(R.id.reading_floatbar);
|
||||
GradientDrawable gradient;
|
||||
|
|
|
@ -85,6 +85,16 @@ public class DatabaseConstants {
|
|||
STORY_PERMALINK, STORY_READ, STORY_SHARE_COUNT, STORY_TAGS, STORY_TITLE, STORY_SHARED_USER_IDS
|
||||
};
|
||||
|
||||
|
||||
public static final String FOLDER_INTELLIGENCE_ALL = " HAVING SUM(" + DatabaseConstants.FEED_NEGATIVE_COUNT + " + " + DatabaseConstants.FEED_NEUTRAL_COUNT + " + " + DatabaseConstants.FEED_POSITIVE_COUNT + ") > 0 ";
|
||||
public static final String FOLDER_INTELLIGENCE_SOME = " HAVING SUM(" + DatabaseConstants.FEED_NEUTRAL_COUNT + " + " + DatabaseConstants.FEED_POSITIVE_COUNT + ") > 0 ";
|
||||
public static final String FOLDER_INTELLIGENCE_BEST = " HAVING SUM(" + DatabaseConstants.FEED_POSITIVE_COUNT + ") > 0 ";
|
||||
|
||||
public static final String STORY_INTELLIGENCE_BEST = " (" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + " + " + DatabaseConstants.STORY_INTELLIGENCE_FEED + " + " + DatabaseConstants.STORY_INTELLIGENCE_TAGS + " + " + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") > 0 " +
|
||||
"AND " + DatabaseConstants.STORY_READ + " = '0'";
|
||||
public static final String STORY_INTELLIGENCE_SOME = " (" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + " + " + DatabaseConstants.STORY_INTELLIGENCE_FEED + " + " + DatabaseConstants.STORY_INTELLIGENCE_TAGS + " + " + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") >= 0 " +
|
||||
"AND " + DatabaseConstants.STORY_READ + " = '0'";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,20 +19,12 @@ public class FeedProvider extends ContentProvider {
|
|||
public static final String VERSION = "v1";
|
||||
public static final Uri NEWSBLUR_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION);
|
||||
public static final Uri FEEDS_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/feeds/");
|
||||
public static final Uri MODIFY_COUNT_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/feedcount/");
|
||||
public static final Uri STORIES_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/stories/");
|
||||
public static final Uri STORY_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/story/");
|
||||
public static final Uri COMMENTS_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/comments/");
|
||||
public static final Uri FEED_FOLDER_MAP_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/feedfoldermap/");
|
||||
public static final Uri FOLDERS_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/folders/");
|
||||
|
||||
public static final String FOLDER_INTELLIGENCE_ALL = " HAVING SUM(" + DatabaseConstants.FEED_NEGATIVE_COUNT + " + " + DatabaseConstants.FEED_NEUTRAL_COUNT + " + " + DatabaseConstants.FEED_POSITIVE_COUNT + ") > 0 ";
|
||||
public static final String FOLDER_INTELLIGENCE_SOME = " HAVING SUM(" + DatabaseConstants.FEED_NEUTRAL_COUNT + " + " + DatabaseConstants.FEED_POSITIVE_COUNT + ") > 0 ";
|
||||
public static final String FOLDER_INTELLIGENCE_BEST = " HAVING SUM(" + DatabaseConstants.FEED_POSITIVE_COUNT + ") > 0 ";
|
||||
|
||||
public static final String STORY_INTELLIGENCE_BEST = " (" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + " + " + DatabaseConstants.STORY_INTELLIGENCE_FEED + " + " + DatabaseConstants.STORY_INTELLIGENCE_TAGS + " + " + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") > 0 " +
|
||||
"AND " + DatabaseConstants.STORY_READ + " = '0'";
|
||||
public static final String STORY_INTELLIGENCE_SOME = " (" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + " + " + DatabaseConstants.STORY_INTELLIGENCE_FEED + " + " + DatabaseConstants.STORY_INTELLIGENCE_TAGS + " + " + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") >= 0 " +
|
||||
"AND " + DatabaseConstants.STORY_READ + " = '0'";
|
||||
|
||||
private static final int ALL_FEEDS = 0;
|
||||
private static final int FEED_STORIES = 1;
|
||||
|
@ -43,6 +35,7 @@ public class FeedProvider extends ContentProvider {
|
|||
private static final int INDIVIDUAL_FEED = 6;
|
||||
private static final int STORY_COMMENTS = 7;
|
||||
private static final int INDIVIDUAL_STORY = 8;
|
||||
private static final int DECREMENT_COUNT = 9;
|
||||
|
||||
private BlurDatabase databaseHelper;
|
||||
|
||||
|
@ -51,6 +44,8 @@ public class FeedProvider extends ContentProvider {
|
|||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feeds/", ALL_FEEDS);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feeds/*/", INDIVIDUAL_FEED);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feedcount/", DECREMENT_COUNT);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feed/*/", INDIVIDUAL_FEED);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/stories/#/", FEED_STORIES);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/story/*/", INDIVIDUAL_STORY);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/comments/", STORY_COMMENTS);
|
||||
|
@ -232,6 +227,11 @@ public class FeedProvider extends ContentProvider {
|
|||
return db.update(DatabaseConstants.FEED_TABLE, values, DatabaseConstants.FEED_ID + " = ?", new String[] { uri.getLastPathSegment() });
|
||||
case INDIVIDUAL_STORY:
|
||||
return db.update(DatabaseConstants.STORY_TABLE, values, DatabaseConstants.STORY_ID + " = ?", new String[] { uri.getLastPathSegment() });
|
||||
|
||||
// In order to run a raw SQL query whereby we make decrement the column we need to a dynamic reference - something the usual content provider call easily handle. Hence this circuitous workaround.
|
||||
case DECREMENT_COUNT:
|
||||
db.execSQL("UPDATE " + DatabaseConstants.FEED_TABLE + " SET " + selectionArgs[0] + " = " + selectionArgs[0] + " - 1 WHERE " + DatabaseConstants.FEED_ID + " = " + selectionArgs[1]);
|
||||
return 0;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown URI: " + uri);
|
||||
}
|
||||
|
@ -244,10 +244,10 @@ public class FeedProvider extends ContentProvider {
|
|||
selection = "";
|
||||
break;
|
||||
case (AppConstants.STATE_SOME):
|
||||
selection = FeedProvider.STORY_INTELLIGENCE_SOME;
|
||||
selection = DatabaseConstants.STORY_INTELLIGENCE_SOME;
|
||||
break;
|
||||
case (AppConstants.STATE_BEST):
|
||||
selection = FeedProvider.STORY_INTELLIGENCE_BEST;
|
||||
selection = DatabaseConstants.STORY_INTELLIGENCE_BEST;
|
||||
break;
|
||||
}
|
||||
return selection;
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.content.ContentResolver;
|
|||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.SimpleCursorTreeAdapter;
|
||||
|
||||
import com.newsblur.domain.Folder;
|
||||
|
@ -12,7 +11,7 @@ import com.newsblur.domain.Folder;
|
|||
public class FolderTreeAdapter extends SimpleCursorTreeAdapter {
|
||||
|
||||
ContentResolver resolver;
|
||||
public String currentState = FeedProvider.FOLDER_INTELLIGENCE_ALL;
|
||||
public String currentState = DatabaseConstants.FOLDER_INTELLIGENCE_ALL;
|
||||
private String TAG = "FolderTreeAdapter";
|
||||
|
||||
public FolderTreeAdapter(Context context, Cursor cursor, int collapsedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo) {
|
||||
|
|
|
@ -121,5 +121,7 @@ public class Story implements Serializable {
|
|||
public int intelligenceTitle = 0;
|
||||
}
|
||||
|
||||
|
||||
public int getIntelligenceTotal() {
|
||||
return (intelligence.intelligenceAuthors + intelligence.intelligenceFeed + intelligence.intelligenceTags + intelligence.intelligenceTitle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ public class FolderFeedListFragment extends Fragment implements OnGroupClickList
|
|||
private int leftBound, rightBound;
|
||||
private APIManager apiManager;
|
||||
private int currentState = AppConstants.STATE_SOME;
|
||||
private int FEEDCHECK = 0x01;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -48,7 +49,7 @@ public class FolderFeedListFragment extends Fragment implements OnGroupClickList
|
|||
apiManager = new APIManager(getActivity());
|
||||
|
||||
|
||||
Cursor cursor = resolver.query(FeedProvider.FOLDERS_URI, null, null, new String[] { FeedProvider.FOLDER_INTELLIGENCE_SOME }, null);
|
||||
Cursor cursor = resolver.query(FeedProvider.FOLDERS_URI, null, null, new String[] { DatabaseConstants.FOLDER_INTELLIGENCE_SOME }, null);
|
||||
viewBinder = new FolderTreeViewBinder();
|
||||
|
||||
leftBound = UIUtils.convertDPsToPixels(getActivity(), 20);
|
||||
|
@ -132,13 +133,13 @@ public class FolderFeedListFragment extends Fragment implements OnGroupClickList
|
|||
|
||||
switch (state) {
|
||||
case (AppConstants.STATE_ALL):
|
||||
selection = FeedProvider.FOLDER_INTELLIGENCE_ALL;
|
||||
selection = DatabaseConstants.FOLDER_INTELLIGENCE_ALL;
|
||||
break;
|
||||
case (AppConstants.STATE_SOME):
|
||||
selection = FeedProvider.FOLDER_INTELLIGENCE_SOME;
|
||||
selection = DatabaseConstants.FOLDER_INTELLIGENCE_SOME;
|
||||
break;
|
||||
case (AppConstants.STATE_BEST):
|
||||
selection = FeedProvider.FOLDER_INTELLIGENCE_BEST;
|
||||
selection = DatabaseConstants.FOLDER_INTELLIGENCE_BEST;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -165,7 +166,7 @@ public class FolderFeedListFragment extends Fragment implements OnGroupClickList
|
|||
String feedId = childCursor.getString(childCursor.getColumnIndex(DatabaseConstants.FEED_ID));
|
||||
intent.putExtra(ItemsList.EXTRA_FEED, feedId);
|
||||
intent.putExtra(ItemsList.EXTRA_STATE, currentState);
|
||||
getActivity().startActivity(intent);
|
||||
getActivity().startActivityForResult(intent, FEEDCHECK );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ public class ItemListFragment extends Fragment implements LoaderManager.LoaderCa
|
|||
}
|
||||
}
|
||||
|
||||
public void updated() {
|
||||
public void hasUpdated() {
|
||||
getLoaderManager().restartLoader(ITEMLIST_LOADER , null, this);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,11 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.newsblur.database.DatabaseConstants;
|
||||
import com.newsblur.database.FeedProvider;
|
||||
import com.newsblur.domain.Feed;
|
||||
import com.newsblur.domain.Story;
|
||||
import com.newsblur.fragment.SyncUpdateFragment;
|
||||
import com.newsblur.service.SyncService;
|
||||
|
@ -18,7 +20,8 @@ public class MarkStoryAsReadTask extends AsyncTask<Story, Void, Void> {
|
|||
private ContentResolver contentResolver;
|
||||
private Context context;
|
||||
private SyncUpdateFragment receiver;
|
||||
|
||||
private Feed feed;
|
||||
|
||||
public MarkStoryAsReadTask(final Context context, final ContentResolver resolver, final SyncUpdateFragment fragment) {
|
||||
this.contentResolver = resolver;
|
||||
this.context = context;
|
||||
|
@ -28,11 +31,22 @@ public class MarkStoryAsReadTask extends AsyncTask<Story, Void, Void> {
|
|||
protected Void doInBackground(Story... params) {
|
||||
for (Story story : params) {
|
||||
if (story.read.equals("0")) {
|
||||
|
||||
String[] selectionArgs;
|
||||
if (story.getIntelligenceTotal() > 0) {
|
||||
selectionArgs = new String[] { DatabaseConstants.FEED_POSITIVE_COUNT, story.feedId } ;
|
||||
} else if (story.getIntelligenceTotal() == 0) {
|
||||
selectionArgs = new String[] { DatabaseConstants.FEED_NEUTRAL_COUNT, story.feedId } ;
|
||||
} else {
|
||||
selectionArgs = new String[] { DatabaseConstants.FEED_NEGATIVE_COUNT, story.feedId } ;
|
||||
}
|
||||
Log.d("TAG", "Returned: " + contentResolver.update(FeedProvider.MODIFY_COUNT_URI, null, null, selectionArgs));
|
||||
|
||||
Uri storyUri = FeedProvider.STORY_URI.buildUpon().appendPath(story.id).build();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(DatabaseConstants.STORY_READ, true);
|
||||
|
||||
contentResolver.update(storyUri, values, null, null);
|
||||
|
||||
final Intent intent = new Intent(Intent.ACTION_SYNC, null, context, SyncService.class);
|
||||
intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, receiver.receiver);
|
||||
intent.putExtra(SyncService.SYNCSERVICE_TASK, SyncService.EXTRA_TASK_MARK_STORY_READ);
|
||||
|
|
Loading…
Add table
Reference in a new issue