mirror of
				https://github.com/SimpleMobileTools/Simple-Clock.git
				synced 2025-06-05 22:19:17 +02:00 
			
		
		
		
	Merge pull request #528 from esensar/fix/update-crash
Try reading stored timer in both obfuscated and non-obfuscated state
This commit is contained in:
		| @@ -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) | ||||
|                 } | ||||
|         set(alarm) = prefs.edit().putString(TIMER_LAST_CONFIG, gson.toJson(alarm)).apply() | ||||
|             } catch (e: Exception) { | ||||
|                 null | ||||
|             } | ||||
|         } | ||||
|         set(timer) = prefs.edit().putString(TIMER_LAST_CONFIG, gson.toJson(timer)).apply() | ||||
|  | ||||
|     var timerChannelId: String? | ||||
|         get() = prefs.getString(TIMER_CHANNEL_ID, null) | ||||
|   | ||||
| @@ -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 | ||||
|     ) | ||||
| } | ||||
|   | ||||
| @@ -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() | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user