1
0
Fork 0

big code cleanup

This commit is contained in:
sspanak 2025-05-15 18:54:50 +03:00 committed by Dimo Karaivanov
parent 0fd7a97739
commit 3e03968609
12 changed files with 17 additions and 43 deletions

View file

@ -154,7 +154,6 @@ abstract public class CommandHandler extends TextEditingHandler {
determineTextCase(); determineTextCase();
} }
suggestionOps.setInputMode(mInputMode);
settings.saveInputMode(mInputMode.getId()); settings.saveInputMode(mInputMode.getId());
} }

View file

@ -73,7 +73,6 @@ public abstract class TypingHandler extends KeyPadHandler {
mInputMode = determineInputMode(); mInputMode = determineInputMode();
determineTextCase(); determineTextCase();
suggestionOps.set(null); suggestionOps.set(null);
suggestionOps.setInputMode(mInputMode);
return true; return true;
} }
@ -91,7 +90,6 @@ public abstract class TypingHandler extends KeyPadHandler {
// changing the TextField and notifying all interested classes is an atomic operation // changing the TextField and notifying all interested classes is an atomic operation
appHacks = new AppHacks(inputType, textField, textSelection); appHacks = new AppHacks(inputType, textField, textSelection);
suggestionOps.setTextField(textField); suggestionOps.setTextField(textField);
suggestionOps.setInputMode(mInputMode);
} }

View file

