Improve robustness of fragment transactions for loading dialogue

Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
This commit is contained in:
ZetaTom 2024-09-11 10:48:48 +02:00
Родитель 1497f93584
Коммит 89d6cf36e9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: BC815CEC88F62FBA
1 изменённых файлов: 11 добавлений и 7 удалений

Просмотреть файл

@ -543,14 +543,16 @@ public abstract class FileActivity extends DrawerActivity
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 abstract class FileActivity extends DrawerActivity
* 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();
}
}
}