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 @@
android:checked="true"
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
android:orientation="horizontal"
android:layout_width="fill_parent"
......
......@@ -114,6 +114,7 @@
<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="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_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 -->
......
......@@ -368,13 +368,14 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
* xmpp account type can be replaced depend on server part.
* @param syncable
* @param storePassword
* @param useOrbot
* @return assigned account name.
* @throws NetworkException
* if user or server part are invalid.
*/
public String addAccount(String user, String password,
AccountType accountType, boolean syncable, boolean storePassword)
throws NetworkException {
AccountType accountType, boolean syncable, boolean storePassword,
boolean useOrbot) throws NetworkException {
if (accountType.getProtocol().isOAuth()) {
int index = 1;
while (true) {
......@@ -410,6 +411,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
String host = accountType.getHost();
int port = accountType.getPort();
boolean tlsRequired = accountType.isTLSRequired();
if (useOrbot)
tlsRequired = true;
if ("".equals(serverName)) {
throw new NetworkException(R.string.EMPTY_SERVER_NAME);
......@@ -446,8 +449,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
getNextColorIndex(), 0, StatusMode.available,
SettingsManager.statusText(), true, true,
tlsRequired ? TLSMode.required : TLSMode.enabled, false,
ProxyType.none, "localhost", 8080, "", "", syncable, null,
null, ArchiveMode.available);
useOrbot ? ProxyType.orbot : ProxyType.none, "localhost", 8080,
"", "", syncable, null, null, ArchiveMode.available);
onAccountChanged(accountItem.getAccount());
if (accountItems.size() > 1
&& SettingsManager.contactsEnableShowAccounts())
......
......@@ -14,6 +14,7 @@
*/
package com.xabber.android.ui;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
......@@ -33,7 +34,9 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.AccountType;
import com.xabber.android.data.intent.AccountIntentBuilder;
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.OrbotHelper;
import com.xabber.androiddev.R;
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 ORBOT_DIALOG_ID = 9050;
private CheckBox storePasswordView;
private CheckBox useOrbotView;
private CheckBox syncableView;
private Spinner accountTypeView;
......@@ -56,6 +62,7 @@ public class AccountAdd extends ManagedActivity implements
setContentView(R.layout.account_add);
storePasswordView = (CheckBox) findViewById(R.id.store_password);
useOrbotView = (CheckBox) findViewById(R.id.use_orbot);
syncableView = (CheckBox) findViewById(R.id.syncable);
if (!Application.getInstance().isContactsSupported()) {
syncableView.setVisibility(View.GONE);
......@@ -111,7 +118,8 @@ public class AccountAdd extends ManagedActivity implements
(AccountType) accountTypeView
.getSelectedItem(),
syncableView.isChecked(),
storePasswordView.isChecked());
storePasswordView.isChecked(),
useOrbotView.isChecked());
} catch (NetworkException e) {
Application.getInstance().onError(e);
return;
......@@ -128,6 +136,10 @@ public class AccountAdd extends ManagedActivity implements
public void onClick(View view) {
switch (view.getId()) {
case R.id.ok:
if (useOrbotView.isChecked() && !OrbotHelper.isOrbotInstalled()) {
showDialog(ORBOT_DIALOG_ID);
return;
}
AccountType accountType = (AccountType) accountTypeView
.getSelectedItem();
if (accountType.getProtocol().isOAuth()) {
......@@ -144,7 +156,8 @@ public class AccountAdd extends ManagedActivity implements
userView.getText().toString(),
passwordView.getText().toString(), accountType,
syncableView.isChecked(),
storePasswordView.isChecked());
storePasswordView.isChecked(),
useOrbotView.isChecked());
} catch (NetworkException e) {
Application.getInstance().onError(e);
return;
......@@ -178,6 +191,15 @@ public class AccountAdd extends ManagedActivity implements
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) {
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