1
0
Fork 0

big code cleanup and code style fixes of the entire project

This commit is contained in:
sspanak 2023-04-18 12:08:45 +03:00 committed by Dimo Karaivanov
parent 4e5416f6b4
commit eb67ab18ea
23 changed files with 31 additions and 77 deletions

View file

@ -3,7 +3,7 @@ package io.github.sspanak.tt9;
import android.util.Log; import android.util.Log;
public class Logger { public class Logger {
public static int LEVEL = BuildConfig.DEBUG ? Log.DEBUG : Log.ERROR; public static final int LEVEL = BuildConfig.DEBUG ? Log.DEBUG : Log.ERROR;
static public void v(String tag, String msg) { static public void v(String tag, String msg) {
if (LEVEL <= Log.VERBOSE) { if (LEVEL <= Log.VERBOSE) {

View file

@ -2,6 +2,7 @@ package io.github.sspanak.tt9.db.migrations;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull;
import androidx.room.migration.Migration; import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase; import androidx.sqlite.db.SupportSQLiteDatabase;
@ -74,7 +75,7 @@ public class DB7 {
} }
@Override @Override
public void migrate(SupportSQLiteDatabase database) { public void migrate(@NonNull SupportSQLiteDatabase database) {
migrateSQL(database); migrateSQL(database);
migrateSettings(); migrateSettings();
} }

View file

@ -114,12 +114,6 @@ abstract class KeyPadHandler extends InputMethodService {
} }
@Override
public void onDestroy() {
super.onDestroy();
}
/** /**
* Use this to monitor key events being delivered to the application. We get * Use this to monitor key events being delivered to the application. We get
* first crack at them, and can either resume them or let them continue to * first crack at them, and can either resume them or let them continue to
@ -283,7 +277,6 @@ abstract class KeyPadHandler extends InputMethodService {
// toggle handlers // toggle handlers
abstract protected boolean shouldTrackUpDown(); abstract protected boolean shouldTrackUpDown();
abstract protected boolean shouldTrackLeftRight(); abstract protected boolean shouldTrackLeftRight();
abstract protected boolean shouldTrackNumPress();
// default hardware key handlers // default hardware key handlers
abstract public boolean onBackspace(); abstract public boolean onBackspace();

View file

@ -383,11 +383,6 @@ public class TraditionalT9 extends KeyPadHandler {
} }
protected boolean shouldTrackNumPress() {
return mInputMode.shouldTrackNumPress();
}
protected boolean shouldTrackUpDown() { protected boolean shouldTrackUpDown() {
return mEditing != EDITING_STRICT_NUMERIC && !isSuggestionViewHidden() && mInputMode.shouldTrackUpDown(); return mEditing != EDITING_STRICT_NUMERIC && !isSuggestionViewHidden() && mInputMode.shouldTrackUpDown();
} }
@ -641,7 +636,6 @@ public class TraditionalT9 extends KeyPadHandler {
private void determineNextTextCase() { private void determineNextTextCase() {
mInputMode.determineNextWordTextCase( mInputMode.determineNextWordTextCase(
settings,
textField.isThereText(), textField.isThereText(),
textField.getTextBeforeCursor() textField.getTextBeforeCursor()
); );

View file

@ -25,7 +25,7 @@ public class InputType {
* Special or limited input type means the input connection is not rich, * Special or limited input type means the input connection is not rich,
* or it can not process or show things like candidate text, nor retrieve the current text. * or it can not process or show things like candidate text, nor retrieve the current text.
* *
* https://developer.android.com/reference/android/text/InputType#TYPE_NULL * <a href="https://developer.android.com/reference/android/text/InputType#TYPE_NULL">...</a>
*/ */
public boolean isLimited() { public boolean isLimited() {
return field != null && field.inputType == android.text.InputType.TYPE_NULL; return field != null && field.inputType == android.text.InputType.TYPE_NULL;

View file

@ -22,14 +22,14 @@ abstract public class InputMode {
public static final int CASE_CAPITALIZE = 1; public static final int CASE_CAPITALIZE = 1;
public static final int CASE_LOWER = 2; public static final int CASE_LOWER = 2;
public static final int CASE_DICTIONARY = 3; // do not force it, but use the dictionary word as-is public static final int CASE_DICTIONARY = 3; // do not force it, but use the dictionary word as-is
protected ArrayList<Integer> allowedTextCases = new ArrayList<>(); protected final ArrayList<Integer> allowedTextCases = new ArrayList<>();
protected int textCase = CASE_LOWER; protected int textCase = CASE_LOWER;
protected int textFieldTextCase = CASE_UNDEFINED; protected int textFieldTextCase = CASE_UNDEFINED;
// data // data
protected int autoAcceptTimeout = -1; protected int autoAcceptTimeout = -1;
protected Language language; protected Language language;
protected ArrayList<String> suggestions = new ArrayList<>(); protected final ArrayList<String> suggestions = new ArrayList<>();
protected int keyCode = 0; protected int keyCode = 0;
@ -87,7 +87,7 @@ abstract public class InputMode {
public boolean shouldAddAutoSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually, int incomingKey, boolean hold, boolean repeat) { return false; } public boolean shouldAddAutoSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually, int incomingKey, boolean hold, boolean repeat) { return false; }
public boolean shouldDeletePrecedingSpace(InputType inputType) { return false; } public boolean shouldDeletePrecedingSpace(InputType inputType) { return false; }
public boolean shouldSelectNextSuggestion() { return false; } public boolean shouldSelectNextSuggestion() { return false; }
public boolean shouldTrackNumPress() { return true; }
public boolean shouldTrackUpDown() { return false; } public boolean shouldTrackUpDown() { return false; }
public boolean shouldTrackLeftRight() { return false; } public boolean shouldTrackLeftRight() { return false; }
@ -122,7 +122,7 @@ abstract public class InputMode {
textCase = allowedTextCases.get(nextIndex); textCase = allowedTextCases.get(nextIndex);
} }
public void determineNextWordTextCase(SettingsStore settings, boolean isThereText, String textBeforeCursor) {} public void determineNextWordTextCase(boolean isThereText, String textBeforeCursor) {}
// Based on the internal logic of the mode (punctuation or grammar rules), re-adjust the text case for when getSuggestions() is called. // Based on the internal logic of the mode (punctuation or grammar rules), re-adjust the text case for when getSuggestions() is called.
protected String adjustSuggestionTextCase(String word, int newTextCase) { return word; } protected String adjustSuggestionTextCase(String word, int newTextCase) { return word; }

View file

@ -28,7 +28,6 @@ public class Mode123 extends InputMode {
@Override final public boolean is123() { return true; } @Override final public boolean is123() { return true; }
@Override public int getSequenceLength() { return 0; } @Override public int getSequenceLength() { return 0; }
@Override public boolean shouldTrackNumPress() { return false; }
@NonNull @NonNull
@Override @Override

View file

@ -257,7 +257,7 @@ public class ModePredictive extends InputMode {
} }
@Override @Override
public void determineNextWordTextCase(SettingsStore settings, boolean isThereText, String textBeforeCursor) { public void determineNextWordTextCase(boolean isThereText, String textBeforeCursor) {
textCase = autoTextCase.determineNextWordTextCase(isThereText, textCase, textFieldTextCase, textBeforeCursor); textCase = autoTextCase.determineNextWordTextCase(isThereText, textCase, textFieldTextCase, textBeforeCursor);
} }

View file

@ -73,9 +73,8 @@ public class Predictions {
return this; return this;
} }
public Predictions setWordsChangedHandler(Handler handler) { public void setWordsChangedHandler(Handler handler) {
wordsChangedHandler = handler; wordsChangedHandler = handler;
return this;
} }
public ArrayList<String> getList() { public ArrayList<String> getList() {

View file

@ -8,8 +8,5 @@ public class InvalidLanguageCharactersException extends Exception {
this.language = language; this.language = language;
} }
public Language getLanguage() {
return language;
}
} }

View file

@ -19,9 +19,9 @@ public class Spanish extends English {
characterMap.set(1, new ArrayList<>(Characters.Sentence)); characterMap.set(1, new ArrayList<>(Characters.Sentence));
characterMap.get(1).addAll(Arrays.asList("¡", "¿")); characterMap.get(1).addAll(Arrays.asList("¡", "¿"));
characterMap.get(2).addAll(Collections.singletonList("á")); characterMap.get(2).add("á");
characterMap.get(3).addAll(Collections.singletonList("é")); characterMap.get(3).add("é");
characterMap.get(4).addAll(Collections.singletonList("í")); characterMap.get(4).add("í");
characterMap.set(6, new ArrayList<>(Arrays.asList("m", "n", "ñ", "o", "ó"))); characterMap.set(6, new ArrayList<>(Arrays.asList("m", "n", "ñ", "o", "ó")));
characterMap.get(8).addAll(Arrays.asList("ú", "ü")); characterMap.get(8).addAll(Arrays.asList("ú", "ü"));
} }

View file

@ -198,11 +198,8 @@ public class SettingsStore {
return getFunctionKey(SectionKeymap.ITEM_SHOW_SETTINGS); return getFunctionKey(SectionKeymap.ITEM_SHOW_SETTINGS);
} }
/************* UI settings *************/ /************* UI settings *************/
public boolean getNotifyNextLanguageInModeAbc() { return prefs.getBoolean("notify_next_language_in_mode_abc", true); }
public boolean getDarkTheme() { return prefs.getBoolean("pref_dark_theme", true); } public boolean getDarkTheme() { return prefs.getBoolean("pref_dark_theme", true); }
public boolean getShowSoftKeys() { return prefs.getBoolean("pref_show_soft_keys", true); } public boolean getShowSoftKeys() { return prefs.getBoolean("pref_show_soft_keys", true); }

View file

@ -28,7 +28,7 @@ abstract class ItemClickable {
* *
* My smashed Qin F21 Pro+ occasionally does this, if I press the keys hard. * My smashed Qin F21 Pro+ occasionally does this, if I press the keys hard.
* There were reports the same happens on Kyocera KYF31, causing absolutely undesirable side effects. * There were reports the same happens on Kyocera KYF31, causing absolutely undesirable side effects.
* @see: https://github.com/sspanak/tt9/issues/117 * @see: <a href="https://github.com/sspanak/tt9/issues/117">...</a>
*/ */
protected boolean debounceClick(Preference p) { protected boolean debounceClick(Preference p) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();

View file

@ -46,9 +46,9 @@ public class ItemSelectLanguage {
} }
public ItemSelectLanguage enableValidation() { public void enableValidation() {
if (item == null) { if (item == null) {
return this; return;
} }
item.setOnPreferenceChangeListener((preference, newValue) -> { item.setOnPreferenceChangeListener((preference, newValue) -> {
@ -65,7 +65,6 @@ public class ItemSelectLanguage {
return false; return false;
}); });
return this;
} }

View file

@ -41,10 +41,10 @@ public class ItemSelectZeroKeyCharacter {
} }
public ItemSelectZeroKeyCharacter activate() { public void activate() {
if (item == null) { if (item == null) {
Logger.w("tt9/ItemSelectZeroKeyChar.activate", "Cannot set a click listener a NULL item. Ignoring."); Logger.w("tt9/ItemSelectZeroKeyChar.activate", "Cannot set a click listener a NULL item. Ignoring.");
return this; return;
} }
item.setOnPreferenceChangeListener((preference, newChar) -> { item.setOnPreferenceChangeListener((preference, newChar) -> {
@ -53,7 +53,6 @@ public class ItemSelectZeroKeyCharacter {
return true; return true;
}); });
return this;
} }

View file

@ -46,12 +46,11 @@ public class SectionKeymap {
} }
public SectionKeymap activate() { public void activate() {
for (DropDownPreference item : items) { for (DropDownPreference item : items) {
onItemClick(item); onItemClick(item);
} }
return this;
} }

View file

@ -40,14 +40,13 @@ public class AddWordAct extends AppCompatActivity {
word = i.getStringExtra("io.github.sspanak.tt9.word"); word = i.getStringExtra("io.github.sspanak.tt9.word");
lang = i.getIntExtra("io.github.sspanak.tt9.lang", -1); lang = i.getIntExtra("io.github.sspanak.tt9.lang", -1);
View v = View.inflate(this, R.layout.addwordview, null); main = View.inflate(this, R.layout.addwordview, null);
EditText et = v.findViewById(R.id.add_word_text); EditText et = main.findViewById(R.id.add_word_text);
et.setOnClickListener(this::addWord); et.setOnClickListener(this::addWord);
et.setText(word); et.setText(word);
et.setSelection(word.length()); et.setSelection(word.length());
setContentView(v); setContentView(main);
main = v;
} }

View file

@ -170,14 +170,11 @@ public class DictionaryLoadingBar {
if (lang == null || errorType.equals(InvalidLanguageException.class.getSimpleName())) { if (lang == null || errorType.equals(InvalidLanguageException.class.getSimpleName())) {
message = resources.getString(R.string.add_word_invalid_language); message = resources.getString(R.string.add_word_invalid_language);
} else if (errorType.equals(DictionaryImportException.class.getSimpleName()) || errorType.equals(InvalidLanguageCharactersException.class.getSimpleName())) { } else if (errorType.equals(DictionaryImportException.class.getSimpleName()) || errorType.equals(InvalidLanguageCharactersException.class.getSimpleName())) {
String languageName = lang.getName(); message = resources.getString(R.string.dictionary_load_bad_char, word, line, lang.getName());
message = resources.getString(R.string.dictionary_load_bad_char, word, line, languageName);
} else if (errorType.equals(IOException.class.getSimpleName()) || errorType.equals(FileNotFoundException.class.getSimpleName())) { } else if (errorType.equals(IOException.class.getSimpleName()) || errorType.equals(FileNotFoundException.class.getSimpleName())) {
String languageName = lang.getName(); message = resources.getString(R.string.dictionary_not_found, lang.getName());
message = resources.getString(R.string.dictionary_not_found, languageName);
} else { } else {
String languageName = lang.getName(); message = resources.getString(R.string.dictionary_load_error, lang.getName(), errorType);
message = resources.getString(R.string.dictionary_load_error, languageName, errorType);
} }
title = generateTitle(-1); title = generateTitle(-1);

View file

@ -4,13 +4,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.widget.Toast; import android.widget.Toast;
import io.github.sspanak.tt9.Logger;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.ime.TraditionalT9; import io.github.sspanak.tt9.ime.TraditionalT9;
import io.github.sspanak.tt9.ime.modes.InputMode;
import io.github.sspanak.tt9.languages.Language;
import io.github.sspanak.tt9.preferences.PreferencesActivity; import io.github.sspanak.tt9.preferences.PreferencesActivity;
import io.github.sspanak.tt9.preferences.SettingsStore;
public class UI { public class UI {
public static void showAddWordDialog(TraditionalT9 tt9, int language, String currentWord) { public static void showAddWordDialog(TraditionalT9 tt9, int language, String currentWord) {

View file

@ -9,7 +9,7 @@ import io.github.sspanak.tt9.ime.TraditionalT9;
import io.github.sspanak.tt9.ui.main.keys.SoftKey; import io.github.sspanak.tt9.ui.main.keys.SoftKey;
abstract class BaseMainLayout { abstract class BaseMainLayout {
protected TraditionalT9 tt9; protected final TraditionalT9 tt9;
private final int xml; private final int xml;
protected View view = null; protected View view = null;
@ -56,18 +56,6 @@ abstract class BaseMainLayout {
return view; return view;
} }
public void show() {
if (view != null) {
view.setVisibility(View.VISIBLE);
}
}
public void hide() {
if (view != null) {
view.setVisibility(View.GONE);
}
}
public void enableClickHandlers() { public void enableClickHandlers() {
for (SoftKey key : getKeys()) { for (SoftKey key : getKeys()) {
key.setTT9(tt9); key.setTT9(tt9);

View file

@ -19,17 +19,16 @@ public class StatusBar {
} }
public StatusBar setText(String text) { public void setText(String text) {
statusText = "[ " + text + " ]"; statusText = "[ " + text + " ]";
this.render(); this.render();
return this;
} }
public StatusBar setDarkTheme(boolean darkTheme) { public void setDarkTheme(boolean darkTheme) {
if (statusView == null) { if (statusView == null) {
Logger.w("StatusBar.setDarkTheme", "Not changing the theme of a NULL View."); Logger.w("StatusBar.setDarkTheme", "Not changing the theme of a NULL View.");
return this; return;
} }
Context context = statusView.getContext(); Context context = statusView.getContext();
@ -47,7 +46,6 @@ public class StatusBar {
statusView.setTextColor(color); statusView.setTextColor(color);
this.render(); this.render();
return this;
} }
private void render() { private void render() {

View file

@ -71,7 +71,7 @@ public class SuggestionsAdapter extends RecyclerView.Adapter<SuggestionsAdapter.
public class ViewHolder extends RecyclerView.ViewHolder { public class ViewHolder extends RecyclerView.ViewHolder {
TextView suggestionItem; final TextView suggestionItem;
ViewHolder(View itemView) { ViewHolder(View itemView) {
super(itemView); super(itemView);

View file

@ -161,7 +161,7 @@ public class SuggestionsBar {
* system context and theme. * system context and theme.
* *
* More info: * More info:
* https://stackoverflow.com/questions/72382886/system-applies-night-mode-to-views-added-in-service-type-application-overlay * <a href="https://stackoverflow.com/questions/72382886/system-applies-night-mode-to-views-added-in-service-type-application-overlay">...</a>
*/ */
public void setDarkTheme(boolean darkEnabled) { public void setDarkTheme(boolean darkEnabled) {
isDarkThemeEnabled = darkEnabled; isDarkThemeEnabled = darkEnabled;