|
@@ -47,7 +47,7 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
47
|
47
|
|
48
|
48
|
fun updateIsWakingUpSummary(preference: SwitchPreferenceCompat?, newValue: Boolean? = true, forceTime: Int? = null, forceDays: Set<String>? = null)
|
49
|
49
|
{
|
50
|
|
- val dateLong = RadioAlarm.instance.findNextAlarmTime(context!!, forceTime, forceDays)
|
|
50
|
+ val dateLong = RadioAlarm.instance.findNextAlarmTime(requireContext(), forceTime, forceDays)
|
51
|
51
|
val calendar = Calendar.getInstance()
|
52
|
52
|
calendar.timeInMillis = dateLong
|
53
|
53
|
if (newValue == true && calendar.timeInMillis > 0)
|
|
@@ -65,14 +65,14 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
65
|
65
|
|
66
|
66
|
val hourOfDayDefault = 7
|
67
|
67
|
val minuteDefault = 0
|
68
|
|
- if (!PreferenceManager.getDefaultSharedPreferences(context!!).contains("alarmTimeFromMidnight"))
|
|
68
|
+ if (!PreferenceManager.getDefaultSharedPreferences(requireContext()).contains("alarmTimeFromMidnight"))
|
69
|
69
|
{
|
70
|
|
- PreferenceManager.getDefaultSharedPreferences(context!!).edit {
|
|
70
|
+ PreferenceManager.getDefaultSharedPreferences(requireContext()).edit {
|
71
|
71
|
putInt("alarmTimeFromMidnight", (60*hourOfDayDefault+minuteDefault))
|
72
|
72
|
commit()
|
73
|
73
|
}
|
74
|
74
|
}
|
75
|
|
- val time = PreferenceManager.getDefaultSharedPreferences(context!!).getInt("alarmTimeFromMidnight", (60*hourOfDayDefault+minuteDefault))
|
|
75
|
+ val time = PreferenceManager.getDefaultSharedPreferences(requireContext()).getInt("alarmTimeFromMidnight", (60*hourOfDayDefault+minuteDefault))
|
76
|
76
|
val hourOfDay = time / 60
|
77
|
77
|
val minute = time % 60
|
78
|
78
|
timeSet?.summary = "${if (hourOfDay < 10) "0" else ""}$hourOfDay:${if (minute < 10) "0" else ""}$minute"
|
|
@@ -80,16 +80,16 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
80
|
80
|
|
81
|
81
|
timeSet?.setOnPreferenceClickListener {
|
82
|
82
|
val timePickerOnTimeSetListener = TimePickerDialog.OnTimeSetListener { _, hourOfDay, minute ->
|
83
|
|
- PreferenceManager.getDefaultSharedPreferences(context!!).edit {
|
|
83
|
+ PreferenceManager.getDefaultSharedPreferences(requireContext()).edit {
|
84
|
84
|
putInt("alarmTimeFromMidnight", (60*hourOfDay+minute))
|
85
|
85
|
commit()
|
86
|
86
|
}
|
87
|
87
|
timeSet.summary = "${if (hourOfDay < 10) "0" else ""}$hourOfDay:${if (minute < 10) "0" else ""}$minute"
|
88
|
|
- RadioAlarm.instance.cancelAlarm(context!!)
|
89
|
|
- RadioAlarm.instance.setNextAlarm(context!!, isForce = true, forceTime = hourOfDay*60+minute)
|
|
88
|
+ RadioAlarm.instance.cancelAlarm(requireContext())
|
|
89
|
+ RadioAlarm.instance.setNextAlarm(requireContext(), isForce = true, forceTime = hourOfDay*60+minute)
|
90
|
90
|
updateIsWakingUpSummary(isWakingUp, isWakingUp?.isChecked, forceTime = hourOfDay*60+minute)
|
91
|
91
|
}
|
92
|
|
- val timeNew = PreferenceManager.getDefaultSharedPreferences(context!!).getInt("alarmTimeFromMidnight", 7*60)
|
|
92
|
+ val timeNew = PreferenceManager.getDefaultSharedPreferences(requireContext()).getInt("alarmTimeFromMidnight", 7*60)
|
93
|
93
|
val hourOfDayNew = timeNew / 60
|
94
|
94
|
val minuteNew = timeNew % 60
|
95
|
95
|
val timePicker = TimePickerDialog(context, timePickerOnTimeSetListener, hourOfDayNew, minuteNew, true)
|
|
@@ -103,8 +103,8 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
103
|
103
|
val fullWeek = weekdays.toSet()
|
104
|
104
|
val workingWeek = weekdays.toSet().minusElement(weekdays.last()).minusElement(weekdays.elementAt(weekdays.size - 2))
|
105
|
105
|
val listOfDays = when (newValue) {
|
106
|
|
- fullWeek -> context!!.getString(R.string.every_day)
|
107
|
|
- workingWeek -> context!!.getString(R.string.working_days)
|
|
106
|
+ fullWeek -> requireContext().getString(R.string.every_day)
|
|
107
|
+ workingWeek -> requireContext().getString(R.string.working_days)
|
108
|
108
|
else -> {
|
109
|
109
|
// build ORDERED LIST of days... I don't know why the original one is in shambles!!
|
110
|
110
|
val fullWeekOrdered = weekdays
|
|
@@ -119,12 +119,12 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
119
|
119
|
preference?.summary = listOfDays
|
120
|
120
|
}
|
121
|
121
|
|
122
|
|
- updateDays(alarmDays, PreferenceManager.getDefaultSharedPreferences(context).getStringSet("alarmDays", setOf()))
|
|
122
|
+ updateDays(alarmDays, PreferenceManager.getDefaultSharedPreferences(requireContext()).getStringSet("alarmDays", setOf()))
|
123
|
123
|
alarmDays?.setOnPreferenceChangeListener { preference, newValue ->
|
124
|
124
|
@Suppress("UNCHECKED_CAST")
|
125
|
125
|
updateDays(preference as MultiSelectListPreference, newValue as Set<String>)
|
126
|
|
- RadioAlarm.instance.cancelAlarm(context!!)
|
127
|
|
- RadioAlarm.instance.setNextAlarm(context!!, isForce = true, forceDays = newValue)
|
|
126
|
+ RadioAlarm.instance.cancelAlarm(requireContext())
|
|
127
|
+ RadioAlarm.instance.setNextAlarm(requireContext(), isForce = true, forceDays = newValue)
|
128
|
128
|
updateIsWakingUpSummary(isWakingUp, isWakingUp?.isChecked, forceDays = newValue)
|
129
|
129
|
true
|
130
|
130
|
}
|
|
@@ -133,9 +133,9 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
133
|
133
|
|
134
|
134
|
isWakingUp?.setOnPreferenceChangeListener { _, newValue ->
|
135
|
135
|
if (newValue as Boolean)
|
136
|
|
- RadioAlarm.instance.setNextAlarm(context!!, isForce = true)
|
|
136
|
+ RadioAlarm.instance.setNextAlarm(requireContext(), isForce = true)
|
137
|
137
|
else
|
138
|
|
- RadioAlarm.instance.cancelAlarm(context!!)
|
|
138
|
+ RadioAlarm.instance.cancelAlarm(requireContext())
|
139
|
139
|
timeSet?.isEnabled = newValue
|
140
|
140
|
alarmDays?.isEnabled = newValue
|
141
|
141
|
snoozeDuration?.isEnabled = newValue
|