mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
fixed issue where weekly picker dialog isn't being restored on rotation
squash! fixed issue where weekly picker dialog isn't being restored on rotation
This commit is contained in:
@@ -22,6 +22,8 @@ package org.isoron.uhabits.activities.common.dialogs;
|
||||
import android.app.*;
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.*;
|
||||
|
||||
@@ -38,6 +40,7 @@ public class WeekdayPickerDialog extends AppCompatDialogFragment implements
|
||||
DialogInterface.OnMultiChoiceClickListener,
|
||||
DialogInterface.OnClickListener
|
||||
{
|
||||
private static final String KEY_SELECTED_DAYS = "selectedDays";
|
||||
private boolean[] selectedDays;
|
||||
|
||||
private OnWeekdaysPickedListener listener;
|
||||
@@ -48,6 +51,21 @@ public class WeekdayPickerDialog extends AppCompatDialogFragment implements
|
||||
selectedDays[which] = isChecked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if(savedInstanceState != null){
|
||||
selectedDays = savedInstanceState.getBooleanArray(KEY_SELECTED_DAYS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBooleanArray(KEY_SELECTED_DAYS, selectedDays);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
|
||||
@@ -23,8 +23,10 @@ import android.app.Dialog;
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.*;
|
||||
import android.text.format.*;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
|
||||
import com.android.datetimepicker.time.*;
|
||||
@@ -47,6 +49,8 @@ public class EditHabitDialog extends AppCompatDialogFragment
|
||||
public static final String BUNDLE_HABIT_ID = "habitId";
|
||||
|
||||
public static final String BUNDLE_HABIT_TYPE = "habitType";
|
||||
public static final String EDIT_HABIT_TAG = "editHabit";
|
||||
private static final String WEEKDAY_PICKER_TAG = "weekdayPicker";
|
||||
|
||||
protected Habit originalHabit;
|
||||
|
||||
@@ -109,6 +113,8 @@ public class EditHabitDialog extends AppCompatDialogFragment
|
||||
setupReminderController();
|
||||
setupNameController();
|
||||
|
||||
restoreChildFragmentListeners();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -268,8 +274,21 @@ public class EditHabitDialog extends AppCompatDialogFragment
|
||||
WeekdayPickerDialog dialog = new WeekdayPickerDialog();
|
||||
dialog.setListener(reminderPanel);
|
||||
dialog.setSelectedDays(currentDays);
|
||||
dialog.show(getFragmentManager(), "weekdayPicker");
|
||||
dialog.show(getChildFragmentManager(), WEEKDAY_PICKER_TAG);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to restore any child fragment listeners on rotation/config change.
|
||||
*
|
||||
* Can possibly be refactored to use ViewModel/
|
||||
*/
|
||||
private void restoreChildFragmentListeners() {
|
||||
final WeekdayPickerDialog weekdayPickerDialog =
|
||||
(WeekdayPickerDialog) getChildFragmentManager().findFragmentByTag(WEEKDAY_PICKER_TAG);
|
||||
if(weekdayPickerDialog != null) {
|
||||
weekdayPickerDialog.setListener(reminderPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user