mirror of
				https://github.com/SimpleMobileTools/Simple-Clock.git
				synced 2025-06-05 22:19:17 +02:00 
			
		
		
		
	Migrate last alarm to unobfuscated storage as well
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.ObfuscatedAlarm | ||||
| import com.simplemobiletools.clock.models.ObfuscatedTimer | ||||
| import com.simplemobiletools.clock.models.Timer | ||||
| import com.simplemobiletools.commons.extensions.getDefaultAlarmSound | ||||
| @@ -66,8 +67,16 @@ class Config(context: Context) : BaseConfig(context) { | ||||
|  | ||||
|     var alarmLastConfig: Alarm? | ||||
|         get() = prefs.getString(ALARM_LAST_CONFIG, null)?.let { lastAlarm -> | ||||
|             try { | ||||
|                 if (lastAlarm.contains("\"b\"")) { | ||||
|                     gson.fromJson(lastAlarm, ObfuscatedAlarm::class.java).toAlarm() | ||||
|                 } else { | ||||
|                     gson.fromJson(lastAlarm, Alarm::class.java) | ||||
|                 } | ||||
|             } catch (e: Exception) { | ||||
|                 null | ||||
|             } | ||||
|         } | ||||
|         set(alarm) = prefs.edit().putString(ALARM_LAST_CONFIG, gson.toJson(alarm)).apply() | ||||
|  | ||||
|     var timerLastConfig: Timer? | ||||
|   | ||||
| @@ -1,5 +1,8 @@ | ||||
| package com.simplemobiletools.clock.models | ||||
|  | ||||
| import androidx.annotation.Keep | ||||
|  | ||||
| @Keep | ||||
| data class Alarm( | ||||
|     var id: Int, | ||||
|     var timeInMinutes: Int, | ||||
| @@ -11,3 +14,18 @@ data class Alarm( | ||||
|     var label: String, | ||||
|     var oneShot: Boolean = false | ||||
| ) | ||||
|  | ||||
| @Keep | ||||
| data class ObfuscatedAlarm( | ||||
|     var a: Int, | ||||
|     var b: Int, | ||||
|     var c: Int, | ||||
|     var d: Boolean, | ||||
|     var e: Boolean, | ||||
|     var f: String, | ||||
|     var g: String, | ||||
|     var h: String, | ||||
|     var i: Boolean = false | ||||
| ) { | ||||
|     fun toAlarm() = Alarm(a, b, c, d, e, f, g, h, i) | ||||
| } | ||||
|   | ||||
| @@ -33,16 +33,5 @@ data class ObfuscatedTimer( | ||||
|     var i: String? = null, | ||||
|     var j: Boolean = false | ||||
| ) { | ||||
|     fun toTimer(): Timer = Timer( | ||||
|         a, | ||||
|         b, | ||||
|         TimerState.Idle, | ||||
|         d, | ||||
|         e, | ||||
|         f, | ||||
|         g, | ||||
|         h, | ||||
|         i, | ||||
|         j | ||||
|     ) | ||||
|     fun toTimer() = Timer(a, b, TimerState.Idle, d, e, f, g, h, i, j) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user