Merge branch 'edi_habit_crash' into dev

pull/542/head
Alinson S. Xavier 6 years ago
commit b9c9d6852a

@ -19,17 +19,19 @@
package org.isoron.uhabits.activities.common.dialogs;
import android.app.*;
import android.content.*;
import android.os.*;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.*;
import android.support.v7.app.AppCompatDialogFragment;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.utils.*;
import org.isoron.uhabits.R;
import org.isoron.uhabits.core.models.WeekdayList;
import org.isoron.uhabits.core.utils.DateUtils;
import java.util.*;
import java.util.Calendar;
/**
* Dialog that allows the user to pick one or more days of the week.
@ -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)
{

@ -19,7 +19,7 @@
package org.isoron.uhabits.activities.habits.edit;
import android.app.Dialog;
import android.app.*;
import android.content.*;
import android.os.*;
import android.support.annotation.*;
@ -27,7 +27,7 @@ import android.support.v7.app.*;
import android.text.format.*;
import android.view.*;
import com.android.datetimepicker.time.*;
import com.android.datetimepicker.time.TimePickerDialog;
import org.isoron.uhabits.*;
import org.isoron.uhabits.R;
@ -40,7 +40,7 @@ import org.isoron.uhabits.core.preferences.*;
import butterknife.*;
import static android.view.View.GONE;
import static android.view.View.*;
public class EditHabitDialog extends AppCompatDialogFragment
{
@ -48,6 +48,8 @@ public class EditHabitDialog extends AppCompatDialogFragment
public static final String BUNDLE_HABIT_TYPE = "habitType";
private static final String WEEKDAY_PICKER_TAG = "weekdayPicker";
protected Habit originalHabit;
protected Preferences prefs;
@ -109,6 +111,8 @@ public class EditHabitDialog extends AppCompatDialogFragment
setupReminderController();
setupNameController();
restoreChildFragmentListeners();
return view;
}
@ -268,8 +272,16 @@ 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);
}
});
}
private void restoreChildFragmentListeners()
{
final WeekdayPickerDialog dialog =
(WeekdayPickerDialog) getChildFragmentManager()
.findFragmentByTag(WEEKDAY_PICKER_TAG);
if(dialog != null) dialog.setListener(reminderPanel);
}
}

Loading…
Cancel
Save