made plugin update interval configurable

This commit is contained in:
Philipp Schaefer
2014-05-16 17:43:40 +02:00
parent 4bec474b21
commit 7c68567d17
4 changed files with 40 additions and 3 deletions

View File

@ -51,9 +51,10 @@ public class IITC_FileManager {
"script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));\n"
+ "(document.body || document.head || document.documentElement).appendChild(script);";
private long mUpdateInterval = 1000*60*60*24*7;
public static final String DOMAIN = ".iitcm.localhost";
// update interval is 2 days by default
public static long updateInterval = 1000*60*60*24*2;
/**
* copies the contents of a stream into another stream and (optionally) closes the output stream afterwards
@ -319,12 +320,14 @@ public class IITC_FileManager {
}
public void updatePlugins(boolean force) {
// do nothing if updates are disabled
if (mUpdateInterval == 0 && !force) return;
// check last script update
final long lastUpdated = mPrefs.getLong("pref_last_plugin_update", 0);
final long now = System.currentTimeMillis();
// return if no update wanted
if (!force && (now - lastUpdated < updateInterval)) return;
if ((now - lastUpdated < mUpdateInterval) && !force) return;
// get the plugin preferences
final TreeMap<String, ?> all_prefs = new TreeMap<String, Object>(mPrefs.getAll());
@ -343,6 +346,10 @@ public class IITC_FileManager {
.commit();
}
public void setUpdateInterval(int interval) {
mUpdateInterval = 1000*60*60*24 * interval;
}
private class FileRequest extends WebResourceResponse implements ResponseHandler, Runnable {
private Intent mData;
private final String mFunctionName;

View File

@ -145,6 +145,7 @@ public class IITC_Mobile extends Activity
mIitcWebView.updateFullscreenStatus();
mFileManager = new IITC_FileManager(this);
mFileManager.setUpdateInterval(Integer.parseInt(mSharedPrefs.getString("pref_update_plugins_interval", "7")));
mUserLocation = new IITC_UserLocation(this);
mUserLocation.setLocationMode(Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0")));
@ -195,6 +196,10 @@ public class IITC_Mobile extends Activity
Long forceUpdate = sharedPreferences.getLong("pref_last_plugin_update", 0);
if (forceUpdate == 0) mFileManager.updatePlugins(true);
return;
} else if (key.equals("pref_update_plugins_interval")) {
final int interval = Integer.parseInt(mSharedPrefs.getString("pref_update_plugins_interval", "7"));
mFileManager.setUpdateInterval(interval);
return;
} else if (key.equals("pref_press_twice_to_exit")
|| key.equals("pref_share_selected_tab")
|| key.equals("pref_messages")