Skip to content

Commit

Permalink
Improve robustness of fragment transactions for loading dialogue
Browse files Browse the repository at this point in the history
Signed-off-by: ZetaTom <[email protected]>
  • Loading branch information
ZetaTom authored and alperozturk96 committed Sep 11, 2024
1 parent a2eba07 commit 7053670
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand All @@ -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();
}
}
}
Expand Down

0 comments on commit 7053670

Please sign in to comment.