2025-01-25 22:07:56 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
package helium314.keyboard.settings
|
|
|
|
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.widget.RelativeLayout
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.compose.material3.Surface
|
|
|
|
import androidx.compose.ui.platform.ComposeView
|
|
|
|
import androidx.core.view.isGone
|
|
|
|
import helium314.keyboard.latin.R
|
|
|
|
import helium314.keyboard.latin.settings.Settings
|
2025-02-01 08:35:14 +01:00
|
|
|
import helium314.keyboard.latin.utils.prefs
|
2025-01-25 22:07:56 +01:00
|
|
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
|
|
|
2025-02-01 08:35:14 +01:00
|
|
|
// todo (roughly in order)
|
2025-02-02 13:38:55 +01:00
|
|
|
// make all prefs actually work
|
2025-02-02 17:58:18 +01:00
|
|
|
// advanced
|
|
|
|
// preferences
|
2025-02-01 09:19:58 +01:00
|
|
|
// try moving the recomposition of pref change somewhere else, so it's not duplicated everywhere
|
2025-02-01 08:35:14 +01:00
|
|
|
// make the pref lists more compact (compare with old settings)
|
|
|
|
// try making text size similar to old state (also in dialogs)
|
2025-02-05 05:42:10 +01:00
|
|
|
// more similar dialog style args (for all dialogs, or for none)
|
2025-02-01 08:35:14 +01:00
|
|
|
// check whether dialogs have the same colors, i think currently it's a bit inconsistent
|
2025-02-02 19:57:09 +01:00
|
|
|
// see all the properties for each alertDialog -> any way to set it in a single place?
|
2025-02-05 17:00:06 +01:00
|
|
|
// yes/no/default can now be confirmDialog
|
2025-02-02 19:57:09 +01:00
|
|
|
// title too huge for bg image and text on spacebar dialogs, also maybe somewhere else -> where to set in one place?
|
2025-02-01 10:32:06 +01:00
|
|
|
// check dark and light theme (don't have dynamic)
|
2025-02-01 08:35:14 +01:00
|
|
|
// rename both settingsActivities
|
|
|
|
// work on todos in other files
|
2025-02-05 16:29:26 +01:00
|
|
|
// calling KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext()) while keyboard is showing shows just full screen background
|
2025-02-01 08:35:14 +01:00
|
|
|
// use better / more structured and clear names and arrangement of files
|
2025-02-01 09:19:58 +01:00
|
|
|
// the prefDef and AllPrefs, also be clear about pref <-> key <-> prefKey (all used, probably should be latter)
|
2025-02-01 10:32:06 +01:00
|
|
|
// there is a lot more ambiguous naming...
|
2025-02-01 08:35:14 +01:00
|
|
|
// animations when stuff (dis)appears
|
|
|
|
// LaunchedEffect, AnimatedVisibility
|
2025-02-05 18:01:17 +01:00
|
|
|
// bg image inconsistent about being on toolbar or not
|
2025-02-01 08:35:14 +01:00
|
|
|
// performance
|
|
|
|
// find a nice way of testing (probably add logs for measuring time and recompositions)
|
2025-02-01 09:19:58 +01:00
|
|
|
// consider that stuff in composables can get called quite often on any changes
|
|
|
|
// -> use remember for things that are slow, but be careful about things that can change (e.g. values derived from prefs)
|
2025-02-01 08:35:14 +01:00
|
|
|
// improve performance when loading screens with many settings (lazyColumn?)
|
|
|
|
// first check whether it's really necessary (test advanced or correction screen normal and with lazyColumn)
|
|
|
|
// screens could have a lazy column of preferences and category separators, and the list has an if-setting-then-null for hiding
|
|
|
|
// lazyColumn also has a "key", this should be used and be the pref name (or maybe title because that's also for category separators)
|
|
|
|
// nice arrows (in top bar, and as next-screen indicator)
|
2025-02-01 01:07:21 +01:00
|
|
|
// PRs adding prefs -> need to do before continuing
|
|
|
|
// 1319 (soon)
|
|
|
|
// 1263 (no response for 3 weeks)
|
|
|
|
// merge main to implement all the new settings
|
2025-01-25 22:07:56 +01:00
|
|
|
// consider IME insets when searching
|
2025-01-29 21:30:43 +01:00
|
|
|
// dialogs should be rememberSaveable to survive display orientation change and stuff?
|
2025-02-01 08:35:14 +01:00
|
|
|
// try making old fragment back stuff work better, and try the different themes (with and without top bar)
|
|
|
|
// any way to get rid of the "old" background on starting settings? probably comes from app theme, can we avoid it?
|
|
|
|
// consider using simple list picker dialog (but the "full" one is probably better for language settings stuff)
|
|
|
|
// spdx headers everywhere
|
|
|
|
|
|
|
|
// what should be done, but not in this PR
|
|
|
|
// in general: changes to anything outside the new settings (unless necessary), and changes to how screens / fragments work
|
|
|
|
// re-organize screens, no need to keep exactly the same arrangement
|
|
|
|
// language settings (should change more than just move to compose)
|
|
|
|
// user dictionary settings (or maybe leave old state for a while?)
|
|
|
|
// color settings (should at least change how colors are stored, and have a color search/filter)
|
2025-02-01 09:19:58 +01:00
|
|
|
// allow users to add custom themes instead of only having a single one (maybe also switchable in colors settings)
|
2025-02-01 08:35:14 +01:00
|
|
|
// one single place for default values (to be used in composables and settings)
|
|
|
|
// make auto_correct_threshold a float directly with the list pref (needs pref upgrade)
|
|
|
|
// using context.prefs() outside settings
|
|
|
|
// merge PREF_TOOLBAR_CUSTOM_KEY_CODES and PREF_TOOLBAR_CUSTOM_LONGPRESS_CODES into one pref (don't forget settings upgrade)
|
|
|
|
// adjust debug settings
|
|
|
|
// have them in main screen?
|
|
|
|
// allow users to find the individual settings in search even if debug settings are not enabled?
|
2025-01-25 22:07:56 +01:00
|
|
|
|
|
|
|
// consider disabled settings & search
|
|
|
|
// don't show -> users confused
|
|
|
|
// show as disabled -> users confused
|
|
|
|
// show (but change will not do anything because another setting needs to be enabled first)
|
2025-02-01 08:35:14 +01:00
|
|
|
// -> last is probably best, but people will probably open issues no matter what
|
|
|
|
|
|
|
|
// maybe do after the PR
|
|
|
|
// bottom dummy text field (though we have the search now anyway, and thus maybe don't need it)
|
2025-01-25 22:07:56 +01:00
|
|
|
// search only in current pref screen, except when in main?
|
|
|
|
// try getting rid of appcompat stuff (activity, dialogs, ...)
|
2025-02-01 00:58:42 +01:00
|
|
|
// rearrange settings screens? now it should be very simple to do (definitely separate PR)
|
2025-01-25 22:07:56 +01:00
|
|
|
|
|
|
|
// preliminary results:
|
|
|
|
// looks ok (ugly M3 switches)
|
|
|
|
// performance
|
|
|
|
// time until app and screens are shown is clearly worse than previously (2-4x)
|
|
|
|
// gets much better when opening same screen again
|
|
|
|
// material3 is ~25% faster than material2
|
|
|
|
// debug is MUCH slower than release
|
2025-02-01 00:58:42 +01:00
|
|
|
// much of this is before the app actually starts (before App.onCreate), maybe loading the many compose classes slows down startup
|
2025-01-25 22:07:56 +01:00
|
|
|
// -> should be fine on reasonably recent phones (imo even still acceptable on S4 mini)
|
|
|
|
// apk size increase
|
|
|
|
// ca 900 kb with base + material2
|
|
|
|
// another 300 kb with navHost (and activity-compose, but not needed)
|
|
|
|
// another 300 kb when switching material2 to material3
|
|
|
|
// ca 150 kb reduction when removing androidx.preference
|
|
|
|
// -> too much, but still ok if we can get nicer preference stuff
|
2025-01-28 16:14:42 +01:00
|
|
|
// meh, and using a TextField adds another 300 kb... huge chunks for sth that seems so small
|
2025-01-25 22:07:56 +01:00
|
|
|
|
|
|
|
class SettingsActivity2 : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
|
2025-01-29 05:58:57 +01:00
|
|
|
private val prefs by lazy { this.prefs() }
|
2025-01-25 22:07:56 +01:00
|
|
|
val prefChanged = MutableStateFlow(0) // simple counter, as the only relevant information is that something changed
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
if (Settings.getInstance().current == null)
|
|
|
|
Settings.init(this)
|
|
|
|
|
|
|
|
allPrefs = AllPrefs(this)
|
2025-02-01 08:35:14 +01:00
|
|
|
|
|
|
|
// todo: when removing old settings completely, remove settings_activity.xml and supportFragmentManager stuff
|
|
|
|
// val cv = ComposeView(context = this)
|
|
|
|
// setContentView(cv)
|
2025-01-25 22:07:56 +01:00
|
|
|
setContentView(R.layout.settings_activity)
|
|
|
|
supportFragmentManager.addOnBackStackChangedListener {
|
|
|
|
updateContainerVisibility()
|
|
|
|
}
|
2025-02-01 08:35:14 +01:00
|
|
|
// cv.setContent { // todo: when removing old settings
|
2025-01-25 22:07:56 +01:00
|
|
|
findViewById<ComposeView>(R.id.navHost).setContent {
|
|
|
|
Theme {
|
|
|
|
Surface {
|
|
|
|
SettingsNavHost(
|
|
|
|
onClickBack = {
|
2025-02-01 08:35:14 +01:00
|
|
|
// this.finish() // todo: when removing old settings
|
|
|
|
if (supportFragmentManager.findFragmentById(R.id.settingsFragmentContainer) == null)
|
2025-01-25 22:07:56 +01:00
|
|
|
this.finish()
|
2025-02-01 08:35:14 +01:00
|
|
|
else supportFragmentManager.popBackStack()
|
2025-01-25 22:07:56 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-01 08:35:14 +01:00
|
|
|
private fun updateContainerVisibility() { // todo: remove when removing old settings
|
2025-01-25 22:07:56 +01:00
|
|
|
findViewById<RelativeLayout>(R.id.settingsFragmentContainer).isGone = supportFragmentManager.findFragmentById(R.id.settingsFragmentContainer) == null
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStop() {
|
|
|
|
prefs.unregisterOnSharedPreferenceChangeListener(this)
|
|
|
|
super.onStop()
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
// public write so compose previews can show the pref screens
|
|
|
|
lateinit var allPrefs: AllPrefs
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSharedPreferenceChanged(prefereces: SharedPreferences?, key: String?) {
|
|
|
|
prefChanged.value++
|
|
|
|
}
|
|
|
|
}
|
2025-02-01 08:35:14 +01:00
|
|
|
|
|
|
|
@JvmField
|
2025-02-01 08:43:04 +01:00
|
|
|
var keyboardNeedsReload = false
|