new dev bug: fixed crashing when not possible to show the new popup windows
This commit is contained in:
parent
fe0d09eb28
commit
44bd6ce084
9 changed files with 98 additions and 30 deletions
|
|
@ -159,10 +159,10 @@ abstract public class CommandHandler extends TextEditingHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void changeLang() {
|
protected boolean changeLang() {
|
||||||
suggestionOps.cancelDelayedAccept();
|
suggestionOps.cancelDelayedAccept();
|
||||||
stopVoiceInput();
|
stopVoiceInput();
|
||||||
new ChangeLanguageDialog(getFinalContext(), this::setLang).show();
|
return new ChangeLanguageDialog(getFinalContext(), this::setLang).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -298,10 +298,8 @@ public abstract class HotkeyHandler extends CommandHandler {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.getQuickSwitchLanguage()) {
|
if (settings.getQuickSwitchLanguage() || !changeLang()) {
|
||||||
nextLang();
|
nextLang();
|
||||||
} else {
|
|
||||||
changeLang();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package io.github.sspanak.tt9.preferences.screens.languages;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.preference.SwitchPreferenceCompat;
|
||||||
|
|
||||||
|
import io.github.sspanak.tt9.R;
|
||||||
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
|
|
||||||
|
public class AddWordsWithoutConfirmationSwitch extends SwitchPreferenceCompat {
|
||||||
|
public AddWordsWithoutConfirmationSwitch(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddWordsWithoutConfirmationSwitch(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddWordsWithoutConfirmationSwitch(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddWordsWithoutConfirmationSwitch(@NonNull Context context) {
|
||||||
|
super(context);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Context context) {
|
||||||
|
setKey("add_word_no_confirmation");
|
||||||
|
setTitle(R.string.add_word_no_confirmation);
|
||||||
|
setVisible(!new SettingsStore(context).isMainLayoutStealth());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package io.github.sspanak.tt9.preferences.screens.languages;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.preference.SwitchPreferenceCompat;
|
||||||
|
|
||||||
|
import io.github.sspanak.tt9.R;
|
||||||
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
|
|
||||||
|
public class QuickSwitchLanguagePreference extends SwitchPreferenceCompat {
|
||||||
|
public QuickSwitchLanguagePreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickSwitchLanguagePreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickSwitchLanguagePreference(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickSwitchLanguagePreference(@NonNull Context context) {
|
||||||
|
super(context);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Context context) {
|
||||||
|
setDefaultValue(true);
|
||||||
|
setKey("pref_quick_switch_language");
|
||||||
|
setTitle(R.string.pref_quick_switch_language_summary);
|
||||||
|
setVisible(!new SettingsStore(context).isMainLayoutStealth());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -132,6 +132,11 @@ public class PopupBuilder {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (main.getView().getWindowToken() == null) {
|
||||||
|
Logger.d(LOG_TAG, "Not creating popup dialog, because the Main view has no token yet. Try again when it is shown to the user.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Dialog dialog = DeviceInfo.AT_LEAST_ANDROID_12 ? builder12.create() : builderLegacy.create();
|
Dialog dialog = DeviceInfo.AT_LEAST_ANDROID_12 ? builder12.create() : builderLegacy.create();
|
||||||
|
|
||||||
Window window = dialog.getWindow();
|
Window window = dialog.getWindow();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package io.github.sspanak.tt9.ui.dialogs;
|
package io.github.sspanak.tt9.ui.dialogs;
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
|
@ -11,20 +9,15 @@ import io.github.sspanak.tt9.ime.TraditionalT9;
|
||||||
import io.github.sspanak.tt9.languages.Language;
|
import io.github.sspanak.tt9.languages.Language;
|
||||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
import io.github.sspanak.tt9.ui.UI;
|
import io.github.sspanak.tt9.ui.UI;
|
||||||
import io.github.sspanak.tt9.ui.main.MainView;
|
|
||||||
|
|
||||||
public class AddWordDialog extends PopupDialog {
|
public class AddWordDialog extends PopupDialog {
|
||||||
@Nullable private final MainView mainView;
|
|
||||||
@NonNull private final Language language;
|
@NonNull private final Language language;
|
||||||
@NonNull private final SettingsStore settings;
|
@NonNull private final SettingsStore settings;
|
||||||
@Nullable private final String word;
|
@Nullable private final String word;
|
||||||
|
|
||||||
private Dialog popup;
|
|
||||||
|
|
||||||
|
|
||||||
public AddWordDialog(@NonNull TraditionalT9 tt9, @NonNull Language language, @Nullable String word) {
|
public AddWordDialog(@NonNull TraditionalT9 tt9, @NonNull Language language, @Nullable String word) {
|
||||||
super(tt9, R.style.TTheme_AddWord);
|
super(tt9, R.style.TTheme_AddWord);
|
||||||
mainView = tt9.getMainView();
|
|
||||||
|
|
||||||
title = tt9.getResources().getString(R.string.add_word_title);
|
title = tt9.getResources().getString(R.string.add_word_title);
|
||||||
OKLabel = tt9.getResources().getString(R.string.add_word_add);
|
OKLabel = tt9.getResources().getString(R.string.add_word_add);
|
||||||
|
|
@ -57,6 +50,8 @@ public class AddWordDialog extends PopupDialog {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
render(this::onOK, null, null);
|
if (!render(this::onOK, null, null)) {
|
||||||
|
onOK();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package io.github.sspanak.tt9.ui.dialogs;
|
package io.github.sspanak.tt9.ui.dialogs;
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -18,17 +17,14 @@ import io.github.sspanak.tt9.languages.Language;
|
||||||
import io.github.sspanak.tt9.languages.LanguageCollection;
|
import io.github.sspanak.tt9.languages.LanguageCollection;
|
||||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
import io.github.sspanak.tt9.ui.LanguageRadioButton;
|
import io.github.sspanak.tt9.ui.LanguageRadioButton;
|
||||||
import io.github.sspanak.tt9.ui.main.MainView;
|
|
||||||
import io.github.sspanak.tt9.util.ConsumerCompat;
|
import io.github.sspanak.tt9.util.ConsumerCompat;
|
||||||
import io.github.sspanak.tt9.util.sys.DeviceInfo;
|
import io.github.sspanak.tt9.util.sys.DeviceInfo;
|
||||||
|
|
||||||
public class ChangeLanguageDialog extends PopupDialog {
|
public class ChangeLanguageDialog extends PopupDialog {
|
||||||
private final ArrayList<Language> languages;
|
private final ArrayList<Language> languages;
|
||||||
private final MainView mainView;
|
|
||||||
private final SettingsStore settings;
|
private final SettingsStore settings;
|
||||||
|
|
||||||
private final ConsumerCompat<Integer> onLanguageChanged;
|
private final ConsumerCompat<Integer> onLanguageChanged;
|
||||||
private Dialog popup;
|
|
||||||
private final ArrayList<LanguageRadioButton> radioButtonsCache = new ArrayList<>();
|
private final ArrayList<LanguageRadioButton> radioButtonsCache = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -38,7 +34,6 @@ public class ChangeLanguageDialog extends PopupDialog {
|
||||||
title = tt9.getResources().getString(R.string.language_popup_title);
|
title = tt9.getResources().getString(R.string.language_popup_title);
|
||||||
OKLabel = null;
|
OKLabel = null;
|
||||||
|
|
||||||
mainView = tt9.getMainView();
|
|
||||||
settings = tt9.getSettings();
|
settings = tt9.getSettings();
|
||||||
languages = LanguageCollection.getAll(settings.getEnabledLanguageIds(), true);
|
languages = LanguageCollection.getAll(settings.getEnabledLanguageIds(), true);
|
||||||
onLanguageChanged = changeHandler;
|
onLanguageChanged = changeHandler;
|
||||||
|
|
@ -139,7 +134,7 @@ public class ChangeLanguageDialog extends PopupDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void show() {
|
public boolean show() {
|
||||||
render(null, this::close, generateRadioButtons());
|
return render(null, this::close, generateRadioButtons());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ abstract public class PopupDialog implements DialogInterface.OnKeyListener {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Dialog render(Runnable onOK, Runnable onCancel, View customView) {
|
protected boolean render(Runnable onOK, Runnable onCancel, View customView) {
|
||||||
PopupBuilder popupBuilder = new PopupBuilder(context);
|
PopupBuilder popupBuilder = new PopupBuilder(context);
|
||||||
if (onOK != null) {
|
if (onOK != null) {
|
||||||
popupBuilder.setPositiveButton(OKLabel, onOK);
|
popupBuilder.setPositiveButton(OKLabel, onOK);
|
||||||
|
|
@ -59,12 +59,14 @@ abstract public class PopupDialog implements DialogInterface.OnKeyListener {
|
||||||
popupBuilder.setView(customView);
|
popupBuilder.setView(customView);
|
||||||
}
|
}
|
||||||
|
|
||||||
return popup = popupBuilder
|
popup = popupBuilder
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setNegativeButton(true, onCancel)
|
.setNegativeButton(true, onCancel)
|
||||||
.setOnKeyListener(this)
|
.setOnKeyListener(this)
|
||||||
.showFromIme(mainView);
|
.showFromIme(mainView);
|
||||||
|
|
||||||
|
return popup != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,19 +29,13 @@
|
||||||
app:key="dictionary_truncate"
|
app:key="dictionary_truncate"
|
||||||
app:title="@string/dictionary_truncate_title" />
|
app:title="@string/dictionary_truncate_title" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<io.github.sspanak.tt9.preferences.screens.languages.QuickSwitchLanguagePreference />
|
||||||
app:defaultValue="true"
|
|
||||||
app:key="pref_quick_switch_language"
|
|
||||||
app:title="@string/pref_quick_switch_language"
|
|
||||||
app:summary="@string/pref_quick_switch_language_summary" />
|
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
app:title="@string/pref_category_custom_words"
|
app:title="@string/pref_category_custom_words"
|
||||||
app:singleLineTitle="true">
|
app:singleLineTitle="true">
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<io.github.sspanak.tt9.preferences.screens.languages.AddWordsWithoutConfirmationSwitch />
|
||||||
app:key="add_word_no_confirmation"
|
|
||||||
app:title="@string/add_word_no_confirmation" />
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
app:key="dictionary_import_custom"
|
app:key="dictionary_import_custom"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue