Consolidate settings decoding
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -40,7 +40,7 @@ public final class LayoutFragment extends Fragment {
|
|||||||
View root = inflater.inflate(R.layout.fragment_layout, container, false);
|
View root = inflater.inflate(R.layout.fragment_layout, container, false);
|
||||||
SharedPreferences prefs = requireContext()
|
SharedPreferences prefs = requireContext()
|
||||||
.getSharedPreferences(SbtSettings.PREFS_NAME, Context.MODE_PRIVATE);
|
.getSharedPreferences(SbtSettings.PREFS_NAME, Context.MODE_PRIVATE);
|
||||||
hideUnlockedSubpageObsoleteControls(root);
|
configureUnlockedOnlyModeControls(root);
|
||||||
reorderItemCards(root, prefs);
|
reorderItemCards(root, prefs);
|
||||||
|
|
||||||
setupPositionSection(root,
|
setupPositionSection(root,
|
||||||
@@ -508,7 +508,7 @@ public final class LayoutFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideUnlockedSubpageObsoleteControls(View root) {
|
private void configureUnlockedOnlyModeControls(View root) {
|
||||||
hide(root, R.id.clock_position_mode_lockscreen);
|
hide(root, R.id.clock_position_mode_lockscreen);
|
||||||
hide(root, R.id.notif_position_mode_aod);
|
hide(root, R.id.notif_position_mode_aod);
|
||||||
hide(root, R.id.notif_position_mode_lockscreen);
|
hide(root, R.id.notif_position_mode_lockscreen);
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package se.ajpanton.statusbartweak.shell.settings;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public final class SbtSettingsTest {
|
||||||
|
@Test
|
||||||
|
public void emptySourceMatchesRepresentativeDefaults() {
|
||||||
|
SbtSettings defaults = SbtSettings.defaults();
|
||||||
|
SbtSettings decoded = SbtSettings.fromSource(new MapSource());
|
||||||
|
|
||||||
|
assertEquals(defaults.clockEnabled, decoded.clockEnabled);
|
||||||
|
assertEquals(defaults.clockCustomFormat, decoded.clockCustomFormat);
|
||||||
|
assertEquals(defaults.batteryBarPosition, decoded.batteryBarPosition);
|
||||||
|
assertEquals(defaults.batteryBarThicknessDp, decoded.batteryBarThicknessDp);
|
||||||
|
assertEquals(defaults.layoutNotifUnlockedCount, decoded.layoutNotifUnlockedCount);
|
||||||
|
assertEquals(defaults.layoutStatusUnlockedCount, decoded.layoutStatusUnlockedCount);
|
||||||
|
assertEquals(defaults.systemIconBlockedModes, decoded.systemIconBlockedModes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sourceDecodingPreservesSettingsNormalization() {
|
||||||
|
MapSource source = new MapSource();
|
||||||
|
source.put(SbtSettings.KEY_CLOCK_ENABLED, false);
|
||||||
|
source.put(SbtSettings.KEY_CLOCK_CUSTOM_FORMAT, "H:mm:ss");
|
||||||
|
source.put(SbtSettings.KEY_UNLOCKED_MAX_ICONS_PER_ROW, 0);
|
||||||
|
source.put(SbtSettings.KEY_CLOCK_VERTICAL_OFFSET_PX, 500);
|
||||||
|
source.put(SbtSettings.KEY_BATTERY_BAR_CURVED_GEOMETRY_MODE, "unsupported");
|
||||||
|
source.put(SbtSettings.KEY_LAYOUT_NOTIF_UNLOCKED_COUNT, 100);
|
||||||
|
source.put(SbtSettings.KEY_SYSTEM_ICON_DUAL_SIM_SIGNAL_MODE, "unsupported");
|
||||||
|
source.put(
|
||||||
|
SystemIconRules.PREF_KEY_BLOCKED_MODES,
|
||||||
|
setOf("wifi|5", "invalid", "wifi|not-a-number"));
|
||||||
|
source.put(
|
||||||
|
SbtSettings.KEY_APP_ICON_BLOCKED_MODES,
|
||||||
|
setOf("app.example|1|0|1", "bad-entry"));
|
||||||
|
|
||||||
|
SbtSettings decoded = SbtSettings.fromSource(source);
|
||||||
|
|
||||||
|
assertFalse(decoded.clockEnabled);
|
||||||
|
assertEquals("H:mm:ss", decoded.clockCustomFormat);
|
||||||
|
assertEquals(SbtDefaults.UNLOCKED_MAX_ICONS_PER_ROW_MIN, decoded.unlockedMaxIconsPerRow);
|
||||||
|
assertEquals(500, decoded.clockVerticalOffsetPx);
|
||||||
|
assertEquals(SbtSettings.BATTERY_BAR_CURVED_GEOMETRY_OFF, decoded.batteryBarCurvedGeometryMode);
|
||||||
|
assertEquals(SbtDefaults.LAYOUT_ICON_CONTAINER_COUNT_MAX, decoded.layoutNotifUnlockedCount);
|
||||||
|
assertEquals(
|
||||||
|
SbtDefaults.SYSTEM_ICON_DUAL_SIM_SIGNAL_MODE_DEFAULT,
|
||||||
|
decoded.systemIconDualSimSignalMode);
|
||||||
|
assertEquals(Integer.valueOf(5), decoded.systemIconBlockedModes.get("wifi"));
|
||||||
|
assertEquals(Integer.valueOf(AppIconRules.MODE_AOD | AppIconRules.MODE_UNLOCK),
|
||||||
|
decoded.appIconBlockedModes.get("app.example"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<String> setOf(String... values) {
|
||||||
|
HashSet<String> result = new HashSet<>();
|
||||||
|
Collections.addAll(result, values);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class MapSource implements SbtSettings.SettingsSource {
|
||||||
|
private final Map<String, Object> values = new HashMap<>();
|
||||||
|
|
||||||
|
void put(String key, Object value) {
|
||||||
|
values.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getBoolean(String key, boolean defaultValue) {
|
||||||
|
Object value = values.get(key);
|
||||||
|
return value instanceof Boolean ? (Boolean) value : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getInt(String key, int defaultValue) {
|
||||||
|
Object value = values.get(key);
|
||||||
|
return value instanceof Integer ? (Integer) value : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getString(String key, String defaultValue) {
|
||||||
|
Object value = values.get(key);
|
||||||
|
return value instanceof String ? (String) value : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Set<String> getStringSet(String key) {
|
||||||
|
Object value = values.get(key);
|
||||||
|
return value instanceof Set ? (Set<String>) value : Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(String key) {
|
||||||
|
return values.containsKey(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user