mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Refresh keyboard on changing action key
This commit is contained in:
parent
270ff11fea
commit
9355b32466
@ -137,9 +137,25 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
||||
|
||||
private var lastEditorInfo: EditorInfo? = null
|
||||
|
||||
private var settingsRefreshRequired = false
|
||||
private fun recreateKeyboard() {
|
||||
latinIMELegacy.updateTheme()
|
||||
latinIMELegacy.mKeyboardSwitcher.mState.onLoadKeyboard(latinIMELegacy.currentAutoCapsState, latinIMELegacy.currentRecapitalizeState);
|
||||
|
||||
if(settingsRefreshRequired) {
|
||||
latinIMELegacy.mKeyboardSwitcher.loadKeyboard(
|
||||
currentInputEditorInfo ?: return,
|
||||
latinIMELegacy.mSettings.current,
|
||||
latinIMELegacy.currentAutoCapsState,
|
||||
latinIMELegacy.currentRecapitalizeState
|
||||
)
|
||||
} else {
|
||||
latinIMELegacy.mKeyboardSwitcher.mState.onLoadKeyboard(
|
||||
latinIMELegacy.currentAutoCapsState,
|
||||
latinIMELegacy.currentRecapitalizeState
|
||||
)
|
||||
}
|
||||
|
||||
settingsRefreshRequired = false
|
||||
}
|
||||
|
||||
private var isNavigationBarVisible = false
|
||||
@ -197,6 +213,18 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
||||
}
|
||||
}
|
||||
|
||||
private fun invalidateKeyboard(refreshSettings: Boolean = false) {
|
||||
settingsRefreshRequired = settingsRefreshRequired || refreshSettings
|
||||
|
||||
if(!uixManager.isMainKeyboardHidden) {
|
||||
println("Recreating keyboard")
|
||||
recreateKeyboard()
|
||||
} else {
|
||||
println("Pend recreate keyboard")
|
||||
pendingRecreateKeyboard = true
|
||||
}
|
||||
}
|
||||
|
||||
fun updateTheme(newTheme: ThemeOption) {
|
||||
assert(newTheme.available(this))
|
||||
|
||||
@ -204,12 +232,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
||||
activeThemeOption = newTheme
|
||||
updateDrawableProvider(newTheme.obtainColors(this))
|
||||
deferSetSetting(THEME_KEY, newTheme.key)
|
||||
|
||||
if(!uixManager.isMainKeyboardHidden) {
|
||||
recreateKeyboard()
|
||||
} else {
|
||||
pendingRecreateKeyboard = true
|
||||
}
|
||||
invalidateKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,11 +321,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
||||
if (provider.hasUpdated(it)) {
|
||||
activeThemeOption?.obtainColors?.let { f ->
|
||||
updateDrawableProvider(f(this@LatinIME))
|
||||
if (!uixManager.isMainKeyboardHidden) {
|
||||
recreateKeyboard()
|
||||
} else {
|
||||
pendingRecreateKeyboard = true
|
||||
}
|
||||
invalidateKeyboard()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -339,6 +358,15 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
||||
}
|
||||
|
||||
uixManager.onCreate()
|
||||
|
||||
Settings.getInstance().settingsChangedListeners.add { oldSettings, newSettings ->
|
||||
val differs = (oldSettings.mActionKeyId != newSettings.mActionKeyId)
|
||||
|| (oldSettings.mShowsActionKey != newSettings.mShowsActionKey)
|
||||
|
||||
if (differs) {
|
||||
invalidateKeyboard(refreshSettings = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
@ -354,6 +382,8 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
||||
languageModelFacilitator.destroyModel()
|
||||
}
|
||||
|
||||
Settings.getInstance().settingsChangedListeners.clear()
|
||||
|
||||
latinIMELegacy.onDestroy()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import org.futo.inputmethod.latin.utils.RunInLocale;
|
||||
import org.futo.inputmethod.latin.utils.StatsUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@ -140,6 +141,11 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||
|
||||
private static final Settings sInstance = new Settings();
|
||||
|
||||
public interface SettingsChangedListener {
|
||||
void onChanged(SettingsValues old, SettingsValues settings);
|
||||
}
|
||||
public HashSet<SettingsChangedListener> settingsChangedListeners = new HashSet<>();
|
||||
|
||||
public static Settings getInstance() {
|
||||
return sInstance;
|
||||
}
|
||||
@ -189,6 +195,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||
public void loadSettings(final Context context, final Locale locale,
|
||||
@Nonnull final InputAttributes inputAttributes) {
|
||||
mSettingsValuesLock.lock();
|
||||
|
||||
SettingsValues oldSettings = mSettingsValues;
|
||||
|
||||
mContext = context;
|
||||
try {
|
||||
final SharedPreferences prefs = mPrefs;
|
||||
@ -202,6 +211,14 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||
} finally {
|
||||
mSettingsValuesLock.unlock();
|
||||
}
|
||||
|
||||
for (SettingsChangedListener x : settingsChangedListeners) {
|
||||
try {
|
||||
x.onChanged(oldSettings, mSettingsValues);
|
||||
} catch(Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this method and add proxy method to SettingsValues.
|
||||
|
Loading…
Reference in New Issue
Block a user