aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index 631c08227..faa8bdc37 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -32,6 +32,7 @@ package de.pixart.messenger.ui;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
@@ -56,6 +57,7 @@ import de.pixart.messenger.ui.interfaces.OnConversationArchived;
import de.pixart.messenger.ui.interfaces.OnConversationRead;
import de.pixart.messenger.ui.interfaces.OnConversationSelected;
import de.pixart.messenger.ui.interfaces.OnConversationsListItemUpdated;
+import de.pixart.messenger.ui.util.PendingItem;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS;
@@ -72,9 +74,21 @@ public class ConversationActivity extends XmppActivity implements OnConversation
//secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
private static final @IdRes
int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment};
+ private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
private ActivityConversationsBinding binding;
+ private static boolean isViewIntent(Intent i) {
+ return i != null && ACTION_VIEW_CONVERSATION.equals(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION);
+ }
+
+ private static Intent createLauncherIntent(Context context) {
+ final Intent intent = new Intent(context, ConversationActivity.class);
+ intent.setAction(Intent.ACTION_MAIN);
+ intent.addCategory(Intent.CATEGORY_LAUNCHER);
+ return intent;
+ }
+
@Override
protected void refreshUiReal() {
for(@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
@@ -88,6 +102,10 @@ public class ConversationActivity extends XmppActivity implements OnConversation
notifyFragmentOfBackendConnected(id);
}
invalidateActionBarTitle();
+ Intent intent = pendingViewIntent.pop();
+ if (intent != null) {
+ processViewIntent(intent);
+ }
}
private void notifyFragmentOfBackendConnected(@IdRes int id) {
@@ -104,6 +122,16 @@ public class ConversationActivity extends XmppActivity implements OnConversation
}
}
+ private void processViewIntent(Intent intent) {
+ String uuid = intent.getStringExtra(EXTRA_CONVERSATION);
+ Conversation conversation = uuid != null ? xmppConnectionService.findConversationByUuid(uuid) : null;
+ if (conversation == null) {
+ Log.d(Config.LOGTAG, "unable to view conversation with uuid:" + uuid);
+ return;
+ }
+ openConversation(conversation, intent.getExtras());
+ }
+
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -112,6 +140,11 @@ public class ConversationActivity extends XmppActivity implements OnConversation
this.getFragmentManager().addOnBackStackChangedListener(this::invalidateActionBarTitle);
this.initializeFragments();
this.invalidateActionBarTitle();
+ final Intent intent = getIntent();
+ if (isViewIntent(intent)) {
+ pendingViewIntent.push(intent);
+ setIntent(createLauncherIntent(this));
+ }
}
@Override
@@ -123,6 +156,10 @@ public class ConversationActivity extends XmppActivity implements OnConversation
@Override
public void onConversationSelected(Conversation conversation) {
Log.d(Config.LOGTAG, "selected " + conversation.getName());
+ openConversation(conversation, null);
+ }
+
+ private void openConversation(Conversation conversation, Bundle extras) {
ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
final boolean mainNeedsRefresh;
if (conversationFragment == null) {
@@ -155,6 +192,17 @@ public class ConversationActivity extends XmppActivity implements OnConversation
return super.onOptionsItemSelected(item);
}
+ @Override
+ protected void onNewIntent(final Intent intent) {
+ if (isViewIntent(intent)) {
+ if (xmppConnectionService != null) {
+ processViewIntent(intent);
+ } else {
+ pendingViewIntent.push(intent);
+ }
+ }
+ }
+
private void initializeFragments() {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);