Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/twidere/util/sync/UserColorsSyncProcessor.kt

32 lines
900 B
Kotlin
Raw Normal View History

2017-01-02 09:33:27 +01:00
package org.mariotaku.twidere.util.sync
import android.content.SharedPreferences
import android.graphics.Color
import org.mariotaku.ktextension.HexColorFormat
import org.mariotaku.ktextension.toHexColor
/**
* Created by mariotaku on 2017/1/2.
*/
object UserColorsSyncProcessor : FileBasedPreferencesValuesSyncAction.Processor {
2017-01-02 09:33:27 +01:00
override fun loadValue(map: MutableMap<String, String>, key: String, value: Any?) {
if (value is Int) {
2020-06-08 23:07:20 +02:00
map[key] = toHexColor(value, format = HexColorFormat.RGB)
2017-01-02 09:33:27 +01:00
}
}
override fun saveValue(editor: SharedPreferences.Editor, key: String, value: String) {
try {
editor.putInt(key, Color.parseColor(value))
} catch (e: IllegalArgumentException) {
// Ignore
}
}
override val whatData: String = "user colors"
override val snapshotFileName: String = "user_colors.xml"
}