Fix: Fixed issue where backup was not doing numbers currently.

Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
This commit is contained in:
HeCodes2Much
2024-07-18 20:26:37 +01:00
parent f26ad38929
commit f18b4e394c
3 changed files with 17 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
var showStatusBar: Boolean
get() = prefs.getBoolean(Constants.SHOW_STATUS_BAR, true)
set(value) = prefs.edit().putBoolean(Constants.SHOW_STATUS_BAR, value).apply()
var showTime: Boolean
get() = prefs.getBoolean(Constants.SHOW_TIME, true)
set(value) = prefs.edit().putBoolean(Constants.SHOW_TIME, value).apply()
@@ -268,22 +269,26 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
fun loadFromString(json: String) {
val editor = prefs.edit()
val all: HashMap<String, Any?> =
Gson().fromJson(json, object : TypeToken<HashMap<String, Any?>>() {}.type)
val all: HashMap<String, Any?> = Gson().fromJson(json, object : TypeToken<HashMap<String, Any?>>() {}.type)
for ((key, value) in all) {
when (value) {
is String -> editor.putString(key, value)
is Boolean -> editor.putBoolean(key, value)
is Int -> editor.putInt(key, value)
is Double -> editor.putInt(key, value.toInt()) // we store everything as int
is Float -> editor.putInt(key, value.toInt())
is Number -> {
if (value.toDouble() == value.toInt().toDouble()) {
editor.putInt(key, value.toInt())
} else {
editor.putFloat(key, value.toFloat())
}
}
is MutableSet<*> -> {
val list = value.filterIsInstance<String>().toSet()
editor.putStringSet(key, list)
}
else -> {
Log.d("backup error", "$value")
Log.d("backup error", "$key | $value")
}
}
}

View File

@@ -5,6 +5,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.BatteryManager
import android.os.Build
@@ -113,6 +114,10 @@ class HomeFragment : Fragment(),
observeSwipeTouchListener()
observeUserInterfaceSettings()
val prefs: SharedPreferences = context.getSharedPreferences(Constants.PACKAGE_PREFS, 0)
Log.d("preferenceHelper", prefs.all.toString())
if (context.hasInternetPermission()) {
updateManager = UpdateManagerHelper(this)
updateManager.checkForUpdates()

View File

@@ -117,8 +117,8 @@ class SettingsFragment : Fragment(),
appPackageName: String?,
textView: TextView
) {
val appName = appPackageName?.let { context.getAppNameFromPackageName(it) }
val actionText = if (action == Constants.Action.OpenApp) {
val appName = appPackageName?.let { context.getAppNameFromPackageName(it) }
context.getString(R.string.settings_actions_open_app_run, appName)
} else {
action.getString(context)