diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d028886b1..ef84c57b3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -7,6 +7,7 @@
@@ -47,7 +44,7 @@ import info.guardianproject.netcipher.proxy.OrbotHelper;
* along with NewPipe. If not, see .
*/
-public class PlayVideoActivity extends AppCompatActivity implements OnSharedPreferenceChangeListener {
+public class PlayVideoActivity extends AppCompatActivity {
//// TODO: 11.09.15 add "choose stream" menu
@@ -173,9 +170,6 @@ public class PlayVideoActivity extends AppCompatActivity implements OnSharedPref
if(prefs.getBoolean(PREF_IS_LANDSCAPE, false) && !isLandscape) {
toggleOrientation();
}
-
- setTorPreference(prefs);
- prefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
@@ -197,7 +191,6 @@ public class PlayVideoActivity extends AppCompatActivity implements OnSharedPref
protected void onDestroy() {
super.onDestroy();
prefs = getPreferences(Context.MODE_PRIVATE);
- prefs.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
@@ -361,21 +354,4 @@ public class PlayVideoActivity extends AppCompatActivity implements OnSharedPref
editor.putBoolean(PREF_IS_LANDSCAPE, isLandscape);
editor.apply();
}
-
- private void setTorPreference(SharedPreferences prefs) {
- // if Orbot is installed, then default to using Tor, the user can still override
- if(prefs.getBoolean(getString(R.string.useTor), OrbotHelper.isOrbotInstalled(this))) {
- NetCipher.useTor();
- } else {
- NetCipher.setProxy(null);
- }
- }
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
- if(key.equals(getString(R.string.useTor))) {
- setTorPreference(prefs);
- }
- }
-
}
diff --git a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java
index c8a548ab6..c8c089a98 100644
--- a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java
@@ -2,6 +2,8 @@ package org.schabi.newpipe;
import android.content.res.Configuration;
import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.support.annotation.LayoutRes;
@@ -13,6 +15,8 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import info.guardianproject.netcipher.proxy.OrbotHelper;
+
/**
* Created by Christian Schabesberger on 31.08.15.
*
@@ -52,10 +56,25 @@ public class SettingsActivity extends PreferenceActivity {
}
public static class SettingsFragment extends PreferenceFragment {
+ private CheckBoxPreference useTorCheckBox;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings_screen);
+
+ // if Orbot is installed, then default to using Tor, the user can still override
+ useTorCheckBox = (CheckBoxPreference) findPreference(getString(R.string.useTor));
+ boolean useTor = OrbotHelper.isOrbotInstalled(getActivity());
+ useTorCheckBox.setDefaultValue(useTor);
+ useTorCheckBox.setChecked(useTor);
+ useTorCheckBox.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object useTor) {
+ App.configureTor((Boolean) useTor);
+ return true;
+ }
+ });
}
}
diff --git a/app/src/main/res/xml/settings_screen.xml b/app/src/main/res/xml/settings_screen.xml
index f7ab99a53..4d21b457b 100644
--- a/app/src/main/res/xml/settings_screen.xml
+++ b/app/src/main/res/xml/settings_screen.xml
@@ -75,8 +75,7 @@
+ android:summary="@string/useTorSummary" />