1
0
Fork 0

reordered the Appearance settings a bit

This commit is contained in:
sspanak 2025-02-03 10:22:49 +02:00 committed by Dimo Karaivanov
parent 5401f1e40c
commit 3f69ba4e3b
10 changed files with 46 additions and 35 deletions

View file

@ -32,21 +32,18 @@ public class AppearanceScreen extends BaseScreenFragment {
ItemShowArrows showArrows = new ItemShowArrows(findPreference(ItemShowArrows.NAME), activity.getSettings());
ItemNumpadFnKeyScale fnKeyWidth = new ItemNumpadFnKeyScale(findPreference(ItemNumpadFnKeyScale.NAME), activity.getSettings());
ItemSelectLayoutType selectLayout = new ItemSelectLayoutType(findPreference(ItemSelectLayoutType.NAME), activity)
.addOnChangeItem(alignment)
.addOnChangeItem(fnKeyWidth)
.addOnChangeItem(keyboardWidth)
.addOnChangeItem(numpadKeyHeight)
.addOnChangeItem(numpadShape)
.addOnChangeItem(showArrows);
ItemDropDown[] items = {
new ItemSelectTheme(findPreference(ItemSelectTheme.NAME), activity),
new ItemSelectLayoutType(
findPreference(ItemSelectLayoutType.NAME),
activity,
(layout) -> { // on layout change
numpadKeyHeight.onLayoutChange(layout);
alignment.onLayoutChange(layout);
keyboardWidth.onLayoutChange(layout);
numpadShape.onLayoutChange(layout);
showArrows.onLayoutChange(layout);
fnKeyWidth.onLayoutChange(layout);
}
),
new ItemSelectSettingsFontSize(findPreference(ItemSelectSettingsFontSize.NAME), this),
selectLayout,
numpadKeyHeight,
alignment,
keyboardWidth,

View file

@ -11,7 +11,7 @@ import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemAlignment extends ItemDropDown {
public class ItemAlignment extends ItemDropDown implements ItemLayoutChangeReactive {
public static final String NAME = "pref_numpad_alignment";
private final SettingsStore settings;
@ -41,7 +41,7 @@ public class ItemAlignment extends ItemDropDown {
return this;
}
void onLayoutChange(int mainViewLayout) {
public void onLayoutChange(int mainViewLayout) {
if (item != null) {
item.setVisible(mainViewLayout != SettingsStore.LAYOUT_STEALTH);
item.setIconSpaceReserved(false);

View file

@ -0,0 +1,5 @@
package io.github.sspanak.tt9.preferences.screens.appearance;
public interface ItemLayoutChangeReactive {
void onLayoutChange(int mainViewLayout);
}

View file

@ -7,7 +7,7 @@ import java.util.LinkedHashMap;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemNumpadFnKeyScale extends ItemDropDown {
public class ItemNumpadFnKeyScale extends ItemDropDown implements ItemLayoutChangeReactive {
public static final String NAME = "pref_numpad_fn_key_width";
private final SettingsStore settings;
@ -26,8 +26,10 @@ public class ItemNumpadFnKeyScale extends ItemDropDown {
LinkedHashMap<String, String> options = new LinkedHashMap<>();
options.put("1", "100 ");
options.put("0.85", "115 ");
options.put("0.75", "125 ");
options.put("0.675", "135 ");
options.put("0.477", "150 "); // whatever...
options.put("0.576", "145 ");
options.put("0.477", "155 "); // whatever...
super.populate(options);
super.setValue(getClosestOption(settings.getNumpadFnKeyScale(), options));
@ -53,7 +55,7 @@ public class ItemNumpadFnKeyScale extends ItemDropDown {
return closest;
}
void onLayoutChange(int mainViewLayout) {
public void onLayoutChange(int mainViewLayout) {
if (item != null) {
item.setVisible(mainViewLayout == SettingsStore.LAYOUT_NUMPAD);
item.setIconSpaceReserved(false);

View file

@ -7,7 +7,7 @@ import java.util.LinkedHashMap;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemNumpadKeyHeight extends ItemDropDown {
public class ItemNumpadKeyHeight extends ItemDropDown implements ItemLayoutChangeReactive {
public static final String NAME = "pref_numpad_key_height";
private final SettingsStore settings;
@ -41,7 +41,7 @@ public class ItemNumpadKeyHeight extends ItemDropDown {
return this;
}
void onLayoutChange(int mainViewLayout) {
public void onLayoutChange(int mainViewLayout) {
if (item != null) {
item.setVisible(mainViewLayout == SettingsStore.LAYOUT_NUMPAD);
item.setIconSpaceReserved(false);

View file

@ -10,7 +10,7 @@ import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemNumpadShape extends ItemDropDown {
public class ItemNumpadShape extends ItemDropDown implements ItemLayoutChangeReactive {
static final String NAME = "pref_numpad_shape";
private final SettingsStore settings;
@ -40,7 +40,7 @@ public class ItemNumpadShape extends ItemDropDown {
return this;
}
void onLayoutChange(int mainViewLayout) {
public void onLayoutChange(int mainViewLayout) {
if (item != null) {
item.setVisible(mainViewLayout == SettingsStore.LAYOUT_NUMPAD);
item.setIconSpaceReserved(false);

View file

@ -1,26 +1,26 @@
package io.github.sspanak.tt9.preferences.screens.appearance;
import androidx.annotation.NonNull;
import androidx.preference.DropDownPreference;
import androidx.preference.Preference;
import java.util.ArrayList;
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;
import io.github.sspanak.tt9.preferences.settings.SettingsUI;
import io.github.sspanak.tt9.util.ConsumerCompat;
public class ItemSelectLayoutType extends ItemDropDown {
public static final String NAME = "pref_layout_type";
private final PreferencesActivity activity;
private final ConsumerCompat<Integer> onChange;
private final ArrayList<ItemLayoutChangeReactive> onChangeReactiveItems = new ArrayList<>();
public ItemSelectLayoutType(DropDownPreference item, PreferencesActivity activity, ConsumerCompat<Integer> onChange) {
public ItemSelectLayoutType(DropDownPreference item, PreferencesActivity activity) {
super(item);
this.activity = activity;
this.onChange = onChange;
}
public ItemDropDown populate() {
@ -36,11 +36,18 @@ public class ItemSelectLayoutType extends ItemDropDown {
return this;
}
public ItemSelectLayoutType addOnChangeItem(@NonNull ItemLayoutChangeReactive reactiveItem) {
onChangeReactiveItems.add(reactiveItem);
return this;
}
@Override
protected boolean onClick(Preference preference, Object newKey) {
if (onChange != null) {
onChange.accept(Integer.parseInt(newKey.toString()));
int newLayout = Integer.parseInt(newKey.toString());
for (ItemLayoutChangeReactive item : onChangeReactiveItems) {
item.onLayoutChange(newLayout);
}
return super.onClick(preference, newKey);
}
}

View file

@ -5,7 +5,7 @@ import androidx.preference.SwitchPreferenceCompat;
import io.github.sspanak.tt9.preferences.items.ItemSwitch;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemShowArrows extends ItemSwitch {
public class ItemShowArrows extends ItemSwitch implements ItemLayoutChangeReactive {
public final static String NAME = "pref_arrow_keys_visible";
private final SettingsStore settings;
@ -26,7 +26,7 @@ public class ItemShowArrows extends ItemSwitch {
}
void onLayoutChange(int mainViewLayout) {
public void onLayoutChange(int mainViewLayout) {
if (item != null) {
item.setVisible(mainViewLayout == SettingsStore.LAYOUT_NUMPAD);
item.setIconSpaceReserved(false);

View file

@ -7,7 +7,7 @@ import java.util.LinkedHashMap;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemWidth extends ItemDropDown {
public class ItemWidth extends ItemDropDown implements ItemLayoutChangeReactive {
public static final String NAME = "pref_numpad_width";
private final SettingsStore settings;
@ -35,7 +35,7 @@ public class ItemWidth extends ItemDropDown {
return this;
}
void onLayoutChange(int mainViewLayout) {
public void onLayoutChange(int mainViewLayout) {
if (item != null) {
item.setEnabled(mainViewLayout != SettingsStore.LAYOUT_STEALTH);
}

View file

@ -31,14 +31,14 @@
app:key="pref_numpad_key_height"
app:title="@string/pref_numpad_key_height" />
<DropDownPreference
app:key="pref_numpad_fn_key_width"
app:title="@string/pref_numpad_fn_key_width" />
<SwitchPreferenceCompat
app:key="pref_arrow_keys_visible"
app:title="@string/pref_arrow_keys_visible"
app:summary="@string/pref_arrow_keys_visible_summary" />
<DropDownPreference
app:key="pref_numpad_fn_key_width"
app:title="@string/pref_numpad_fn_key_width" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/pref_category_hacks">