Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added string resource for week days #276

Merged
merged 5 commits into from Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.bnyro.clock.R
Expand Down Expand Up @@ -107,14 +108,14 @@ fun AlarmFilterSection(

@Composable
fun WeekDayRow(weekDays: List<Int>, onClickWeekDay: (List<Int>) -> Unit) {

val context = LocalContext.current
Row(
modifier = Modifier
.fillMaxWidth()
.padding(20.dp),
horizontalArrangement = Arrangement.Start
) {
val daysOfWeek = remember { AlarmHelper.getDaysOfWeekByLocale() }
val daysOfWeek = remember { AlarmHelper.getDaysOfWeekByLocale(context) }
val chosenDays = remember { weekDays.toMutableList() }

Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fun AlarmRow(alarm: Alarm, alarmModel: AlarmModel) {

else -> {
val daysOfWeek = remember {
AlarmHelper.getDaysOfWeekByLocale()
AlarmHelper.getDaysOfWeekByLocale(context)
}
daysOfWeek.forEach { (day, index) ->
val enabled = alarm.days.contains(index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -51,6 +52,7 @@ import com.bnyro.clock.util.TimeHelper
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AlarmSettingsSheet(onDismissRequest: () -> Unit, currentAlarm: Alarm, onSave: (Alarm) -> Unit) {
val context = LocalContext.current
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
var showRingtoneDialog by remember { mutableStateOf(false) }
var showSnoozeDialog by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -103,7 +105,7 @@ fun AlarmSettingsSheet(onDismissRequest: () -> Unit, currentAlarm: Alarm, onSave
horizontalArrangement = Arrangement.SpaceBetween
) {
val daysOfWeek = remember {
AlarmHelper.getDaysOfWeekByLocale()
AlarmHelper.getDaysOfWeekByLocale(context)
}

daysOfWeek.forEach { (day, index) ->
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/bnyro/clock/util/AlarmHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.annotation.RequiresApi
import com.bnyro.clock.R
import com.bnyro.clock.obj.Alarm
import com.bnyro.clock.receivers.AlarmReceiver
import com.bnyro.clock.ui.MainActivity
Expand All @@ -14,7 +15,6 @@ import java.util.GregorianCalendar

object AlarmHelper {
const val EXTRA_ID = "alarm_id"
private val availableDays = listOf("S", "M", "T", "W", "T", "F", "S")

fun enqueue(context: Context, alarm: Alarm) {
cancel(context, alarm)
Expand Down Expand Up @@ -150,7 +150,8 @@ object AlarmHelper {
* @return the days of the week mapped to an index 0-Sunday, 1-Monday, ..., 6-Saturday.
* The list order will match the user preferred days of the week order.
*/
fun getDaysOfWeekByLocale(): List<Pair<String, Int>> {
fun getDaysOfWeekByLocale(context: Context): List<Pair<String, Int>> {
val availableDays = context.resources.getStringArray(R.array.available_days).toList()
val firstDayIndex = GregorianCalendar().firstDayOfWeek - 1
val daysWithIndex = availableDays.mapIndexed { index, s -> s to index }
return daysWithIndex.subList(firstDayIndex, 7) + daysWithIndex.subList(0, firstDayIndex)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="available_days" translatable="false">
<item>@string/available_days_0</item>
<item>@string/available_days_1</item>
<item>@string/available_days_2</item>
<item>@string/available_days_3</item>
<item>@string/available_days_4</item>
<item>@string/available_days_5</item>
<item>@string/available_days_6</item>
</string-array>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,11 @@
<item quantity="other">%d minutes</item>
</plurals>

<string name="available_days_0">S</string>
<string name="available_days_1">M</string>
<string name="available_days_2">T</string>
<string name="available_days_3">W</string>
<string name="available_days_4">T</string>
<string name="available_days_5">F</string>
<string name="available_days_6">S</string>
</resources>
Loading