Show progress dialog after screen rotation

This commit is contained in:
Vitaliy 2020-03-04 12:38:50 +02:00
parent 6262c8ca71
commit cdbdf4a78b

View file

@ -15,6 +15,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
@ -132,6 +133,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
changedProfile = new ApplicationProfileObject(); changedProfile = new ApplicationProfileObject();
if (savedInstanceState != null) { if (savedInstanceState != null) {
restoreState(savedInstanceState); restoreState(savedInstanceState);
checkSavingProfile();
} else { } else {
changedProfile.stringKey = profile.stringKey; changedProfile.stringKey = profile.stringKey;
changedProfile.parent = profile.parent; changedProfile.parent = profile.parent;
@ -693,7 +695,19 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
private void saveProfile() { private void saveProfile() {
if (isNewProfile) { if (isNewProfile) {
showNewProfileSavingDialog(); DialogInterface.OnShowListener showListener = new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
ApplicationMode mode = saveNewProfile();
saveProfileBackup(mode, exportListener);
}
});
}
};
showNewProfileSavingDialog(showListener);
} else { } else {
ApplicationMode mode = getSelectedAppMode(); ApplicationMode mode = getSelectedAppMode();
mode.setParentAppMode(changedProfile.parent); mode.setParentAppMode(changedProfile.parent);
@ -743,54 +757,25 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} }
} }
private void showNewProfileSavingDialog() { private void showNewProfileSavingDialog(@Nullable DialogInterface.OnShowListener showListener) {
ProgressDialog progress = new ProgressDialog(getContext()); if (progress != null) {
progress.setMessage(getString(R.string.saving_new_profile));
progress.setCancelable(false);
final WeakReference<ProgressDialog> progressRef = new WeakReference<>(progress);
final SettingsHelper.SettingsExportListener listener = new SettingsHelper.SettingsExportListener() {
@Override
public void onSettingsExportFinished(@NonNull File file, boolean succeed) {
ProgressDialog progress = progressRef.get();
if (progress != null && progress.isShowing()) {
progress.dismiss(); progress.dismiss();
} }
if (succeed) { progress = new ProgressDialog(getContext());
profileSaved(); progress.setMessage(getString(R.string.saving_new_profile));
} else { progress.setCancelable(false);
app.showToastMessage(R.string.profile_backup_failed); progress.setOnShowListener(showListener);
}
}
};
progress.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
ApplicationMode mode = saveNewProfile();
saveProfileBackup(mode, listener);
}
});
}
});
progress.show(); progress.show();
} }
private void profileSaved() { private void checkSavingProfile() {
FragmentActivity activity = getActivity(); File file = ConfigureProfileFragment.getBackupFileForCustomMode(app, changedProfile.stringKey);
if (activity != null) { boolean fileExporting = app.getSettingsHelper().isFileExporting(file);
profile = changedProfile; if (fileExporting) {
if (isNewProfile) { showNewProfileSavingDialog(null);
ProfileAppearanceFragment.this.dismiss(); app.getSettingsHelper().updateExportListener(file, exportListener);
BaseSettingsFragment.showInstance(activity, SettingsScreenType.CONFIGURE_PROFILE, } else if (isNewProfile) {
ApplicationMode.valueOfStringKey(changedProfile.stringKey, null)); customProfileSaved();
} else {
activity.onBackPressed();
}
} }
} }