Commit 60825441 authored by Alexander Ivanov's avatar Alexander Ivanov

Prompt to install Orbot if selected in account preferences.

parent 629e17bb
......@@ -114,6 +114,8 @@
<string name="account_proxy_port">Proxy port</string>
<string name="account_proxy_user">Proxy user</string>
<string name="account_proxy_password">Proxy password</string>
<string name="orbot_required_title">Install Orbot?</string>
<string name="orbot_required_message">In order to process using TOR you must have Orbot installed and activated to proxy traffic through it. Would you like to install it from Google Play?</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_02.png -->
<string name="account_sasl">Use SASL Authentication (recommended)</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_02.png -->
......
......@@ -33,7 +33,9 @@ import com.xabber.android.data.account.ArchiveMode;
import com.xabber.android.data.connection.ProxyType;
import com.xabber.android.data.connection.TLSMode;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder;
import com.xabber.android.ui.helper.BaseSettingsActivity;
import com.xabber.android.ui.helper.OrbotHelper;
import com.xabber.androiddev.R;
public class AccountEditor extends BaseSettingsActivity implements
......@@ -45,6 +47,8 @@ public class AccountEditor extends BaseSettingsActivity implements
private static final String INVALIDATED_TOKEN = "com.xabber.android.ui.AccountEditor.INVALIDATED";
private static final int ORBOT_DIALOG_ID = 9050;
private String account;
private AccountItem accountItem;
......@@ -242,6 +246,12 @@ public class AccountEditor extends BaseSettingsActivity implements
@Override
protected boolean setValues(Map<String, Object> source,
Map<String, Object> result) {
ProxyType proxyType = ProxyType.values()[getInt(result,
R.string.account_proxy_type_key)];
if (proxyType == ProxyType.orbot && !OrbotHelper.isOrbotInstalled()) {
showDialog(ORBOT_DIALOG_ID);
return false;
}
AccountManager
.getInstance()
.updateAccount(
......@@ -260,8 +270,7 @@ public class AccountEditor extends BaseSettingsActivity implements
TLSMode.values()[getInt(result,
R.string.account_tls_mode_key)],
getBoolean(result, R.string.account_compression_key),
ProxyType.values()[getInt(result,
R.string.account_proxy_type_key)],
proxyType,
getString(result, R.string.account_proxy_host_key),
getInt(result, R.string.account_proxy_port_key),
getString(result, R.string.account_proxy_user_key),
......@@ -272,6 +281,15 @@ public class AccountEditor extends BaseSettingsActivity implements
return true;
}
@Override
protected Dialog onCreateDialog(int id) {
if (id == ORBOT_DIALOG_ID) {
return new OrbotInstallerDialogBuilder(this, ORBOT_DIALOG_ID)
.create();
}
return super.onCreateDialog(id);
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
......
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.dialog;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import com.xabber.android.ui.helper.OrbotHelper;
import com.xabber.androiddev.R;
/**
* Orbot installer dialog builder.
*
* @author alexander.ivanov
*
*/
public class OrbotInstallerDialogBuilder extends DialogBuilder {
private final static String MARKET_SEARCH = "market://search?q=pname:%s";
public OrbotInstallerDialogBuilder(final Activity activity, int dialogId) {
super(activity, dialogId);
setIcon(android.R.drawable.ic_dialog_alert);
setTitle(R.string.orbot_required_title);
setMessage(R.string.orbot_required_message);
setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int w) {
Uri uri = Uri.parse(String.format(MARKET_SEARCH,
OrbotHelper.URI_ORBOT));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(intent);
}
});
setNegativeButton(android.R.string.no, null);
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.helper;
import android.content.pm.PackageManager;
import com.xabber.android.data.Application;
public class OrbotHelper {
public final static String URI_ORBOT = "org.torproject.android";
public static boolean isOrbotInstalled() {
PackageManager packageManager = Application.getInstance()
.getPackageManager();
try {
packageManager.getPackageInfo(URI_ORBOT,
PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment