Skip to content

Commit

Permalink
Merge pull request #52 from 42SK/master
Browse files Browse the repository at this point in the history
Added "accept cookies" option
  • Loading branch information
martykan committed Apr 14, 2016
2 parents f7d9927 + 5fc9ff3 commit 4354a80
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/src/main/java/cz/martykan/webtube/MenuHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class MenuHelper implements ActionMenuView.OnMenuItemClickListener {
DrawerLayout drawerLayout;
View bookmarksPanel;

public static final String PREF_COOKIES_ENABLED = "cookiesEnabled";

public MenuHelper(Context context, WebView webView, TorHelper torHelper, BackgroundPlayHelper backgroundPlayHelper, View appWindow) {
this.context = context;
this.webView = webView;
Expand Down Expand Up @@ -76,6 +78,7 @@ public void setUpMenu(final ActionMenuView actionMenu, final DrawerLayout drawer
PackageManager pm = context.getPackageManager();

menu.findItem(R.id.action_backgroundPlay).setChecked(sp.getBoolean(BackgroundPlayHelper.PREF_BACKGROUND_PLAY_ENABLED, true));
menu.findItem(R.id.action_accept_cookies).setChecked(sp.getBoolean(PREF_COOKIES_ENABLED,true));

// Tor button
if (OrbotHelper.isOrbotInstalled(context.getApplicationContext())) {
Expand Down Expand Up @@ -176,10 +179,12 @@ public boolean onMenuItemClick(final MenuItem item) {
return true;

case R.id.action_tor:
final MenuItem cookieItem = actionMenu.getMenu().findItem(R.id.action_accept_cookies);
try {
if (sp.getBoolean(TorHelper.PREF_TOR_ENABLED, false)) {
torHelper.torDisable();
item.setChecked(false);
cookieItem.setChecked(sp.getBoolean(PREF_COOKIES_ENABLED, true)).setEnabled(true);
} else {
AlertDialog alert = new AlertDialog.Builder(context).create();
alert.setTitle(context.getString(R.string.enableTor) + "?");
Expand All @@ -190,6 +195,7 @@ public boolean onMenuItemClick(final MenuItem item) {
public void onClick(DialogInterface dialog, int buttonId) {
torHelper.torEnable();
item.setChecked(true);
cookieItem.setChecked(false).setEnabled(false);
}
});
alert.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(android.R.string.cancel),
Expand All @@ -213,6 +219,20 @@ public void onClick(DialogInterface dialog, int buttonId) {
new Downloader(context).download(webView.getUrl());
}
return true;

case R.id.action_accept_cookies:
if (sp.getBoolean(PREF_COOKIES_ENABLED, true)) {
CookieHelper.acceptCookies(webView,false);
CookieHelper.deleteCookies();
item.setChecked(false);
} else {
CookieHelper.acceptCookies(webView,true);
item.setChecked(true);
}
SharedPreferences.Editor spEdit = sp.edit();
spEdit.putBoolean(PREF_COOKIES_ENABLED,!sp.getBoolean(PREF_COOKIES_ENABLED,true));
spEdit.commit();
return true;
}

return false;
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
android:title="@string/download"
app:showAsAction="never" />

<item
android:id="@+id/action_accept_cookies"
android:title="@string/acceptCookies"
android:checkable="true"
android:checked="true"
app:showAsAction="never" />

<item
android:id="@+id/action_cast_to_kodi"
android:enabled="false"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
<string name="share_with">Teilen mit…</string>
<string name="menu">Menü</string>
<string name="set_as_home">Als Startseite festlegen</string>
<string name="acceptCookies">Cookies akzeptieren</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<string name="bookmarks">Bookmarks</string>
<string name="openInBrowser">Open in browser</string>
<string name="castToKodi">Cast to Kodi</string>
<string name="acceptCookies">Accept cookies</string>
<string name="share">Share</string>
<string name="enableTor">Enable Tor</string>
<string name="disableTor">Disable Tor</string>
Expand Down

0 comments on commit 4354a80

Please sign in to comment.