Skip to content

Commit 22c9459

Browse files
committed
refactor(Config): minor refactor of the getter holder classes
1 parent af8d0df commit 22c9459

File tree

1 file changed

+17
-15
lines changed
  • app/src/main/java/com/osfans/trime/data/theme

1 file changed

+17
-15
lines changed

app/src/main/java/com/osfans/trime/data/theme/Config.java

+17-15
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static Config get() {
6565
private static final String defaultThemeName = "trime";
6666
private String currentSchemaId, currentColorSchemeId;
6767

68+
private Map<String, Object> generalStyle;
6869
private Map<String, String> fallbackColors;
6970
private Map<String, Map<String, String>> presetColorSchemes;
7071
private Map<String, Map<String, Object>> presetKeyboards;
@@ -163,15 +164,16 @@ public void init(boolean skipDeployment) {
163164
Objects.requireNonNull(fullThemeConfigMap, "The theme file cannot be empty!");
164165
Timber.d("Fetching done");
165166

166-
style = new Style((Map<String, Object>) fullThemeConfigMap.get("style"));
167+
generalStyle = (Map<String, Object>) fullThemeConfigMap.get("style");
167168
fallbackColors = (Map<String, String>) fullThemeConfigMap.get("fallback_colors");
168169
Key.presetKeys = (Map<String, Map<String, Object>>) fullThemeConfigMap.get("preset_keys");
169170
presetColorSchemes =
170171
(Map<String, Map<String, String>>) fullThemeConfigMap.get("preset_color_schemes");
171172
presetKeyboards =
172173
(Map<String, Map<String, Object>>) fullThemeConfigMap.get("preset_keyboards");
173174
liquidKeyboard = (Map<String, Object>) fullThemeConfigMap.get("liquid_keyboard");
174-
liquid = new Liquid(liquidKeyboard);
175+
style = new Style(this);
176+
liquid = new Liquid(this);
175177
long end = System.currentTimeMillis();
176178
Timber.d("Setting up all theme config map takes %s ms", end - start);
177179
initLiquidKeyboard();
@@ -269,46 +271,46 @@ public static boolean obtainBoolean(Map<String, Object> map, @NonNull String key
269271
}
270272

271273
public static class Style {
272-
private final Map<String, Object> styleConfigMap;
274+
private final Config theme;
273275

274-
public Style(final Map<String, Object> styleConfigMap) {
275-
this.styleConfigMap = styleConfigMap;
276+
public Style(@NonNull final Config theme) {
277+
this.theme = theme;
276278
}
277279

278280
public String getString(@NonNull String key) {
279-
return obtainString(styleConfigMap, key);
281+
return obtainString(theme.generalStyle, key);
280282
}
281283

282284
public int getInt(@NonNull String key) {
283-
return obtainInt(styleConfigMap, key);
285+
return obtainInt(theme.generalStyle, key);
284286
}
285287

286288
public float getFloat(@NonNull String key) {
287-
return obtainFloat(styleConfigMap, key);
289+
return obtainFloat(theme.generalStyle, key);
288290
}
289291

290292
public boolean getBoolean(@NonNull String key) {
291-
return obtainBoolean(styleConfigMap, key);
293+
return obtainBoolean(theme.generalStyle, key);
292294
}
293295

294296
public Object getObject(@NonNull String key) {
295-
return obtainValue(styleConfigMap, key);
297+
return obtainValue(theme.generalStyle, key);
296298
}
297299
}
298300

299301
public static class Liquid {
300-
private final Map<String, Object> liquidConfigMap;
302+
private final Config theme;
301303

302-
public Liquid(@NonNull Map<String, Object> liquidConfigMap) {
303-
this.liquidConfigMap = liquidConfigMap;
304+
public Liquid(@NonNull final Config theme) {
305+
this.theme = theme;
304306
}
305307

306308
public int getInt(@NonNull String key) {
307-
return obtainInt(liquidConfigMap, key);
309+
return obtainInt(theme.liquidKeyboard, key);
308310
}
309311

310312
public float getFloat(@NonNull String key) {
311-
return obtainFloat(liquidConfigMap, key, self.style.getFloat(key));
313+
return obtainFloat(theme.liquidKeyboard, key, theme.style.getFloat(key));
312314
}
313315
}
314316

0 commit comments

Comments
 (0)