added caching mode preference (fixes #495)
This commit is contained in:
parent
1535cd5c57
commit
6589cd454f
@ -99,6 +99,20 @@
|
||||
<string name="pref_select_iitc">IITC source</string>
|
||||
<string name="pref_select_iitc_sum">Load IITC main script from url or use local script. Currently used source:</string>
|
||||
|
||||
<string name="pref_caching">Aggressive Caching</string>
|
||||
<string name="pref_caching_sum">Prefer cached values even if they are expired…saves traffic but
|
||||
may result in login issues</string>
|
||||
<string-array name="pref_caching_array">
|
||||
<item>Always</item>
|
||||
<item>Mobile data only (default)</item>
|
||||
<item>Never</item>
|
||||
</string-array>
|
||||
<string-array name="pref_caching_array_vals">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
<string name="menu_clear_cookies">Clear Cookies</string>
|
||||
<string name="menu_search">Search</string>
|
||||
<string name="choose_account_to_login">Choose account to login</string>
|
||||
|
@ -72,6 +72,14 @@
|
||||
android:title="@string/pref_advanced_options"
|
||||
android:persistent="false">
|
||||
|
||||
<ListPreference
|
||||
android:key="pref_caching"
|
||||
android:title="@string/pref_caching"
|
||||
android:summary="@string/pref_caching_sum"
|
||||
android:defaultValue="1"
|
||||
android:entries="@array/pref_caching_array"
|
||||
android:entryValues="@array/pref_caching_array_vals" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_advanced_menu"
|
||||
android:title="@string/pref_advanced_menu"
|
||||
|
@ -126,6 +126,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
return;
|
||||
} else if (key.equals("pref_fake_user_agent")) {
|
||||
mIitcWebView.setUserAgent();
|
||||
} else if (key.equals("pref_caching")) {
|
||||
mIitcWebView.updateCaching();
|
||||
} else if (key.equals("pref_press_twice_to_exit")
|
||||
|| key.equals("pref_share_selected_tab")
|
||||
|| key.equals("pref_messages"))
|
||||
|
@ -26,6 +26,7 @@ public class IITC_WebView extends WebView {
|
||||
private IITC_WebViewClient mIitcWebViewClient;
|
||||
private IITC_JSInterface mJsInterface;
|
||||
private Context mContext;
|
||||
private SharedPreferences mSharedPrefs;
|
||||
private boolean mDisableJs = false;
|
||||
private String mDefaultUserAgent;
|
||||
private final String mDesktopUserAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:17.0)" +
|
||||
@ -49,6 +50,7 @@ public class IITC_WebView extends WebView {
|
||||
.getAbsolutePath());
|
||||
mJsInterface = new IITC_JSInterface((IITC_Mobile) mContext);
|
||||
addJavascriptInterface(mJsInterface, "android");
|
||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
mDefaultUserAgent = mSettings.getUserAgentString();
|
||||
setUserAgent();
|
||||
|
||||
@ -158,18 +160,28 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
public void updateCaching() {
|
||||
boolean login = false;
|
||||
if (getUrl() != null) {
|
||||
login = getUrl().contains("accounts.google.com");
|
||||
}
|
||||
// use cache if on mobile network...saves traffic
|
||||
if (!isConnectedToWifi() && !login) {
|
||||
Log.d("iitcm", "not connected to wifi...load tiles from cache");
|
||||
mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||
} else {
|
||||
if (login) Log.d("iitcm", "login...load tiles from network");
|
||||
else Log.d("iitcm", "connected to wifi...load tiles from network");
|
||||
mSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
||||
switch(Integer.parseInt(mSharedPrefs.getString("pref_caching", "1"))) {
|
||||
case 0:
|
||||
mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||
break;
|
||||
case 2:
|
||||
mSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
||||
break;
|
||||
default:
|
||||
boolean login = false;
|
||||
if (getUrl() != null) {
|
||||
login = getUrl().contains("accounts.google.com");
|
||||
}
|
||||
// use cache if on mobile network...saves traffic
|
||||
if (!isConnectedToWifi() && !login) {
|
||||
Log.d("iitcm", "not connected to wifi...load tiles from cache");
|
||||
mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||
} else {
|
||||
if (login) Log.d("iitcm", "login...load tiles from network");
|
||||
else Log.d("iitcm", "connected to wifi...load tiles from network");
|
||||
mSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,8 +207,7 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
public void setUserAgent() {
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
String ua = sharedPrefs.getBoolean("pref_fake_user_agent", false) ? mDesktopUserAgent : mDefaultUserAgent;
|
||||
String ua = mSharedPrefs.getBoolean("pref_fake_user_agent", false) ? mDesktopUserAgent : mDefaultUserAgent;
|
||||
Log.d("iitcm", "setting user agent to: " + ua);
|
||||
mSettings.setUserAgentString(ua);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user