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

32 lines
903 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 : FileBasedPreferencesValuesSyncHelper.Processor {
override fun loadValue(map: MutableMap<String, String>, key: String, value: Any?) {
if (value is Int) {
map.put(key, toHexColor(value, format = HexColorFormat.RGB))
}
}
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"
}