1
0
Fork 0

added Compatibility sections in each screen and moved each option where it belongs, instead of keeping them all on the Initial Setup screen

This commit is contained in:
sspanak 2024-04-25 18:41:59 +03:00 committed by Dimo Karaivanov
parent 72a26c920d
commit 2760a30af2
13 changed files with 97 additions and 106 deletions

View file

@ -8,7 +8,7 @@ import java.util.LinkedHashMap;
import io.github.sspanak.tt9.util.Logger;
public class ItemDropDown {
abstract public class ItemDropDown {
private final DropDownPreference item;
private LinkedHashMap<String, String> values;
@ -27,6 +27,8 @@ public class ItemDropDown {
populate(stringifiedValues);
}
abstract public ItemDropDown populate();
protected void populate(LinkedHashMap<String, String> values) {
if (item == null) {
Logger.w("ItemDropDown.populate", "Cannot populate a NULL item. Ignoring.");

View file

@ -2,6 +2,8 @@ package io.github.sspanak.tt9.preferences.screens.appearance;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.PreferencesActivity;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
import io.github.sspanak.tt9.preferences.items.ItemSwitch;
import io.github.sspanak.tt9.preferences.screens.BaseScreenFragment;
public class AppearanceScreen extends BaseScreenFragment {
@ -15,32 +17,34 @@ public class AppearanceScreen extends BaseScreenFragment {
@Override
protected void onCreate() {
(new ItemSelectTheme(activity, findPreference(ItemSelectTheme.NAME)))
.populate()
.preview()
.enableClickHandler();
(new ItemSelectLayoutType(activity, findPreference(ItemSelectLayoutType.NAME)))
.populate()
.preview()
.enableClickHandler();
(new ItemStatusIcon(findPreference(ItemStatusIcon.NAME), activity.getSettings())).populate();
(new ItemSelectSettingsFontSize(findPreference(ItemSelectSettingsFontSize.NAME), this))
.populate()
.preview()
.enableClickHandler();
(new ItemCandidatesView(findPreference(ItemCandidatesView.NAME), activity.getSettings()))
.populate()
.enableClickHandler();
(new ItemClearInsets(findPreference(ItemClearInsets.NAME), activity.getSettings()))
.populate()
.enableClickHandler();
createMainSection();
createHacksSection();
resetFontSize(true);
}
private void createMainSection() {
(new ItemStatusIcon(findPreference(ItemStatusIcon.NAME), activity.getSettings())).populate();
ItemDropDown[] items = {
new ItemSelectTheme(findPreference(ItemSelectTheme.NAME), activity),
new ItemSelectLayoutType(findPreference(ItemSelectLayoutType.NAME), activity),
new ItemSelectSettingsFontSize(findPreference(ItemSelectSettingsFontSize.NAME), this)
};
for (ItemDropDown item : items) {
item.populate().preview().enableClickHandler();
}
}
private void createHacksSection() {
ItemSwitch[] items = {
new ItemAlternativeSuggestionScrolling(findPreference(ItemAlternativeSuggestionScrolling.NAME), activity.getSettings()),
new ItemCandidatesView(findPreference(ItemCandidatesView.NAME), activity.getSettings()),
new ItemClearInsets(findPreference(ItemClearInsets.NAME), activity.getSettings())
};
for (ItemSwitch item : items) {
item.populate().enableClickHandler();
}
}
}

View file

@ -0,0 +1,22 @@
package io.github.sspanak.tt9.preferences.screens.appearance;
import androidx.preference.SwitchPreferenceCompat;
import io.github.sspanak.tt9.preferences.items.ItemSwitch;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemAlternativeSuggestionScrolling extends ItemSwitch {
public static final String NAME = "pref_alternative_suggestion_scrolling";
private final SettingsStore settings;
public ItemAlternativeSuggestionScrolling(SwitchPreferenceCompat item, SettingsStore settings) {
super(item);
this.settings = settings;
}
@Override
protected boolean getDefaultValue() {
return settings.getSuggestionScrollingDelay() > 0;
}
}

View file

@ -14,8 +14,7 @@ public class ItemSelectLayoutType extends ItemDropDown {
private final PreferencesActivity activity;
public ItemSelectLayoutType(PreferencesActivity activity, DropDownPreference item) {
public ItemSelectLayoutType(DropDownPreference item, PreferencesActivity activity) {
super(item);
this.activity = activity;
}

View file

@ -16,7 +16,7 @@ class ItemSelectTheme extends ItemDropDown {
private final Context context;
ItemSelectTheme(Context context, DropDownPreference item) {
ItemSelectTheme(DropDownPreference item, Context context) {
super(item);
this.context = context;
}

View file

@ -1,4 +1,4 @@
package io.github.sspanak.tt9.preferences.screens.setup;
package io.github.sspanak.tt9.preferences.screens.keypad;
import android.content.Context;
@ -7,27 +7,30 @@ import androidx.preference.DropDownPreference;
import java.util.LinkedHashMap;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.PreferencesActivity;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
class ItemKeyPadDebounceTime extends ItemDropDown {
public static final String NAME = "pref_key_pad_debounce_time";
private final Context context;
private final PreferencesActivity activity;
ItemKeyPadDebounceTime(Context context, DropDownPreference item) {
ItemKeyPadDebounceTime(DropDownPreference item, PreferencesActivity activity) {
super(item);
this.context = context;
this.activity = activity;
}
public ItemDropDown populate() {
LinkedHashMap<String, String> dropDownOptions = new LinkedHashMap<>();
dropDownOptions.put("0", context.getString(R.string.pref_hack_key_pad_debounce_off));
dropDownOptions.put("0", activity.getString(R.string.pref_hack_key_pad_debounce_off));
String[] values = new String[] { "20", "30", "50", "75", "100", "150", "250", "350" };
for (String value : values) {
dropDownOptions.put(value, value + " ms");
}
super.populate(dropDownOptions);
super.setValue(String.valueOf(activity.getSettings().getKeyPadDebounceTime()));
return this;
}

View file

@ -2,6 +2,7 @@ package io.github.sspanak.tt9.preferences.screens.keypad;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.PreferencesActivity;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
import io.github.sspanak.tt9.preferences.screens.BaseScreenFragment;
public class KeyPadScreen extends BaseScreenFragment {
@ -15,15 +16,15 @@ public class KeyPadScreen extends BaseScreenFragment {
@Override
protected void onCreate() {
(new ItemSelectZeroKeyCharacter(findPreference(ItemSelectZeroKeyCharacter.NAME), activity))
.populate()
.enableClickHandler()
.preview();
ItemDropDown[] items = {
new ItemSelectZeroKeyCharacter(findPreference(ItemSelectZeroKeyCharacter.NAME), activity),
new ItemSelectABCAutoAccceptTime(findPreference(ItemSelectABCAutoAccceptTime.NAME), activity),
new ItemKeyPadDebounceTime(findPreference(ItemKeyPadDebounceTime.NAME), activity)
};
(new ItemSelectABCAutoAccceptTime(findPreference(ItemSelectABCAutoAccceptTime.NAME), activity))
.populate()
.enableClickHandler()
.preview();
for (ItemDropDown item : items) {
item.populate().enableClickHandler().preview();
}
resetFontSize(false);
}

View file

@ -1,31 +0,0 @@
package io.github.sspanak.tt9.preferences.screens.setup;
import androidx.preference.SwitchPreferenceCompat;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemAlternativeSuggestionScrolling {
public static final String NAME = "pref_alternative_suggestion_scrolling";
private final SwitchPreferenceCompat item;
private final SettingsStore settings;
public ItemAlternativeSuggestionScrolling(SwitchPreferenceCompat item, SettingsStore settings) {
this.item = item;
this.settings = settings;
}
public ItemAlternativeSuggestionScrolling populate() {
if (item != null) {
item.setChecked(settings.getSuggestionScrollingDelay() > 0);
}
return this;
}
public void setEnabled(boolean yes) {
if (item != null) {
item.setEnabled(yes);
}
}
}

View file

@ -48,10 +48,6 @@ public class SetupScreen extends BaseScreenFragment {
}
private void createHacksSection(boolean isTT9On) {
(new ItemAlternativeSuggestionScrolling(findPreference(ItemAlternativeSuggestionScrolling.NAME), activity.getSettings()))
.populate()
.setEnabled(isTT9On);
Preference hackGoogleChat = findPreference("pref_hack_google_chat");
if (hackGoogleChat != null) {
hackGoogleChat.setEnabled(isTT9On);
@ -61,13 +57,5 @@ public class SetupScreen extends BaseScreenFragment {
if (hackFBMessenger != null) {
hackFBMessenger.setEnabled(isTT9On);
}
ItemKeyPadDebounceTime item = new ItemKeyPadDebounceTime(activity, findPreference(ItemKeyPadDebounceTime.NAME));
item.populate().preview();
if (isTT9On) {
item.enable();
} else {
item.disable();
}
}
}

View file

@ -21,6 +21,11 @@
<PreferenceCategory app:title="@string/pref_category_hacks">
<SwitchPreferenceCompat
app:key="pref_alternative_suggestion_scrolling"
app:title="@string/pref_alternative_suggestion_scrolling"
app:summary="@string/pref_alternative_suggestion_scrolling_summary"/>
<SwitchPreferenceCompat
app:key="pref_candidates_view"
app:title="@string/pref_hack_candidate_view" />

View file

@ -15,9 +15,7 @@
app:summary="@string/pref_upside_down_keys_summary"
app:title="@string/pref_upside_down_keys" />
<PreferenceCategory
android:title="@string/pref_category_predictive_mode"
app:singleLineTitle="true">
<PreferenceCategory android:title="@string/pref_category_predictive_mode">
<SwitchPreferenceCompat
app:defaultValue="true"
@ -47,14 +45,17 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_category_abc_mode"
app:singleLineTitle="true">
<PreferenceCategory android:title="@string/pref_category_abc_mode">
<DropDownPreference
app:defaultValue="800"
app:key="pref_abc_auto_accept_time"
app:title="@string/pref_abc_auto_accept" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_hacks">
<DropDownPreference
app:key="pref_key_pad_debounce_time"
app:title="@string/pref_hack_key_pad_debounce_time" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -9,14 +9,7 @@
app:key="global_default_keyboard"
app:title="@string/setup_default_keyboard" />
<PreferenceCategory
app:title="@string/pref_category_hacks"
app:singleLineTitle="true">
<SwitchPreferenceCompat
app:key="pref_alternative_suggestion_scrolling"
app:title="@string/pref_alternative_suggestion_scrolling"
app:summary="@string/pref_alternative_suggestion_scrolling_summary"/>
<PreferenceCategory app:title="@string/pref_category_hacks">
<SwitchPreferenceCompat
app:defaultValue="false"
@ -29,9 +22,5 @@
app:key="pref_hack_fb_messenger"
app:title="@string/pref_hack_fb_messenger"/>
<DropDownPreference
app:key="pref_key_pad_debounce_time"
app:title="@string/pref_hack_key_pad_debounce_time" />
</PreferenceCategory>
</PreferenceScreen>