diff --git a/app/build.gradle b/app/build.gradle index b2891c1..0bf7100 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,6 +59,8 @@ dependencies { implementation 'com.google.android.material:material:1.3.0-rc01' implementation "androidx.biometric:biometric:1.1.0" + implementation "dev.sasikanth:colorsheet:1.0.1" + //ROOM DB def room_version = "2.2.6" implementation "androidx.room:room-runtime:$room_version" diff --git a/app/src/main/java/corewala/buran/ui/settings/SettingsFragment.kt b/app/src/main/java/corewala/buran/ui/settings/SettingsFragment.kt index e77e5c4..82983b2 100644 --- a/app/src/main/java/corewala/buran/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/corewala/buran/ui/settings/SettingsFragment.kt @@ -18,6 +18,8 @@ import androidx.preference.* import corewala.buran.Buran import corewala.buran.R 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 @@ -262,7 +264,7 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang themePreference.entryValues = themeValues.toTypedArray() appearanceCategory.addPreference(themePreference) - themePreference.setOnPreferenceChangeListener{ _, theme -> + themePreference.setOnPreferenceChangeListener { _, theme -> when (theme) { "theme_FollowSystem" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) "theme_Light" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) @@ -272,30 +274,37 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang true } - val coloursCSV = resources.openRawResource(R.raw.colours).bufferedReader().use { it.readLines() } - - val colourLabels = mutableListOf() - val colourValues = mutableListOf() - - coloursCSV.forEach{ line -> - val colour = line.split(",") - colourLabels.add(colour[0]) - colourValues.add(colour[1]) - } - - val backgroundColourPreference = ListPreference(context) + // Background colour picker + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity) + val backgroundColourPreference = Preference(context) backgroundColourPreference.key = "background_colour" - backgroundColourPreference.setDialogTitle(R.string.prefs_override_page_background_dialog_title) backgroundColourPreference.setTitle(R.string.prefs_override_page_background_title) backgroundColourPreference.setSummary(R.string.prefs_override_page_background) - backgroundColourPreference.setDefaultValue("#XXXXXX") - backgroundColourPreference.entries = colourLabels.toTypedArray() - backgroundColourPreference.entryValues = colourValues.toTypedArray() + backgroundColourPreference.setOnPreferenceClickListener { + ColorSheet().colorPicker( + 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 -> + val hex = ColorSheetUtils.colorToHex(colour as Int) when (colour) { - "#XXXXXX" -> this.view?.background = null - else -> this.view?.background = ColorDrawable(Color.parseColor("$colour")) + ColorSheet.NO_COLOR -> this.view?.background = null + else -> this.view?.background = ColorDrawable(Color.parseColor("$hex")) } true