mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Merge branch 'master' into muserstory_remove
# By Samuel Clay (1) and ojiikun (1) * master: Correcting for feedburner stupidity. Auto-sync the feed/folder list if it has been more than 10 minutes since the last refresh.
This commit is contained in:
commit
9a5a4f9562
4 changed files with 37 additions and 1 deletions
|
@ -438,7 +438,8 @@ class Feed(models.Model):
|
|||
feed_address = feed_address_from_link
|
||||
|
||||
if feed_address:
|
||||
if feed_address.endswith('feedburner.com/atom.xml'):
|
||||
if (feed_address.endswith('feedburner.com/atom.xml') or
|
||||
feed_address.endswith('feedburner.com/feed/')):
|
||||
logging.debug(" ---> Feed points to 'Wierdo', ignoring.")
|
||||
return False, self
|
||||
try:
|
||||
|
|
|
@ -54,11 +54,20 @@ public class Main extends NbFragmentActivity implements StateChangedListener, Sy
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (PrefsUtils.isTimeToAutoSync(this)) {
|
||||
triggerRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers an initial two-phase sync, so the UI can display quickly using /reader/feeds and
|
||||
* then call /reader/refresh_feeds to get updated counts.
|
||||
*/
|
||||
private void triggerFirstSync() {
|
||||
PrefsUtils.updateLastSyncTime(this);
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
if (menu != null) {
|
||||
menu.findItem(R.id.menu_refresh).setEnabled(false);
|
||||
|
@ -74,6 +83,7 @@ public class Main extends NbFragmentActivity implements StateChangedListener, Sy
|
|||
* Triggers a full, manually requested refresh of feed/folder data and counts.
|
||||
*/
|
||||
private void triggerRefresh() {
|
||||
PrefsUtils.updateLastSyncTime(this);
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
if (menu != null) {
|
||||
menu.findItem(R.id.menu_refresh).setEnabled(false);
|
||||
|
|
|
@ -22,4 +22,10 @@ public class AppConstants {
|
|||
|
||||
// the max number of mark-as-read ops to batch up before flushing to the server
|
||||
public static final int MAX_MARK_READ_BATCH = 5;
|
||||
|
||||
// a pref for the time we completed the last full sync of the feed/fodler list
|
||||
public static final String LAST_SYNC_TIME = "LAST_SYNC_TIME";
|
||||
|
||||
// how long to wait before auto-syncing the feed/folder list
|
||||
public static final long AUTO_SYNC_TIME_MILLIS = 10L * 60L * 1000L;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Date;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -159,5 +160,23 @@ public class PrefsUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if it has been sufficiently long since the last sync of the feed/folder
|
||||
* data to justify automatically syncing again.
|
||||
*/
|
||||
public static boolean isTimeToAutoSync(Context context) {
|
||||
SharedPreferences prefs = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
|
||||
long lastTime = prefs.getLong(AppConstants.LAST_SYNC_TIME, 1L);
|
||||
return ( (lastTime + AppConstants.AUTO_SYNC_TIME_MILLIS) < (new Date()).getTime() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make note that a sync of the feed/folder list has been completed, so we can track
|
||||
* how long it has been until another is needed.
|
||||
*/
|
||||
public static void updateLastSyncTime(Context context) {
|
||||
SharedPreferences prefs = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
|
||||
prefs.edit().putLong(AppConstants.LAST_SYNC_TIME, (new Date()).getTime()).commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue