use of acr.browser.lightning.browser.ProxyChoice in project Lightning-Browser by anthonycr.
the class ProxyUtils method checkForProxy.
/*
* If Orbot/Tor or I2P is installed, prompt the user if they want to enable
* proxying for this session
*/
public void checkForProxy(@NonNull final Activity activity) {
final ProxyChoice currentProxyChoice = userPreferences.getProxyChoice();
final boolean orbotInstalled = OrbotHelper.isOrbotInstalled(activity);
boolean orbotChecked = developerPreferences.getCheckedForTor();
boolean orbot = orbotInstalled && !orbotChecked;
boolean i2pInstalled = i2PAndroidHelper.isI2PAndroidInstalled();
boolean i2pChecked = developerPreferences.getCheckedForI2P();
boolean i2p = i2pInstalled && !i2pChecked;
// Do only once per install
if (currentProxyChoice != ProxyChoice.NONE && (orbot || i2p)) {
if (orbot) {
developerPreferences.setCheckedForTor(true);
}
if (i2p) {
developerPreferences.setCheckedForI2P(true);
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
if (orbotInstalled && i2pInstalled) {
String[] proxyChoices = activity.getResources().getStringArray(R.array.proxy_choices_array);
final List<ProxyChoice> values = Arrays.asList(ProxyChoice.NONE, ProxyChoice.ORBOT, ProxyChoice.I2P);
final List<Pair<ProxyChoice, String>> list = new ArrayList<>();
for (ProxyChoice proxyChoice : values) {
list.add(new Pair<>(proxyChoice, proxyChoices[proxyChoice.getValue()]));
}
builder.setTitle(activity.getResources().getString(R.string.http_proxy));
AlertDialogExtensionsKt.withSingleChoiceItems(builder, list, userPreferences.getProxyChoice(), newProxyChoice -> {
userPreferences.setProxyChoice(newProxyChoice);
return Unit.INSTANCE;
});
builder.setPositiveButton(activity.getResources().getString(R.string.action_ok), (dialog, which) -> {
if (userPreferences.getProxyChoice() != ProxyChoice.NONE) {
initializeProxy(activity);
}
});
} else {
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
switch(which) {
case DialogInterface.BUTTON_POSITIVE:
userPreferences.setProxyChoice(orbotInstalled ? ProxyChoice.ORBOT : ProxyChoice.I2P);
initializeProxy(activity);
break;
case DialogInterface.BUTTON_NEGATIVE:
userPreferences.setProxyChoice(ProxyChoice.NONE);
break;
}
};
builder.setMessage(orbotInstalled ? R.string.use_tor_prompt : R.string.use_i2p_prompt).setPositiveButton(R.string.yes, dialogClickListener).setNegativeButton(R.string.no, dialogClickListener);
}
Dialog dialog = builder.show();
BrowserDialog.setDialogSize(activity, dialog);
}
}
Aggregations