adding some UI improvements to dayless alarms

This commit is contained in:
tibbi 2020-11-05 10:44:19 +01:00
parent 9b55486462
commit b0c8dfe535
5 changed files with 144 additions and 110 deletions

View File

@ -8,12 +8,15 @@ import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.SimpleActivity
import com.simplemobiletools.clock.extensions.config
import com.simplemobiletools.clock.extensions.dbHelper
import com.simplemobiletools.clock.extensions.getAlarmSelectedDaysString
import com.simplemobiletools.clock.extensions.getFormattedTime
import com.simplemobiletools.clock.interfaces.ToggleAlarmInterface
import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.isVisible
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.views.MyRecyclerView
import kotlinx.android.synthetic.main.item_alarm.view.*
import java.util.*
@ -90,7 +93,7 @@ class AlarmsAdapter(activity: SimpleActivity, var alarms: ArrayList<Alarm>, val
alarm_time.text = activity.getFormattedTime(alarm.timeInMinutes * 60, false, true)
alarm_time.setTextColor(textColor)
alarm_days.text = activity.getSelectedDaysString(alarm.days)
alarm_days.text = activity.getAlarmSelectedDaysString(alarm.days)
alarm_days.setTextColor(textColor)
alarm_label.text = alarm.label

View File

@ -9,6 +9,8 @@ import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.SimpleActivity
import com.simplemobiletools.clock.extensions.*
import com.simplemobiletools.clock.helpers.PICK_AUDIO_FILE_INTENT_ID
import com.simplemobiletools.clock.helpers.TODAY_BIT
import com.simplemobiletools.clock.helpers.TOMORROW_BIT
import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.commons.dialogs.SelectAlarmSoundDialog
import com.simplemobiletools.commons.extensions.*
@ -68,11 +70,15 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
val day = activity.layoutInflater.inflate(R.layout.alarm_day, edit_alarm_days_holder, false) as TextView
day.text = dayLetters[it]
val isDayChecked = alarm.days and pow != 0
val isDayChecked = alarm.days > 0 && alarm.days and pow != 0
day.background = getProperDayDrawable(isDayChecked)
day.setTextColor(if (isDayChecked) context.config.backgroundColor else textColor)
day.setOnClickListener {
if (alarm.days < 0) {
alarm.days = 0
}
val selectDay = alarm.days and pow == 0
if (selectDay) {
alarm.days = alarm.days.addBit(pow)
@ -94,9 +100,12 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
.create().apply {
activity.setupDialogStuff(view, this) {
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (alarm.days == 0) {
activity.toast(R.string.no_days_selected)
return@setOnClickListener
if (alarm.days <= 0) {
alarm.days = if (alarm.timeInMinutes > getCurrentDayMinutes()) {
TODAY_BIT
} else {
TOMORROW_BIT
}
}
alarm.label = view.edit_alarm_label.value
@ -145,19 +154,21 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
}
private fun checkDaylessAlarm() {
if (alarm.days == 0) {
val calendar = Calendar.getInstance()
val currentMinutesOfDay = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE)
val textId = if (alarm.timeInMinutes > currentMinutesOfDay) {
R.string.tomorrow
} else {
if (alarm.days <= 0) {
val textId = if (alarm.timeInMinutes > getCurrentDayMinutes()) {
R.string.today
} else {
R.string.tomorrow
}
view.edit_alarm_dayless_label.text = "(${activity.getString(textId)})"
}
view.edit_alarm_dayless_label.beVisibleIf(alarm.days == 0)
view.edit_alarm_dayless_label.beVisibleIf(alarm.days <= 0)
}
private fun getCurrentDayMinutes(): Int {
val calendar = Calendar.getInstance()
return calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE)
}
private fun getProperDayDrawable(selected: Boolean): Drawable {

View File

@ -392,3 +392,11 @@ fun Context.checkAlarmsWithDeletedSoundUri(uri: String) {
dbHelper.updateAlarm(it)
}
}
fun Context.getAlarmSelectedDaysString(bitMask: Int): String {
return when (bitMask) {
TODAY_BIT -> getString(R.string.today)
TOMORROW_BIT -> getString(R.string.tomorrow)
else -> getSelectedDaysString(bitMask)
}
}

View File

@ -12,6 +12,7 @@ import com.simplemobiletools.clock.adapters.AlarmsAdapter
import com.simplemobiletools.clock.dialogs.EditAlarmDialog
import com.simplemobiletools.clock.extensions.*
import com.simplemobiletools.clock.helpers.DEFAULT_ALARM_MINUTES
import com.simplemobiletools.clock.helpers.getNextDayBit
import com.simplemobiletools.clock.interfaces.ToggleAlarmInterface
import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.commons.extensions.toast
@ -19,7 +20,6 @@ import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.models.AlarmSound
import kotlinx.android.synthetic.main.fragment_alarm.view.*
import java.util.*
import kotlin.math.pow
class AlarmFragment : Fragment(), ToggleAlarmInterface {
private var alarms = ArrayList<Alarm>()
@ -60,12 +60,7 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
alarm_fab.setOnClickListener {
val newAlarm = context.createNewAlarm(DEFAULT_ALARM_MINUTES, 0)
newAlarm.isEnabled = true
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_WEEK, 1) // set the next alarm to the next day by default
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
newAlarm.days = 2.0.pow(dayOfWeek).toInt()
newAlarm.days = getNextDayBit()
openEditAlarm(newAlarm)
}
}

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.clock.helpers
import com.simplemobiletools.clock.models.MyTimeZone
import java.util.*
import kotlin.math.pow
// shared preferences
const val SHOW_SECONDS = "show_seconds"
@ -47,6 +48,9 @@ const val SORT_BY_LAP = 1
const val SORT_BY_LAP_TIME = 2
const val SORT_BY_TOTAL_TIME = 4
const val TODAY_BIT = -1
const val TOMORROW_BIT = -2
fun getDefaultTimeZoneTitle(id: Int) = getAllTimeZones().firstOrNull { it.id == id }?.title ?: ""
fun getMSTillNextMinute(): Long {
@ -76,94 +80,107 @@ fun formatTime(showSeconds: Boolean, use24HourFormat: Boolean, hours: Int, minut
}
}
fun getTodayBit(): Int {
val calendar = Calendar.getInstance()
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
return 2.0.pow(dayOfWeek).toInt()
}
fun getNextDayBit(): Int {
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_WEEK, 1)
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
return 2.0.pow(dayOfWeek).toInt()
}
fun getAllTimeZones() = arrayListOf(
MyTimeZone(1, "GMT-11:00 Midway", "Pacific/Midway"),
MyTimeZone(2, "GMT-10:00 Honolulu", "Pacific/Honolulu"),
MyTimeZone(3, "GMT-09:00 Anchorage", "America/Anchorage"),
MyTimeZone(4, "GMT-08:00 Los Angeles", "America/Los_Angeles"),
MyTimeZone(5, "GMT-08:00 Tijuana", "America/Tijuana"),
MyTimeZone(6, "GMT-07:00 Phoenix", "America/Phoenix"),
MyTimeZone(7, "GMT-07:00 Chihuahua", "America/Chihuahua"),
MyTimeZone(8, "GMT-07:00 Denver", "America/Denver"),
MyTimeZone(9, "GMT-06:00 Costa Rica", "America/Costa_Rica"),
MyTimeZone(10, "GMT-06:00 Chicago", "America/Chicago"),
MyTimeZone(11, "GMT-06:00 Mexico City", "America/Mexico_City"),
MyTimeZone(12, "GMT-06:00 Regina", "America/Regina"),
MyTimeZone(13, "GMT-05:00 Bogota", "America/Bogota"),
MyTimeZone(14, "GMT-05:00 New York", "America/New_York"),
MyTimeZone(15, "GMT-04:30 Caracas", "America/Caracas"),
MyTimeZone(16, "GMT-04:00 Barbados", "America/Barbados"),
MyTimeZone(17, "GMT-04:00 Halifax", "America/Halifax"),
MyTimeZone(18, "GMT-04:00 Manaus", "America/Manaus"),
MyTimeZone(19, "GMT-03:30 St. John's", "America/St_Johns"),
MyTimeZone(20, "GMT-03:00 Santiago", "America/Santiago"),
MyTimeZone(21, "GMT-03:00 Recife", "America/Recife"),
MyTimeZone(22, "GMT-03:00 Sao Paulo", "America/Sao_Paulo"),
MyTimeZone(23, "GMT-03:00 Buenos Aires", "America/Buenos_Aires"),
MyTimeZone(24, "GMT-03:00 Nuuk", "America/Godthab"),
MyTimeZone(25, "GMT-03:00 Montevideo", "America/Montevideo"),
MyTimeZone(26, "GMT-02:00 South Georgia", "Atlantic/South_Georgia"),
MyTimeZone(27, "GMT-01:00 Azores", "Atlantic/Azores"),
MyTimeZone(28, "GMT-01:00 Cape Verde", "Atlantic/Cape_Verde"),
MyTimeZone(29, "GMT+00:00 Casablanca", "Africa/Casablanca"),
MyTimeZone(30, "GMT+00:00 Greenwich Mean Time", "Etc/Greenwich"),
MyTimeZone(31, "GMT+01:00 Amsterdam", "Europe/Amsterdam"),
MyTimeZone(32, "GMT+01:00 Belgrade", "Europe/Belgrade"),
MyTimeZone(33, "GMT+01:00 Brussels", "Europe/Brussels"),
MyTimeZone(34, "GMT+01:00 Madrid", "Europe/Madrid"),
MyTimeZone(35, "GMT+01:00 Sarajevo", "Europe/Sarajevo"),
MyTimeZone(36, "GMT+01:00 Brazzaville", "Africa/Brazzaville"),
MyTimeZone(37, "GMT+02:00 Windhoek", "Africa/Windhoek"),
MyTimeZone(38, "GMT+02:00 Amman", "Asia/Amman"),
MyTimeZone(39, "GMT+02:00 Athens", "Europe/Athens"),
MyTimeZone(40, "GMT+02:00 Istanbul", "Europe/Istanbul"),
MyTimeZone(41, "GMT+02:00 Beirut", "Asia/Beirut"),
MyTimeZone(42, "GMT+02:00 Cairo", "Africa/Cairo"),
MyTimeZone(43, "GMT+02:00 Helsinki", "Europe/Helsinki"),
MyTimeZone(44, "GMT+02:00 Jerusalem", "Asia/Jerusalem"),
MyTimeZone(45, "GMT+02:00 Harare", "Africa/Harare"),
MyTimeZone(46, "GMT+03:00 Minsk", "Europe/Minsk"),
MyTimeZone(47, "GMT+03:00 Baghdad", "Asia/Baghdad"),
MyTimeZone(48, "GMT+03:00 Moscow", "Europe/Moscow"),
MyTimeZone(49, "GMT+03:00 Kuwait", "Asia/Kuwait"),
MyTimeZone(50, "GMT+03:00 Nairobi", "Africa/Nairobi"),
MyTimeZone(51, "GMT+03:30 Tehran", "Asia/Tehran"),
MyTimeZone(52, "GMT+04:00 Baku", "Asia/Baku"),
MyTimeZone(53, "GMT+04:00 Tbilisi", "Asia/Tbilisi"),
MyTimeZone(54, "GMT+04:00 Yerevan", "Asia/Yerevan"),
MyTimeZone(55, "GMT+04:00 Dubai", "Asia/Dubai"),
MyTimeZone(56, "GMT+04:30 Kabul", "Asia/Kabul"),
MyTimeZone(57, "GMT+05:00 Karachi", "Asia/Karachi"),
MyTimeZone(58, "GMT+05:00 Oral", "Asia/Oral"),
MyTimeZone(59, "GMT+05:00 Yekaterinburg", "Asia/Yekaterinburg"),
MyTimeZone(60, "GMT+05:30 Kolkata", "Asia/Kolkata"),
MyTimeZone(61, "GMT+05:30 Colombo", "Asia/Colombo"),
MyTimeZone(62, "GMT+05:45 Kathmandu", "Asia/Kathmandu"),
MyTimeZone(63, "GMT+06:00 Almaty", "Asia/Almaty"),
MyTimeZone(64, "GMT+06:30 Rangoon", "Asia/Rangoon"),
MyTimeZone(65, "GMT+07:00 Krasnoyarsk", "Asia/Krasnoyarsk"),
MyTimeZone(66, "GMT+07:00 Bangkok", "Asia/Bangkok"),
MyTimeZone(67, "GMT+07:00 Jakarta", "Asia/Jakarta"),
MyTimeZone(68, "GMT+08:00 Shanghai", "Asia/Shanghai"),
MyTimeZone(69, "GMT+08:00 Hong Kong", "Asia/Hong_Kong"),
MyTimeZone(70, "GMT+08:00 Irkutsk", "Asia/Irkutsk"),
MyTimeZone(71, "GMT+08:00 Kuala Lumpur", "Asia/Kuala_Lumpur"),
MyTimeZone(72, "GMT+08:00 Perth", "Australia/Perth"),
MyTimeZone(73, "GMT+08:00 Taipei", "Asia/Taipei"),
MyTimeZone(74, "GMT+09:00 Seoul", "Asia/Seoul"),
MyTimeZone(75, "GMT+09:00 Tokyo", "Asia/Tokyo"),
MyTimeZone(76, "GMT+09:00 Yakutsk", "Asia/Yakutsk"),
MyTimeZone(77, "GMT+09:30 Darwin", "Australia/Darwin"),
MyTimeZone(78, "GMT+10:00 Brisbane", "Australia/Brisbane"),
MyTimeZone(79, "GMT+10:00 Vladivostok", "Asia/Vladivostok"),
MyTimeZone(80, "GMT+10:00 Guam", "Pacific/Guam"),
MyTimeZone(81, "GMT+10:00 Magadan", "Asia/Magadan"),
MyTimeZone(82, "GMT+10:30 Adelaide", "Australia/Adelaide"),
MyTimeZone(83, "GMT+11:00 Hobart", "Australia/Hobart"),
MyTimeZone(84, "GMT+11:00 Sydney", "Australia/Sydney"),
MyTimeZone(85, "GMT+11:00 Noumea", "Pacific/Noumea"),
MyTimeZone(86, "GMT+12:00 Majuro", "Pacific/Majuro"),
MyTimeZone(87, "GMT+12:00 Fiji", "Pacific/Fiji"),
MyTimeZone(88, "GMT+13:00 Auckland", "Pacific/Auckland"),
MyTimeZone(89, "GMT+13:00 Tongatapu", "Pacific/Tongatapu")
MyTimeZone(1, "GMT-11:00 Midway", "Pacific/Midway"),
MyTimeZone(2, "GMT-10:00 Honolulu", "Pacific/Honolulu"),
MyTimeZone(3, "GMT-09:00 Anchorage", "America/Anchorage"),
MyTimeZone(4, "GMT-08:00 Los Angeles", "America/Los_Angeles"),
MyTimeZone(5, "GMT-08:00 Tijuana", "America/Tijuana"),
MyTimeZone(6, "GMT-07:00 Phoenix", "America/Phoenix"),
MyTimeZone(7, "GMT-07:00 Chihuahua", "America/Chihuahua"),
MyTimeZone(8, "GMT-07:00 Denver", "America/Denver"),
MyTimeZone(9, "GMT-06:00 Costa Rica", "America/Costa_Rica"),
MyTimeZone(10, "GMT-06:00 Chicago", "America/Chicago"),
MyTimeZone(11, "GMT-06:00 Mexico City", "America/Mexico_City"),
MyTimeZone(12, "GMT-06:00 Regina", "America/Regina"),
MyTimeZone(13, "GMT-05:00 Bogota", "America/Bogota"),
MyTimeZone(14, "GMT-05:00 New York", "America/New_York"),
MyTimeZone(15, "GMT-04:30 Caracas", "America/Caracas"),
MyTimeZone(16, "GMT-04:00 Barbados", "America/Barbados"),
MyTimeZone(17, "GMT-04:00 Halifax", "America/Halifax"),
MyTimeZone(18, "GMT-04:00 Manaus", "America/Manaus"),
MyTimeZone(19, "GMT-03:30 St. John's", "America/St_Johns"),
MyTimeZone(20, "GMT-03:00 Santiago", "America/Santiago"),
MyTimeZone(21, "GMT-03:00 Recife", "America/Recife"),
MyTimeZone(22, "GMT-03:00 Sao Paulo", "America/Sao_Paulo"),
MyTimeZone(23, "GMT-03:00 Buenos Aires", "America/Buenos_Aires"),
MyTimeZone(24, "GMT-03:00 Nuuk", "America/Godthab"),
MyTimeZone(25, "GMT-03:00 Montevideo", "America/Montevideo"),
MyTimeZone(26, "GMT-02:00 South Georgia", "Atlantic/South_Georgia"),
MyTimeZone(27, "GMT-01:00 Azores", "Atlantic/Azores"),
MyTimeZone(28, "GMT-01:00 Cape Verde", "Atlantic/Cape_Verde"),
MyTimeZone(29, "GMT+00:00 Casablanca", "Africa/Casablanca"),
MyTimeZone(30, "GMT+00:00 Greenwich Mean Time", "Etc/Greenwich"),
MyTimeZone(31, "GMT+01:00 Amsterdam", "Europe/Amsterdam"),
MyTimeZone(32, "GMT+01:00 Belgrade", "Europe/Belgrade"),
MyTimeZone(33, "GMT+01:00 Brussels", "Europe/Brussels"),
MyTimeZone(34, "GMT+01:00 Madrid", "Europe/Madrid"),
MyTimeZone(35, "GMT+01:00 Sarajevo", "Europe/Sarajevo"),
MyTimeZone(36, "GMT+01:00 Brazzaville", "Africa/Brazzaville"),
MyTimeZone(37, "GMT+02:00 Windhoek", "Africa/Windhoek"),
MyTimeZone(38, "GMT+02:00 Amman", "Asia/Amman"),
MyTimeZone(39, "GMT+02:00 Athens", "Europe/Athens"),
MyTimeZone(40, "GMT+02:00 Istanbul", "Europe/Istanbul"),
MyTimeZone(41, "GMT+02:00 Beirut", "Asia/Beirut"),
MyTimeZone(42, "GMT+02:00 Cairo", "Africa/Cairo"),
MyTimeZone(43, "GMT+02:00 Helsinki", "Europe/Helsinki"),
MyTimeZone(44, "GMT+02:00 Jerusalem", "Asia/Jerusalem"),
MyTimeZone(45, "GMT+02:00 Harare", "Africa/Harare"),
MyTimeZone(46, "GMT+03:00 Minsk", "Europe/Minsk"),
MyTimeZone(47, "GMT+03:00 Baghdad", "Asia/Baghdad"),
MyTimeZone(48, "GMT+03:00 Moscow", "Europe/Moscow"),
MyTimeZone(49, "GMT+03:00 Kuwait", "Asia/Kuwait"),
MyTimeZone(50, "GMT+03:00 Nairobi", "Africa/Nairobi"),
MyTimeZone(51, "GMT+03:30 Tehran", "Asia/Tehran"),
MyTimeZone(52, "GMT+04:00 Baku", "Asia/Baku"),
MyTimeZone(53, "GMT+04:00 Tbilisi", "Asia/Tbilisi"),
MyTimeZone(54, "GMT+04:00 Yerevan", "Asia/Yerevan"),
MyTimeZone(55, "GMT+04:00 Dubai", "Asia/Dubai"),
MyTimeZone(56, "GMT+04:30 Kabul", "Asia/Kabul"),
MyTimeZone(57, "GMT+05:00 Karachi", "Asia/Karachi"),
MyTimeZone(58, "GMT+05:00 Oral", "Asia/Oral"),
MyTimeZone(59, "GMT+05:00 Yekaterinburg", "Asia/Yekaterinburg"),
MyTimeZone(60, "GMT+05:30 Kolkata", "Asia/Kolkata"),
MyTimeZone(61, "GMT+05:30 Colombo", "Asia/Colombo"),
MyTimeZone(62, "GMT+05:45 Kathmandu", "Asia/Kathmandu"),
MyTimeZone(63, "GMT+06:00 Almaty", "Asia/Almaty"),
MyTimeZone(64, "GMT+06:30 Rangoon", "Asia/Rangoon"),
MyTimeZone(65, "GMT+07:00 Krasnoyarsk", "Asia/Krasnoyarsk"),
MyTimeZone(66, "GMT+07:00 Bangkok", "Asia/Bangkok"),
MyTimeZone(67, "GMT+07:00 Jakarta", "Asia/Jakarta"),
MyTimeZone(68, "GMT+08:00 Shanghai", "Asia/Shanghai"),
MyTimeZone(69, "GMT+08:00 Hong Kong", "Asia/Hong_Kong"),
MyTimeZone(70, "GMT+08:00 Irkutsk", "Asia/Irkutsk"),
MyTimeZone(71, "GMT+08:00 Kuala Lumpur", "Asia/Kuala_Lumpur"),
MyTimeZone(72, "GMT+08:00 Perth", "Australia/Perth"),
MyTimeZone(73, "GMT+08:00 Taipei", "Asia/Taipei"),
MyTimeZone(74, "GMT+09:00 Seoul", "Asia/Seoul"),
MyTimeZone(75, "GMT+09:00 Tokyo", "Asia/Tokyo"),
MyTimeZone(76, "GMT+09:00 Yakutsk", "Asia/Yakutsk"),
MyTimeZone(77, "GMT+09:30 Darwin", "Australia/Darwin"),
MyTimeZone(78, "GMT+10:00 Brisbane", "Australia/Brisbane"),
MyTimeZone(79, "GMT+10:00 Vladivostok", "Asia/Vladivostok"),
MyTimeZone(80, "GMT+10:00 Guam", "Pacific/Guam"),
MyTimeZone(81, "GMT+10:00 Magadan", "Asia/Magadan"),
MyTimeZone(82, "GMT+10:30 Adelaide", "Australia/Adelaide"),
MyTimeZone(83, "GMT+11:00 Hobart", "Australia/Hobart"),
MyTimeZone(84, "GMT+11:00 Sydney", "Australia/Sydney"),
MyTimeZone(85, "GMT+11:00 Noumea", "Pacific/Noumea"),
MyTimeZone(86, "GMT+12:00 Majuro", "Pacific/Majuro"),
MyTimeZone(87, "GMT+12:00 Fiji", "Pacific/Fiji"),
MyTimeZone(88, "GMT+13:00 Auckland", "Pacific/Auckland"),
MyTimeZone(89, "GMT+13:00 Tongatapu", "Pacific/Tongatapu")
)