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

remotes/origin/devel
yattoz 2019-12-16 22:39:07 +01:00
parent 5920c8cd21
commit ef83c693d0
7 changed files with 36 additions and 30 deletions

View File

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

View File

@ -2,10 +2,23 @@ package fr.forum_thalie.tsumugi
import android.content.SharedPreferences
import android.content.res.ColorStateList
import kotlin.collections.ArrayList
const val tag = "fr.forum_thalie.tsumugi"
const val noConnectionValue = "No connection"
const val noConnectionValue = "Arrêté."
const val streamDownValue = "Tsumugi est HS !"
val weekdaysArray : Array<String> = arrayOf( "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche")
val weekdays = ArrayList<String>().apply { weekdaysArray.forEach { add(it) } }
val weekdaysSundayFirst = ArrayList<String>().apply {
weekdays.forEach {
add(it)
}
val lastDay = last()
removeAt(size - 1)
add(0, lastDay)
}
var colorBlue: Int = 0
var colorWhited: Int = 0
var colorGreenList: ColorStateList? = ColorStateList.valueOf(0)

View File

@ -10,6 +10,7 @@ import fr.forum_thalie.tsumugi.BootBroadcastReceiver
import androidx.preference.PreferenceManager
import fr.forum_thalie.tsumugi.*
import java.util.*
import kotlin.collections.ArrayList
class RadioAlarm {
@ -38,7 +39,7 @@ class RadioAlarm {
val alarmManager = c.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarmIntent = Intent(c, BootBroadcastReceiver::class.java).let { intent ->
intent.putExtra("action", "fr.forum_thalie.tsumugi.${Actions.PLAY_OR_FALLBACK.name}")
intent.putExtra("action", "$tag.${Actions.PLAY_OR_FALLBACK.name}")
PendingIntent.getBroadcast(c, 0, intent, 0)
}
val showIntent = Intent(c, ParametersActivity::class.java).let { intent ->
@ -60,7 +61,7 @@ class RadioAlarm {
val hourOfDay = time / 60 //time is in minutes
val minute = time % 60
val fullWeekOrdered = arrayListOf("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
val fullWeekOrdered = weekdaysSundayFirst //Sunday --> Saturday
val selectedDays = arrayListOf<Int>()
for (item in fullWeekOrdered)
{
@ -100,7 +101,7 @@ class RadioAlarm {
{
val alarmManager = c.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarmIntent = Intent(c, BootBroadcastReceiver::class.java).let { intent ->
intent.putExtra("action", "fr.forum_thalie.tsumugi.${Actions.PLAY_OR_FALLBACK.name}")
intent.putExtra("action", "$tag.${Actions.PLAY_OR_FALLBACK.name}")
PendingIntent.getBroadcast(c, 0, intent, 0)
}
val showIntent = Intent(c, ParametersActivity::class.java).let { intent ->

View File

@ -5,6 +5,7 @@ import android.os.Bundle
import android.util.Log
import androidx.core.content.edit
import androidx.preference.*
import fr.forum_thalie.tsumugi.*
import fr.forum_thalie.tsumugi.R
import fr.forum_thalie.tsumugi.alarm.RadioAlarm
import java.util.*
@ -18,6 +19,9 @@ class AlarmFragment : PreferenceFragmentCompat() {
val alarmDays = findPreference<MultiSelectListPreference>("alarmDays")
val snoozeDuration = findPreference<ListPreference>("snoozeDuration")
alarmDays?.entries = weekdaysArray
alarmDays?.entryValues = weekdaysArray
alarmDays?.setDefaultValue(weekdaysArray)
fun updateIsWakingUpSummary(preference: SwitchPreferenceCompat?, newValue: Boolean? = true, forceTime: Int? = null, forceDays: Set<String>? = null)
{
@ -26,15 +30,13 @@ class AlarmFragment : PreferenceFragmentCompat() {
calendar.timeInMillis = dateLong
if (newValue == true && calendar.timeInMillis > 0)
{
val fullWeekOrdered = arrayListOf("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
preference?.summary = "Next alarm on ${fullWeekOrdered[calendar.get(Calendar.DAY_OF_WEEK) - 1]} " +
"at ${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)}"
val fullWeekOrdered = weekdaysSundayFirst
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)}"
} else if (newValue == true)
preference?.summary = "Select at least one day"
preference?.summary = getString(R.string.select_one_day)
else
{
preference?.summary = "No alarm set"
preference?.summary = getString(R.string.no_alarm_set)
}
}
@ -76,17 +78,15 @@ class AlarmFragment : PreferenceFragmentCompat() {
fun updateDays(preference : MultiSelectListPreference?, newValue : Set<String>?)
{
Log.d(tag, newValue.toString())
val listOfDays : String
val fullWeek = context!!.resources.getStringArray(R.array.weekdays).toSet()
val workingWeek = context!!.resources.getStringArray(R.array.weekdays).toSet().minusElement("Saturday").minusElement("Sunday")
listOfDays = when (newValue) {
val fullWeek = weekdays.toSet()
val workingWeek = weekdays.toSet().minusElement(weekdays.last()).minusElement(weekdays.elementAt(weekdays.size - 2))
val listOfDays = when (newValue) {
fullWeek -> context!!.getString(R.string.every_day)
workingWeek -> context!!.getString(R.string.working_days)
else -> {
// build ORDERED LIST of days... I don't know why the original one is in shambles!!
val fullWeekOrdered = arrayListOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
val selectedDays = arrayListOf<String>()
val fullWeekOrdered = weekdays
val selectedDays = ArrayList<String>()
for (item in fullWeekOrdered) {
if (newValue!!.contains(item))
selectedDays.add(item)

View File

@ -1,15 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="weekdays">
<item name="monday">Monday</item>
<item name="tuesday">Tuesday</item>
<item name="wednesday">Wednesday</item>
<item name="thursday">Thursday</item>
<item name="friday">Friday</item>
<item name="saturday">Saturday</item>
<item name="sunday">Sunday</item>
</string-array>
<string-array name="snoozeValues">
<item name="0">@string/disable</item>
<item name="1">1</item>

View File

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

View File

@ -23,9 +23,7 @@
app:iconSpaceReserved="false"
app:title="Select days of the week"
app:singleLineTitle="false"
android:entries="@array/weekdays"
android:entryValues="@array/weekdays"
android:defaultValue="@array/weekdays"
/>
<ListPreference