mirror of https://github.com/Corewala/Buran
Implement background color picker
Signed-off-by: Ariel Costas <arielcostas@mailbox.org>
This commit is contained in:
parent
2bd546d7ed
commit
11ffe839f9
|
@ -59,6 +59,8 @@ dependencies {
|
||||||
implementation 'com.google.android.material:material:1.3.0-rc01'
|
implementation 'com.google.android.material:material:1.3.0-rc01'
|
||||||
implementation "androidx.biometric:biometric:1.1.0"
|
implementation "androidx.biometric:biometric:1.1.0"
|
||||||
|
|
||||||
|
implementation "dev.sasikanth:colorsheet:1.0.1"
|
||||||
|
|
||||||
//ROOM DB
|
//ROOM DB
|
||||||
def room_version = "2.2.6"
|
def room_version = "2.2.6"
|
||||||
implementation "androidx.room:room-runtime:$room_version"
|
implementation "androidx.room:room-runtime:$room_version"
|
||||||
|
|
|
@ -18,6 +18,8 @@ import androidx.preference.*
|
||||||
import corewala.buran.Buran
|
import corewala.buran.Buran
|
||||||
import corewala.buran.R
|
import corewala.buran.R
|
||||||
import corewala.buran.io.keymanager.BuranBiometricManager
|
import corewala.buran.io.keymanager.BuranBiometricManager
|
||||||
|
import dev.sasikanth.colorsheet.ColorSheet
|
||||||
|
import dev.sasikanth.colorsheet.utils.ColorSheetUtils
|
||||||
|
|
||||||
const val PREFS_SET_CLIENT_CERT_REQ = 20
|
const val PREFS_SET_CLIENT_CERT_REQ = 20
|
||||||
|
|
||||||
|
@ -262,7 +264,7 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
||||||
themePreference.entryValues = themeValues.toTypedArray()
|
themePreference.entryValues = themeValues.toTypedArray()
|
||||||
appearanceCategory.addPreference(themePreference)
|
appearanceCategory.addPreference(themePreference)
|
||||||
|
|
||||||
themePreference.setOnPreferenceChangeListener{ _, theme ->
|
themePreference.setOnPreferenceChangeListener { _, theme ->
|
||||||
when (theme) {
|
when (theme) {
|
||||||
"theme_FollowSystem" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
"theme_FollowSystem" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
"theme_Light" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
"theme_Light" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
|
@ -272,30 +274,37 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
val coloursCSV = resources.openRawResource(R.raw.colours).bufferedReader().use { it.readLines() }
|
// Background colour picker
|
||||||
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
val colourLabels = mutableListOf<String>()
|
val backgroundColourPreference = Preference(context)
|
||||||
val colourValues = mutableListOf<String>()
|
|
||||||
|
|
||||||
coloursCSV.forEach{ line ->
|
|
||||||
val colour = line.split(",")
|
|
||||||
colourLabels.add(colour[0])
|
|
||||||
colourValues.add(colour[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
val backgroundColourPreference = ListPreference(context)
|
|
||||||
backgroundColourPreference.key = "background_colour"
|
backgroundColourPreference.key = "background_colour"
|
||||||
backgroundColourPreference.setDialogTitle(R.string.prefs_override_page_background_dialog_title)
|
|
||||||
backgroundColourPreference.setTitle(R.string.prefs_override_page_background_title)
|
backgroundColourPreference.setTitle(R.string.prefs_override_page_background_title)
|
||||||
backgroundColourPreference.setSummary(R.string.prefs_override_page_background)
|
backgroundColourPreference.setSummary(R.string.prefs_override_page_background)
|
||||||
backgroundColourPreference.setDefaultValue("#XXXXXX")
|
backgroundColourPreference.setOnPreferenceClickListener {
|
||||||
backgroundColourPreference.entries = colourLabels.toTypedArray()
|
ColorSheet().colorPicker(
|
||||||
backgroundColourPreference.entryValues = colourValues.toTypedArray()
|
selectedColor = sharedPreferences.getInt(
|
||||||
|
"background_colour_id",
|
||||||
|
ColorSheet.NO_COLOR
|
||||||
|
),
|
||||||
|
colors = listOf(Color.BLUE, Color.RED, Color.GREEN).toIntArray(),
|
||||||
|
noColorOption = true,
|
||||||
|
listener = {
|
||||||
|
val editor = sharedPreferences.edit()
|
||||||
|
editor.putString(backgroundColourPreference.key, ColorSheetUtils.colorToHex(it))
|
||||||
|
editor.putInt("background_colour_id", it)
|
||||||
|
editor.commit()
|
||||||
|
backgroundColourPreference.callChangeListener(it)
|
||||||
|
}
|
||||||
|
).show(parentFragmentManager)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receives the ColorSheet color code, converts to hex and if it's a color sets it for the current view
|
||||||
backgroundColourPreference.setOnPreferenceChangeListener { _, colour ->
|
backgroundColourPreference.setOnPreferenceChangeListener { _, colour ->
|
||||||
|
val hex = ColorSheetUtils.colorToHex(colour as Int)
|
||||||
when (colour) {
|
when (colour) {
|
||||||
"#XXXXXX" -> this.view?.background = null
|
ColorSheet.NO_COLOR -> this.view?.background = null
|
||||||
else -> this.view?.background = ColorDrawable(Color.parseColor("$colour"))
|
else -> this.view?.background = ColorDrawable(Color.parseColor("$hex"))
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
Loading…
Reference in New Issue