Skip to content

Commit

Permalink
Toggle clearing WebView cookies + added manual menu button (closes #134)
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Dec 16, 2020
1 parent bdb9e84 commit c2f57eb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/java/com/gianlu/aria2app/PK.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public final class PK extends CommonPK {
public static final Prefs.KeyWithDefault<Boolean> A2_ADD_BEST_TRACKERS = new Prefs.KeyWithDefault<>("a2_addBestTrackers", false);
public static final Prefs.KeyWithDefault<Boolean> A2_SKIP_WEBVIEW_DIALOG = new Prefs.KeyWithDefault<>("a2_skipWebViewDialog", false);
public static final Prefs.Key WEBVIEW_HOMEPAGE = new Prefs.Key("webView_homepage");
public static final Prefs.KeyWithDefault<Boolean> WEBVIEW_CLEAR_COOKIES = new Prefs.KeyWithDefault<>("webView_clearCookies", true);
public static final Prefs.Key TRACKERS_LIST_CACHE = new Prefs.Key("trackersListCache");
public static final Prefs.Key TRACKERS_LIST_CACHE_AGE = new Prefs.Key("trackersListCacheAge");
@Deprecated
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/gianlu/aria2app/PreferenceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ protected void buildPreferences(@NonNull Context context) {
// skipWebViewDialog.setIcon(R.drawable.baseline_track_changes_24);
addPreference(skipWebViewDialog);

MaterialCheckboxPreference clearWebViewCookies = new MaterialCheckboxPreference.Builder(context)
.key(PK.WEBVIEW_CLEAR_COOKIES.key())
.defaultValue(PK.WEBVIEW_CLEAR_COOKIES.fallback())
.build();
clearWebViewCookies.setTitle(R.string.prefs_clearWebViewCookies);
clearWebViewCookies.setSummary(R.string.prefs_clearWebViewCookies_summary);
// clearWebViewCookies.setIcon(R.drawable.baseline_track_changes_24);
addPreference(clearWebViewCookies);

if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
MaterialStandardPreference webviewShortcut = new MaterialStandardPreference(context);
webviewShortcut.setTitle(R.string.addWebViewShortcutToHomePage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ protected void onCreate(Bundle savedInstanceState) {

setSupportActionBar(findViewById(R.id.webView_toolbar));

CookieManager.getInstance().removeAllCookies(null);
if (Prefs.getBoolean(PK.WEBVIEW_CLEAR_COOKIES))
CookieManager.getInstance().removeAllCookies(null);

web = findViewById(R.id.webView_webView);
progress = findViewById(R.id.webView_progress);
Expand Down Expand Up @@ -247,6 +248,9 @@ public boolean onOptionsItemSelected(@NotNull MenuItem item) {
case R.id.webView_goTo:
showGoToDialog(false);
return true;
case R.id.webView_clearCookies:
CookieManager.getInstance().removeAllCookies(null);
return true;
case R.id.webView_download:
int pos;
InterceptedRequest req;
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/menu/web_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
android:id="@+id/webView_toggleDesktop"
android:checkable="true"
android:title="@string/desktopMode" />

<item
android:id="@+id/webView_clearCookies"
android:title="@string/clearCookies" />
</menu>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,7 @@
<string name="pathLabel">Path</string>
<string name="sambaPathHelp">This is the relative path from the share to the downloads folder of aria2.</string>
<string name="previous">Previous</string>
<string name="prefs_clearWebViewCookies">Clear WebView cookies</string>
<string name="prefs_clearWebViewCookies_summary">Clear the cookies when the WebView is opened.</string>
<string name="clearCookies">Clear cookies</string>
</resources>

0 comments on commit c2f57eb

Please sign in to comment.