Search in sources :

Example 1 with ProxyChoice

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);
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) AlertDialogExtensionsKt(acr.browser.lightning.extensions.AlertDialogExtensionsKt) Arrays(java.util.Arrays) AlertDialog(androidx.appcompat.app.AlertDialog) I2PAndroidHelper(net.i2p.android.ui.I2PAndroidHelper) NonNull(androidx.annotation.NonNull) Pair(kotlin.Pair) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) OrbotHelper(info.guardianproject.netcipher.proxy.OrbotHelper) Singleton(javax.inject.Singleton) BrowserApp(acr.browser.lightning.BrowserApp) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) List(java.util.List) UserPreferences(acr.browser.lightning.preference.UserPreferences) Unit(kotlin.Unit) DeveloperPreferences(acr.browser.lightning.preference.DeveloperPreferences) ActivityExtensions(acr.browser.lightning.extensions.ActivityExtensions) R(acr.browser.lightning.R) ProxyChoice(acr.browser.lightning.browser.ProxyChoice) Activity(android.app.Activity) Log(android.util.Log) DialogInterface(android.content.DialogInterface) WebkitProxy(info.guardianproject.netcipher.webkit.WebkitProxy) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) ProxyChoice(acr.browser.lightning.browser.ProxyChoice) AlertDialog(androidx.appcompat.app.AlertDialog) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) Pair(kotlin.Pair)

Aggregations

BrowserApp (acr.browser.lightning.BrowserApp)1 R (acr.browser.lightning.R)1 ProxyChoice (acr.browser.lightning.browser.ProxyChoice)1 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)1 ActivityExtensions (acr.browser.lightning.extensions.ActivityExtensions)1 AlertDialogExtensionsKt (acr.browser.lightning.extensions.AlertDialogExtensionsKt)1 DeveloperPreferences (acr.browser.lightning.preference.DeveloperPreferences)1 UserPreferences (acr.browser.lightning.preference.UserPreferences)1 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 Log (android.util.Log)1 NonNull (androidx.annotation.NonNull)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 OrbotHelper (info.guardianproject.netcipher.proxy.OrbotHelper)1 WebkitProxy (info.guardianproject.netcipher.webkit.WebkitProxy)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Inject (javax.inject.Inject)1