executePendingTransactions before trying to access secondary_fragment

If we don’t executePendingTransactions we might still access the overview fragment
while a replacement operation is in the works. This will lead to two
conversationfragments opening.
This commit is contained in:
Daniel Gultsch 2021-08-25 18:54:00 +02:00
parent 581eb511b9
commit f975b5ddac

View file

@ -425,16 +425,18 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
}
private void openConversation(Conversation conversation, Bundle extras) {
ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
final FragmentManager fragmentManager = getFragmentManager();
fragmentManager.executePendingTransactions();
ConversationFragment conversationFragment = (ConversationFragment) fragmentManager.findFragmentById(R.id.secondary_fragment);
final boolean mainNeedsRefresh;
if (conversationFragment == null) {
mainNeedsRefresh = false;
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
if (mainFragment instanceof ConversationFragment) {
conversationFragment = (ConversationFragment) mainFragment;
} else {
conversationFragment = new ConversationFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
fragmentTransaction.addToBackStack(null);
try {
@ -562,17 +564,18 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
}
private void initializeFragments() {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
final FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
final Fragment secondaryFragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
if (mainFragment != null) {
if (binding.secondaryFragment != null) {
if (mainFragment instanceof ConversationFragment) {
getFragmentManager().popBackStack();
transaction.remove(mainFragment);
transaction.commit();
getFragmentManager().executePendingTransactions();
transaction = getFragmentManager().beginTransaction();
fragmentManager.executePendingTransactions();
transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.secondary_fragment, mainFragment);
transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
transaction.commit();
@ -583,7 +586,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
transaction.remove(secondaryFragment);
transaction.commit();
getFragmentManager().executePendingTransactions();
transaction = getFragmentManager().beginTransaction();
transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.main_fragment, secondaryFragment);
transaction.addToBackStack(null);
transaction.commit();