From 770d01ae66b6e0643df072a1fd310e3b3e77379a Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 29 Mar 2018 22:41:26 +0200 Subject: handle view conversation action when ConversationFragment is already open --- .../pixart/messenger/ui/ConversationActivity.java | 17 ++++++++---- .../pixart/messenger/ui/ConversationFragment.java | 6 +++++ .../ui/ConversationsOverviewFragment.java | 31 +++++++++++++--------- 3 files changed, 36 insertions(+), 18 deletions(-) (limited to 'src/main/java/de/pixart/messenger/ui') diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index c3fdfefa2..2103b63e5 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -173,17 +173,24 @@ public class ConversationActivity extends XmppActivity implements OnConversation final boolean mainNeedsRefresh; if (conversationFragment == null) { mainNeedsRefresh = false; - conversationFragment = new ConversationFragment(); - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.main_fragment, conversationFragment); - fragmentTransaction.addToBackStack(null); - fragmentTransaction.commit(); + Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment); + if (mainFragment != null && mainFragment instanceof ConversationFragment) { + conversationFragment = (ConversationFragment) mainFragment; + } else { + conversationFragment = new ConversationFragment(); + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.main_fragment, conversationFragment); + fragmentTransaction.addToBackStack(null); + fragmentTransaction.commit(); + } } else { mainNeedsRefresh = true; } conversationFragment.reInit(conversation); if (mainNeedsRefresh) { refreshFragment(R.id.main_fragment); + } else { + invalidateActionBarTitle(); } } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index f5fc419a1..4e898b66d 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -976,6 +976,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } + @Override + public void onDetach() { + super.onDetach(); + this.activity = null; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java index 173d09cc7..8c77b7c51 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java @@ -52,11 +52,22 @@ import de.pixart.messenger.ui.util.PendingItem; public class ConversationsOverviewFragment extends XmppFragment { private final List conversations = new ArrayList<>(); + private final PendingItem swipedConversation = new PendingItem<>(); private FragmentConversationsOverviewBinding binding; private ConversationAdapter conversationsAdapter; private XmppActivity activity; - private final PendingItem swipedConversation = new PendingItem<>(); + public static Conversation getSuggestion(Activity activity) { + Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment); + if (fragment != null && fragment instanceof ConversationsOverviewFragment) { + List conversations = ((ConversationsOverviewFragment) fragment).conversations; + if (conversations.size() > 0) { + return conversations.get(0); + } + } + return null; + + } @Override public void onAttach(Activity activity) { @@ -69,6 +80,12 @@ public class ConversationsOverviewFragment extends XmppFragment { } } + @Override + public void onDetach() { + super.onDetach(); + this.activity = null; + } + @Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(Config.LOGTAG, "onCreateView"); @@ -115,16 +132,4 @@ public class ConversationsOverviewFragment extends XmppFragment { this.activity.xmppConnectionService.populateWithOrderedConversations(this.conversations); this.conversationsAdapter.notifyDataSetChanged(); } - - public static Conversation getSuggestion(Activity activity) { - Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment); - if (fragment != null && fragment instanceof ConversationsOverviewFragment) { - List conversations = ((ConversationsOverviewFragment) fragment).conversations; - if (conversations.size() > 0) { - return conversations.get(0); - } - } - return null; - - } } \ No newline at end of file -- cgit v1.2.3