1
0
Fork 0

new dev bug: fixed crashing when not possible to show the new popup windows

This commit is contained in:
sspanak 2025-05-13 13:56:39 +03:00 committed by Dimo Karaivanov
parent fe0d09eb28
commit 44bd6ce084
9 changed files with 98 additions and 30 deletions

View file

@ -159,10 +159,10 @@ abstract public class CommandHandler extends TextEditingHandler {
}
protected void changeLang() {
protected boolean changeLang() {
suggestionOps.cancelDelayedAccept();
stopVoiceInput();
new ChangeLanguageDialog(getFinalContext(), this::setLang).show();
return new ChangeLanguageDialog(getFinalContext(), this::setLang).show();
}

View file

@ -298,10 +298,8 @@ public abstract class HotkeyHandler extends CommandHandler {
return true;
}
if (settings.getQuickSwitchLanguage()) {
if (settings.getQuickSwitchLanguage() || !changeLang()) {
nextLang();
} else {
changeLang();
}
return true;

View file

@ -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());
}
}

View file

@ -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());
}
}

View file

@ -132,6 +132,11 @@ public class PopupBuilder {
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();
Window window = dialog.getWindow();

View file

@ -1,7 +1,5 @@
package io.github.sspanak.tt9.ui.dialogs;
import android.app.Dialog;
import androidx.annotation.NonNull;
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.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.ui.UI;
import io.github.sspanak.tt9.ui.main.MainView;
public class AddWordDialog extends PopupDialog {
@Nullable private final MainView mainView;
@NonNull private final Language language;
@NonNull private final SettingsStore settings;
@Nullable private final String word;
private Dialog popup;
public AddWordDialog(@NonNull TraditionalT9 tt9, @NonNull Language language, @Nullable String word) {
super(tt9, R.style.TTheme_AddWord);
mainView = tt9.getMainView();
title = tt9.getResources().getString(R.string.add_word_title);
OKLabel = tt9.getResources().getString(R.string.add_word_add);
@ -57,6 +50,8 @@ public class AddWordDialog extends PopupDialog {
return;
}
render(this::onOK, null, null);
if (!render(this::onOK, null, null)) {
onOK();
}
}
}

View file

@ -1,6 +1,5 @@
package io.github.sspanak.tt9.ui.dialogs;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.KeyEvent;
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.preferences.settings.SettingsStore;
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.sys.DeviceInfo;
public class ChangeLanguageDialog extends PopupDialog {
private final ArrayList<Language> languages;
private final MainView mainView;
private final SettingsStore settings;
private final ConsumerCompat<Integer> onLanguageChanged;
private Dialog popup;
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);
OKLabel = null;
mainView = tt9.getMainView();
settings = tt9.getSettings();
languages = LanguageCollection.getAll(settings.getEnabledLanguageIds(), true);
onLanguageChanged = changeHandler;
@ -139,7 +134,7 @@ public class ChangeLanguageDialog extends PopupDialog {
}
public void show() {
render(null, this::close, generateRadioButtons());
public boolean show() {
return render(null, this::close, generateRadioButtons());
}
}

View file

@ -50,7 +50,7 @@ abstract public class PopupDialog implements DialogInterface.OnKeyListener {
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);
if (onOK != null) {
popupBuilder.setPositiveButton(OKLabel, onOK);
@ -59,12 +59,14 @@ abstract public class PopupDialog implements DialogInterface.OnKeyListener {
popupBuilder.setView(customView);
}
return popup = popupBuilder
popup = popupBuilder
.setCancelable(true)
.setTitle(title)
.setMessage(message)
.setNegativeButton(true, onCancel)
.setOnKeyListener(this)
.showFromIme(mainView);
return popup != null;
}
}

View file

@ -29,19 +29,13 @@
app:key="dictionary_truncate"
app:title="@string/dictionary_truncate_title" />
<SwitchPreferenceCompat
app:defaultValue="true"
app:key="pref_quick_switch_language"
app:title="@string/pref_quick_switch_language"
app:summary="@string/pref_quick_switch_language_summary" />
<io.github.sspanak.tt9.preferences.screens.languages.QuickSwitchLanguagePreference />
<PreferenceCategory
app:title="@string/pref_category_custom_words"
app:singleLineTitle="true">
<SwitchPreferenceCompat
app:key="add_word_no_confirmation"
app:title="@string/add_word_no_confirmation" />
<io.github.sspanak.tt9.preferences.screens.languages.AddWordsWithoutConfirmationSwitch />
<Preference
app:key="dictionary_import_custom"