Commit 640f6a30 authored by Grigory Fedorov's avatar Grigory Fedorov

Merge branch 'inband-registration' of...

Merge branch 'inband-registration' of https://github.com/aelmahmoudy/xabber-android into aelmahmoudy-inband-registration
parents e6b453db 8a28b947
......@@ -27,6 +27,7 @@ Supported protocols
* XEP-0059: Result Set Management
* XEP-0136: Message Archiving
* XEP-0224: Attention
* XEP-0077: In-Band Registration
Translations
============
......
......@@ -344,13 +344,19 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
boolean compression, ProxyType proxyType, String proxyHost,
int proxyPort, String proxyUser, String proxyPassword,
boolean syncable, KeyPair keyPair, Date lastSync,
ArchiveMode archiveMode) {
ArchiveMode archiveMode,
boolean registerNewAccount) {
AccountItem accountItem = new AccountItem(protocol, custom, host, port,
serverName, userName, resource, storePassword, password, color,
priority, statusMode, statusText, enabled, saslEnabled,
tlsMode, compression, proxyType, proxyHost, proxyPort,
proxyUser, proxyPassword, syncable, keyPair, lastSync,
archiveMode);
if(registerNewAccount) {
// TODO: attempt to register account, if that fails return null;
accountItem.registerAccount();
//return(null);
}
requestToWriteAccount(accountItem);
addAccount(accountItem);
accountItem.updateConnection(true);
......@@ -371,7 +377,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
*/
public String addAccount(String user, String password,
AccountType accountType, boolean syncable, boolean storePassword,
boolean useOrbot) throws NetworkException {
boolean useOrbot,
boolean registerNewAccount) throws NetworkException {
if (accountType.getProtocol().isOAuth()) {
int index = 1;
while (true) {
......@@ -446,7 +453,11 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
SettingsManager.statusText(), true, true,
tlsRequired ? TLSMode.required : TLSMode.enabled, false,
useOrbot ? ProxyType.orbot : ProxyType.none, "localhost", 8080,
"", "", syncable, null, null, ArchiveMode.available);
"", "", syncable, null, null, ArchiveMode.available, registerNewAccount);
if(accountItem == null) {
throw new NetworkException(R.string.ACCOUNT_REGISTER_FAILED);
}
onAccountChanged(accountItem.getAccount());
if (accountItems.size() > 1
&& SettingsManager.contactsEnableShowAccounts())
......@@ -609,7 +620,7 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
priority, statusMode, statusText, enabled, saslEnabled,
tlsMode, compression, proxyType, proxyHost, proxyPort,
proxyUser, proxyPassword, syncable, keyPair, lastSync,
archiveMode);
archiveMode, false);
}
onAccountChanged(result.getAccount());
}
......
......@@ -53,6 +53,11 @@ public abstract class ConnectionItem {
*/
private boolean disconnectionRequested;
/**
* Need to register account on XMPP server.
*/
private boolean registerNewAccount;
public ConnectionItem(AccountProtocol protocol, boolean custom,
String host, int port, String serverName, String userName,
String resource, boolean storePassword, String password,
......@@ -69,6 +74,20 @@ public abstract class ConnectionItem {
state = ConnectionState.offline;
}
/**
* Register new account on server.
*/
public void registerAccount() {
registerNewAccount = true;
}
/**
* Report if this connection is to register a new account on XMPP server.
*/
public boolean isRegisterAccount() {
return(registerNewAccount);
}
/**
* Gets current connection thread.
*
......@@ -152,10 +171,10 @@ public abstract class ConnectionItem {
connectionThread = new ConnectionThread(this);
if (connectionSettings.isCustom())
connectionThread.start(connectionSettings.getHost(),
connectionSettings.getPort(), false);
connectionSettings.getPort(), false, registerNewAccount);
else
connectionThread.start(connectionSettings.getServerName(),
5222, true);
5222, true, registerNewAccount);
return true;
} else {
return false;
......@@ -235,6 +254,17 @@ public abstract class ConnectionItem {
* Connection has been established.
*/
protected void onConnected(ConnectionThread connectionThread) {
if (isRegisterAccount())
state = ConnectionState.registration;
else if (isManaged(connectionThread))
state = ConnectionState.authentication;
}
/**
* New account has been registered on XMPP server.
*/
protected void onAccountRegistered(ConnectionThread connectionThread) {
registerNewAccount = false;
if (isManaged(connectionThread))
state = ConnectionState.authentication;
}
......@@ -302,7 +332,7 @@ public abstract class ConnectionItem {
if (onDisconnect(connectionThread)) {
state = ConnectionState.connecting;
this.connectionThread = new ConnectionThread(this);
this.connectionThread.start(fqdn, port, useSrvLookup);
this.connectionThread.start(fqdn, port, useSrvLookup, registerNewAccount);
}
}
......
......@@ -38,6 +38,11 @@ public enum ConnectionState {
*/
connecting,
/**
* Connection was established, registration is in progress.
*/
registration,
/**
* Connection was established, authentication is in progress.
*/
......@@ -73,6 +78,8 @@ public enum ConnectionState {
return R.string.account_state_waiting;
else if (this == ConnectionState.connecting)
return R.string.account_state_connecting;
else if (this == ConnectionState.registration)
return R.string.account_state_registration;
else if (this == ConnectionState.authentication)
return R.string.account_state_authentication;
else if (this == ConnectionState.connected)
......
......@@ -106,6 +106,8 @@ public class ConnectionThread implements
private boolean started;
private boolean registerNewAccount;
public ConnectionThread(final ConnectionItem connectionItem) {
this.connectionItem = connectionItem;
executorService = Executors
......@@ -488,14 +490,60 @@ public class ConnectionThread implements
private void onConnected(final String password) {
connectionItem.onConnected(this);
ConnectionManager.getInstance().onConnected(this);
runOnConnectionThread(new Runnable() {
if(registerNewAccount) {
runOnConnectionThread(new Runnable() {
@Override
public void run() {
registerAccount(password);
}
});
}
else {
runOnConnectionThread(new Runnable() {
@Override
public void run() {
authorization(password);
}
});
}
}
/**
* Register new account.
*
* @param password
*/
private void registerAccount(final String password) {
try {
xmppConnection.getAccountManager().createAccount(login, password);
}
catch (XMPPException e) {
LogManager.exception(connectionItem, e);
connectionClosedOnError(e);
// Server will destroy connection, but we can speedup
// it.
xmppConnection.disconnect();
return;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
authorization(password);
onAccountRegistered(password);
}
});
}
/**
* New account has been registerd on the server.
*
* @param password
*/
private void onAccountRegistered(final String password) {
LogManager.i(this, "Account registered");
connectionItem.onAccountRegistered(this);
authorization(password);
}
/**
* Login.
*
......@@ -621,10 +669,12 @@ public class ConnectionThread implements
* @param useSRVLookup Whether SRV lookup should be used.
*/
synchronized void start(final String fqdn, final int port,
final boolean useSRVLookup) {
final boolean useSRVLookup,
final boolean registerNewAccount) {
if (started)
throw new IllegalStateException();
started = true;
this.registerNewAccount = registerNewAccount;
runOnConnectionThread(new Runnable() {
@Override
public void run() {
......
......@@ -27,6 +27,8 @@ import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
......@@ -51,6 +53,7 @@ public class AccountAdd extends ManagedActivity implements
private CheckBox storePasswordView;
private CheckBox useOrbotView;
private CheckBox syncableView;
private CheckBox createAccount;
private Spinner accountTypeView;
@Override
......@@ -68,6 +71,7 @@ public class AccountAdd extends ManagedActivity implements
syncableView.setVisibility(View.GONE);
syncableView.setChecked(false);
}
createAccount = (CheckBox) findViewById(R.id.register_account);
accountTypeView = (Spinner) findViewById(R.id.account_type);
accountTypeView.setAdapter(new AccountTypeAdapter(this));
......@@ -87,6 +91,7 @@ public class AccountAdd extends ManagedActivity implements
}
((Button) findViewById(R.id.ok)).setOnClickListener(this);
createAccount.setOnClickListener(this);
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(findViewById(R.id.ok)
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
......@@ -121,7 +126,8 @@ public class AccountAdd extends ManagedActivity implements
.getSelectedItem(),
syncableView.isChecked(),
storePasswordView.isChecked(),
useOrbotView.isChecked());
useOrbotView.isChecked(),
false);
} catch (NetworkException e) {
Application.getInstance().onError(e);
return;
......@@ -152,6 +158,13 @@ public class AccountAdd extends ManagedActivity implements
} else {
EditText userView = (EditText) findViewById(R.id.account_user_name);
EditText passwordView = (EditText) findViewById(R.id.account_password);
EditText passwordConfirmView = (EditText) findViewById(R.id.confirm_password);
if(createAccount.isChecked() &&
!passwordView.getText().toString().contentEquals(passwordConfirmView.getText().toString())) {
Toast.makeText(this, getString(R.string.CONFIRM_PASSWORD),
Toast.LENGTH_LONG).show();
return;
}
String account;
try {
account = AccountManager.getInstance().addAccount(
......@@ -159,7 +172,8 @@ public class AccountAdd extends ManagedActivity implements
passwordView.getText().toString(), accountType,
syncableView.isChecked(),
storePasswordView.isChecked(),
useOrbotView.isChecked());
useOrbotView.isChecked(),
createAccount.isChecked());
} catch (NetworkException e) {
Application.getInstance().onError(e);
return;
......@@ -168,6 +182,14 @@ public class AccountAdd extends ManagedActivity implements
finish();
}
break;
case R.id.register_account:
LinearLayout passwordConfirmView = (LinearLayout) findViewById(R.id.confirm_password_layout);
if(createAccount.isChecked()) {
passwordConfirmView.setVisibility(View.VISIBLE);
}
else {
passwordConfirmView.setVisibility(View.GONE);
}
default:
break;
}
......
......@@ -83,6 +83,30 @@
android:checked="false"
android:text="@string/account_use_orbot" />
<CheckBox
android:id="@+id/register_account"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/account_register" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/confirm_password_layout"
android:visibility="gone">
<TextView android:text="@string/confirm_password" android:layout_width="match_parent" android:layout_height="wrap_content" />
<EditText
android:id="@+id/confirm_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:password="true"
android:singleLine="true"
android:text=""
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
......
......@@ -10,6 +10,7 @@
<string name="account_host">Host</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_01.png -->
<string name="account_password">Password</string>
<string name="confirm_password">Confirm password</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_02.png -->
<string name="account_port">Port</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_02.png -->
......@@ -45,7 +46,7 @@
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_helps_vkontakte">You can enter you name (e.g. masha.v.kontakte) or id (e.g. id123456). You can not login to VKontakte chat using your email. To set up chat you have to provide your Vkontakte.ru username and password. Check http://vk.com/help.php?page=jabber for details.</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_helps_xmpp">If you want to learn more about XMPP (Jabber) here: https://xmpp.org\nTo register new XMPP account please go to https://register.jabber.org, or any other Jabber server.</string>
<string name="account_type_helps_xmpp">If you want to learn more about XMPP (Jabber) here: https://xmpp.org</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_helps_ya">If you don\'t have Ya.Online account you may create one at http://yandex.com</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_type.png -->
......@@ -68,6 +69,7 @@
<string name="EMPTY_SERVER_NAME">Server name is not specified</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_error.png -->
<string name="EMPTY_USER_NAME">Username is not specified</string>
<string name="CONFIRM_PASSWORD">Passwords do not match</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_03.png -->
<string name="account_archive_mode">Store message history</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_history.png -->
......@@ -159,4 +161,5 @@
<string name="INCORRECT_USER_NAME">Incorrect user name. Check help text below for details.</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_title">Install Orbot?</string>
</resources>
\ No newline at end of file
<string name="ACCOUNT_REGISTER_FAILED">Failed to register account on the server.</string>
</resources>
......@@ -4,11 +4,14 @@
<string name="account_delete_confirm">Do you really want to delete account %s?\n(it won\'t be deleted from server, just from Xabber)</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_list.png -->
<string name="account_add">Add account</string>
<string name="account_register">Register new account</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_list_context_menu.png -->
<string name="account_delete">Delete account</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_list_context_menu.png -->
<string name="account_editor">Edit account</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_list.png -->
<string name="account_state_registration">Registering</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_list.png -->
<string name="account_state_authentication">Authorizing</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_list.png -->
<string name="account_state_connected">Online</string>
......@@ -20,4 +23,4 @@
<string name="account_state_offline">Offline</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_list.png -->
<string name="account_state_waiting">Waiting to reconnect</string>
</resources>
\ No newline at end of file
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/market.png -->
<string name="production_description">Open source Jabber (XMPP) client with multi-account support and clean and simple interface. Being both free (as in freedom!) and ad-free, Xabber is designed to be the best Jabber client for Android.\n\nFeatures:\n- Multiple accounts\n- Quick switch between simultaneous chats\n- Rich visibility settings for contacts and groups\n- Compatible with all standard XMPP servers\n- Pre-configured support of Gtalk, Facebook chat, Livejournal chat, Vkontakte, Ya.Online, Google Apps Gtalk accounts\n- Multi user chat (MUC)\n- Chat history\n- Export history to SD card\n- Server side message archive support\n- Emoticons\n- Inline hyperlink support (web pages, YouTube, e-mail, phone numbers, XMPP Uri)\n- Avatars\n- View contact\'s information (vCard)\n- Grouping contacts by groups and/or accounts\n- Contact list management: add/remove/edit contacts, groups, subscriptions\n- Contact search\n- Integration into phone\'s contact list (call from the chat and chat from the phone contact list)\n- Notification setting for each contact\n- Notifications based on key phrase\n- Full Unicode support, chat in any language\n- Portrait and landscape views\n- Stream compression (not all servers supported for now)\n- Resources/priorities\n- OTR encription\n- TLS support\n- Legacy SSL support\n- SASL support\n- Check for the server certificate\n- SRV record and DNS round robin support\n- Client software icons in contact list (Adium, Empathy, Gajim, Gtalk, iChat, Miranda, Pidgin, Psi, QIP, Xabber, Xabber VIP)\n- Typing notification support\n- Message delivery receipts\n- Shortcut to a chat on home screen\n\nList of supported (pre-configured) services:\n- GTalk (Google Talk, Google Apps accounts are supported too)\n- Windows Live Messenger / MSN (Android 2.2 or higher required)\n- Facebook chat\n- Livejournal chat\n- VKontakte\n- Ya.Online\n- QIP\n- Odnoklassniki\n\nComing soon:\n- Tablet interface\n- File transfer\n\nSupported protocols:\nRFC-3920: Core\nRFC-3921: Instant Messaging and Presence\nXEP-0030: Service Discovery\nXEP-0128: Service Discovery Extensions\nXEP-0115: Entity Capabilities\nXEP-0054: vcard-temp\nXEP-0153: vCard-Based Avatars\nXEP-0045: Multi-User Chat (incompletely)\nXEP-0078: Non-SASL Authentication\nXEP-0138: Stream Compression\nXEP-0203: Delayed Delivery\nXEP-0091: Legacy Delayed Delivery\nXEP-0199: XMPP Ping\nXEP-0147: XMPP URI Scheme Query Components\nXEP-0085: Chat State Notifications\nXEP-0184: Message Delivery Receipts\nXEP-0155: Stanza Session Negotiation\nXEP-0059: Result Set Management\nXEP-0136: Message Archiving\nXEP-0224: Attention\n\nCheck Xabber Development version for new functionality.\n\nSource code of Xabber is available at https://github.com/redsolution/xabber-android under GNU GPLv3 license.\n\nFor more information visit our website http://xabber.com or follow @xabber_xmpp at twitter.</string>
<string name="production_description">Open source Jabber (XMPP) client with multi-account support and clean and simple interface. Being both free (as in freedom!) and ad-free, Xabber is designed to be the best Jabber client for Android.\n\nFeatures:\n- Multiple accounts\n- Quick switch between simultaneous chats\n- Rich visibility settings for contacts and groups\n- Compatible with all standard XMPP servers\n- Pre-configured support of Gtalk, Facebook chat, Livejournal chat, Vkontakte, Ya.Online, Google Apps Gtalk accounts\n- Multi user chat (MUC)\n- Chat history\n- Export history to SD card\n- Server side message archive support\n- Emoticons\n- Inline hyperlink support (web pages, YouTube, e-mail, phone numbers, XMPP Uri)\n- Avatars\n- View contact\'s information (vCard)\n- Grouping contacts by groups and/or accounts\n- Contact list management: add/remove/edit contacts, groups, subscriptions\n- Contact search\n- Integration into phone\'s contact list (call from the chat and chat from the phone contact list)\n- Notification setting for each contact\n- Notifications based on key phrase\n- Full Unicode support, chat in any language\n- Portrait and landscape views\n- Stream compression (not all servers supported for now)\n- Resources/priorities\n- OTR encription\n- TLS support\n- Legacy SSL support\n- SASL support\n- Check for the server certificate\n- SRV record and DNS round robin support\n- Client software icons in contact list (Adium, Empathy, Gajim, Gtalk, iChat, Miranda, Pidgin, Psi, QIP, Xabber, Xabber VIP)\n- Typing notification support\n- Message delivery receipts\n- Shortcut to a chat on home screen\n\nList of supported (pre-configured) services:\n- GTalk (Google Talk, Google Apps accounts are supported too)\n- Windows Live Messenger / MSN (Android 2.2 or higher required)\n- Facebook chat\n- Livejournal chat\n- VKontakte\n- Ya.Online\n- QIP\n- Odnoklassniki\n\nComing soon:\n- Tablet interface\n- File transfer\n\nSupported protocols:\nRFC-3920: Core\nRFC-3921: Instant Messaging and Presence\nXEP-0030: Service Discovery\nXEP-0128: Service Discovery Extensions\nXEP-0115: Entity Capabilities\nXEP-0054: vcard-temp\nXEP-0153: vCard-Based Avatars\nXEP-0045: Multi-User Chat (incompletely)\nXEP-0078: Non-SASL Authentication\nXEP-0138: Stream Compression\nXEP-0203: Delayed Delivery\nXEP-0091: Legacy Delayed Delivery\nXEP-0199: XMPP Ping\nXEP-0147: XMPP URI Scheme Query Components\nXEP-0085: Chat State Notifications\nXEP-0184: Message Delivery Receipts\nXEP-0155: Stanza Session Negotiation\nXEP-0059: Result Set Management\nXEP-0136: Message Archiving\nXEP-0224: Attention\nXEP-0077: In-Band Registration\n\nCheck Xabber Development version for new functionality.\n\nSource code of Xabber is available at https://github.com/redsolution/xabber-android under GNU GPLv3 license.\n\nFor more information visit our website http://xabber.com or follow @xabber_xmpp at twitter.</string>
<!-- Can be used for Google Play promotion -->
<string name="production_promo">Multi-account XMPP (Jabber) client.</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/market.png -->
......@@ -17,4 +17,4 @@
<string name="vip_description">VIP version of Xabber — great open source Jabber (XMPP) client with multi-account support and clean and simple interface. Xabber is designed to be the best Jabber client for Android.\n\nThis VIP version of Xabber is in no way any better than regular version of Xabber, gold coin on an application icon being it\'s only distinct feature. It is very useful to show off how gorgeous you are when buying something that anyone can get for free.\n\n...</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/market.png -->
<string name="vip_title">Xabber VIP</string>
</resources>
\ No newline at end of file
</resources>
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