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-10 13:23:52 +0100
commit5a41f4bc38683bac27254d99bb6f8cc2b3374b5d (patch)
tree46073105c1a306f0a4fc134be500c1fad20600be
parent6393b20cc27f4162395c87c475574ca431386a62 (diff)
Add ShareViaAccountActivity
-rw-r--r--src/main/AndroidManifest.xml4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ShareViaAccountActivity.java130
-rw-r--r--src/main/res/values-de/strings.xml1
-rw-r--r--src/main/res/values/strings.xml1
4 files changed, 136 insertions, 0 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index af011e0..2791463 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -135,6 +135,10 @@
android:label="@string/title_activity_manage_accounts"
android:launchMode="singleTask" />
<activity
+ android:name=".ui.ShareViaAccountActivity"
+ android:label="@string/title_activity_share_via_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/ShareViaAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareViaAccountActivity.java
new file mode 100644
index 0000000..cd90397
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/ui/ShareViaAccountActivity.java
@@ -0,0 +1,130 @@
+package eu.siacs.conversations.ui;
+
+import android.app.ActionBar;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.ui.adapter.AccountAdapter;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
+import eu.siacs.conversations.xmpp.jid.Jid;
+
+public class ShareViaAccountActivity extends XmppActivity {
+ public static final String EXTRA_CONTACT = "contact";
+ public static final String EXTRA_BODY = "body";
+
+ protected final List<Account> accountList = new ArrayList<>();
+ protected ListView accountListView;
+ protected AccountAdapter mAccountAdapter;
+
+ @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);
+
+ 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 String body = getIntent().getStringExtra(EXTRA_BODY);
+
+ try {
+ final Jid contact = Jid.fromString(getIntent().getStringExtra(EXTRA_CONTACT));
+ final Conversation conversation = xmppConnectionService.findOrCreateConversation(
+ account, contact, false, false);
+ switchToConversation(conversation, body, false);
+ } catch (InvalidJidException e) {
+ // ignore error
+ }
+
+ finish();
+ }
+ });
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ final int theme = findTheme();
+ if (this.mTheme != theme) {
+ recreate();
+ }
+ }
+
+ @Override
+ void onBackendConnected() {
+ final int numAccounts = xmppConnectionService.getAccounts().size();
+
+ if (numAccounts == 0) {
+ Toast.makeText(this, R.string.no_accounts, Toast.LENGTH_SHORT).show();
+ finish();
+ } else if (numAccounts == 1) {
+ final String body = getIntent().getStringExtra(EXTRA_BODY);
+ final Account account = xmppConnectionService.getAccounts().get(0);
+
+ try {
+ final Jid contact = Jid.fromString(getIntent().getStringExtra(EXTRA_CONTACT));
+ final Conversation conversation = xmppConnectionService.findOrCreateConversation(
+ account, contact, false, false);
+ switchToConversation(conversation, body, false);
+ } catch (InvalidJidException e) {
+ // ignore error
+ }
+
+ finish();
+ } else {
+ refreshUiReal();
+ }
+ }
+
+ @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();
+ }
+ }
+}
diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml
index 881bf53..121418c 100644
--- a/src/main/res/values-de/strings.xml
+++ b/src/main/res/values-de/strings.xml
@@ -20,6 +20,7 @@
<string name="title_activity_sharewith">Mit Unterhaltung teilen</string>
<string name="title_activity_start_conversation">Unterhaltung beginnen</string>
<string name="title_activity_choose_contact">Kontakt auswählen</string>
+ <string name="title_activity_share_via_account">Über Account teilen</string>
<string name="title_activity_block_list">Sperrliste</string>
<string name="just_now">gerade</string>
<string name="minute_ago">vor einer Minute</string>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 18cf59b..143af59 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_share_via_account">Share via 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>