@ -56,7 +56,7 @@ abstract class UiHandler extends AbstractHandler {
protected void setStatusIcon(InputMode mode, Language language) { protected void setStatusIcon(InputMode mode, Language language) {
int resId = new StatusIcon(this, settings, mode, language).resourceId; int resId = new StatusIcon(settings, mode, language).resourceId;
if (resId == 0) { if (resId == 0) {
hideStatusIcon(); hideStatusIcon();
} else { } else {

View file

@ -8,10 +8,8 @@ import androidx.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import io.github.sspanak.tt9.ime.modes.InputMode;
import io.github.sspanak.tt9.languages.Language; import io.github.sspanak.tt9.languages.Language;
import io.github.sspanak.tt9.languages.LanguageKind; import io.github.sspanak.tt9.languages.LanguageKind;
import io.github.sspanak.tt9.languages.NullLanguage;
import io.github.sspanak.tt9.preferences.settings.SettingsStore; import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.ui.main.ResizableMainView; import io.github.sspanak.tt9.ui.main.ResizableMainView;
import io.github.sspanak.tt9.ui.tray.SuggestionsBar; import io.github.sspanak.tt9.ui.tray.SuggestionsBar;
@ -23,9 +21,6 @@ public class SuggestionOps {
@NonNull private final Handler delayedAcceptHandler; @NonNull private final Handler delayedAcceptHandler;
@NonNull private final ConsumerCompat<String> onDelayedAccept; @NonNull private final ConsumerCompat<String> onDelayedAccept;
@Nullable private InputMode inputMode;
@NonNull private Language language;
@Nullable private final SettingsStore settings;
@Nullable protected SuggestionsBar suggestionBar; @Nullable protected SuggestionsBar suggestionBar;
@NonNull private TextField textField; @NonNull private TextField textField;
@ -34,8 +29,6 @@ public class SuggestionOps {
delayedAcceptHandler = new Handler(Looper.getMainLooper()); delayedAcceptHandler = new Handler(Looper.getMainLooper());
this.onDelayedAccept = onDelayedAccept != null ? onDelayedAccept : s -> {}; this.onDelayedAccept = onDelayedAccept != null ? onDelayedAccept : s -> {};
language = new NullLanguage();
this.settings = settings;
this.textField = textField != null ? textField : new TextField(null, null, null); this.textField = textField != null ? textField : new TextField(null, null, null);
if (settings != null && mainView != null && onSuggestionClick != null) { if (settings != null && mainView != null && onSuggestionClick != null) {
@ -43,16 +36,9 @@ public class SuggestionOps {
} }
} }
public void setLanguage(@Nullable Language newLanguage) {
public void setInputMode(@Nullable InputMode inputMode) {
this.inputMode = inputMode;
}
public void setLanguage(@Nullable Language language) {
this.language = language == null ? new NullLanguage() : language;
if (suggestionBar != null) { if (suggestionBar != null) {
suggestionBar.setRTL(LanguageKind.isRTL(language)); suggestionBar.setRTL(LanguageKind.isRTL(newLanguage));
} }
} }

View file

@ -32,8 +32,4 @@ public class InputModeKind {
mode.getId() == InputMode.MODE_KATAKANA mode.getId() == InputMode.MODE_KATAKANA
); );
} }
public static boolean isCheonjiin(InputMode mode) {
return mode != null && mode.getClass().equals(ModeCheonjiin.class);
}
} }

View file

@ -1,7 +1,6 @@
package io.github.sspanak.tt9.ime.modes; package io.github.sspanak.tt9.ime.modes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
@ -56,15 +55,15 @@ class Mode123 extends ModePassthrough {
private void setDefaultSpecialCharacters() { private void setDefaultSpecialCharacters() {
Language english = LanguageCollection.getByLocale("en"); Language english = LanguageCollection.getByLocale("en");
KEY_CHARACTERS.add( KEY_CHARACTERS.add(
TextTools.removeLettersFromList(orderCharsForNumericField(settings.getOrderedKeyChars(english, 0), null)) TextTools.removeLettersFromList(orderCharsForNumericField(settings.getOrderedKeyChars(english, 0)))
); );
KEY_CHARACTERS.add( KEY_CHARACTERS.add(
TextTools.removeLettersFromList(orderCharsForNumericField(settings.getOrderedKeyChars(english, 1), null)) TextTools.removeLettersFromList(orderCharsForNumericField(settings.getOrderedKeyChars(english, 1)))
); );
} }
private ArrayList<String> orderCharsForNumericField(@NonNull ArrayList<String> unordered, @Nullable ArrayList<String> o) { private ArrayList<String> orderCharsForNumericField(@NonNull ArrayList<String> unordered) {
ArrayList<String> ordered = new ArrayList<>(); ArrayList<String> ordered = new ArrayList<>();
if (unordered.contains(".")) { if (unordered.contains(".")) {

View file

@ -88,7 +88,7 @@ public class ModeBopomofo extends ModePinyin {
} }
/******************************* ACCEPT WORDS *********************************/ /* ****************************** ACCEPT WORDS *********************************/
/** /**
* In Bopomofo mode, the 0-key is not Spacebar, so we do not rely on the parents to handle accepting * In Bopomofo mode, the 0-key is not Spacebar, so we do not rely on the parents to handle accepting

View file

@ -135,8 +135,6 @@ public class AutoSpace {
* Similar to "shouldAddAfterPunctuation()", but determines whether to add a space after words. * Similar to "shouldAddAfterPunctuation()", but determines whether to add a space after words.
*/ */
private boolean shouldAddAfterWord(boolean isWordAcceptedManually, String previousChars, Text nextChars, int nextKey) { private boolean shouldAddAfterWord(boolean isWordAcceptedManually, String previousChars, Text nextChars, int nextKey) {
char firstNextChar = nextChars.isEmpty() ? 0 : nextChars.toString().charAt(0);
return return
isWordAcceptedManually // Do not add space when auto-accepting words, because it feels very confusing when typing. isWordAcceptedManually // Do not add space when auto-accepting words, because it feels very confusing when typing.
&& isLanguageWithAlphabet && isLanguageWithAlphabet

View file

@ -115,8 +115,12 @@ public class PopupBuilder {
} }
public Dialog show() { public void show() {
return DeviceInfo.AT_LEAST_ANDROID_12 ? builder12.show() : builderLegacy.show(); if (DeviceInfo.AT_LEAST_ANDROID_12) {
builder12.show();
} else {
builderLegacy.show();
}
} }

File diff suppressed because one or more lines are too long

View file

@ -3,10 +3,6 @@ package io.github.sspanak.tt9.util.colors;
public class SystemColor { public class SystemColor {
protected int color; protected int color;
protected SystemColor(int color) {
this.color = color;
}
public SystemColor() { public SystemColor() {
color = 0; color = 0;
} }

View file

@ -73,7 +73,7 @@ public class SystemSettings {
/** /**
* Even though the background changes automatically on Android 15, thanks to edge-to-edge, * Even though the background changes automatically on Android 15, thanks to edge-to-edge,
* the text/icon color remains the device default. This function allows us to change it. * the text/icon color remains the device default. This function allows us to change it.
* @see: <a href="https://stackoverflow.com/a/77240330">the only working solution</a>. * {@code @see:} <a href="https://stackoverflow.com/a/77240330">the only working solution</a>.
*/ */
public static void setNavigationBarDarkTheme(@Nullable Window window, boolean dark) { public static void setNavigationBarDarkTheme(@Nullable Window window, boolean dark) {
if (!DeviceInfo.AT_LEAST_ANDROID_11) { if (!DeviceInfo.AT_LEAST_ANDROID_11) {