mirror of
https://github.com/FossifyOrg/Clock.git
synced 2026-05-19 04:24:44 -04:00
Added choosing first day of the week (#19(
This commit is contained in:
@@ -43,6 +43,7 @@ class MainActivity : SimpleActivity() {
|
||||
initFragments()
|
||||
setupTabs()
|
||||
updateWidgets()
|
||||
setFirstDayOfTheWeek()
|
||||
|
||||
getEnabledAlarms { enabledAlarms ->
|
||||
if (enabledAlarms.isNullOrEmpty()) {
|
||||
@@ -298,4 +299,13 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
|
||||
}
|
||||
|
||||
private fun setFirstDayOfTheWeek() {
|
||||
// check existing config.isSundayFirst to migrate setting value
|
||||
if (config.isSundayFirst) {
|
||||
config.firstDayOfWeek = 6
|
||||
// revert old setting to not run this code anymore
|
||||
config.isSundayFirst = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,13 @@ import org.fossify.clock.databinding.ActivitySettingsBinding
|
||||
import org.fossify.clock.extensions.config
|
||||
import org.fossify.clock.helpers.DEFAULT_MAX_ALARM_REMINDER_SECS
|
||||
import org.fossify.clock.helpers.DEFAULT_MAX_TIMER_REMINDER_SECS
|
||||
import org.fossify.commons.dialogs.RadioGroupDialog
|
||||
import org.fossify.commons.extensions.*
|
||||
import org.fossify.commons.helpers.IS_CUSTOMIZING_COLORS
|
||||
import org.fossify.commons.helpers.MINUTE_SECONDS
|
||||
import org.fossify.commons.helpers.NavigationIcon
|
||||
import org.fossify.commons.helpers.isTiramisuPlus
|
||||
import org.fossify.commons.models.RadioItem
|
||||
import java.util.Locale
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
@@ -35,7 +37,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
setupUseEnglish()
|
||||
setupLanguage()
|
||||
setupPreventPhoneFromSleeping()
|
||||
setupSundayFirst()
|
||||
setupStartWeekOn()
|
||||
setupAlarmMaxReminder()
|
||||
setupUseSameSnooze()
|
||||
setupSnoozeTime()
|
||||
@@ -94,11 +96,24 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSundayFirst() {
|
||||
binding.settingsSundayFirst.isChecked = config.isSundayFirst
|
||||
binding.settingsSundayFirstHolder.setOnClickListener {
|
||||
binding.settingsSundayFirst.toggle()
|
||||
config.isSundayFirst = binding.settingsSundayFirst.isChecked
|
||||
private fun setupStartWeekOn() {
|
||||
val items = arrayListOf(
|
||||
RadioItem(6, getString(org.fossify.commons.R.string.sunday)),
|
||||
RadioItem(0, getString(org.fossify.commons.R.string.monday)),
|
||||
RadioItem(1, getString(org.fossify.commons.R.string.tuesday)),
|
||||
RadioItem(2, getString(org.fossify.commons.R.string.wednesday)),
|
||||
RadioItem(3, getString(org.fossify.commons.R.string.thursday)),
|
||||
RadioItem(4, getString(org.fossify.commons.R.string.friday)),
|
||||
RadioItem(5, getString(org.fossify.commons.R.string.saturday)),
|
||||
)
|
||||
|
||||
binding.settingsStartWeekOn.text = resources.getStringArray(org.fossify.commons.R.array.week_days)[config.firstDayOfWeek]
|
||||
binding.settingsStartWeekOnHolder.setOnClickListener {
|
||||
RadioGroupDialog(this@SettingsActivity, items, config.firstDayOfWeek) { day ->
|
||||
val firstDayOfWeek = day as Int
|
||||
config.firstDayOfWeek = firstDayOfWeek
|
||||
binding.settingsStartWeekOn.text = resources.getStringArray(org.fossify.commons.R.array.week_days)[config.firstDayOfWeek]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,10 +92,7 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val onDism
|
||||
editAlarm.setText(alarm.label)
|
||||
|
||||
val dayLetters = activity.resources.getStringArray(org.fossify.commons.R.array.week_day_letters).toList() as ArrayList<String>
|
||||
val dayIndexes = arrayListOf(0, 1, 2, 3, 4, 5, 6)
|
||||
if (activity.config.isSundayFirst) {
|
||||
dayIndexes.moveLastItemToFront()
|
||||
}
|
||||
val dayIndexes = activity.orderDaysList(arrayListOf(0, 1, 2, 3, 4, 5, 6))
|
||||
|
||||
dayIndexes.forEach {
|
||||
val pow = Math.pow(2.0, it.toDouble()).toInt()
|
||||
|
||||
@@ -548,20 +548,24 @@ fun Context.getAlarmSelectedDaysString(bitMask: Int): String {
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.orderDaysList(days: List<Int>): List<Int> {
|
||||
if (config.firstDayOfWeek > 0) {
|
||||
val range = (config.firstDayOfWeek..6).toList() + (0..<config.firstDayOfWeek).toList()
|
||||
return days.slice(range)
|
||||
} else {
|
||||
return days
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.firstDayOrder(bitMask: Int): Int {
|
||||
if (bitMask == TODAY_BIT) return -2
|
||||
if (bitMask == TOMORROW_BIT) return -1
|
||||
|
||||
val dayBits = arrayListOf(MONDAY_BIT, TUESDAY_BIT, WEDNESDAY_BIT, THURSDAY_BIT, FRIDAY_BIT, SATURDAY_BIT, SUNDAY_BIT)
|
||||
val dayBits = orderDaysList(arrayListOf(MONDAY_BIT, TUESDAY_BIT, WEDNESDAY_BIT, THURSDAY_BIT, FRIDAY_BIT, SATURDAY_BIT, SUNDAY_BIT))
|
||||
|
||||
val sundayFirst = baseConfig.isSundayFirst
|
||||
if (sundayFirst) {
|
||||
dayBits.moveLastItemToFront()
|
||||
}
|
||||
|
||||
dayBits.forEach { bit ->
|
||||
dayBits.forEachIndexed { i, bit ->
|
||||
if (bitMask and bit != 0) {
|
||||
return if (bit == SUNDAY_BIT && sundayFirst) 0 else bit
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.fossify.commons.extensions.getDefaultAlarmSound
|
||||
import org.fossify.commons.extensions.getDefaultAlarmTitle
|
||||
import org.fossify.commons.helpers.BaseConfig
|
||||
import org.fossify.commons.helpers.SORT_DESCENDING
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
class Config(context: Context) : BaseConfig(context) {
|
||||
companion object {
|
||||
@@ -104,4 +106,11 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
var wasInitialWidgetSetUp: Boolean
|
||||
get() = prefs.getBoolean(WAS_INITIAL_WIDGET_SET_UP, false)
|
||||
set(wasInitialWidgetSetUp) = prefs.edit().putBoolean(WAS_INITIAL_WIDGET_SET_UP, wasInitialWidgetSetUp).apply()
|
||||
|
||||
var firstDayOfWeek: Int
|
||||
get() {
|
||||
val defaultFirstDayOfWeek = Calendar.getInstance(Locale.getDefault()).firstDayOfWeek
|
||||
return prefs.getInt(FIRST_DAY_OF_WEEK, getDayNumber(defaultFirstDayOfWeek))
|
||||
}
|
||||
set(firstDayOfWeek) = prefs.edit().putInt(FIRST_DAY_OF_WEEK, firstDayOfWeek).apply()
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ const val INCREASE_VOLUME_GRADUALLY = "increase_volume_gradually"
|
||||
const val ALARMS_SORT_BY = "alarms_sort_by"
|
||||
const val STOPWATCH_LAPS_SORT_BY = "stopwatch_laps_sort_by"
|
||||
const val WAS_INITIAL_WIDGET_SET_UP = "was_initial_widget_set_up"
|
||||
const val FIRST_DAY_OF_WEEK = "first_day_of_week"
|
||||
|
||||
const val TABS_COUNT = 4
|
||||
const val EDITED_TIME_ZONE_SEPARATOR = ":"
|
||||
@@ -108,16 +109,18 @@ fun formatTime(showSeconds: Boolean, use24HourFormat: Boolean, hours: Int, minut
|
||||
}
|
||||
}
|
||||
|
||||
fun getDayNumber(calendarDay: Int): Int = (calendarDay + 5) % 7
|
||||
|
||||
fun getTomorrowBit(): Int {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.add(Calendar.DAY_OF_WEEK, 1)
|
||||
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
||||
val dayOfWeek = getDayNumber(calendar.get(Calendar.DAY_OF_WEEK))
|
||||
return 2.0.pow(dayOfWeek).toInt()
|
||||
}
|
||||
|
||||
fun getTodayBit(): Int {
|
||||
val calendar = Calendar.getInstance()
|
||||
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
||||
val dayOfWeek = getDayNumber(calendar.get(Calendar.DAY_OF_WEEK))
|
||||
return 2.0.pow(dayOfWeek).toInt()
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,29 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_start_week_on_holder"
|
||||
style="@style/SettingsHolderTextViewStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<org.fossify.commons.views.MyTextView
|
||||
android:id="@+id/settings_start_week_on_label"
|
||||
style="@style/SettingsTextLabelStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/start_week_on" />
|
||||
|
||||
<org.fossify.commons.views.MyTextView
|
||||
android:id="@+id/settings_start_week_on"
|
||||
style="@style/SettingsTextValueStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/settings_start_week_on_label"
|
||||
tools:text="@string/monday" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_prevent_phone_from_sleeping_holder"
|
||||
style="@style/SettingsHolderCheckboxStyle"
|
||||
@@ -148,21 +171,6 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_sunday_first_holder"
|
||||
style="@style/SettingsHolderCheckboxStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<org.fossify.commons.views.MyAppCompatCheckbox
|
||||
android:id="@+id/settings_sunday_first"
|
||||
style="@style/SettingsCheckboxStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sunday_first" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<include
|
||||
android:id="@+id/settings_general_settings_divider"
|
||||
layout="@layout/divider" />
|
||||
|
||||
Reference in New Issue
Block a user