Add better colors to be picked

Colors picked are red, orange, yellow, green, sky and purple -100 and -900 from https://tailwindcss.com/docs/customizing-colors#default-color-palette

Signed-off-by: Ariel Costas <arielcostas@mailbox.org>
This commit is contained in:
Ariel Costas 2022-09-03 21:53:01 +02:00
parent a7312e44ee
commit 0e3abd3537
1 changed files with 530 additions and 501 deletions

View File

@ -22,7 +22,7 @@ import dev.sasikanth.colorsheet.utils.ColorSheetUtils
const val PREFS_SET_CLIENT_CERT_REQ = 20
class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
lateinit var prefs: SharedPreferences
@ -54,15 +54,15 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
Buran.DEFAULT_HOME_CAPSULE
)?.trim()
homePreference.summary = if(homecapsule.isNullOrEmpty()){
homePreference.summary = if (homecapsule.isNullOrEmpty()) {
context.getString(R.string.no_home_capsule_set)
}else if(
} else if (
!homecapsule.startsWith("gemini://")
or homecapsule.contains(" ")
or !homecapsule.contains(".")
){
) {
context.getString(R.string.not_valid_address)
}else{
} else {
homecapsule
}
@ -70,20 +70,20 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
homePreference.negativeButtonText = getString(R.string.cancel)
homePreference.setOnPreferenceChangeListener { _, newValue ->
val newHomecapsule = newValue.toString().trim()
homePreference.summary = if(newHomecapsule.isNullOrEmpty()){
homePreference.summary = if (newHomecapsule.isNullOrEmpty()) {
context.getString(R.string.no_home_capsule_set)
}else if(
} else if (
!newHomecapsule.startsWith("gemini://")
or newHomecapsule.contains(" ")
or !newHomecapsule.contains(".")
){
) {
context.getString(R.string.not_valid_address)
}else{
} else {
newHomecapsule
}
true
}
homePreference.setOnBindEditTextListener{ editText ->
homePreference.setOnBindEditTextListener { editText ->
editText.imeOptions = EditorInfo.IME_ACTION_DONE
editText.setSelection(editText.text.toString().length)//Set caret position to end
}
@ -100,17 +100,17 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
Buran.DEFAULT_SEARCH_BASE
)?.trim()
searchPreference.summary = if(searchengine.isNullOrEmpty()){
searchPreference.summary = if (searchengine.isNullOrEmpty()) {
Buran.DEFAULT_SEARCH_BASE
}else if(
} else if (
!searchengine.startsWith("gemini://")
or searchengine.contains(" ")
or !searchengine.contains(".")
){
) {
context.getString(R.string.not_valid_address)
}else if(!searchengine.endsWith("?")){
} else if (!searchengine.endsWith("?")) {
context.getString(R.string.not_valid_search_string)
}else{
} else {
searchengine
}
@ -118,22 +118,22 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
searchPreference.negativeButtonText = getString(R.string.cancel)
searchPreference.setOnPreferenceChangeListener { _, newValue ->
val newSearchBase = newValue.toString().trim()
searchPreference.summary = if(newSearchBase.isNullOrEmpty()){
searchPreference.summary = if (newSearchBase.isNullOrEmpty()) {
Buran.DEFAULT_SEARCH_BASE
}else if(
} else if (
!newSearchBase.startsWith("gemini://")
or newSearchBase.contains(" ")
or !newSearchBase.contains(".")
){
) {
context.getString(R.string.not_valid_address)
}else if(!newSearchBase.endsWith("?")){
} else if (!newSearchBase.endsWith("?")) {
context.getString(R.string.not_valid_search_string)
}else{
} else {
newSearchBase
}
true
}
searchPreference.setOnBindEditTextListener{ editText ->
searchPreference.setOnBindEditTextListener { editText ->
editText.imeOptions = EditorInfo.IME_ACTION_DONE
editText.setSelection(editText.text.toString().length)//Set caret position to end
}
@ -168,7 +168,7 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
preferenceScreen = screen
}
private fun buildWebSection(context: Context?, screen: PreferenceScreen){
private fun buildWebSection(context: Context?, screen: PreferenceScreen) {
val webCategory = PreferenceCategory(context)
webCategory.key = "web_category"
webCategory.title = getString(R.string.web_content)
@ -202,15 +202,15 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
null
)?.trim()
httpGeminiProxy.summary = if(httpProxy.isNullOrEmpty()){
httpGeminiProxy.summary = if (httpProxy.isNullOrEmpty()) {
getString(R.string.no_http_proxy_set)
}else if(
} else if (
!httpProxy.startsWith("gemini://")
or httpProxy.contains(" ")
or !httpProxy.contains(".")
){
) {
getString(R.string.not_valid_address)
}else{
} else {
httpProxy
}
@ -218,20 +218,20 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
httpGeminiProxy.negativeButtonText = getString(R.string.cancel)
httpGeminiProxy.setOnPreferenceChangeListener { _, newValue ->
val newHomecapsule = newValue.toString().trim()
httpGeminiProxy.summary = if(newHomecapsule.isNullOrEmpty()){
httpGeminiProxy.summary = if (newHomecapsule.isNullOrEmpty()) {
getString(R.string.no_http_proxy_set)
}else if(
} else if (
!newHomecapsule.startsWith("gemini://")
or newHomecapsule.contains(" ")
or !newHomecapsule.contains(".")
){
) {
getString(R.string.not_valid_address)
}else{
} else {
newHomecapsule
}
true
}
httpGeminiProxy.setOnBindEditTextListener{ editText ->
httpGeminiProxy.setOnBindEditTextListener { editText ->
editText.imeOptions = EditorInfo.IME_ACTION_DONE
editText.setSelection(editText.text.toString().length)//Set caret position to end
}
@ -285,7 +285,22 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
"background_colour_id",
ColorSheet.NO_COLOR
),
colors = listOf(Color.BLUE, Color.RED, Color.GREEN).toIntArray(),
colors = listOf(
Color.parseColor("#fee2e2"),
Color.parseColor("#ffedd5"),
Color.parseColor("#fef9c3"),
Color.parseColor("#dcfce7"),
Color.parseColor("#e0f2fe"),
Color.parseColor("#f3e8ff"),
Color.parseColor("#7f1d1d"),
Color.parseColor("#7c2d12"),
Color.parseColor("#713f12"),
Color.parseColor("#14532d"),
Color.parseColor("#0c4a6e"),
Color.parseColor("#581c87"),
).toIntArray(),
noColorOption = true,
listener = {
val editor = sharedPreferences.edit()
@ -301,7 +316,7 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
appearanceCategory.addPreference(backgroundColourPreference)
}
private fun buildsAccessibility(context: Context?, screen: PreferenceScreen){
private fun buildsAccessibility(context: Context?, screen: PreferenceScreen) {
val accessibilityCategory = PreferenceCategory(context)
accessibilityCategory.key = "accessibility_category"
accessibilityCategory.title = getString(R.string.accessibility)
@ -386,7 +401,8 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
} else {
clientCertPassword.summary = getString(R.string.no_password)
}
clientCertPassword.isVisible = !preferenceManager.sharedPreferences.getBoolean("use_biometrics", false)
clientCertPassword.isVisible =
!preferenceManager.sharedPreferences.getBoolean("use_biometrics", false)
certificateCategory.addPreference(clientCertPassword)
val useBiometrics = SwitchPreferenceCompat(context)
@ -407,8 +423,9 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
passwordInitVector.isVisible = false
certificateCategory.addPreference(passwordInitVector)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){
useBiometrics.isVisible = (certPassword?.isNotEmpty() ?: false) or useBiometrics.isChecked
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
useBiometrics.isVisible =
(certPassword?.isNotEmpty() ?: false) or useBiometrics.isChecked
useBiometrics.setOnPreferenceChangeListener { _, newValue ->
val biometricManager = BuranBiometricManager()
@ -419,26 +436,35 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
println("Authentication error: $errorCode: $errString")
useBiometrics.isChecked = !(newValue as Boolean)
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
println("Authentication failed")
useBiometrics.isChecked = !(newValue as Boolean)
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
println("Authentication succeeded")
if(newValue as Boolean){
if (newValue as Boolean) {
println(certPassword)
val encryptedData = biometricManager.encryptData(certPassword!!, result.cryptoObject?.cipher!!)
val encryptedData = biometricManager.encryptData(
certPassword!!,
result.cryptoObject?.cipher!!
)
val ciphertext = encryptedData.ciphertext
val initializationVector = encryptedData.initializationVector
passwordInitVector.text = initializationVector.contentToString()
passwordCiphertext.text = ciphertext.contentToString()
clientCertPassword.text = null
}else{
val ciphertext = biometricManager.decodeByteArray(passwordCiphertext.text)
clientCertPassword.text = biometricManager.decryptData(ciphertext, result.cryptoObject?.cipher!!)
} else {
val ciphertext =
biometricManager.decodeByteArray(passwordCiphertext.text)
clientCertPassword.text = biometricManager.decryptData(
ciphertext,
result.cryptoObject?.cipher!!
)
clientCertPassword.summary = getDots(clientCertPassword.text)
}
clientCertPassword.isVisible = !(newValue as Boolean)
@ -447,10 +473,11 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
biometricManager.createBiometricPrompt(requireContext(), this, null, callback)
if(newValue as Boolean){
if (newValue as Boolean) {
biometricManager.authenticateToEncryptData()
}else{
val initializationVector = biometricManager.decodeByteArray(passwordInitVector.text)
} else {
val initializationVector =
biometricManager.decodeByteArray(passwordInitVector.text)
biometricManager.authenticateToDecryptData(initializationVector)
}
@ -474,7 +501,7 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
private fun getDots(value: String): String {
val sb = StringBuilder()
repeat(value.length){
repeat(value.length) {
sb.append("")
}
return sb.toString()
@ -485,7 +512,7 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if(requestCode == PREFS_SET_CLIENT_CERT_REQ && resultCode == RESULT_OK){
if (requestCode == PREFS_SET_CLIENT_CERT_REQ && resultCode == RESULT_OK) {
data?.data?.also { uri ->
preferenceManager.sharedPreferences.edit().putString(
Buran.PREF_KEY_CLIENT_CERT_URI,
@ -502,7 +529,8 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
private fun persistPermissions(uri: Uri) {
val contentResolver = requireContext().contentResolver
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
val takeFlags: Int =
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
contentResolver.takePersistableUriPermission(uri, takeFlags)
}
@ -512,7 +540,8 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
if (uri.scheme == "content") {
requireContext().contentResolver.query(uri, null, null, null, null).use { cursor ->
if (cursor != null && cursor.moveToFirst()) {
readableReference = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))
readableReference =
cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))
}
}
}