fixed language search crashing for real this time
This commit is contained in:
parent
b71ed8c705
commit
77085b915c
3 changed files with 16 additions and 21 deletions
|
|
@ -6,6 +6,8 @@ import android.os.Looper;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
@ -19,7 +21,6 @@ import io.github.sspanak.tt9.util.Logger;
|
||||||
|
|
||||||
abstract public class ItemTextInput extends ScreenPreference implements TextWatcher {
|
abstract public class ItemTextInput extends ScreenPreference implements TextWatcher {
|
||||||
@NonNull private final Handler debouncer = new Handler(Looper.getMainLooper());
|
@NonNull private final Handler debouncer = new Handler(Looper.getMainLooper());
|
||||||
private int debounceTime = SettingsStore.TEXT_INPUT_DEBOUNCE_TIME;
|
|
||||||
|
|
||||||
public ItemTextInput(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
public ItemTextInput(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
|
@ -45,6 +46,7 @@ abstract public class ItemTextInput extends ScreenPreference implements TextWatc
|
||||||
Logger.e(getClass().getSimpleName(), "Cannot attach a text change listener. Unable to find the EditText element.");
|
Logger.e(getClass().getSimpleName(), "Cannot attach a text change listener. Unable to find the EditText element.");
|
||||||
} else {
|
} else {
|
||||||
editText.addTextChangedListener(this);
|
editText.addTextChangedListener(this);
|
||||||
|
editText.setOnKeyListener(this::ignoreEnter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,12 +58,16 @@ abstract public class ItemTextInput extends ScreenPreference implements TextWatc
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
if (debounceTime > 0) {
|
|
||||||
debouncer.removeCallbacksAndMessages(null);
|
debouncer.removeCallbacksAndMessages(null);
|
||||||
debouncer.postDelayed(() -> onChange(s.toString()), debounceTime);
|
debouncer.postDelayed(() -> onChange(s.toString()), SettingsStore.TEXT_INPUT_DEBOUNCE_TIME);
|
||||||
} else {
|
|
||||||
onChange(s.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This prevents IllegalStateException "focus search returned a view that wasn't able to take focus!",
|
||||||
|
* which is thrown when the EditText is focused and it receives a simulated ENTER key event.
|
||||||
|
*/
|
||||||
|
private boolean ignoreEnter(View v, int keyCode, KeyEvent e) {
|
||||||
|
return keyCode == KeyEvent.KEYCODE_ENTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void onChange(String word);
|
protected abstract void onChange(String word);
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,13 @@ package io.github.sspanak.tt9.preferences.screens.languageSelection;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.inputmethod.EditorInfo;
|
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import io.github.sspanak.tt9.R;
|
|
||||||
import io.github.sspanak.tt9.preferences.items.ItemTextInput;
|
import io.github.sspanak.tt9.preferences.items.ItemTextInput;
|
||||||
|
|
||||||
public class PreferenceSearchLanguage extends ItemTextInput {
|
public class PreferenceSearchLanguage extends ItemTextInput {
|
||||||
|
|
@ -35,15 +31,6 @@ public class PreferenceSearchLanguage extends ItemTextInput {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(@NonNull PreferenceViewHolder holder) {
|
|
||||||
super.onBindViewHolder(holder);
|
|
||||||
EditText editText = holder.itemView.findViewById(R.id.input_text_input_field);
|
|
||||||
if (editText != null) {
|
|
||||||
editText.setImeOptions(EditorInfo.IME_ACTION_NONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showNoResultItem(boolean show) {
|
private void showNoResultItem(boolean show) {
|
||||||
if (noResultItem != null) {
|
if (noResultItem != null) {
|
||||||
noResultItem.setVisible(show);
|
noResultItem.setVisible(show);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,9 @@
|
||||||
android:focusableInTouchMode="true"
|
android:focusableInTouchMode="true"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:minHeight="@dimen/preferences_text_min_height" />
|
android:minHeight="@dimen/preferences_text_min_height"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:imeOptions="actionNone" />
|
||||||
|
|
||||||
<TextView android:id="@android:id/summary"
|
<TextView android:id="@android:id/summary"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue