mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
Android widget cache stories for quick retrieval
This commit is contained in:
parent
0aaa242723
commit
c86d39f5f6
9 changed files with 16 additions and 17 deletions
|
@ -21,7 +21,7 @@ public class AllStoriesItemsList extends ItemsList {
|
|||
setIntent(intent);
|
||||
if (getIntent().getBooleanExtra(EXTRA_WIDGET_STORY, false)) {
|
||||
String hash = (String) getIntent().getSerializableExtra(EXTRA_STORY_HASH);
|
||||
UIUtils.startReadingActivity(fs, hash, true,this);
|
||||
UIUtils.startReadingActivity(fs, hash, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,10 +70,10 @@ public abstract class ItemsList extends NbActivity implements StoryOrderChangedL
|
|||
|
||||
if (getIntent().getBooleanExtra(EXTRA_WIDGET_STORY, false)) {
|
||||
String hash = (String) getIntent().getSerializableExtra(EXTRA_STORY_HASH);
|
||||
UIUtils.startReadingActivity(fs, hash, true, this);
|
||||
UIUtils.startReadingActivity(fs, hash, this);
|
||||
} else if (PrefsUtils.isAutoOpenFirstUnread(this)) {
|
||||
if (FeedUtils.dbHelper.getUnreadCount(fs, intelState) > 0) {
|
||||
UIUtils.startReadingActivity(fs, Reading.FIND_FIRST_UNREAD, false,this);
|
||||
UIUtils.startReadingActivity(fs, Reading.FIND_FIRST_UNREAD, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
|
|||
public static final String EXTRA_FEEDSET = "feed_set";
|
||||
public static final String EXTRA_POSITION = "feed_position";
|
||||
public static final String EXTRA_STORY_HASH = "story_hash";
|
||||
public static final String EXTRA_WAIT_REFRESH = "wait_refresh";
|
||||
private static final String BUNDLE_POSITION = "position";
|
||||
private static final String BUNDLE_STARTING_UNREAD = "starting_unread";
|
||||
private static final String BUNDLE_SELECTED_FEED_VIEW = "selectedFeedView";
|
||||
|
@ -105,7 +104,6 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
|
|||
private int lastVScrollPos = 0;
|
||||
|
||||
private boolean unreadSearchActive = false;
|
||||
private boolean waitRefresh = false;
|
||||
|
||||
private List<Story> pageHistory;
|
||||
|
||||
|
@ -126,7 +124,6 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
|
|||
|
||||
try {
|
||||
fs = (FeedSet)getIntent().getSerializableExtra(EXTRA_FEEDSET);
|
||||
waitRefresh = getIntent().getBooleanExtra(EXTRA_WAIT_REFRESH, false);
|
||||
} catch (RuntimeException re) {
|
||||
// in the wild, the notification system likes to pass us an Intent that has missing or very stale
|
||||
// Serializable extras.
|
||||
|
@ -318,11 +315,6 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
|
|||
emptyViewText.setVisibility(View.INVISIBLE);
|
||||
storyHash = null;
|
||||
return;
|
||||
} else if (waitRefresh) {
|
||||
// when deep linking from app widget the db might not have the latest stories
|
||||
// that we're looking to read so return and wait for updated cursor
|
||||
waitRefresh = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// if the story wasn't found, try to get more stories into the cursor
|
||||
|
|
|
@ -349,7 +349,7 @@ public class StoryViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
return;
|
||||
}
|
||||
if (gestureL2R || gestureR2L) return;
|
||||
UIUtils.startReadingActivity(fs, story.storyHash, false, context);
|
||||
UIUtils.startReadingActivity(fs, story.storyHash, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -153,7 +153,7 @@ public abstract class ProfileActivityDetailsFragment extends Fragment implements
|
|||
//context.startActivity(intent);
|
||||
}
|
||||
} else if (activity.category == Category.STAR) {
|
||||
UIUtils.startReadingActivity(FeedSet.allSaved(), activity.storyHash, false, context);
|
||||
UIUtils.startReadingActivity(FeedSet.allSaved(), activity.storyHash, context);
|
||||
} else if (isSocialFeedCategory(activity)) {
|
||||
// Strip the social: prefix from feedId
|
||||
String socialFeedId = activity.feedId.substring(7);
|
||||
|
@ -161,7 +161,7 @@ public abstract class ProfileActivityDetailsFragment extends Fragment implements
|
|||
if (feed == null) {
|
||||
Toast.makeText(context, R.string.profile_do_not_follow, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
UIUtils.startReadingActivity(FeedSet.singleSocialFeed(feed.userId, feed.username), activity.storyHash, false, context);
|
||||
UIUtils.startReadingActivity(FeedSet.singleSocialFeed(feed.userId, feed.username), activity.storyHash, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -270,7 +270,7 @@ public class UIUtils {
|
|||
});
|
||||
}
|
||||
|
||||
public static void startReadingActivity(FeedSet fs, String startingHash, boolean waitRefresh, Context context) {
|
||||
public static void startReadingActivity(FeedSet fs, String startingHash, Context context) {
|
||||
Class activityClass;
|
||||
if (fs.isAllSaved()) {
|
||||
activityClass = SavedStoriesReading.class;
|
||||
|
@ -299,7 +299,6 @@ public class UIUtils {
|
|||
Intent i = new Intent(context, activityClass);
|
||||
i.putExtra(Reading.EXTRA_FEEDSET, fs);
|
||||
i.putExtra(Reading.EXTRA_STORY_HASH, startingHash);
|
||||
i.putExtra(Reading.EXTRA_WAIT_REFRESH, waitRefresh);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ public class WidgetProvider extends AppWidgetProvider {
|
|||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
// update each of the app widgets with the remote adapter
|
||||
Log.d(TAG, "onUpdate");
|
||||
WidgetUtils.checkWidgetUpdateAlarm(context);
|
||||
WidgetBackground widgetBackground = PrefsUtils.getWidgetBackground(context);
|
||||
for (int appWidgetId : appWidgetIds) {
|
||||
|
||||
|
|
|
@ -185,6 +185,7 @@ public class WidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsF
|
|||
} else {
|
||||
com.newsblur.util.Log.d(TAG, "Fetched widget stories");
|
||||
processStories(response.stories);
|
||||
FeedUtils.dbHelper.insertStories(response, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.appwidget.AppWidgetManager;
|
|||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.newsblur.R;
|
||||
|
@ -75,6 +74,13 @@ public class WidgetUtils {
|
|||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
public static void checkWidgetUpdateAlarm(Context context) {
|
||||
boolean hasActiveUpdates = PendingIntent.getBroadcast(context, RC_WIDGET_UPDATE, getUpdateIntent(context), PendingIntent.FLAG_NO_CREATE) != null;
|
||||
if (!hasActiveUpdates) {
|
||||
enableWidgetUpdate(context);
|
||||
}
|
||||
}
|
||||
|
||||
private static Intent getUpdateIntent(Context context) {
|
||||
Intent intent = new Intent(context, WidgetUpdateReceiver.class);
|
||||
intent.setAction(ACTION_UPDATE_WIDGET);
|
||||
|
|
Loading…
Add table
Reference in a new issue