Commit 0d25b7fd authored by Alexander Ivanov's avatar Alexander Ivanov

Add option to use Orbot in account add activity.

parent 60825441
...@@ -76,6 +76,13 @@ ...@@ -76,6 +76,13 @@
android:checked="true" android:checked="true"
android:text="@string/account_syncable" /> android:text="@string/account_syncable" />
<CheckBox
android:id="@+id/use_orbot"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/account_use_orbot" />
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
......
...@@ -114,6 +114,7 @@ ...@@ -114,6 +114,7 @@
<string name="account_proxy_port">Proxy port</string> <string name="account_proxy_port">Proxy port</string>
<string name="account_proxy_user">Proxy user</string> <string name="account_proxy_user">Proxy user</string>
<string name="account_proxy_password">Proxy password</string> <string name="account_proxy_password">Proxy password</string>
<string name="account_use_orbot">Chat through TOR anonymity network and force TLS cryptographic protocol\nNot recommended for Google Talk</string>
<string name="orbot_required_title">Install Orbot?</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> <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 --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_02.png -->
......
...@@ -368,13 +368,14 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -368,13 +368,14 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
* xmpp account type can be replaced depend on server part. * xmpp account type can be replaced depend on server part.
* @param syncable * @param syncable
* @param storePassword * @param storePassword
* @param useOrbot
* @return assigned account name. * @return assigned account name.
* @throws NetworkException * @throws NetworkException
* if user or server part are invalid. * if user or server part are invalid.
*/ */
public String addAccount(String user, String password, public String addAccount(String user, String password,
AccountType accountType, boolean syncable, boolean storePassword) AccountType accountType, boolean syncable, boolean storePassword,
throws NetworkException { boolean useOrbot) throws NetworkException {
if (accountType.getProtocol().isOAuth()) { if (accountType.getProtocol().isOAuth()) {
int index = 1; int index = 1;
while (true) { while (true) {
...@@ -410,6 +411,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -410,6 +411,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
String host = accountType.getHost(); String host = accountType.getHost();
int port = accountType.getPort(); int port = accountType.getPort();
boolean tlsRequired = accountType.isTLSRequired(); boolean tlsRequired = accountType.isTLSRequired();
if (useOrbot)
tlsRequired = true;
if ("".equals(serverName)) { if ("".equals(serverName)) {
throw new NetworkException(R.string.EMPTY_SERVER_NAME); throw new NetworkException(R.string.EMPTY_SERVER_NAME);
...@@ -446,8 +449,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -446,8 +449,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
getNextColorIndex(), 0, StatusMode.available, getNextColorIndex(), 0, StatusMode.available,
SettingsManager.statusText(), true, true, SettingsManager.statusText(), true, true,
tlsRequired ? TLSMode.required : TLSMode.enabled, false, tlsRequired ? TLSMode.required : TLSMode.enabled, false,
ProxyType.none, "localhost", 8080, "", "", syncable, null, useOrbot ? ProxyType.orbot : ProxyType.none, "localhost", 8080,
null, ArchiveMode.available); "", "", syncable, null, null, ArchiveMode.available);
onAccountChanged(accountItem.getAccount()); onAccountChanged(accountItem.getAccount());
if (accountItems.size() > 1 if (accountItems.size() > 1
&& SettingsManager.contactsEnableShowAccounts()) && SettingsManager.contactsEnableShowAccounts())
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
package com.xabber.android.ui; package com.xabber.android.ui;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
...@@ -33,7 +34,9 @@ import com.xabber.android.data.account.AccountManager; ...@@ -33,7 +34,9 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.AccountType; import com.xabber.android.data.account.AccountType;
import com.xabber.android.data.intent.AccountIntentBuilder; import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.adapter.AccountTypeAdapter; import com.xabber.android.ui.adapter.AccountTypeAdapter;
import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.OrbotHelper;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class AccountAdd extends ManagedActivity implements public class AccountAdd extends ManagedActivity implements
...@@ -43,7 +46,10 @@ public class AccountAdd extends ManagedActivity implements ...@@ -43,7 +46,10 @@ public class AccountAdd extends ManagedActivity implements
private static final int OAUTH_WML_REQUEST_CODE = 1; private static final int OAUTH_WML_REQUEST_CODE = 1;
private static final int ORBOT_DIALOG_ID = 9050;
private CheckBox storePasswordView; private CheckBox storePasswordView;
private CheckBox useOrbotView;
private CheckBox syncableView; private CheckBox syncableView;
private Spinner accountTypeView; private Spinner accountTypeView;
...@@ -56,6 +62,7 @@ public class AccountAdd extends ManagedActivity implements ...@@ -56,6 +62,7 @@ public class AccountAdd extends ManagedActivity implements
setContentView(R.layout.account_add); setContentView(R.layout.account_add);
storePasswordView = (CheckBox) findViewById(R.id.store_password); storePasswordView = (CheckBox) findViewById(R.id.store_password);
useOrbotView = (CheckBox) findViewById(R.id.use_orbot);
syncableView = (CheckBox) findViewById(R.id.syncable); syncableView = (CheckBox) findViewById(R.id.syncable);
if (!Application.getInstance().isContactsSupported()) { if (!Application.getInstance().isContactsSupported()) {
syncableView.setVisibility(View.GONE); syncableView.setVisibility(View.GONE);
...@@ -111,7 +118,8 @@ public class AccountAdd extends ManagedActivity implements ...@@ -111,7 +118,8 @@ public class AccountAdd extends ManagedActivity implements
(AccountType) accountTypeView (AccountType) accountTypeView
.getSelectedItem(), .getSelectedItem(),
syncableView.isChecked(), syncableView.isChecked(),
storePasswordView.isChecked()); storePasswordView.isChecked(),
useOrbotView.isChecked());
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
return; return;
...@@ -128,6 +136,10 @@ public class AccountAdd extends ManagedActivity implements ...@@ -128,6 +136,10 @@ public class AccountAdd extends ManagedActivity implements
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.ok: case R.id.ok:
if (useOrbotView.isChecked() && !OrbotHelper.isOrbotInstalled()) {
showDialog(ORBOT_DIALOG_ID);
return;
}
AccountType accountType = (AccountType) accountTypeView AccountType accountType = (AccountType) accountTypeView
.getSelectedItem(); .getSelectedItem();
if (accountType.getProtocol().isOAuth()) { if (accountType.getProtocol().isOAuth()) {
...@@ -144,7 +156,8 @@ public class AccountAdd extends ManagedActivity implements ...@@ -144,7 +156,8 @@ public class AccountAdd extends ManagedActivity implements
userView.getText().toString(), userView.getText().toString(),
passwordView.getText().toString(), accountType, passwordView.getText().toString(), accountType,
syncableView.isChecked(), syncableView.isChecked(),
storePasswordView.isChecked()); storePasswordView.isChecked(),
useOrbotView.isChecked());
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
return; return;
...@@ -178,6 +191,15 @@ public class AccountAdd extends ManagedActivity implements ...@@ -178,6 +191,15 @@ public class AccountAdd extends ManagedActivity implements
accountTypeView.setSelection(0); accountTypeView.setSelection(0);
} }
@Override
protected Dialog onCreateDialog(int id) {
if (id == ORBOT_DIALOG_ID) {
return new OrbotInstallerDialogBuilder(this, ORBOT_DIALOG_ID)
.create();
}
return super.onCreateDialog(id);
}
public static Intent createIntent(Context context) { public static Intent createIntent(Context context) {
return new Intent(context, AccountAdd.class); return new Intent(context, AccountAdd.class);
} }
......
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