Merge pull request #372 from ojiikun/master

Android: Bugfixes
This commit is contained in:
Samuel Clay 2013-07-22 20:40:02 -07:00
commit b4de715c7b
10 changed files with 67 additions and 40 deletions

View file

@ -19,7 +19,6 @@ public class AllSharedStoriesReading extends Reading {
private Cursor stories;
private int currentPage;
private ArrayList<String> feedIds;
private boolean requestingPage = false;
private boolean stopLoading = false;
@ -29,8 +28,6 @@ public class AllSharedStoriesReading extends Reading {
setResult(RESULT_OK);
setupCountCursor();
StoryOrder storyOrder = PrefsUtils.getStoryOrderForFolder(this, PrefConstants.ALL_SHARED_STORIES_FOLDER_NAME);
stories = contentResolver.query(FeedProvider.ALL_SHARED_STORIES_URI, null, DatabaseConstants.getStorySelectionFromState(currentState), null, DatabaseConstants.getStorySortOrder(storyOrder));
setTitle(getResources().getString(R.string.all_shared_stories));
@ -41,17 +38,6 @@ public class AllSharedStoriesReading extends Reading {
addStoryToMarkAsRead(readingAdapter.getStory(passedPosition));
}
private void setupCountCursor() {
StoryOrder storyOrder = PrefsUtils.getStoryOrderForFolder(this, PrefConstants.ALL_SHARED_STORIES_FOLDER_NAME);
Cursor cursor = getContentResolver().query(FeedProvider.FEEDS_URI, null, DatabaseConstants.getStorySelectionFromState(currentState), null, DatabaseConstants.getStorySortOrder(storyOrder));
startManagingCursor(cursor);
feedIds = new ArrayList<String>();
while (cursor.moveToNext()) {
feedIds.add(cursor.getString(cursor.getColumnIndex(DatabaseConstants.FEED_ID)));
}
}
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
@ -81,9 +67,7 @@ public class AllSharedStoriesReading extends Reading {
intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, syncFragment.receiver);
intent.putExtra(SyncService.EXTRA_TASK_TYPE, SyncService.TaskType.MULTISOCIALFEED_UPDATE);
String[] feeds = new String[feedIds.size()];
feedIds.toArray(feeds);
intent.putExtra(SyncService.EXTRA_TASK_MULTIFEED_IDS, feeds);
intent.putExtra(SyncService.EXTRA_TASK_MULTIFEED_IDS, new String[0]); // query for all shared storis via wildcard
if (page > 1) {
intent.putExtra(SyncService.EXTRA_TASK_PAGE_NUMBER, Integer.toString(page));
}

View file

@ -1,8 +1,12 @@
package com.newsblur.activity;
import java.util.ArrayList;
import java.util.List;
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;
@ -20,6 +24,7 @@ import com.newsblur.fragment.SyncUpdateFragment;
import com.newsblur.fragment.MarkAllReadDialogFragment.MarkAllReadDialogListener;
import com.newsblur.network.APIManager;
import com.newsblur.service.SyncService;
import com.newsblur.util.AppConstants;
import com.newsblur.util.PrefConstants;
import com.newsblur.util.PrefsUtils;
import com.newsblur.util.ReadFilter;
@ -67,10 +72,25 @@ public class AllStoriesItemsList extends ItemsList implements MarkAllReadDialogL
public void triggerRefresh(int page) {
if (!stopLoading) {
setSupportProgressBarIndeterminateVisibility(true);
String[] feedIds = new String[0]; // default to a wildcard search
// if we're in Focus mode, only query for feeds with a nonzero focus count
if (this.currentState == AppConstants.STATE_BEST) {
Cursor cursor = resolver.query(FeedProvider.FEEDS_URI, null, DatabaseConstants.FEED_FILTER_FOCUS, null, null);
List<String> feedList = new ArrayList<String>();
while (cursor.moveToNext() && (feedList.size() <= AppConstants.MAX_FEED_LIST_SIZE)) {
feedList.add(cursor.getString(cursor.getColumnIndex(DatabaseConstants.FEED_ID)));
}
feedIds = new String[feedList.size()];
feedList.toArray(feedIds);
cursor.close();
}
final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class);
intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, syncFragment.receiver);
intent.putExtra(SyncService.EXTRA_TASK_TYPE, SyncService.TaskType.MULTIFEED_UPDATE);
intent.putExtra(SyncService.EXTRA_TASK_MULTIFEED_IDS, new String[0]); // the API will return all feeds if no IDs are passed
intent.putExtra(SyncService.EXTRA_TASK_MULTIFEED_IDS, feedIds);
intent.putExtra(SyncService.EXTRA_TASK_PAGE_NUMBER, Integer.toString(page));
intent.putExtra(SyncService.EXTRA_TASK_ORDER, getStoryOrder());
intent.putExtra(SyncService.EXTRA_TASK_READ_FILTER, PrefsUtils.getReadFilterForFolder(this, PrefConstants.ALL_STORIES_FOLDER_NAME));

View file

@ -29,8 +29,6 @@ public class AllStoriesReading extends Reading {
setResult(RESULT_OK);
setupCountCursor();
StoryOrder storyOrder = PrefsUtils.getStoryOrderForFolder(this, PrefConstants.ALL_STORIES_FOLDER_NAME);
stories = contentResolver.query(FeedProvider.ALL_STORIES_URI, null, DatabaseConstants.getStorySelectionFromState(currentState), null, DatabaseConstants.getStorySortOrder(storyOrder));
setTitle(getResources().getString(R.string.all_stories_row_title));
@ -41,14 +39,6 @@ public class AllStoriesReading extends Reading {
addStoryToMarkAsRead(readingAdapter.getStory(passedPosition));
}
private void setupCountCursor() {
Cursor cursor = getContentResolver().query(FeedProvider.FEEDS_URI, null, DatabaseConstants.getStorySelectionFromState(currentState), null, null);
feedIds = new ArrayList<String>();
while (cursor.moveToNext()) {
feedIds.add(cursor.getString(cursor.getColumnIndex(DatabaseConstants.FEED_ID)));
}
}
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
@ -78,9 +68,7 @@ public class AllStoriesReading extends Reading {
intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, syncFragment.receiver);
intent.putExtra(SyncService.EXTRA_TASK_TYPE, SyncService.TaskType.MULTIFEED_UPDATE);
String[] feeds = new String[feedIds.size()];
feedIds.toArray(feeds);
intent.putExtra(SyncService.EXTRA_TASK_MULTIFEED_IDS, feeds);
intent.putExtra(SyncService.EXTRA_TASK_MULTIFEED_IDS, new String[0]); // ask for all stories via wildcarding the feed param
if (page > 1) {
intent.putExtra(SyncService.EXTRA_TASK_PAGE_NUMBER, Integer.toString(page));
}

View file

@ -22,6 +22,7 @@ import com.newsblur.fragment.SyncUpdateFragment;
import com.newsblur.network.APIManager;
import com.newsblur.network.MarkFolderAsReadTask;
import com.newsblur.service.SyncService;
import com.newsblur.util.AppConstants;
import com.newsblur.util.PrefsUtils;
import com.newsblur.util.ReadFilter;
import com.newsblur.util.StoryOrder;
@ -45,9 +46,9 @@ public class FolderItemsList extends ItemsList implements MarkAllReadDialogListe
apiManager = new APIManager(this);
final Uri feedsUri = FeedProvider.FEED_FOLDER_MAP_URI.buildUpon().appendPath(folderName).build();
Cursor cursor = getContentResolver().query(feedsUri, new String[] { DatabaseConstants.FEED_ID } , DatabaseConstants.getStorySelectionFromState(currentState), null, null);
Cursor cursor = getContentResolver().query(feedsUri, new String[] { DatabaseConstants.FEED_ID }, DatabaseConstants.getStorySelectionFromState(currentState), null, null);
while (cursor.moveToNext()) {
while (cursor.moveToNext() && (feedIds.size() <= AppConstants.MAX_FEED_LIST_SIZE)) {
feedIds.add(cursor.getString(cursor.getColumnIndex(DatabaseConstants.FEED_ID)));
}

View file

@ -152,6 +152,7 @@ public class DatabaseConstants {
private static final String SOCIAL_INTELLIGENCE_BEST = " (" + DatabaseConstants.SOCIAL_FEED_POSITIVE_COUNT + ") > 0 ";
private static final String SUM_STORY_TOTAL = "storyTotal";
public static final String FEED_FILTER_FOCUS = " WHERE " + FEED_TABLE + "." + FEED_POSITIVE_COUNT + " > 0 ";
private static String STORY_SUM_TOTAL = " CASE " +
"WHEN MAX(" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + "," + DatabaseConstants.STORY_INTELLIGENCE_TAGS + "," + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") > 0 " +

View file

@ -1,5 +1,7 @@
package com.newsblur.database;
import java.util.Arrays;
import android.R.string;
import android.content.ContentProvider;
import android.content.ContentValues;
@ -330,7 +332,10 @@ public class FeedProvider extends ContentProvider {
mdb = db;
}
public Cursor rawQuery(String sql, String[] selectionArgs) {
//Log.d(LoggingDatabase.class.getName(), "rawQuery: " + sql);
if (AppConstants.VERBOSE_LOG) {
Log.d(LoggingDatabase.class.getName(), "rawQuery: " + sql);
Log.d(LoggingDatabase.class.getName(), "selArgs : " + Arrays.toString(selectionArgs));
}
return mdb.rawQuery(sql, selectionArgs);
}
public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy) {
@ -347,10 +352,12 @@ public class FeedProvider extends ContentProvider {
// Query for all feeds (by default only return those that have unread items in them)
case ALL_FEEDS:
return db.rawQuery("SELECT " + TextUtils.join(",", DatabaseConstants.FEED_COLUMNS) + " FROM " + DatabaseConstants.FEED_FOLDER_MAP_TABLE +
String feedsQuery = "SELECT " + TextUtils.join(",", DatabaseConstants.FEED_COLUMNS) + " FROM " + DatabaseConstants.FEED_FOLDER_MAP_TABLE +
" INNER JOIN " + DatabaseConstants.FEED_TABLE +
" ON " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_ID + " = " + DatabaseConstants.FEED_FOLDER_MAP_TABLE + "." + DatabaseConstants.FEED_FOLDER_FEED_ID +
" ORDER BY " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_TITLE + " COLLATE NOCASE", selectionArgs);
((selection == null) ? "" : selection) +
" ORDER BY " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_TITLE + " COLLATE NOCASE";
return db.rawQuery(feedsQuery, selectionArgs);
// Query for a specific feed
case INDIVIDUAL_FEED:

View file

@ -43,8 +43,6 @@ import com.newsblur.view.NewsblurWebview;
public class ReadingItemFragment extends Fragment implements ClassifierDialogFragment.TagUpdateCallback, ShareDialogFragment.SharedCallbackDialog {
private static final long serialVersionUID = -5737027559180364671L;
private static final String TAG = "ReadingItemFragment";
public static final String TEXT_SIZE_CHANGED = "textSizeChanged";
public static final String TEXT_SIZE_VALUE = "textSizeChangeValue";
public Story story;
@ -113,6 +111,20 @@ public class ReadingItemFragment extends Fragment implements ClassifierDialogFra
super.onDestroy();
}
// WebViews don't automatically pause content like audio and video when they lose focus. Chain our own
// state into the webview so it behaves.
@Override
public void onPause() {
if (this.web != null ) { this.web.onPause(); }
super.onPause();
}
@Override
public void onResume() {
if (this.web != null ) { this.web.onResume(); }
super.onResume();
}
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_readingitem, null);

View file

@ -35,7 +35,7 @@ public class APIConstants {
public static final String URL_DELETE_FEED = "http://newsblur.com/reader/delete_feed";
public static final String URL_CLASSIFIER_SAVE = "http://newsblur.com/classifier/save";
public static final String PARAMETER_FEEDS = "feeds";
public static final String PARAMETER_FEEDS = "f";
public static final String PARAMETER_PASSWORD = "password";
public static final String PARAMETER_USER_ID = "user_id";
public static final String PARAMETER_USERNAME = "username";

View file

@ -40,4 +40,8 @@ public class AppConstants {
// the base amount for how long to sleep during exponential API failure backoff
public static final long API_BACKOFF_BASE_MILLIS = 500L;
// when generating a request for multiple feeds, limit the total number requested to prevent
// unworkably long URLs
public static final int MAX_FEED_LIST_SIZE = 250;
}

View file

@ -6,6 +6,7 @@ import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import com.newsblur.util.AppConstants;
@ -46,7 +47,16 @@ public class NewsblurWebview extends WebView {
handler.dispatchMessage(msg);
}
}
public void onPause() {
// TODO: is there anything more we can do to get media content to stop playing on pause?
super.onPause();
}
public void onResume() {
// TODO: restore media content if it was disabled above
super.onResume();
}
public void setHandler(Handler h) {
this.handler = h;