Skip to content

Commit

Permalink
Merge pull request #13556 from nextcloud/bugfix/fix-thread-issue-for-…
Browse files Browse the repository at this point in the history
…dialog

BugFix - Loading Dialog Must Run On Main Thread
  • Loading branch information
alperozturk96 authored Sep 13, 2024
2 parents 7bb16f5 + 5858318 commit 9c590e6
Showing 1 changed file with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,35 +543,39 @@ protected void updateFileFromDB(){
public void showLoadingDialog(String message) {
dismissLoadingDialog();

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 = fragmentManager.beginTransaction();
boolean isDialogFragmentReady = ActivityExtensionsKt.isDialogFragmentReady(this, loadingDialogFragment);
if (isDialogFragmentReady) {
fragmentTransaction.add(loadingDialogFragment, DIALOG_WAIT_TAG);
fragmentTransaction.commitNow();
runOnUiThread(() -> {
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 = fragmentManager.beginTransaction();
boolean isDialogFragmentReady = ActivityExtensionsKt.isDialogFragmentReady(this, loadingDialogFragment);
if (isDialogFragmentReady) {
fragmentTransaction.add(loadingDialogFragment, DIALOG_WAIT_TAG);
fragmentTransaction.commitNow();
}
}
}
});
}

/**
* Dismiss loading dialog
*/
public void dismissLoadingDialog() {
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag(DIALOG_WAIT_TAG);
if (fragment != null) {
Log_OC.d(TAG, "dismiss loading dialog");
LoadingDialog loadingDialogFragment = (LoadingDialog) fragment;
boolean isDialogFragmentReady = ActivityExtensionsKt.isDialogFragmentReady(this, loadingDialogFragment);
if (isDialogFragmentReady) {
loadingDialogFragment.dismiss();
fragmentManager.executePendingTransactions();
runOnUiThread(() -> {
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag(DIALOG_WAIT_TAG);
if (fragment != null) {
Log_OC.d(TAG, "dismiss loading dialog");
LoadingDialog loadingDialogFragment = (LoadingDialog) fragment;
boolean isDialogFragmentReady = ActivityExtensionsKt.isDialogFragmentReady(this, loadingDialogFragment);
if (isDialogFragmentReady) {
loadingDialogFragment.dismiss();
fragmentManager.executePendingTransactions();
}
}
}
});
}

private void doOnResumeAndBound() {
Expand Down

0 comments on commit 9c590e6

Please sign in to comment.