From 7053670121abd8cd9a5af03aec59bdc6345b072f Mon Sep 17 00:00:00 2001 From: ZetaTom <70907959+ZetaTom@users.noreply.github.com> Date: Wed, 11 Sep 2024 10:48:48 +0200 Subject: [PATCH] Improve robustness of fragment transactions for loading dialogue Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com> --- .../android/ui/activity/FileActivity.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java index a32ee12126f3..b24337fce65c 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java @@ -543,14 +543,16 @@ protected void updateFileFromDB(){ public void showLoadingDialog(String message) { dismissLoadingDialog(); - Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG); - if (frag == null) { + FragmentManager fragmentManager = getSupportFragmentManager(); + Fragment fragment = fragmentManager.findFragmentByTag(DIALOG_WAIT_TAG); + if (fragment == null) { Log_OC.d(TAG, "show loading dialog"); LoadingDialog loadingDialogFragment = LoadingDialog.newInstance(message); - FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); boolean isDialogFragmentReady = ActivityExtensionsKt.isDialogFragmentReady(this, loadingDialogFragment); if (isDialogFragmentReady) { - loadingDialogFragment.show(fragmentTransaction, DIALOG_WAIT_TAG); + fragmentTransaction.add(loadingDialogFragment, DIALOG_WAIT_TAG); + fragmentTransaction.commitNow(); } } } @@ -559,13 +561,15 @@ public void showLoadingDialog(String message) { * Dismiss loading dialog */ public void dismissLoadingDialog() { - Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG); - if (frag != null) { + FragmentManager fragmentManager = getSupportFragmentManager(); + Fragment fragment = fragmentManager.findFragmentByTag(DIALOG_WAIT_TAG); + if (fragment != null) { Log_OC.d(TAG, "dismiss loading dialog"); - LoadingDialog loadingDialogFragment = (LoadingDialog) frag; + LoadingDialog loadingDialogFragment = (LoadingDialog) fragment; boolean isDialogFragmentReady = ActivityExtensionsKt.isDialogFragmentReady(this, loadingDialogFragment); if (isDialogFragmentReady) { loadingDialogFragment.dismiss(); + fragmentManager.executePendingTransactions(); } } }