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.
|
|
|
|
*/
|
|
|
|
|
2017-01-06 14:38:05 +01:00
|
|
|
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"
|
|
|
|
|
|
|
|
}
|