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

@ -130,7 +130,9 @@
Note: If just want to use the desktop mode use the \'force desktop mode\' setting</string> Note: If just want to use the desktop mode use the \'force desktop mode\' setting</string>
<string name="pref_android_menu">Configure IITCm menu</string> <string name="pref_android_menu">Configure IITCm menu</string>
<string name="pref_android_menu_sum">Toggle visibility of IITCm menu entries</string> <string name="pref_android_menu_sum">Toggle visibility of IITCm menu entries</string>
<string name="pref_update_plugins_cat">Manage plugin updates</string> <string name="pref_update_plugins_cat">User plugin updates</string>
<string name="pref_update_plugins_interval">Configure plugin update interval</string>
<string name="pref_update_plugins_interval_sum">How often IITCm should search for new plugin versions</string>
<string name="pref_force_plugin_update">Force plugin update</string> <string name="pref_force_plugin_update">Force plugin update</string>
<string name="pref_force_plugin_update_sum">Update all enabled user plugins</string> <string name="pref_force_plugin_update_sum">Update all enabled user plugins</string>
@ -181,6 +183,22 @@
<item>2</item> <item>2</item>
</string-array> </string-array>
<string-array name="pref_update_plugins_interval_titles">
<item>Disable</item>
<item>1 day</item>
<item>2 days</item>
<item>1 week</item>
<item>2 weeks</item>
</string-array>
<string-array name="pref_update_plugins_interval_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>7</item>
<item>14</item>
</string-array>
<string name="menu_reload">Reload IITC</string> <string name="menu_reload">Reload IITC</string>
<string name="menu_toggle_fullscreen">Toggle fullscreen</string> <string name="menu_toggle_fullscreen">Toggle fullscreen</string>
<string name="menu_layer_chooser">Layer Chooser</string> <string name="menu_layer_chooser">Layer Chooser</string>

View File

@ -95,6 +95,13 @@
<PreferenceCategory <PreferenceCategory
android:key="pref_update_plugins" android:key="pref_update_plugins"
android:title="@string/pref_update_plugins_cat"> android:title="@string/pref_update_plugins_cat">
<ListPreference
android:defaultValue="7"
android:entries="@array/pref_update_plugins_interval_titles"
android:entryValues="@array/pref_update_plugins_interval_values"
android:key="pref_update_plugins_interval"
android:title="@string/pref_update_plugins_interval"
android:summary="@string/pref_update_plugins_interval_sum"/>
<com.cradle.iitc_mobile.IITC_ForceUpdatePreference <com.cradle.iitc_mobile.IITC_ForceUpdatePreference
android:key="pref_force_plugin_update" android:key="pref_force_plugin_update"
android:title="@string/pref_force_plugin_update" android:title="@string/pref_force_plugin_update"

View File

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

View File

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