|
@@ -5,6 +5,7 @@ import android.os.Bundle
|
5
|
5
|
import android.util.Log
|
6
|
6
|
import androidx.core.content.edit
|
7
|
7
|
import androidx.preference.*
|
|
8
|
+import fr.forum_thalie.tsumugi.*
|
8
|
9
|
import fr.forum_thalie.tsumugi.R
|
9
|
10
|
import fr.forum_thalie.tsumugi.alarm.RadioAlarm
|
10
|
11
|
import java.util.*
|
|
@@ -18,6 +19,9 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
18
|
19
|
val alarmDays = findPreference<MultiSelectListPreference>("alarmDays")
|
19
|
20
|
val snoozeDuration = findPreference<ListPreference>("snoozeDuration")
|
20
|
21
|
|
|
22
|
+ alarmDays?.entries = weekdaysArray
|
|
23
|
+ alarmDays?.entryValues = weekdaysArray
|
|
24
|
+ alarmDays?.setDefaultValue(weekdaysArray)
|
21
|
25
|
|
22
|
26
|
fun updateIsWakingUpSummary(preference: SwitchPreferenceCompat?, newValue: Boolean? = true, forceTime: Int? = null, forceDays: Set<String>? = null)
|
23
|
27
|
{
|
|
@@ -26,15 +30,13 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
26
|
30
|
calendar.timeInMillis = dateLong
|
27
|
31
|
if (newValue == true && calendar.timeInMillis > 0)
|
28
|
32
|
{
|
29
|
|
- val fullWeekOrdered = arrayListOf("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
|
30
|
|
- preference?.summary = "Next alarm on ${fullWeekOrdered[calendar.get(Calendar.DAY_OF_WEEK) - 1]} " +
|
31
|
|
- "at ${if (calendar.get(Calendar.HOUR_OF_DAY) < 10) "0" else ""}${calendar.get(Calendar.HOUR_OF_DAY)}" +
|
32
|
|
- ":${if (calendar.get(Calendar.MINUTE) < 10) "0" else ""}${calendar.get(Calendar.MINUTE)}"
|
|
33
|
+ val fullWeekOrdered = weekdaysSundayFirst
|
|
34
|
+ preference?.summary = getString(R.string.next_alarm) + " ${fullWeekOrdered[calendar.get(Calendar.DAY_OF_WEEK) - 1]} ${if (calendar.get(Calendar.HOUR_OF_DAY) < 10) "0" else ""}${calendar.get(Calendar.HOUR_OF_DAY)}:${if (calendar.get(Calendar.MINUTE) < 10) "0" else ""}${calendar.get(Calendar.MINUTE)}"
|
33
|
35
|
} else if (newValue == true)
|
34
|
|
- preference?.summary = "Select at least one day"
|
|
36
|
+ preference?.summary = getString(R.string.select_one_day)
|
35
|
37
|
else
|
36
|
38
|
{
|
37
|
|
- preference?.summary = "No alarm set"
|
|
39
|
+ preference?.summary = getString(R.string.no_alarm_set)
|
38
|
40
|
}
|
39
|
41
|
}
|
40
|
42
|
|
|
@@ -76,17 +78,15 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
76
|
78
|
|
77
|
79
|
fun updateDays(preference : MultiSelectListPreference?, newValue : Set<String>?)
|
78
|
80
|
{
|
79
|
|
- Log.d(tag, newValue.toString())
|
80
|
|
- val listOfDays : String
|
81
|
|
- val fullWeek = context!!.resources.getStringArray(R.array.weekdays).toSet()
|
82
|
|
- val workingWeek = context!!.resources.getStringArray(R.array.weekdays).toSet().minusElement("Saturday").minusElement("Sunday")
|
83
|
|
- listOfDays = when (newValue) {
|
|
81
|
+ val fullWeek = weekdays.toSet()
|
|
82
|
+ val workingWeek = weekdays.toSet().minusElement(weekdays.last()).minusElement(weekdays.elementAt(weekdays.size - 2))
|
|
83
|
+ val listOfDays = when (newValue) {
|
84
|
84
|
fullWeek -> context!!.getString(R.string.every_day)
|
85
|
85
|
workingWeek -> context!!.getString(R.string.working_days)
|
86
|
86
|
else -> {
|
87
|
87
|
// build ORDERED LIST of days... I don't know why the original one is in shambles!!
|
88
|
|
- val fullWeekOrdered = arrayListOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
|
89
|
|
- val selectedDays = arrayListOf<String>()
|
|
88
|
+ val fullWeekOrdered = weekdays
|
|
89
|
+ val selectedDays = ArrayList<String>()
|
90
|
90
|
for (item in fullWeekOrdered) {
|
91
|
91
|
if (newValue!!.contains(item))
|
92
|
92
|
selectedDays.add(item)
|