mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2024-12-15 17:58:33 +01:00
day and alarm time sorting order
This commit is contained in:
parent
d6530be356
commit
aae9f1ea2f
@ -6,6 +6,7 @@ import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.helpers.SORT_BY_ALARM_TIME
|
||||
import com.simplemobiletools.clock.helpers.SORT_BY_CREATION_ORDER
|
||||
import com.simplemobiletools.clock.helpers.SORT_BY_DATE_AND_TIME
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import kotlinx.android.synthetic.main.dialog_change_alarm_sort.view.*
|
||||
@ -14,6 +15,7 @@ class ChangeAlarmSortDialog(val activity: BaseSimpleActivity, val callback: () -
|
||||
private var view: View = activity.layoutInflater.inflate(R.layout.dialog_change_alarm_sort, null).apply {
|
||||
val activeRadioButton = when (activity.config.alarmSort) {
|
||||
SORT_BY_ALARM_TIME -> sorting_dialog_radio_alarm_time
|
||||
SORT_BY_DATE_AND_TIME -> sorting_dialog_radio_day_and_time
|
||||
else -> sorting_dialog_radio_creation_order
|
||||
}
|
||||
activeRadioButton?.isChecked = true
|
||||
@ -31,6 +33,7 @@ class ChangeAlarmSortDialog(val activity: BaseSimpleActivity, val callback: () -
|
||||
private fun dialogConfirmed() {
|
||||
val sort = when (view.sorting_dialog_radio_sorting.checkedRadioButtonId) {
|
||||
R.id.sorting_dialog_radio_alarm_time -> SORT_BY_ALARM_TIME
|
||||
R.id.sorting_dialog_radio_day_and_time -> SORT_BY_DATE_AND_TIME
|
||||
else -> SORT_BY_CREATION_ORDER
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,7 @@ import com.simplemobiletools.clock.receivers.HideAlarmReceiver
|
||||
import com.simplemobiletools.clock.receivers.HideTimerReceiver
|
||||
import com.simplemobiletools.clock.services.SnoozeService
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.DAY_MINUTES
|
||||
import com.simplemobiletools.commons.helpers.EVERY_DAY_BIT
|
||||
import com.simplemobiletools.commons.helpers.SILENT
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import java.util.*
|
||||
import kotlin.math.pow
|
||||
|
||||
@ -468,3 +466,23 @@ fun Context.getAlarmSelectedDaysString(bitMask: Int): String {
|
||||
else -> getSelectedDaysString(bitMask)
|
||||
}
|
||||
}
|
||||
|
||||
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 sundayFirst = baseConfig.isSundayFirst
|
||||
if (sundayFirst) {
|
||||
dayBits.moveLastItemToFront()
|
||||
}
|
||||
|
||||
dayBits.forEach { bit ->
|
||||
if (bitMask and bit != 0) {
|
||||
return if (bit == SUNDAY_BIT && sundayFirst) 0 else bit
|
||||
}
|
||||
}
|
||||
|
||||
return bitMask
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import com.simplemobiletools.clock.models.Alarm
|
||||
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_CREATED
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.AlarmSound
|
||||
import kotlinx.android.synthetic.main.fragment_alarm.view.*
|
||||
@ -77,12 +78,11 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
||||
|
||||
private fun setupAlarms() {
|
||||
alarms = context?.dbHelper?.getAlarms() ?: return
|
||||
alarms.sortBy {
|
||||
if (requireContext().config.alarmSort == SORT_BY_ALARM_TIME) {
|
||||
it.timeInMinutes
|
||||
} else {
|
||||
it.id
|
||||
}
|
||||
|
||||
when (requireContext().config.alarmSort) {
|
||||
SORT_BY_ALARM_TIME -> alarms.sortBy { it.timeInMinutes }
|
||||
SORT_BY_DATE_CREATED -> alarms.sortBy { it.id }
|
||||
SORT_BY_DATE_AND_TIME -> alarms.sortWith(compareBy<Alarm> { requireContext().firstDayOrder(it.days) }.thenBy { it.timeInMinutes })
|
||||
}
|
||||
|
||||
if (context?.getNextAlarm()?.isEmpty() == true) {
|
||||
|
@ -54,6 +54,7 @@ const val SORT_BY_TOTAL_TIME = 4
|
||||
// alarm sorting
|
||||
const val SORT_BY_CREATION_ORDER = 0
|
||||
const val SORT_BY_ALARM_TIME = 1
|
||||
const val SORT_BY_DATE_AND_TIME = 2
|
||||
|
||||
const val TODAY_BIT = -1
|
||||
const val TOMORROW_BIT = -2
|
||||
|
@ -29,5 +29,13 @@
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:text="@string/sort_by_alarm_time" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/sorting_dialog_radio_day_and_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:text="@string/sort_by_day_and_alarm_time" />
|
||||
|
||||
</RadioGroup>
|
||||
</ScrollView>
|
||||
|
Loading…
Reference in New Issue
Block a user