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 lastEditorInfo: EditorInfo? = null
|
||||||
|
|
||||||
|
private var settingsRefreshRequired = false
|
||||||
private fun recreateKeyboard() {
|
private fun recreateKeyboard() {
|
||||||
latinIMELegacy.updateTheme()
|
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
|
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) {
|
fun updateTheme(newTheme: ThemeOption) {
|
||||||
assert(newTheme.available(this))
|
assert(newTheme.available(this))
|
||||||
|
|
||||||
@ -204,12 +232,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
|||||||
activeThemeOption = newTheme
|
activeThemeOption = newTheme
|
||||||
updateDrawableProvider(newTheme.obtainColors(this))
|
updateDrawableProvider(newTheme.obtainColors(this))
|
||||||
deferSetSetting(THEME_KEY, newTheme.key)
|
deferSetSetting(THEME_KEY, newTheme.key)
|
||||||
|
invalidateKeyboard()
|
||||||
if(!uixManager.isMainKeyboardHidden) {
|
|
||||||
recreateKeyboard()
|
|
||||||
} else {
|
|
||||||
pendingRecreateKeyboard = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,11 +321,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
|||||||
if (provider.hasUpdated(it)) {
|
if (provider.hasUpdated(it)) {
|
||||||
activeThemeOption?.obtainColors?.let { f ->
|
activeThemeOption?.obtainColors?.let { f ->
|
||||||
updateDrawableProvider(f(this@LatinIME))
|
updateDrawableProvider(f(this@LatinIME))
|
||||||
if (!uixManager.isMainKeyboardHidden) {
|
invalidateKeyboard()
|
||||||
recreateKeyboard()
|
|
||||||
} else {
|
|
||||||
pendingRecreateKeyboard = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,6 +358,15 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
|||||||
}
|
}
|
||||||
|
|
||||||
uixManager.onCreate()
|
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() {
|
override fun onDestroy() {
|
||||||
@ -354,6 +382,8 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
|||||||
languageModelFacilitator.destroyModel()
|
languageModelFacilitator.destroyModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Settings.getInstance().settingsChangedListeners.clear()
|
||||||
|
|
||||||
latinIMELegacy.onDestroy()
|
latinIMELegacy.onDestroy()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import org.futo.inputmethod.latin.utils.RunInLocale;
|
|||||||
import org.futo.inputmethod.latin.utils.StatsUtils;
|
import org.futo.inputmethod.latin.utils.StatsUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@ -140,6 +141,11 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
|
|
||||||
private static final Settings sInstance = new Settings();
|
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() {
|
public static Settings getInstance() {
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
@ -189,6 +195,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
public void loadSettings(final Context context, final Locale locale,
|
public void loadSettings(final Context context, final Locale locale,
|
||||||
@Nonnull final InputAttributes inputAttributes) {
|
@Nonnull final InputAttributes inputAttributes) {
|
||||||
mSettingsValuesLock.lock();
|
mSettingsValuesLock.lock();
|
||||||
|
|
||||||
|
SettingsValues oldSettings = mSettingsValues;
|
||||||
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
try {
|
try {
|
||||||
final SharedPreferences prefs = mPrefs;
|
final SharedPreferences prefs = mPrefs;
|
||||||
@ -202,6 +211,14 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
} finally {
|
} finally {
|
||||||
mSettingsValuesLock.unlock();
|
mSettingsValuesLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (SettingsChangedListener x : settingsChangedListeners) {
|
||||||
|
try {
|
||||||
|
x.onChanged(oldSettings, mSettingsValues);
|
||||||
|
} catch(Exception ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method and add proxy method to SettingsValues.
|
// TODO: Remove this method and add proxy method to SettingsValues.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user