mirror of https://github.com/Corewala/Buran
Implement using a color or another depending on light/dark mode setting
Signed-off-by: Ariel Costas <arielcostas@mailbox.org>
This commit is contained in:
parent
6de0568d11
commit
b364590d4b
|
@ -28,7 +28,6 @@ import androidx.databinding.DataBindingUtil
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import corewala.*
|
|
||||||
import corewala.buran.BuildConfig
|
import corewala.buran.BuildConfig
|
||||||
import corewala.buran.Buran
|
import corewala.buran.Buran
|
||||||
import corewala.buran.OmniTerm
|
import corewala.buran.OmniTerm
|
||||||
|
@ -48,7 +47,14 @@ import corewala.buran.ui.content_text.TextDialog
|
||||||
import corewala.buran.ui.gemtext_adapter.AbstractGemtextAdapter
|
import corewala.buran.ui.gemtext_adapter.AbstractGemtextAdapter
|
||||||
import corewala.buran.ui.modals_menus.history.HistoryDialog
|
import corewala.buran.ui.modals_menus.history.HistoryDialog
|
||||||
import corewala.buran.ui.modals_menus.overflow.OverflowPopup
|
import corewala.buran.ui.modals_menus.overflow.OverflowPopup
|
||||||
|
import corewala.buran.ui.settings.COLORSCHEME_DARK
|
||||||
|
import corewala.buran.ui.settings.COLORSCHEME_LIGHT
|
||||||
|
import corewala.buran.ui.settings.PAIRS
|
||||||
import corewala.buran.ui.settings.SettingsActivity
|
import corewala.buran.ui.settings.SettingsActivity
|
||||||
|
import corewala.hideKeyboard
|
||||||
|
import corewala.showKeyboard
|
||||||
|
import corewala.toURI
|
||||||
|
import corewala.visibleRetainingSpace
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
@ -360,32 +366,35 @@ class GemActivity : AppCompatActivity() {
|
||||||
Buran.DEFAULT_SEARCH_BASE
|
Buran.DEFAULT_SEARCH_BASE
|
||||||
) ?: Buran.DEFAULT_SEARCH_BASE
|
) ?: Buran.DEFAULT_SEARCH_BASE
|
||||||
|
|
||||||
if(
|
if (
|
||||||
!searchBase.startsWith("gemini://")
|
!searchBase.startsWith("gemini://")
|
||||||
or searchBase.contains(" ")
|
or searchBase.contains(" ")
|
||||||
or !searchBase.contains(".")
|
or !searchBase.contains(".")
|
||||||
or !searchBase.endsWith("?")
|
or !searchBase.endsWith("?")
|
||||||
){
|
) {
|
||||||
searchBase = Buran.DEFAULT_SEARCH_BASE
|
searchBase = Buran.DEFAULT_SEARCH_BASE
|
||||||
}
|
}
|
||||||
|
|
||||||
when {
|
if (prefs.contains("bg_name")) {
|
||||||
prefs.contains("background_colour") -> {
|
val backgroundName = prefs.getString("bg_name", "none")
|
||||||
when (val backgroundColor = prefs.getString("background_colour", "#XXXXXX")) {
|
val colorscheme = if (prefs.getString("theme", null) == "theme_Dark") {
|
||||||
"#XXXXXX" -> binding.rootCoord.background = null
|
COLORSCHEME_DARK
|
||||||
else -> binding.rootCoord.background = ColorDrawable(Color.parseColor("$backgroundColor"))
|
} else {
|
||||||
}
|
COLORSCHEME_LIGHT
|
||||||
}
|
}
|
||||||
}
|
val color =
|
||||||
|
PAIRS[backgroundName]?.byTheme(colorscheme) ?: PAIRS["none"]!!.byTheme(colorscheme)
|
||||||
|
binding.rootCoord.background = ColorDrawable(Color.parseColor(color))
|
||||||
|
}
|
||||||
|
|
||||||
val showInlineIcons = prefs.getBoolean(
|
val showInlineIcons = prefs.getBoolean(
|
||||||
"show_inline_icons",
|
"show_inline_icons",
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
adapter.inlineIcons(showInlineIcons)
|
adapter.inlineIcons(showInlineIcons)
|
||||||
|
|
||||||
val showLinkButtons = prefs.getBoolean(
|
val showLinkButtons = prefs.getBoolean(
|
||||||
"show_link_buttons",
|
"show_link_buttons",
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
adapter.linkButtons(showLinkButtons)
|
adapter.linkButtons(showLinkButtons)
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package corewala.buran.ui.settings
|
||||||
|
|
||||||
|
val COLORSCHEME_DARK = "dark";
|
||||||
|
val COLORSCHEME_LIGHT = "light";
|
||||||
|
|
||||||
|
data class ColorPair(val light: String, val dark: String) {
|
||||||
|
fun byTheme(theme: String): String {
|
||||||
|
return if (theme == COLORSCHEME_DARK) dark else light
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val PAIRS: Map<String, ColorPair> = mapOf(
|
||||||
|
Pair("none", ColorPair("#ffffff", "#000000")),
|
||||||
|
Pair("red", ColorPair("#fee2e2", "#7f1d1d")),
|
||||||
|
Pair("orange", ColorPair("#ffedd5", "#7c2d12")),
|
||||||
|
Pair("yellow", ColorPair("#fef9c3", "#713f12")),
|
||||||
|
Pair("green", ColorPair("#dcfce7", "#14532d")),
|
||||||
|
Pair("sky", ColorPair("#e0f2fe", "#0c4a6e")),
|
||||||
|
Pair("purple", ColorPair("#f3e8ff", "#581c87"))
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getNameByColor(color: String, colorscheme: String): String {
|
||||||
|
for ((key, value) in PAIRS) {
|
||||||
|
if (value.byTheme(colorscheme).toUpperCase() == color.toUpperCase()) {
|
||||||
|
return key
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PAIRS["none"]!!.byTheme(colorscheme)
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ const val PREFS_SET_CLIENT_CERT_REQ = 20
|
||||||
|
|
||||||
class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
|
class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
lateinit var prefs: SharedPreferences
|
lateinit var prefs: SharedPreferences
|
||||||
|
|
||||||
private lateinit var clientCertPref: Preference
|
private lateinit var clientCertPref: Preference
|
||||||
|
|
||||||
|
@ -276,36 +276,31 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChan
|
||||||
// Background colour picker
|
// Background colour picker
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity)
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
val backgroundColourPreference = Preference(context)
|
val backgroundColourPreference = Preference(context)
|
||||||
backgroundColourPreference.key = "background_colour"
|
val colorscheme = if (themePreference.value == "theme_Dark") {
|
||||||
|
COLORSCHEME_DARK
|
||||||
|
} else {
|
||||||
|
COLORSCHEME_LIGHT
|
||||||
|
}
|
||||||
|
|
||||||
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.setOnPreferenceClickListener {
|
backgroundColourPreference.setOnPreferenceClickListener {
|
||||||
ColorSheet().colorPicker(
|
ColorSheet().colorPicker(
|
||||||
selectedColor = sharedPreferences.getInt(
|
selectedColor = Color.parseColor(
|
||||||
"background_colour_id",
|
PAIRS[sharedPreferences.getString(
|
||||||
ColorSheet.NO_COLOR
|
"bg_name",
|
||||||
|
null
|
||||||
|
)]?.byTheme(colorscheme) ?: PAIRS["none"]!!.byTheme("none")
|
||||||
),
|
),
|
||||||
colors = listOf(
|
colors = PAIRS.map {
|
||||||
Color.parseColor("#fee2e2"),
|
Color.parseColor(it.value.byTheme(colorscheme))
|
||||||
Color.parseColor("#ffedd5"),
|
}.toIntArray(),
|
||||||
Color.parseColor("#fef9c3"),
|
noColorOption = false,
|
||||||
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 = {
|
listener = {
|
||||||
|
val chosenHex = ColorSheetUtils.colorToHex(it)
|
||||||
val editor = sharedPreferences.edit()
|
val editor = sharedPreferences.edit()
|
||||||
editor.putString(backgroundColourPreference.key, ColorSheetUtils.colorToHex(it))
|
val namebycolor = getNameByColor(chosenHex, colorscheme)
|
||||||
editor.putInt("background_colour_id", it)
|
editor.putString("bg_name", namebycolor)
|
||||||
editor.commit()
|
editor.commit()
|
||||||
backgroundColourPreference.callChangeListener(it)
|
backgroundColourPreference.callChangeListener(it)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue