removing some redundant constants

This commit is contained in:
tibbi 2018-03-05 23:49:14 +01:00
parent eee9458d4e
commit ce033cf6fa
3 changed files with 13 additions and 9 deletions

View File

@ -16,6 +16,7 @@ import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.extensions.updateTextColors
import kotlinx.android.synthetic.main.fragment_alarm.view.* import kotlinx.android.synthetic.main.fragment_alarm.view.*
import java.util.*
class AlarmFragment : Fragment(), ToggleAlarmInterface { class AlarmFragment : Fragment(), ToggleAlarmInterface {
private val DEFAULT_ALARM_MINUTES = 480 private val DEFAULT_ALARM_MINUTES = 480
@ -66,9 +67,19 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
override fun alarmToggled(id: Int, isEnabled: Boolean) { override fun alarmToggled(id: Int, isEnabled: Boolean) {
if (context!!.dbHelper.updateAlarmEnabledState(id, isEnabled)) { if (context!!.dbHelper.updateAlarmEnabledState(id, isEnabled)) {
alarms.firstOrNull { it.id == id }?.isEnabled = isEnabled val alarm = alarms.firstOrNull { it.id == id } ?: return
alarm.isEnabled = isEnabled
if (isEnabled) {
getClosestTriggerTimestamp(alarm)
}
} else { } else {
activity!!.toast(R.string.unknown_error_occurred) activity!!.toast(R.string.unknown_error_occurred)
} }
} }
private fun getClosestTriggerTimestamp(alarm: Alarm) {
val calendar = Calendar.getInstance()
calendar.firstDayOfWeek = Calendar.MONDAY
val currentDay = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
}
} }

View File

@ -11,14 +11,6 @@ const val EDITED_TIME_ZONE_TITLES = "edited_time_zone_titles"
const val TABS_COUNT = 3 const val TABS_COUNT = 3
const val EDITED_TIME_ZONE_SEPARATOR = ":" const val EDITED_TIME_ZONE_SEPARATOR = ":"
const val MONDAY_BIT = 1
const val TUESDAY_BIT = 2
const val WEDNESDAY_BIT = 4
const val THURSDAY_BIT = 8
const val FRIDAY_BIT = 16
const val SATURDAY_BIT = 32
const val SUNDAY_BIT = 64
fun getDefaultTimeZoneTitle(id: Int) = getAllTimeZones().firstOrNull { it.id == id }?.title ?: "" fun getDefaultTimeZoneTitle(id: Int) = getAllTimeZones().firstOrNull { it.id == id }?.title ?: ""
fun getAllTimeZones() = arrayListOf( fun getAllTimeZones() = arrayListOf(

View File

@ -9,6 +9,7 @@ import com.simplemobiletools.clock.extensions.createNewAlarm
import com.simplemobiletools.clock.models.Alarm import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.commons.extensions.getIntValue import com.simplemobiletools.commons.extensions.getIntValue
import com.simplemobiletools.commons.extensions.getStringValue import com.simplemobiletools.commons.extensions.getStringValue
import com.simplemobiletools.commons.helpers.*
import java.util.* import java.util.*
class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) { class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {