Commit 07db7c83 authored by Grigory Fedorov's avatar Grigory Fedorov

Account add: account type selection removed, add to system contacts removed. Xmpp only.

Account type icons removed, AccountTypeAdapter removed.
parent 754348a0
......@@ -138,7 +138,7 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
servers.add(values.getString(i));
}
accountTypes.add(new AccountType(id, protocol, values.getString(1),
values.getString(2), values.getString(3), values.getDrawable(4),
values.getString(2), values.getString(3), null,
values.getBoolean(5, false), values.getString(6), values.getInt(7, 5222),
values.getBoolean(8, false), servers));
values.recycle();
......
......@@ -22,13 +22,10 @@ import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.xabber.android.data.Application;
......@@ -36,26 +33,19 @@ import com.xabber.android.data.NetworkException;
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
View.OnClickListener, OnItemSelectedListener {
private static final String SAVED_ACCOUNT_TYPE = "com.xabber.android.ui.AccountAdd.ACCOUNT_TYPE";
private static final int OAUTH_WML_REQUEST_CODE = 1;
public class AccountAdd extends ManagedActivity implements View.OnClickListener {
private static final int ORBOT_DIALOG_ID = 9050;
private CheckBox storePasswordView;
private CheckBox useOrbotView;
private CheckBox syncableView;
private CheckBox createAccount;
private Spinner accountTypeView;
private AccountType accountType;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -65,33 +55,13 @@ public class AccountAdd extends ManagedActivity implements
setContentView(R.layout.account_add);
accountType = AccountManager.getInstance().getAccountTypes().get(0);
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);
syncableView.setChecked(false);
}
createAccount = (CheckBox) findViewById(R.id.register_account);
accountTypeView = (Spinner) findViewById(R.id.account_type);
accountTypeView.setAdapter(new AccountTypeAdapter(this));
accountTypeView.setOnItemSelectedListener(this);
String accountType;
if (savedInstanceState == null)
accountType = null;
else
accountType = savedInstanceState.getString(SAVED_ACCOUNT_TYPE);
accountTypeView.setSelection(0);
for (int position = 0; position < accountTypeView.getCount(); position++)
if (((AccountType) accountTypeView.getItemAtPosition(position))
.getName().equals(accountType)) {
accountTypeView.setSelection(position);
break;
}
((Button) findViewById(R.id.ok)).setOnClickListener(this);
findViewById(R.id.ok).setOnClickListener(this);
createAccount.setOnClickListener(this);
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(findViewById(R.id.ok)
......@@ -99,91 +69,20 @@ public class AccountAdd extends ManagedActivity implements
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SAVED_ACCOUNT_TYPE,
((AccountType) accountTypeView.getSelectedItem()).getName());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OAUTH_WML_REQUEST_CODE) {
if (resultCode == RESULT_OK && !OAuthActivity.isInvalidated(data)) {
String token = OAuthActivity.getToken(data);
if (token == null) {
Application.getInstance().onError(
R.string.AUTHENTICATION_FAILED);
} else {
String account;
try {
account = AccountManager.getInstance()
.addAccount(
null,
token,
(AccountType) accountTypeView
.getSelectedItem(),
syncableView.isChecked(),
storePasswordView.isChecked(),
useOrbotView.isChecked(),
false);
} catch (NetworkException e) {
Application.getInstance().onError(e);
return;
}
setResult(RESULT_OK,
createAuthenticatorResult(this, account));
finish();
}
}
}
findViewById(R.id.auth_panel).setVisibility(View.VISIBLE);
((TextView) findViewById(R.id.account_user_name)).setHint(accountType.getHint());
((TextView) findViewById(R.id.account_help)).setText(accountType.getHelp());
}
@Override
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()) {
startActivityForResult(
OAuthActivity.createIntent(this,
accountType.getProtocol()),
OAUTH_WML_REQUEST_CODE);
} 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(
userView.getText().toString(),
passwordView.getText().toString(), accountType,
syncableView.isChecked(),
storePasswordView.isChecked(),
useOrbotView.isChecked(),
createAccount.isChecked());
} catch (NetworkException e) {
Application.getInstance().onError(e);
return;
}
setResult(RESULT_OK, createAuthenticatorResult(this, account));
finish();
}
addAccount();
break;
case R.id.register_account:
LinearLayout passwordConfirmView = (LinearLayout) findViewById(R.id.confirm_password_layout);
if(createAccount.isChecked()) {
......@@ -197,31 +96,42 @@ public class AccountAdd extends ManagedActivity implements
}
}
@Override
public void onItemSelected(AdapterView<?> adapterView, View view,
int position, long id) {
AccountType accountType = (AccountType) accountTypeView
.getSelectedItem();
if (accountType.getProtocol().isOAuth())
findViewById(R.id.auth_panel).setVisibility(View.GONE);
else
findViewById(R.id.auth_panel).setVisibility(View.VISIBLE);
((TextView) findViewById(R.id.account_user_name)).setHint(accountType
.getHint());
((TextView) findViewById(R.id.account_help)).setText(accountType
.getHelp());
}
private void addAccount() {
if (useOrbotView.isChecked() && !OrbotHelper.isOrbotInstalled()) {
showDialog(ORBOT_DIALOG_ID);
return;
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
accountTypeView.setSelection(0);
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(
userView.getText().toString(),
passwordView.getText().toString(), accountType,
false,
storePasswordView.isChecked(),
useOrbotView.isChecked(),
createAccount.isChecked());
} catch (NetworkException e) {
Application.getInstance().onError(e);
return;
}
setResult(RESULT_OK, createAuthenticatorResult(account));
finish();
}
@Override
protected Dialog onCreateDialog(int id) {
if (id == ORBOT_DIALOG_ID) {
return new OrbotInstallerDialogBuilder(this, ORBOT_DIALOG_ID)
.create();
return new OrbotInstallerDialogBuilder(this, ORBOT_DIALOG_ID).create();
}
return super.onCreateDialog(id);
}
......@@ -230,13 +140,7 @@ public class AccountAdd extends ManagedActivity implements
return new Intent(context, AccountAdd.class);
}
private static Intent createAuthenticatorResult(Context context,
String account) {
private static Intent createAuthenticatorResult(String account) {
return new AccountIntentBuilder(null, null).setAccount(account).build();
}
public static String getAuthenticatorResultAccount(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.adapter;
import java.util.List;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.AccountType;
import com.xabber.androiddev.R;
/**
* Adapter for drop down list of account's types.
*
* @author alexander.ivanov
*/
public class AccountTypeAdapter extends BaseAdapter {
private final Activity activity;
private final List<AccountType> accountTypes;
public AccountTypeAdapter(Activity activity) {
super();
this.activity = activity;
accountTypes = AccountManager.getInstance().getAccountTypes();
}
@Override
public int getCount() {
return accountTypes.size();
}
@Override
public Object getItem(int position) {
return accountTypes.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View view;
if (convertView == null) {
view = activity.getLayoutInflater().inflate(
R.layout.account_type_item, parent, false);
} else {
view = convertView;
}
final AccountType type = (AccountType) getItem(position);
((ImageView) view.findViewById(R.id.avatar)).setImageDrawable(type
.getIcon());
((TextView) view.findViewById(R.id.name)).setText(type.getName());
return view;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
final View view;
if (convertView == null) {
view = activity.getLayoutInflater().inflate(
R.layout.account_type_dropdown, parent, false);
} else {
view = convertView;
}
final AccountType type = (AccountType) getItem(position);
((ImageView) view.findViewById(R.id.avatar)).setImageDrawable(type
.getIcon());
((TextView) view.findViewById(R.id.name)).setText(type.getName());
return view;
}
}
......@@ -24,16 +24,6 @@
<include layout="@layout/toolbar_default"/>
<TextView android:text="@string/account_type" android:layout_width="match_parent" android:layout_height="wrap_content" />
<Spinner
android:id="@+id/account_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dip"
android:paddingBottom="8dip"
android:prompt="@string/account_type"
/>
<LinearLayout
android:id="@+id/auth_panel"
android:layout_width="match_parent"
......@@ -71,13 +61,6 @@
</LinearLayout>
<CheckBox
android:id="@+id/syncable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/account_syncable" />
<CheckBox
android:id="@+id/use_orbot"
android:layout_width="fill_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dip">
<ImageView
android:id="@+id/avatar"
android:layout_width="32dip"
android:layout_height="32dip"
android:src="@drawable/ic_type_gtalk"
/>
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="6dip"
android:singleLine="true"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:text="GTalk"
/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dip">
<ImageView
android:id="@+id/avatar"
android:layout_width="32dip"
android:layout_height="32dip"
android:src="@drawable/ic_type_gtalk"
/>
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="6dip"
android:singleLine="true"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:text="GTalk"
/>
</LinearLayout>
\ No newline at end of file
......@@ -14,8 +14,6 @@
-->
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string name="account_protocol_xmpp">xmpp</string>
<string name="account_protocol_gtalk">gtalk</string>
<string name="account_protocol_wlm">wlm</string>
<!--
<array name="account_type_name">
......@@ -39,7 +37,7 @@
<item>@string/account_type_names_xmpp</item>
<item>@string/account_type_hints_xmpp</item>
<item>@string/account_type_helps_xmpp</item>
<item>@drawable/ic_type_xmpp</item>
<item></item>
<item>True</item>
<item></item>
<item>5222</item>
......@@ -47,108 +45,8 @@
<item></item>
</array>
<array name="account_type_gtalk">
<item>@string/account_protocol_gtalk</item>
<item>@string/account_type_names_gtalk</item>
<item>@string/account_type_hints_gtalk</item>
<item>@string/account_type_helps_gtalk</item>
<item>@drawable/ic_type_gtalk</item>
<item>True</item>
<item>talk.google.com</item>
<item>5222</item>
<item>True</item>
<item>gmail.com</item>
<item>googlemail.com</item>
</array>
<array name="account_type_wlm">
<item>@string/account_protocol_wlm</item>
<item>@string/account_type_names_wlm</item>
<item>@string/account_type_hints_wlm</item>
<item>@string/account_type_helps_wlm</item>
<item>@drawable/ic_type_wlm</item>
<item>True</item>
<item>xmpp.messenger.live.com</item>
<item>5222</item>
<item>True</item>
<item>messenger.live.com</item>
</array>
<array name="account_type_facebook">
<item>@string/account_protocol_xmpp</item>
<item>@string/account_type_names_facebook</item>
<item>@string/account_type_hints_facebook</item>
<item>@string/account_type_helps_facebook</item>
<item>@drawable/ic_type_facebook</item>
<item>False</item>
<item>chat.facebook.com</item>
<item>5222</item>
<item>True</item>
<item>chat.facebook.com</item>
</array>
<array name="account_type_qip">
<item>@string/account_protocol_xmpp</item>
<item>@string/account_type_names_qip</item>
<item>@string/account_type_hints_qip</item>
<item>@string/account_type_helps_qip</item>
<item>@drawable/ic_type_qip</item>
<item>True</item>
<item>webim.qip.ru</item>
<item>5222</item>
<item>True</item>
<item>qip.ru</item>
</array>
<array name="account_type_ya">
<item>@string/account_protocol_xmpp</item>
<item>@string/account_type_names_ya</item>
<item>@string/account_type_hints_ya</item>
<item>@string/account_type_helps_ya</item>
<item>@drawable/ic_type_yandex</item>
<item>True</item>
<item>xmpp.yandex.ru</item>
<item>5222</item>
<item>True</item>
<item>yandex.ru</item>
<item>ya.ru</item>
</array>
<array name="account_type_livejournal">
<item>@string/account_protocol_xmpp</item>
<item>@string/account_type_names_livejournal</item>
<item>@string/account_type_hints_livejournal</item>
<item>@string/account_type_helps_livejournal</item>
<item>@drawable/ic_type_livejournal</item>
<item>False</item>
<item>livejournal.com</item>
<item>5222</item>
<item>True</item>
<item>livejournal.com</item>
</array>
<array name="account_type_odnoklassniki">
<item>@string/account_protocol_xmpp</item>
<item>@string/account_type_names_odnoklassniki</item>
<item>@string/account_type_hints_odnoklassniki</item>
<item>@string/account_type_helps_odnoklassniki</item>
<item>@drawable/ic_type_odnoklassniki</item>
<item>False</item>
<item>xmpp.odnoklassniki.ru</item>
<item>5222</item>
<item>True</item>
<item>odnoklassniki.ru</item>
</array>
<array name="account_types">
<item>@array/account_type_xmpp</item>
<item>@array/account_type_gtalk</item>
<item>@array/account_type_wlm</item>
<item>@array/account_type_facebook</item>
<item>@array/account_type_qip</item>
<item>@array/account_type_ya</item>
<item>@array/account_type_livejournal</item>
<item>@array/account_type_odnoklassniki</item>
</array>
</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