aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <xmpp-dev@marcschink.de>2017-12-07 16:45:20 +0100
committerAndroid Development <you@example.com>2017-12-07 17:34:48 +0100
commit40d6baa2464becd766992159046651a294b6ab7c (patch)
treeca9ac6144af010b6d2965c72c089d55a993adb7f
parente42f6f1d9022f80b598246e6106f277d1552f162 (diff)
Add account chooser activity
-rw-r--r--src/main/AndroidManifest.xml4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ChooseAccountActivity.java155
-rw-r--r--src/main/res/values/strings.xml1
3 files changed, 160 insertions, 0 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 228b6c1..a9e0bd8 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -128,6 +128,10 @@
android:label="@string/title_activity_manage_accounts"
android:launchMode="singleTask" />
<activity
+ android:name=".ui.ChooseAccountActivity"
+ android:label="@string/title_activity_choose_account"
+ android:launchMode="singleTask" />
+ <activity
android:name=".ui.EditAccountActivity"
android:launchMode="singleTop"
android:windowSoftInputMode="stateHidden|adjustResize" />
diff --git a/src/main/java/eu/siacs/conversations/ui/ChooseAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/ChooseAccountActivity.java
new file mode 100644
index 0000000..0ea467c
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/ui/ChooseAccountActivity.java
@@ -0,0 +1,155 @@
+package eu.siacs.conversations.ui;
+
+import android.app.ActionBar;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.StringRes;
+import android.util.Pair;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ListView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.ui.adapter.AccountAdapter;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
+import eu.siacs.conversations.xmpp.jid.Jid;
+
+public class ChooseAccountActivity extends XmppActivity {
+ private final String STATE_SELECTED_ACCOUNT = "selected_account";
+ public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
+ public static final String EXTRA_SELECTED_ACCOUNT = "selected_account";
+
+ protected Account selectedAccount = null;
+ protected Jid selectedAccountJid = null;
+
+ protected final List<Account> accountList = new ArrayList<>();
+ protected ListView accountListView;
+ protected AccountAdapter mAccountAdapter;
+
+ protected Pair<Integer, Intent> mPostponedActivityResult = null;
+
+ @Override
+ protected void refreshUiReal() {
+ synchronized (this.accountList) {
+ accountList.clear();
+ accountList.addAll(xmppConnectionService.getAccounts());
+ }
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setHomeButtonEnabled(this.accountList.size() > 0);
+ actionBar.setDisplayHomeAsUpEnabled(this.accountList.size() > 0);
+ }
+ mAccountAdapter.notifyDataSetChanged();
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.manage_accounts);
+
+ if (savedInstanceState != null) {
+ String jid = savedInstanceState.getString(STATE_SELECTED_ACCOUNT);
+ if (jid != null) {
+ try {
+ this.selectedAccountJid = Jid.fromString(jid);
+ } catch (InvalidJidException e) {
+ this.selectedAccountJid = null;
+ }
+ }
+ }
+
+ accountListView = (ListView) findViewById(R.id.account_list);
+ this.mAccountAdapter = new AccountAdapter(this, accountList, false);
+ accountListView.setAdapter(this.mAccountAdapter);
+ accountListView.setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View view,
+ int position, long arg3) {
+ final Account account = accountList.get(position);
+ final Intent data = new Intent();
+ data.putExtras(getIntent().getExtras());
+ data.putExtra(EXTRA_SELECTED_ACCOUNT, account.getJid().toString());
+ setResult(RESULT_OK, data);
+ finish();
+ }
+ });
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ final int theme = findTheme();
+ if (this.mTheme != theme) {
+ recreate();
+ }
+
+ Intent intent = getIntent();
+ @StringRes
+ final int res;
+
+ if (intent != null) {
+ res = intent.getIntExtra(EXTRA_TITLE_RES_ID, R.string.title_activity_choose_account);
+ } else {
+ res = R.string.title_activity_choose_account;
+ }
+
+ ActionBar bar = getActionBar();
+ if (bar != null) {
+ try {
+ bar.setTitle(res);
+ } catch (Exception e) {
+ bar.setTitle(R.string.title_activity_choose_account);
+ }
+ }
+
+ }
+
+ @Override
+ public void onSaveInstanceState(final Bundle savedInstanceState) {
+ if (selectedAccount != null) {
+ savedInstanceState.putString(STATE_SELECTED_ACCOUNT,
+ selectedAccount.getJid().toBareJid().toString());
+ }
+ super.onSaveInstanceState(savedInstanceState);
+ }
+
+ @Override
+ void onBackendConnected() {
+ if (selectedAccountJid != null) {
+ this.selectedAccount = xmppConnectionService.findAccountByJid(selectedAccountJid);
+ }
+ refreshUiReal();
+ if (this.mPostponedActivityResult != null) {
+ this.onActivityResult(mPostponedActivityResult.first, RESULT_OK,
+ mPostponedActivityResult.second);
+ }
+ }
+
+ @Override
+ public boolean onNavigateUp() {
+ if (xmppConnectionService.getConversations().size() == 0) {
+ Intent contactsIntent = new Intent(this,
+ StartConversationActivity.class);
+ contactsIntent.setFlags(
+ // if activity exists in stack, pop the stack and go back to it
+ Intent.FLAG_ACTIVITY_CLEAR_TOP |
+ // otherwise, make a new task for it
+ Intent.FLAG_ACTIVITY_NEW_TASK |
+ // don't use the new activity animation; finish
+ // animation runs instead
+ Intent.FLAG_ACTIVITY_NO_ANIMATION);
+ startActivity(contactsIntent);
+ finish();
+ return true;
+ } else {
+ return super.onNavigateUp();
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index dafd16b..e99c633 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -21,6 +21,7 @@
<string name="title_activity_sharewith">Share with Conversation</string>
<string name="title_activity_start_conversation">Start Conversation</string>
<string name="title_activity_choose_contact">Choose Contact</string>
+ <string name="title_activity_choose_account">Choose account</string>
<string name="title_activity_block_list">Block list</string>
<string name="just_now">just now</string>
<string name="minute_ago">1 min ago</string>