mirror of
https://github.com/gsantner/dandelion
synced 2024-11-25 22:02:08 +01:00
Merge pull request #37 from di72nn/add_clear_cache_option
Fix settings and add an option to clear cache
This commit is contained in:
commit
7b1290be69
4 changed files with 60 additions and 25 deletions
|
@ -108,8 +108,10 @@ public class MainActivity extends AppCompatActivity
|
||||||
static final int INPUT_FILE_REQUEST_CODE = 1;
|
static final int INPUT_FILE_REQUEST_CODE = 1;
|
||||||
private static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
|
private static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
|
||||||
public static final int REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE = 124;
|
public static final int REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE = 124;
|
||||||
public static final int REQUEST_CODE_SETTINGS = 125;
|
|
||||||
public static final int RESULT_CODE_CHANGE_ACCOUNT = 130;
|
public static final String ACTION_OPEN_URL = "com.github.dfa.diaspora_android.MainActivity.open_url";
|
||||||
|
public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account";
|
||||||
|
public static final String ACTION_CLEAR_CACHE = "com.github.dfa.diaspora_android.MainActivity.clear_cache";
|
||||||
public static final String URL_MESSAGE = "URL_MESSAGE";
|
public static final String URL_MESSAGE = "URL_MESSAGE";
|
||||||
|
|
||||||
private App app;
|
private App app;
|
||||||
|
@ -243,6 +245,8 @@ public class MainActivity extends AppCompatActivity
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupWebView(Bundle savedInstanceState) {
|
private void setupWebView(Bundle savedInstanceState) {
|
||||||
|
@ -420,18 +424,28 @@ public class MainActivity extends AppCompatActivity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
|
||||||
|
handleIntent(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleIntent(Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
if(ACTION_OPEN_URL.equals(action)) {
|
||||||
|
String url = intent.getStringExtra(URL_MESSAGE);
|
||||||
|
webView.loadUrl(url);
|
||||||
|
} else if(ACTION_CHANGE_ACCOUNT.equals(action)) {
|
||||||
|
app.resetPodData(webView);
|
||||||
|
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
|
||||||
|
} else if(ACTION_CLEAR_CACHE.equals(action)) {
|
||||||
|
webView.clearCache(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if(requestCode == REQUEST_CODE_SETTINGS) {
|
|
||||||
if(resultCode == Activity.RESULT_OK) {
|
|
||||||
String url = data.getStringExtra(URL_MESSAGE);
|
|
||||||
webView.loadUrl(url);
|
|
||||||
} else if(resultCode == RESULT_CODE_CHANGE_ACCOUNT) {
|
|
||||||
app.resetPodData(webView);
|
|
||||||
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
|
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
return;
|
return;
|
||||||
|
@ -931,7 +945,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_settings_app: {
|
case R.id.nav_settings_app: {
|
||||||
startActivityForResult(new Intent(this, SettingsActivity.class), REQUEST_CODE_SETTINGS);
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.github.dfa.diaspora_android.activity;
|
package com.github.dfa.diaspora_android.activity;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -31,7 +30,6 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
sharedPreferences = getPreferenceScreen().getSharedPreferences();
|
sharedPreferences = getPreferenceScreen().getSharedPreferences();
|
||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
setPreferenceSummaries();
|
setPreferenceSummaries();
|
||||||
setResult(Activity.RESULT_CANCELED);
|
|
||||||
sharedPreferences.edit().putBoolean(AppSettings.PREF.PROXY_WAS_ENABLED,
|
sharedPreferences.edit().putBoolean(AppSettings.PREF.PROXY_WAS_ENABLED,
|
||||||
sharedPreferences.getBoolean(AppSettings.PREF.PROXY_ENABLED, false)).apply();
|
sharedPreferences.getBoolean(AppSettings.PREF.PROXY_ENABLED, false)).apply();
|
||||||
}
|
}
|
||||||
|
@ -65,21 +63,21 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
||||||
Intent results = new Intent();
|
Intent intent = new Intent(this, MainActivity.class);
|
||||||
String podDomain = ((App)getApplication()).getSettings().getPodDomain();
|
String podDomain = ((App)getApplication()).getSettings().getPodDomain();
|
||||||
switch(preference.getKey()) {
|
switch(preference.getKey()) {
|
||||||
case "pref_key_personal_settings":
|
case "pref_key_personal_settings":
|
||||||
results.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/user/edit");
|
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
||||||
setResult(Activity.RESULT_OK, results);
|
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/user/edit");
|
||||||
finish();
|
break;
|
||||||
case "pref_key_manage_tags":
|
case "pref_key_manage_tags":
|
||||||
results.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/tag_followings/manage");
|
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
||||||
setResult(Activity.RESULT_OK, results);
|
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/tag_followings/manage");
|
||||||
finish();
|
break;
|
||||||
case "pref_key_manage_contacts":
|
case "pref_key_manage_contacts":
|
||||||
results.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/contacts");
|
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
||||||
setResult(Activity.RESULT_OK, results);
|
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/contacts");
|
||||||
finish();
|
break;
|
||||||
case "pref_key_change_account":
|
case "pref_key_change_account":
|
||||||
new AlertDialog.Builder(SettingsActivity.this)
|
new AlertDialog.Builder(SettingsActivity.this)
|
||||||
.setTitle(getString(R.string.confirmation))
|
.setTitle(getString(R.string.confirmation))
|
||||||
|
@ -88,11 +86,25 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
.setPositiveButton(android.R.string.yes,
|
.setPositiveButton(android.R.string.yes,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
setResult(MainActivity.RESULT_CODE_CHANGE_ACCOUNT);
|
Intent intent = new Intent(SettingsActivity.this, MainActivity.class);
|
||||||
|
intent.setAction(MainActivity.ACTION_CHANGE_ACCOUNT);
|
||||||
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
|
return true;
|
||||||
|
case "pref_key_clear_cache":
|
||||||
|
intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
intent = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(intent != null) {
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return super.onPreferenceTreeClick(screen, preference);
|
return super.onPreferenceTreeClick(screen, preference);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,4 +46,7 @@
|
||||||
<string name="pref_desc_change_account">Erase local session data and switch to another Diaspora pod/account</string>
|
<string name="pref_desc_change_account">Erase local session data and switch to another Diaspora pod/account</string>
|
||||||
<string name="pref_warning_change_account">This will erase all cookies and session data. Do you really want to change your account?</string>
|
<string name="pref_warning_change_account">This will erase all cookies and session data. Do you really want to change your account?</string>
|
||||||
|
|
||||||
|
<string name="pref_title_clear_cache">Clear cache</string>
|
||||||
|
<string name="pref_desc_clear_cache">Clear WebView cache</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -52,6 +52,12 @@
|
||||||
android:summary="@string/pref_desc_load_images"
|
android:summary="@string/pref_desc_load_images"
|
||||||
android:defaultValue="true" />
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:title="@string/pref_title_clear_cache"
|
||||||
|
android:key="pref_key_clear_cache"
|
||||||
|
android:summary="@string/pref_desc_clear_cache">
|
||||||
|
</Preference>
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:title="@string/pref_title_proxy_enabled"
|
android:title="@string/pref_title_proxy_enabled"
|
||||||
android:key="pref_key_proxy_enabled"
|
android:key="pref_key_proxy_enabled"
|
||||||
|
|
Loading…
Reference in a new issue