checking on "Use Tor" when Orbot is not installed starts install

If the user turns on "Use Tor" and they are missing Orbot, bring them to
the screen to install Tor.
This commit is contained in:
Hans-Christoph Steiner 2016-01-01 23:06:16 +01:00
parent 5663e543a4
commit 984dd1cc25
1 changed files with 27 additions and 3 deletions

View File

@ -1,5 +1,8 @@
package org.schabi.newpipe;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
@ -39,6 +42,7 @@ import info.guardianproject.netcipher.proxy.OrbotHelper;
public class SettingsActivity extends PreferenceActivity {
private static final int REQUEST_INSTALL_ORBOT = 0x1234;
private AppCompatDelegate mDelegate = null;
@Override
@ -65,19 +69,39 @@ public class SettingsActivity extends PreferenceActivity {
// 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());
final Activity activity = getActivity();
final boolean useTor = OrbotHelper.isOrbotInstalled(activity);
useTorCheckBox.setDefaultValue(useTor);
useTorCheckBox.setChecked(useTor);
useTorCheckBox.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object useTor) {
App.configureTor((Boolean) useTor);
public boolean onPreferenceChange(Preference preference, Object o) {
boolean useTor = (Boolean) o;
if (useTor) {
if (OrbotHelper.isOrbotInstalled(activity)) {
App.configureTor(true);
} else {
Intent intent = OrbotHelper.getOrbotInstallIntent(activity);
activity.startActivityForResult(intent, REQUEST_INSTALL_ORBOT);
}
} else {
App.configureTor(false);
}
return true;
}
});
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// try to start tor regardless of resultCode since clicking back after
// installing the app does not necessarily return RESULT_OK
App.configureTor(requestCode == REQUEST_INSTALL_ORBOT
&& OrbotHelper.requestStartTor(this));
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);