mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
seperate notification preference
This commit is contained in:
parent
bac5a09741
commit
32215cf797
7 changed files with 70 additions and 10 deletions
|
@ -262,6 +262,8 @@
|
|||
<string name="settings_immersive_enter_single_tap">Immersive Mode Via Single Tap</string>
|
||||
<string name="settings_show_content_preview">Show Content Preview Text</string>
|
||||
<string name="settings_show_thumbnails">Show Image Preview Thumbnails</string>
|
||||
<string name="settings_notifications">Notifications</string>
|
||||
<string name="settings_enable_notifications">Enable Notifications</string>
|
||||
|
||||
<string name="story">Story</string>
|
||||
<string name="text">Text</string>
|
||||
|
|
|
@ -125,4 +125,13 @@
|
|||
android:defaultValue="@string/rtl_gesture_action_value" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/settings_notifications">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="enable_notifications"
|
||||
android:title="@string/settings_enable_notifications" >
|
||||
</CheckBoxPreference>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
@ -987,6 +987,22 @@ public class BlurDatabaseHelper {
|
|||
return rawQuery(DatabaseConstants.NOTIFY_UNREAD_STORY_QUERY, null, null);
|
||||
}
|
||||
|
||||
public Set<String> getNotifyFeeds() {
|
||||
String q = "SELECT " + DatabaseConstants.FEED_ID + " FROM " + DatabaseConstants.FEED_TABLE +
|
||||
" WHERE " + DatabaseConstants.FEED_NOTIFICATION_FILTER + " = '" + Feed.NOTIFY_FILTER_FOCUS + "'" +
|
||||
" OR " + DatabaseConstants.FEED_NOTIFICATION_FILTER + " = '" + Feed.NOTIFY_FILTER_UNREAD + "'";
|
||||
Cursor c = dbRO.rawQuery(q, null);
|
||||
Set<String> feedIds = new HashSet<String>(c.getCount());
|
||||
while (c.moveToNext()) {
|
||||
String id = c.getString(c.getColumnIndexOrThrow(DatabaseConstants.FEED_ID));
|
||||
if (id != null) {
|
||||
feedIds.add(id);
|
||||
}
|
||||
}
|
||||
c.close();
|
||||
return feedIds;
|
||||
}
|
||||
|
||||
public Loader<Cursor> getActiveStoriesLoader(final FeedSet fs) {
|
||||
final StoryOrder order = PrefsUtils.getStoryOrder(context, fs);
|
||||
return new QueryCursorLoader(context) {
|
||||
|
|
|
@ -180,7 +180,7 @@ public class NBSyncService extends Service {
|
|||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, final int startId) {
|
||||
// only perform a sync if the app is actually running or background syncs are enabled
|
||||
if (PrefsUtils.isOfflineEnabled(this) || (NbActivity.getActiveActivityCount() > 0)) {
|
||||
if ((NbActivity.getActiveActivityCount() > 0) || PrefsUtils.isBackgroundNeeded(this)) {
|
||||
// Services actually get invoked on the main system thread, and are not
|
||||
// allowed to do tangible work. We spawn a thread to do so.
|
||||
Runnable r = new Runnable() {
|
||||
|
@ -231,7 +231,9 @@ public class NBSyncService extends Service {
|
|||
housekeeping();
|
||||
|
||||
// check to see if we are on an allowable network only after ensuring we have CPU
|
||||
if (!(PrefsUtils.isBackgroundNetworkAllowed(this) || (NbActivity.getActiveActivityCount() > 0))) {
|
||||
if (!( (NbActivity.getActiveActivityCount() > 0) ||
|
||||
PrefsUtils.isEnableNotifications(this) ||
|
||||
PrefsUtils.isBackgroundNetworkAllowed(this) )) {
|
||||
Log.d(this.getClass().getName(), "Abandoning sync: app not active and network type not appropriate for background sync.");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.newsblur.network.domain.StoriesResponse;
|
|||
import com.newsblur.network.domain.UnreadStoryHashesResponse;
|
||||
import com.newsblur.util.AppConstants;
|
||||
import com.newsblur.util.DefaultFeedView;
|
||||
import com.newsblur.util.FeedUtils;
|
||||
import com.newsblur.util.PrefsUtils;
|
||||
import com.newsblur.util.StoryOrder;
|
||||
|
||||
|
@ -93,6 +94,15 @@ public class UnreadsService extends SubService {
|
|||
com.newsblur.util.Log.i(this.getClass().getName(), "new unreads found: " + sortationList.size());
|
||||
com.newsblur.util.Log.i(this.getClass().getName(), "unreads to retire: " + oldUnreadHashes.size());
|
||||
|
||||
if (parent.stopSync()) return;
|
||||
|
||||
// any stories that we previously thought to be unread but were not found in the
|
||||
// list, mark them read now
|
||||
|
||||
parent.dbHelper.markStoryHashesRead(oldUnreadHashes);
|
||||
|
||||
if (parent.stopSync()) return;
|
||||
|
||||
// now sort the unreads we need to fetch so they are fetched roughly in the order
|
||||
// the user is likely to read them. if the user reads newest first, those come first.
|
||||
final boolean sortNewest = (PrefsUtils.getDefaultStoryOrder(parent) == StoryOrder.NEWEST);
|
||||
|
@ -120,24 +130,29 @@ public class UnreadsService extends SubService {
|
|||
StoryHashQueue.add(tuple[0]);
|
||||
}
|
||||
|
||||
if (parent.stopSync()) return;
|
||||
|
||||
// any stories that we previously thought to be unread but were not found in the
|
||||
// list, mark them read now
|
||||
parent.dbHelper.markStoryHashesRead(oldUnreadHashes);
|
||||
}
|
||||
|
||||
private void getNewUnreadStories() {
|
||||
int totalCount = StoryHashQueue.size();
|
||||
Set<String> notifyFeeds = parent.dbHelper.getNotifyFeeds();
|
||||
unreadsyncloop: while (StoryHashQueue.size() > 0) {
|
||||
if (parent.stopSync()) return;
|
||||
if(!PrefsUtils.isOfflineEnabled(parent)) return;
|
||||
|
||||
boolean isOfflineEnabled = PrefsUtils.isOfflineEnabled(parent);
|
||||
boolean isEnableNotifications = PrefsUtils.isEnableNotifications(parent);
|
||||
if (! (isOfflineEnabled || isEnableNotifications)) return;
|
||||
|
||||
gotWork();
|
||||
startExpensiveCycle();
|
||||
|
||||
List<String> hashBatch = new ArrayList(AppConstants.UNREAD_FETCH_BATCH_SIZE);
|
||||
List<String> hashSkips = new ArrayList(AppConstants.UNREAD_FETCH_BATCH_SIZE);
|
||||
batchloop: for (String hash : StoryHashQueue) {
|
||||
hashBatch.add(hash);
|
||||
if( isOfflineEnabled ||
|
||||
(isEnableNotifications && notifyFeeds.contains(FeedUtils.inferFeedId(hash))) ) {
|
||||
hashBatch.add(hash);
|
||||
} else {
|
||||
hashSkips.add(hash);
|
||||
}
|
||||
if (hashBatch.size() >= AppConstants.UNREAD_FETCH_BATCH_SIZE) break batchloop;
|
||||
}
|
||||
StoriesResponse response = parent.apiManager.getStoriesByHash(hashBatch);
|
||||
|
@ -150,6 +165,9 @@ public class UnreadsService extends SubService {
|
|||
for (String hash : hashBatch) {
|
||||
StoryHashQueue.remove(hash);
|
||||
}
|
||||
for (String hash : hashSkips) {
|
||||
StoryHashQueue.remove(hash);
|
||||
}
|
||||
|
||||
for (Story story : response.stories) {
|
||||
if (story.imageUrls != null) {
|
||||
|
|
|
@ -78,4 +78,6 @@ public class PrefConstants {
|
|||
|
||||
public static final String LTR_GESTURE_ACTION = "ltr_gesture_action";
|
||||
public static final String RTL_GESTURE_ACTION = "rtl_gesture_action";
|
||||
|
||||
public static final String ENABLE_NOTIFICATIONS = "enable_notifications";
|
||||
}
|
||||
|
|
|
@ -140,6 +140,8 @@ public class PrefsUtils {
|
|||
s.append("\n");
|
||||
s.append("prefetch: ").append(isOfflineEnabled(context) ? "yes" : "no");
|
||||
s.append("\n");
|
||||
s.append("notifications: ").append(isEnableNotifications(context) ? "yes" : "no");
|
||||
s.append("\n");
|
||||
s.append("keepread: ").append(isKeepOldStories(context) ? "yes" : "no");
|
||||
s.append("\n");
|
||||
s.append("thumbs: ").append(isShowThumbnails(context) ? "yes" : "no");
|
||||
|
@ -678,4 +680,13 @@ public class PrefsUtils {
|
|||
SharedPreferences prefs = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
|
||||
return GestureAction.valueOf(prefs.getString(PrefConstants.RTL_GESTURE_ACTION, GestureAction.GEST_ACTION_MARKUNREAD.toString()));
|
||||
}
|
||||
|
||||
public static boolean isEnableNotifications(Context context) {
|
||||
SharedPreferences prefs = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
|
||||
return prefs.getBoolean(PrefConstants.ENABLE_NOTIFICATIONS, false);
|
||||
}
|
||||
|
||||
public static boolean isBackgroundNeeded(Context context) {
|
||||
return (isEnableNotifications(context) || isOfflineEnabled(context));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue