Fixed an issue where the state of several input fields was being reset upon orientation change.

pull/559/head
Bryan de Ridder 6 years ago
parent 58d8c799ce
commit 6bf7822b92

@ -52,6 +52,12 @@ public class EditHabitDialog extends AppCompatDialogFragment
private static final String WEEKDAY_PICKER_TAG = "weekdayPicker"; private static final String WEEKDAY_PICKER_TAG = "weekdayPicker";
private static final String KEY_NUMERATOR = "numerator";
private static final String KEY_DENOMINATOR = "denominator";
private static final String KEY_DESCRIPTION = "description";
protected Habit originalHabit; protected Habit originalHabit;
protected Preferences prefs; protected Preferences prefs;
@ -109,7 +115,7 @@ public class EditHabitDialog extends AppCompatDialogFragment
originalHabit = parseHabitFromArguments(); originalHabit = parseHabitFromArguments();
getDialog().setTitle(getTitle()); getDialog().setTitle(getTitle());
populateForm(); populateForm(savedInstanceState);
setupReminderController(); setupReminderController();
setupNameController(); setupNameController();
@ -213,7 +219,7 @@ public class EditHabitDialog extends AppCompatDialogFragment
return habit; return habit;
} }
private void populateForm() private void populateForm(Bundle bundle)
{ {
Habit habit = modelFactory.buildHabit(); Habit habit = modelFactory.buildHabit();
habit.setFrequency(Frequency.DAILY); habit.setFrequency(Frequency.DAILY);
@ -222,6 +228,8 @@ public class EditHabitDialog extends AppCompatDialogFragment
if (originalHabit != null) habit.copyFrom(originalHabit); if (originalHabit != null) habit.copyFrom(originalHabit);
if (bundle != null) populateFormWithBundle(bundle, habit);
if (habit.isNumerical()) frequencyPanel.setVisibility(GONE); if (habit.isNumerical()) frequencyPanel.setVisibility(GONE);
else targetPanel.setVisibility(GONE); else targetPanel.setVisibility(GONE);
@ -232,6 +240,15 @@ public class EditHabitDialog extends AppCompatDialogFragment
if (habit.hasReminder()) reminderPanel.setReminder(habit.getReminder()); if (habit.hasReminder()) reminderPanel.setReminder(habit.getReminder());
} }
private void populateFormWithBundle(Bundle bundle, Habit habit)
{
int numerator = bundle.getInt(KEY_NUMERATOR);
int denominator = bundle.getInt(KEY_DENOMINATOR);
String description = bundle.getString(KEY_DESCRIPTION);
habit.setFrequency(new Frequency(numerator, denominator));
if (description != null) habit.setDescription(description);
}
private void setupNameController() private void setupNameController()
{ {
namePanel.setController(new NameDescriptionPanel.Controller() namePanel.setController(new NameDescriptionPanel.Controller()
@ -286,4 +303,12 @@ public class EditHabitDialog extends AppCompatDialogFragment
.findFragmentByTag(WEEKDAY_PICKER_TAG); .findFragmentByTag(WEEKDAY_PICKER_TAG);
if(dialog != null) dialog.setListener(reminderPanel); if(dialog != null) dialog.setListener(reminderPanel);
} }
@Override
public void onSaveInstanceState(@NonNull Bundle outState)
{
outState.putString(KEY_DESCRIPTION, namePanel.getDescription());
outState.putInt(KEY_NUMERATOR, frequencyPanel.getFrequency().getNumerator());
outState.putInt(KEY_DENOMINATOR, frequencyPanel.getFrequency().getDenominator());
}
} }

Loading…
Cancel
Save