Commit c6889da4 authored by Grigory Fedorov's avatar Grigory Fedorov

AccountAdd use AccountAddFragment now.

parent 822f8cb9
...@@ -18,30 +18,15 @@ import android.content.Context; ...@@ -18,30 +18,15 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.Menu;
import android.view.inputmethod.InputMethodManager; import android.view.MenuInflater;
import android.widget.CheckBox; import android.view.MenuItem;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.xabber.android.data.Application;
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.data.intent.AccountIntentBuilder;
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 View.OnClickListener { public class AccountAdd extends ManagedActivity {
private CheckBox storePasswordView;
private CheckBox useOrbotView;
private CheckBox createAccount;
private AccountType accountType;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -51,84 +36,43 @@ public class AccountAdd extends ManagedActivity implements View.OnClickListener ...@@ -51,84 +36,43 @@ public class AccountAdd extends ManagedActivity implements View.OnClickListener
setContentView(R.layout.account_add); setContentView(R.layout.account_add);
accountType = AccountManager.getInstance().getAccountTypes().get(0); if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.container, AccountAddFragment.newInstance()).commit();
storePasswordView = (CheckBox) findViewById(R.id.store_password); }
useOrbotView = (CheckBox) findViewById(R.id.use_orbot);
createAccount = (CheckBox) findViewById(R.id.register_account);
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);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
findViewById(R.id.auth_panel).setVisibility(View.VISIBLE); getSupportActionBar().setTitle(null);
((TextView) findViewById(R.id.account_user_name)).setHint(accountType.getHint());
((TextView) findViewById(R.id.account_help)).setText(accountType.getHelp());
} }
@Override @Override
public void onClick(View view) { public boolean onCreateOptionsMenu(Menu menu) {
switch (view.getId()) { MenuInflater inflater=getMenuInflater();
case R.id.ok: inflater.inflate(R.menu.add_account, menu);
addAccount(); menu.findItem(R.id.action_add_account).setIcon(null);
break;
case R.id.register_account: return true;
LinearLayout passwordConfirmView = (LinearLayout) findViewById(R.id.confirm_password_layout);
if(createAccount.isChecked()) {
passwordConfirmView.setVisibility(View.VISIBLE);
}
else {
passwordConfirmView.setVisibility(View.GONE);
}
default:
break;
}
} }
private void addAccount() { @Override
if (useOrbotView.isChecked() && !OrbotHelper.isOrbotInstalled()) { public boolean onOptionsItemSelected(MenuItem item) {
OrbotInstallerDialogBuilder.show(this); switch (item.getItemId()) {
return; case R.id.action_add_account:
} ((AccountAddFragment)getSupportFragmentManager().findFragmentById(R.id.container)).addAccount();
EditText userView = (EditText) findViewById(R.id.account_user_name); return true;
EditText passwordView = (EditText) findViewById(R.id.account_password);
EditText passwordConfirmView = (EditText) findViewById(R.id.confirm_password); default:
if(createAccount.isChecked() && return super.onOptionsItemSelected(item);
!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();
} }
public static Intent createIntent(Context context) { public static Intent createIntent(Context context) {
return new Intent(context, AccountAdd.class); return new Intent(context, AccountAdd.class);
} }
private static Intent createAuthenticatorResult(String account) { public static Intent createAuthenticatorResult(String account) {
return new AccountIntentBuilder(null, null).setAccount(account).build(); return new AccountIntentBuilder(null, null).setAccount(account).build();
} }
} }
package com.xabber.android.ui;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.AccountType;
import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder;
import com.xabber.android.ui.helper.OrbotHelper;
import com.xabber.androiddev.R;
public class AccountAddFragment extends Fragment implements View.OnClickListener {
private CheckBox storePasswordView;
private CheckBox useOrbotView;
private CheckBox createAccountCheckBox;
private AccountType accountType;
private LinearLayout passwordConfirmView;
private EditText userView;
private EditText passwordView;
private EditText passwordConfirmEditText;
public static AccountAddFragment newInstance() {
return new AccountAddFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.account_add_fragment, container, false);
accountType = AccountManager.getInstance().getAccountTypes().get(0);
storePasswordView = (CheckBox) view.findViewById(R.id.store_password);
useOrbotView = (CheckBox) view.findViewById(R.id.use_orbot);
createAccountCheckBox = (CheckBox) view.findViewById(R.id.register_account);
createAccountCheckBox.setOnClickListener(this);
userView = (EditText) view.findViewById(R.id.account_user_name);
passwordView = (EditText) view.findViewById(R.id.account_password);
passwordConfirmEditText = (EditText) view.findViewById(R.id.confirm_password);
passwordConfirmView = (LinearLayout) view.findViewById(R.id.confirm_password_layout);
view.findViewById(R.id.auth_panel).setVisibility(View.VISIBLE);
userView.setHint(accountType.getHint());
((TextView) view.findViewById(R.id.account_help)).setText(accountType.getHelp());
return view;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.register_account:
if(createAccountCheckBox.isChecked()) {
passwordConfirmView.setVisibility(View.VISIBLE);
} else {
passwordConfirmView.setVisibility(View.GONE);
}
default:
break;
}
}
public void addAccount() {
if (useOrbotView.isChecked() && !OrbotHelper.isOrbotInstalled()) {
OrbotInstallerDialogBuilder.show(getActivity());
return;
}
if (createAccountCheckBox.isChecked() &&
!passwordView.getText().toString().contentEquals(passwordConfirmEditText.getText().toString())) {
Toast.makeText(getActivity(), 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(),
createAccountCheckBox.isChecked());
} catch (NetworkException e) {
Application.getInstance().onError(e);
return;
}
getActivity().setResult(Activity.RESULT_OK, AccountAdd.createAuthenticatorResult(account));
getActivity().finish();
}
}
...@@ -46,7 +46,7 @@ public class AccountList extends BaseListEditor<String> implements ...@@ -46,7 +46,7 @@ public class AccountList extends BaseListEditor<String> implements
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_accounts))); getSupportActionBar().setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_accounts)));
} }
@Override @Override
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013, Redsolution LTD. All rights reserved. <RelativeLayout
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/.
-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
<LinearLayout >
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar_default"/>
<LinearLayout
android:id="@+id/auth_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView android:text="@string/account_user_name" android:layout_width="match_parent" android:layout_height="wrap_content" />
<EditText
android:id="@+id/account_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:singleLine="true"
android:text=""
android:hint=""
/>
<TextView android:text="@string/account_password" android:layout_width="match_parent" android:layout_height="wrap_content" />
<EditText
android:id="@+id/account_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:password="true"
android:singleLine="true"
android:text=""
/>
<CheckBox
android:id="@+id/store_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/account_store_password" />
</LinearLayout> <include layout="@layout/toolbar_default"
android:layout_height="wrap_content"
<CheckBox android:layout_width="match_parent"
android:id="@+id/use_orbot" android:layout_alignParentTop="true"
android:layout_width="fill_parent" android:id="@+id/toolbar_default"
android:layout_height="wrap_content"
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"
android:layout_height="wrap_content">
<Button
android:text="@string/account_add"
android:id="@+id/ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView
android:id="@+id/account_help"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
/> />
</LinearLayout>
</ScrollView> <FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_default"
>
</FrameLayout>
</RelativeLayout>
\ 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
>
<LinearLayout
android:id="@+id/auth_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<TextView
android:text="@string/account_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/account_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:singleLine="true"
android:text=""
android:hint=""
/>
<TextView
android:text="@string/account_password"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/account_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:singleLine="true"
android:text=""
/>
<CheckBox
android:id="@+id/store_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/account_store_password" />
</LinearLayout>
<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" />
<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:inputType="textPassword"
android:singleLine="true"
android:text=""/>
</LinearLayout>
<TextView
android:id="@+id/account_help"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
/>
</LinearLayout>
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
<string name="account_type_names_odnoklassniki">Одноклассники</string> <string name="account_type_names_odnoklassniki">Одноклассники</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_type.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_type.png -->
<string name="account_type_names_wlm">Windows Live Messenger</string> <string name="account_type_names_wlm">Windows Live Messenger</string>
<string name="account_use_orbot">Использовать анонимное соединения через TOR и требовать TLS шифрования\nНе рекомендуется для Google Talk</string> <string name="account_use_orbot">Использовать анонимное соединения через TOR и требовать TLS шифрования</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_confirm.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_confirm.png -->
<string name="confirm_cancellation">Вы уверены, что хотите отменить все не сохраненные изменения?</string> <string name="confirm_cancellation">Вы уверены, что хотите отменить все не сохраненные изменения?</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_error.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_error.png -->
......
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
<string name="account_type_names_odnoklassniki">Odnoklassniki</string> <string name="account_type_names_odnoklassniki">Odnoklassniki</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_type.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_type.png -->
<string name="account_type_names_wlm">Windows Live Messenger</string> <string name="account_type_names_wlm">Windows Live Messenger</string>
<string name="account_use_orbot">Chat through TOR anonymity network and force TLS cryptographic protocol\nNot recommended for Google Talk</string> <string name="account_use_orbot">Chat through TOR anonymity network and force TLS cryptographic protocol</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_confirm.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_confirm.png -->
<string name="confirm_cancellation">Are you sure you want to discard all the changes?</string> <string name="confirm_cancellation">Are you sure you want to discard all the changes?</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_error.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_error.png -->
......
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