Try reading stored timer in both obfuscated and non-obfuscated state

This commit is contained in:
Ensar Sarajčić 2023-09-22 12:20:56 +02:00
parent e6adbe5e50
commit 0419b3aaaf
3 changed files with 49 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import android.content.Context
import android.media.RingtoneManager
import com.simplemobiletools.clock.extensions.gson.gson
import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.clock.models.ObfuscatedTimer
import com.simplemobiletools.clock.models.Timer
import com.simplemobiletools.commons.extensions.getDefaultAlarmSound
import com.simplemobiletools.commons.extensions.getDefaultAlarmTitle
@ -70,10 +71,18 @@ class Config(context: Context) : BaseConfig(context) {
set(alarm) = prefs.edit().putString(ALARM_LAST_CONFIG, gson.toJson(alarm)).apply()
var timerLastConfig: Timer?
get() = prefs.getString(TIMER_LAST_CONFIG, null)?.let { lastAlarm ->
gson.fromJson(lastAlarm, Timer::class.java)
get() = prefs.getString(TIMER_LAST_CONFIG, null)?.let { lastTimer ->
try {
if (lastTimer.contains("\"b\"")) {
gson.fromJson(lastTimer, ObfuscatedTimer::class.java).toTimer()
} else {
gson.fromJson(lastTimer, Timer::class.java)
}
} catch (e: Exception) {
null
}
}
set(alarm) = prefs.edit().putString(TIMER_LAST_CONFIG, gson.toJson(alarm)).apply()
set(timer) = prefs.edit().putString(TIMER_LAST_CONFIG, gson.toJson(timer)).apply()
var timerChannelId: String?
get() = prefs.getString(TIMER_CHANNEL_ID, null)

View file

@ -1,9 +1,11 @@
package com.simplemobiletools.clock.models
import androidx.annotation.Keep
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "timers")
@Keep
data class Timer(
@PrimaryKey(autoGenerate = true) var id: Int?,
var seconds: Int,
@ -16,3 +18,31 @@ data class Timer(
var channelId: String? = null,
var oneShot: Boolean = false
)
@Keep
data class ObfuscatedTimer(
var a: Int?,
var b: Int,
// We ignore timer state and will just use idle
val c: Map<Any, Any>,
var d: Boolean,
var e: String,
var f: String,
var g: String,
var h: Long,
var i: String? = null,
var j: Boolean = false
) {
fun toTimer(): Timer = Timer(
a,
b,
TimerState.Idle,
d,
e,
f,
g,
h,
i,
j
)
}

View file

@ -1,8 +1,15 @@
package com.simplemobiletools.clock.models
import androidx.annotation.Keep
@Keep
sealed class TimerState {
@Keep
object Idle : TimerState()
@Keep
data class Running(val duration: Long, val tick: Long) : TimerState()
@Keep
data class Paused(val duration: Long, val tick: Long) : TimerState()
@Keep
object Finished : TimerState()
}