minor style cleanup, moving some classes into own files
This commit is contained in:
parent
9f6271eb2f
commit
09ff527a1e
|
@ -67,7 +67,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.22.14'
|
||||
implementation 'com.simplemobiletools:commons:5.23.0'
|
||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
|
||||
implementation 'com.shawnlin:number-picker:2.4.6'
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.simplemobiletools.clock.extensions.config
|
|||
import com.simplemobiletools.clock.extensions.getOpenTimerTabIntent
|
||||
import com.simplemobiletools.clock.extensions.getTimerNotification
|
||||
import com.simplemobiletools.clock.helpers.TIMER_NOTIF_ID
|
||||
import com.simplemobiletools.clock.services.TimerState
|
||||
import com.simplemobiletools.clock.models.TimerState
|
||||
import com.simplemobiletools.clock.services.TimerStopService
|
||||
import com.simplemobiletools.clock.services.startTimerService
|
||||
import com.simplemobiletools.commons.extensions.checkUseEnglish
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.simplemobiletools.clock.extensions.gson
|
|||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.TypeAdapterFactory
|
||||
import com.simplemobiletools.clock.services.TimerState
|
||||
import com.simplemobiletools.clock.models.TimerState
|
||||
|
||||
val timerStates = valueOf<TimerState>()
|
||||
.registerSubtype(TimerState.Idle::class.java)
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.simplemobiletools.clock.activities.SimpleActivity
|
|||
import com.simplemobiletools.clock.dialogs.MyTimePickerDialogDialog
|
||||
import com.simplemobiletools.clock.extensions.*
|
||||
import com.simplemobiletools.clock.helpers.PICK_AUDIO_FILE_INTENT_ID
|
||||
import com.simplemobiletools.clock.services.TimerState
|
||||
import com.simplemobiletools.clock.models.TimerState
|
||||
import com.simplemobiletools.commons.dialogs.SelectAlarmSoundDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ALARM_SOUND_TYPE_ALARM
|
||||
|
@ -65,23 +65,12 @@ class TimerFragment : Fragment() {
|
|||
val state = config.timerState
|
||||
|
||||
when (state) {
|
||||
is TimerState.Idle -> {
|
||||
EventBus.getDefault().post(TimerState.Start(config.timerSeconds.secondsToMillis))
|
||||
is TimerState.Idle -> EventBus.getDefault().post(TimerState.Start(config.timerSeconds.secondsToMillis))
|
||||
is TimerState.Paused -> EventBus.getDefault().post(TimerState.Start(state.tick))
|
||||
is TimerState.Running -> EventBus.getDefault().post(TimerState.Pause(state.tick))
|
||||
is TimerState.Finished -> EventBus.getDefault().post(TimerState.Start(config.timerSeconds.secondsToMillis))
|
||||
else -> {
|
||||
}
|
||||
|
||||
is TimerState.Paused -> {
|
||||
EventBus.getDefault().post(TimerState.Start(state.tick))
|
||||
}
|
||||
|
||||
is TimerState.Running -> {
|
||||
EventBus.getDefault().post(TimerState.Pause(state.tick))
|
||||
}
|
||||
|
||||
is TimerState.Finished -> {
|
||||
EventBus.getDefault().post(TimerState.Start(config.timerSeconds.secondsToMillis))
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +143,6 @@ class TimerFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun updateViewStates(state: TimerState) {
|
||||
|
||||
val resetPossible = state is TimerState.Running || state is TimerState.Paused || state is TimerState.Finished
|
||||
view.timer_reset.beVisibleIf(resetPossible)
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ package com.simplemobiletools.clock.helpers
|
|||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.clock.extensions.gson.gson
|
||||
import com.simplemobiletools.clock.services.StateWrapper
|
||||
import com.simplemobiletools.clock.services.TimerState
|
||||
import com.simplemobiletools.clock.models.StateWrapper
|
||||
import com.simplemobiletools.clock.models.TimerState
|
||||
import com.simplemobiletools.commons.extensions.getDefaultAlarmTitle
|
||||
import com.simplemobiletools.commons.extensions.getDefaultAlarmUri
|
||||
import com.simplemobiletools.commons.helpers.ALARM_SOUND_TYPE_ALARM
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package com.simplemobiletools.clock.models
|
||||
|
||||
data class StateWrapper(val state: TimerState)
|
|
@ -0,0 +1,11 @@
|
|||
package com.simplemobiletools.clock.models
|
||||
|
||||
sealed class TimerState {
|
||||
object Idle : TimerState()
|
||||
data class Start(val duration: Long) : TimerState()
|
||||
data class Running(val duration: Long, val tick: Long) : TimerState()
|
||||
data class Pause(val duration: Long) : TimerState()
|
||||
data class Paused(val duration: Long, val tick: Long) : TimerState()
|
||||
data class Finish(val duration: Long) : TimerState()
|
||||
object Finished : TimerState()
|
||||
}
|
|
@ -4,7 +4,7 @@ import android.content.BroadcastReceiver
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.clock.extensions.hideTimerNotification
|
||||
import com.simplemobiletools.clock.services.TimerState
|
||||
import com.simplemobiletools.clock.models.TimerState
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class HideTimerReceiver : BroadcastReceiver() {
|
||||
|
|
|
@ -21,15 +21,6 @@ import org.greenrobot.eventbus.EventBus
|
|||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun startTimerService(context: Context) {
|
||||
if (isOreoPlus()) {
|
||||
context.startForegroundService(Intent(context, TimerService::class.java))
|
||||
} else {
|
||||
context.startService(Intent(context, TimerService::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
class TimerService : Service() {
|
||||
|
||||
private val bus = EventBus.getDefault()
|
||||
|
@ -97,18 +88,13 @@ class TimerService : Service() {
|
|||
}
|
||||
}
|
||||
|
||||
data class StateWrapper(val state: TimerState)
|
||||
|
||||
object TimerStopService
|
||||
|
||||
sealed class TimerState {
|
||||
object Idle : TimerState()
|
||||
data class Start(val duration: Long) : TimerState()
|
||||
data class Running(val duration: Long, val tick: Long) : TimerState()
|
||||
data class Pause(val duration: Long) : TimerState()
|
||||
data class Paused(val duration: Long, val tick: Long) : TimerState()
|
||||
data class Finish(val duration: Long) : TimerState()
|
||||
object Finished : TimerState()
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun startTimerService(context: Context) {
|
||||
if (isOreoPlus()) {
|
||||
context.startForegroundService(Intent(context, TimerService::class.java))
|
||||
} else {
|
||||
context.startService(Intent(context, TimerService::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object TimerStopService
|
||||
|
|
Loading…
Reference in New Issue