소스 검색

refactored weekday list to keep in a single place all days names.

yattoz 4 년 전
부모
커밋
ef83c693d0

+ 1 - 1
app/src/main/java/fr/forum_thalie/tsumugi/BootBroadcastReceiver.kt 파일 보기

@@ -20,7 +20,7 @@ class BootBroadcastReceiver : BroadcastReceiver(){
20 20
             RadioAlarm.instance.setNextAlarm(context) // schedule next alarm
21 21
         }
22 22
 
23
-        if (arg1.getStringExtra("action") == "fr.forum_thalie.tsumugi.${Actions.PLAY_OR_FALLBACK.name}" )
23
+        if (arg1.getStringExtra("action") == "$tag.${Actions.PLAY_OR_FALLBACK.name}" )
24 24
         {
25 25
             RadioAlarm.instance.setNextAlarm(context) // schedule next alarm
26 26
             if (PlayerStore.instance.streamerName.value.isNullOrBlank())

+ 14 - 1
app/src/main/java/fr/forum_thalie/tsumugi/Values.kt 파일 보기

@@ -2,10 +2,23 @@ package fr.forum_thalie.tsumugi
2 2
 
3 3
 import android.content.SharedPreferences
4 4
 import android.content.res.ColorStateList
5
+import kotlin.collections.ArrayList
5 6
 
6 7
 const val tag = "fr.forum_thalie.tsumugi"
7
-const val noConnectionValue = "No connection"
8
+const val noConnectionValue = "Arrêté."
8 9
 const val streamDownValue = "Tsumugi est HS !"
10
+val weekdaysArray : Array<String> = arrayOf( "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche")
11
+
12
+val weekdays = ArrayList<String>().apply { weekdaysArray.forEach { add(it) } }
13
+val weekdaysSundayFirst = ArrayList<String>().apply {
14
+    weekdays.forEach {
15
+        add(it)
16
+    }
17
+    val lastDay = last()
18
+    removeAt(size - 1)
19
+    add(0, lastDay)
20
+}
21
+
9 22
 var colorBlue: Int = 0
10 23
 var colorWhited: Int = 0
11 24
 var colorGreenList: ColorStateList? = ColorStateList.valueOf(0)

+ 4 - 3
app/src/main/java/fr/forum_thalie/tsumugi/alarm/RadioAlarm.kt 파일 보기

@@ -10,6 +10,7 @@ import fr.forum_thalie.tsumugi.BootBroadcastReceiver
10 10
 import androidx.preference.PreferenceManager
11 11
 import fr.forum_thalie.tsumugi.*
12 12
 import java.util.*
13
+import kotlin.collections.ArrayList
13 14
 
14 15
 class RadioAlarm {
15 16
 
@@ -38,7 +39,7 @@ class RadioAlarm {
38 39
 
39 40
         val alarmManager = c.getSystemService(Context.ALARM_SERVICE) as AlarmManager
40 41
         alarmIntent = Intent(c, BootBroadcastReceiver::class.java).let { intent ->
41
-            intent.putExtra("action", "fr.forum_thalie.tsumugi.${Actions.PLAY_OR_FALLBACK.name}")
42
+            intent.putExtra("action", "$tag.${Actions.PLAY_OR_FALLBACK.name}")
42 43
             PendingIntent.getBroadcast(c, 0, intent, 0)
43 44
         }
44 45
         val showIntent = Intent(c, ParametersActivity::class.java).let { intent ->
@@ -60,7 +61,7 @@ class RadioAlarm {
60 61
         val hourOfDay = time / 60 //time is in minutes
61 62
         val minute = time % 60
62 63
 
63
-        val fullWeekOrdered = arrayListOf("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
64
+        val fullWeekOrdered = weekdaysSundayFirst //Sunday --> Saturday
64 65
         val selectedDays = arrayListOf<Int>()
65 66
         for (item in fullWeekOrdered)
66 67
         {
@@ -100,7 +101,7 @@ class RadioAlarm {
100 101
         {
101 102
             val alarmManager = c.getSystemService(Context.ALARM_SERVICE) as AlarmManager
102 103
             alarmIntent = Intent(c, BootBroadcastReceiver::class.java).let { intent ->
103
-                intent.putExtra("action", "fr.forum_thalie.tsumugi.${Actions.PLAY_OR_FALLBACK.name}")
104
+                intent.putExtra("action", "$tag.${Actions.PLAY_OR_FALLBACK.name}")
104 105
                 PendingIntent.getBroadcast(c, 0, intent, 0)
105 106
             }
106 107
             val showIntent = Intent(c, ParametersActivity::class.java).let { intent ->

+ 13 - 13
app/src/main/java/fr/forum_thalie/tsumugi/preferences/AlarmFragment.kt 파일 보기

@@ -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)

+ 0 - 9
app/src/main/res/values/arrays.xml 파일 보기

@@ -1,15 +1,6 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <resources>
3 3
 
4
-    <string-array name="weekdays">
5
-        <item name="monday">Monday</item>
6
-        <item name="tuesday">Tuesday</item>
7
-        <item name="wednesday">Wednesday</item>
8
-        <item name="thursday">Thursday</item>
9
-        <item name="friday">Friday</item>
10
-        <item name="saturday">Saturday</item>
11
-        <item name="sunday">Sunday</item>
12
-    </string-array>
13 4
     <string-array name="snoozeValues">
14 5
         <item name="0">@string/disable</item>
15 6
         <item name="1">1</item>

+ 3 - 0
app/src/main/res/values/strings.xml 파일 보기

@@ -44,5 +44,8 @@
44 44
     <string name="website_url">https://tsumugi.forum-thalie.fr/</string>
45 45
     <string name="rss_url">https://tsumugi.forum-thalie.fr/?feed=rss2</string>
46 46
     <string name="planning_url">ADD SOME URL HERE...</string>
47
+    <string name="select_one_day">Select at least one day</string>
48
+    <string name="no_alarm_set">No alarm set</string>
49
+    <string name="next_alarm">Next alarm:</string>
47 50
 
48 51
 </resources>

+ 1 - 3
app/src/main/res/xml/alarm_preferences.xml 파일 보기

@@ -23,9 +23,7 @@
23 23
         app:iconSpaceReserved="false"
24 24
         app:title="Select days of the week"
25 25
         app:singleLineTitle="false"
26
-        android:entries="@array/weekdays"
27
-        android:entryValues="@array/weekdays"
28
-        android:defaultValue="@array/weekdays"
26
+
29 27
         />
30 28
 
31 29
     <ListPreference