Skip to content

Commit 14468e5

Browse files
wbrunetteclarlars
authored andcommitted
add state based on when onSaveInstanceState is called (odk-x#146)
* add state based on when onSaveInstanceState is called * state fixes for 'dialogsClearedForFragmentShutdown' and 'onSaveInstanceStateCalled' * add logging
1 parent 45895e0 commit 14468e5

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

androidlibrary_lib/src/main/java/org/opendatakit/fragment/AlertNProgessMsgFragmentMger.java

+39-3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public enum DialogState {
101101
private boolean alertDismissActivity;
102102
private boolean progressDismissActivity;
103103

104+
private boolean onSaveInstanceStateCalled;
105+
104106
// Make default constructor private
105107
private AlertNProgessMsgFragmentMger() {
106108
}
@@ -115,6 +117,7 @@ public AlertNProgessMsgFragmentMger(String appName, String initAlertDialogTag,
115117
progressDismissActivity) {
116118
mDialogState = DialogState.None;
117119
dialogsClearedForFragmentShutdown = false;
120+
onSaveInstanceStateCalled = false;
118121
this.appName = appName;
119122
this.alertDialogTag = initAlertDialogTag;
120123
this.progressDialogTag = initDialogProgressTag;
@@ -128,6 +131,7 @@ public AlertNProgessMsgFragmentMger(String appName, String initAlertDialogTag,
128131
* @param bundleOfState
129132
*/
130133
public void addStateToSaveStateBundle(Bundle bundleOfState) {
134+
onSaveInstanceStateCalled = true;
131135
bundleOfState.putString(APPNAME_KEY, appName);
132136
bundleOfState.putString(ALERT_TAG_KEY, alertDialogTag);
133137
bundleOfState.putString(PROGRESS_TAG_KEY, progressDialogTag);
@@ -145,6 +149,7 @@ public void addStateToSaveStateBundle(Bundle bundleOfState) {
145149
*/
146150
public void restoreDialog(FragmentManager fragmentManager, int fragmentId) {
147151
dialogsClearedForFragmentShutdown = false;
152+
onSaveInstanceStateCalled = false;
148153
switch (mDialogState) {
149154
case Progress:
150155
restoreProgressDialog(fragmentManager);
@@ -159,7 +164,7 @@ public void restoreDialog(FragmentManager fragmentManager, int fragmentId) {
159164
}
160165

161166
public boolean displayingProgressDialog() {
162-
return mDialogState == DialogState.Progress && !dialogsClearedForFragmentShutdown;
167+
return mDialogState == DialogState.Progress && !dialogsClearedForFragmentShutdown && !onSaveInstanceStateCalled;
163168
}
164169

165170
public boolean hasDialogBeenCreated() {
@@ -212,13 +217,22 @@ public void createAlertDialog(String title, String message, FragmentManager frag
212217
throw new IllegalArgumentException("FragmentManager cannot be null");
213218
}
214219

220+
if(dialogsClearedForFragmentShutdown) {
221+
throw new IllegalStateException("Getting an create" +
222+
"alert when the dialogs have been cleared for shutdown");
223+
}
224+
225+
if(onSaveInstanceStateCalled) {
226+
WebLogger.getLogger(appName).e(TAG, "Trying to create an Alert Dialog after" +
227+
"onSaveStateInstance is called");
228+
}
229+
215230
if (mDialogState == DialogState.Progress) {
216231
dismissProgressDialog(fragmentManager);
217232
}
218233

219234
currentTitle = title;
220235
currentMessage = message;
221-
dialogsClearedForFragmentShutdown = false;
222236
restoreAlertDialog(fragmentManager, fragmentId);
223237
}
224238

@@ -238,13 +252,22 @@ public void createProgressDialog(String title, String message, FragmentManager f
238252
throw new IllegalArgumentException("FragmentManager cannot be null");
239253
}
240254

255+
if(dialogsClearedForFragmentShutdown) {
256+
throw new IllegalStateException("Getting an create" +
257+
"progress when the dialogs have been cleared for shutdown");
258+
}
259+
260+
if(onSaveInstanceStateCalled) {
261+
WebLogger.getLogger(appName).e(TAG, "Trying to create an Progress Dialog after" +
262+
"onSaveStateInstance is called");
263+
}
264+
241265
if (mDialogState == DialogState.Alert) {
242266
dismissAlertDialog(fragmentManager);
243267
}
244268

245269
currentTitle = title;
246270
currentMessage = message;
247-
dialogsClearedForFragmentShutdown = false;
248271
restoreProgressDialog(fragmentManager);
249272
}
250273

@@ -262,6 +285,12 @@ public void updateProgressDialogMessage(String message, FragmentManager fragment
262285
throw new IllegalArgumentException("FragmentManager cannot be null");
263286
}
264287

288+
if(onSaveInstanceStateCalled) {
289+
// we are in the middle of shutting down, update will be lost
290+
WebLogger.getLogger(appName).e(TAG, "Trying to Update an Progress Dialog after" +
291+
"onSaveStateInstance is called");
292+
}
293+
265294
if(dialogsClearedForFragmentShutdown) {
266295
throw new IllegalStateException("Getting an update when the dialogs have been cleared "
267296
+ "for shutdown, should check displayingProgressDialog()");
@@ -295,6 +324,13 @@ public void updateProgressDialogMessage(String message, int progressStep, int ma
295324
throw new IllegalArgumentException("FragmentManager cannot be null");
296325
}
297326

327+
if(onSaveInstanceStateCalled) {
328+
// we are in the middle of shutting down, update will be lost
329+
WebLogger.getLogger(appName).e(TAG, "Trying to Update an Progress Dialog after" +
330+
"onSaveStateInstance is called");
331+
return;
332+
}
333+
298334
if(dialogsClearedForFragmentShutdown) {
299335
throw new IllegalStateException("Getting an update when the dialogs have been cleared "
300336
+ "for shutdown, should check displayingProgressDialog()");

0 commit comments

Comments
 (0)