Skip to content

Commit dcc213d

Browse files
committed
feat: add class & mapper to hold style parameters
Add `Mapper` to map data held in `Map` to its related class, so that error handling with default value can be added and return with strong typed data.
1 parent 9096817 commit dcc213d

File tree

13 files changed

+2457
-1
lines changed

13 files changed

+2457
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.osfans.trime.data.theme.mapper
2+
3+
import com.osfans.trime.data.theme.model.CompositionComponent
4+
import com.osfans.trime.util.config.ConfigItem
5+
6+
class CompositionWindowStyleMapper(
7+
style: Map<String, ConfigItem?>?,
8+
) : Mapper(style) {
9+
fun map(): CompositionComponent {
10+
val start = getString("start")
11+
val move = getString("move")
12+
val end = getString("end")
13+
val composition = getString("composition")
14+
val letterSpacing = getInt("letter_spacing")
15+
val label = getString("label")
16+
val candidate = getString("candidate")
17+
val comment = getString("comment")
18+
val sep = getString("sep")
19+
val align = getString("align")
20+
val whenStr = getString("when")
21+
val click = getString("click")
22+
23+
return CompositionComponent(
24+
start,
25+
move,
26+
end,
27+
composition,
28+
letterSpacing,
29+
label,
30+
candidate,
31+
comment,
32+
sep,
33+
align,
34+
whenStr,
35+
click,
36+
)
37+
}
38+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.osfans.trime.data.theme.mapper
2+
3+
import com.osfans.trime.data.theme.model.EnterLabel
4+
import com.osfans.trime.util.config.ConfigItem
5+
6+
class EnterLabelStyleMapper(
7+
style: Map<String, ConfigItem?>?,
8+
) : Mapper(style) {
9+
fun map(): EnterLabel {
10+
val go = getString("go", "go")
11+
val done = getString("done", "done")
12+
val next = getString("next", "next")
13+
val pre = getString("pre", "pre")
14+
val search = getString("search", "search")
15+
val send = getString("send", "send")
16+
val default = getString("default", "Enter")
17+
18+
return EnterLabel(
19+
go,
20+
done,
21+
next,
22+
pre,
23+
search,
24+
send,
25+
default,
26+
)
27+
}
28+
}
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
package com.osfans.trime.data.theme.mapper
2+
3+
import com.osfans.trime.data.theme.model.GeneralStyle
4+
import com.osfans.trime.ime.symbol.CandidateAdapter.CommentPosition
5+
import com.osfans.trime.util.config.ConfigItem
6+
7+
class GeneralStyleMapper(
8+
style: Map<String, ConfigItem?>?,
9+
) : Mapper(style) {
10+
fun map(): GeneralStyle {
11+
val autoCaps = getString("auto_caps")
12+
13+
val backgroundDimAmount = getFloat("background_dim_amount")
14+
15+
val candidateBorder = getInt("candidate_border")
16+
val candidateBorderRound = getInt("candidate_border_round")
17+
18+
val candidateFont = getStringList("candidate_font")
19+
20+
val candidatePadding = getInt("candidate_padding")
21+
22+
val candidateSpacing = getFloat("candidate_spacing")
23+
24+
val candidateTextSize = getInt("candidate_text_size")
25+
26+
val candidateUseCursor = getBoolean("candidate_use_cursor")
27+
28+
val candidateViewHeight = getInt("candidate_view_height")
29+
30+
val colorScheme = getString("color_scheme")
31+
32+
val commentFont = getStringList("comment_font")
33+
34+
val commentHeight = getInt("comment_height")
35+
36+
val commentOnTop = getBoolean("comment_on_top")
37+
val commentPosition =
38+
runCatching {
39+
val s = getString("comment_position")
40+
CommentPosition.valueOf(s.uppercase())
41+
}.getOrElse {
42+
CommentPosition.UNKNOWN
43+
}
44+
45+
val commentTextSize = getInt("comment_text_size")
46+
47+
val hanbFont = getStringList("hanb_font")
48+
49+
val horizontal = getBoolean("horizontal")
50+
51+
val horizontalGap = getInt("horizontal_gap")
52+
53+
val keyboardPadding = getInt("keyboard_padding")
54+
55+
val keyboardPaddingLeft = getInt("keyboard_padding_left")
56+
57+
val keyboardPaddingRight = getInt("keyboard_padding_right")
58+
59+
val keyboardPaddingBottom = getInt("keyboard_padding_bottom")
60+
61+
val keyboardPaddingLand = getInt("keyboard_padding_land")
62+
63+
val keyboardPaddingLandBottom = getInt("keyboard_padding_land_bottom")
64+
65+
val layout =
66+
getObject("layout").let {
67+
LayoutStyleMapper(it).map()
68+
}
69+
70+
val window =
71+
(getList("window")).map {
72+
val compositionWindowStyleMapper = CompositionWindowStyleMapper(it.configMap)
73+
compositionWindowStyleMapper.map()
74+
}
75+
val liquidKeyboardWindow =
76+
(getList("liquid_keyboard_window")).map {
77+
val mapper = CompositionWindowStyleMapper(it.configMap)
78+
mapper.map()
79+
}
80+
val keyFont = getStringList("key_font")
81+
val keyBorder = getInt("key_border")
82+
83+
val keyHeight = getInt("key_height")
84+
85+
val keyLongTextSize = getInt("key_long_text_size")
86+
87+
val keyTextSize = getInt("key_text_size")
88+
89+
val keyTextOffsetX = getInt("key_text_offset_x")
90+
val keyTextOffsetY = getInt("key_text_offset_y")
91+
val keySymbolOffsetX = getInt("key_symbol_offset_x")
92+
val keySymbolOffsetY = getInt("key_symbol_offset_y")
93+
val keyHintOffsetX = getInt("key_hint_offset_x")
94+
val keyHintOffsetY = getInt("key_hint_offset_y")
95+
val keyPressOffsetX = getInt("key_press_offset_x")
96+
val keyPressOffsetY = getInt("key_press_offset_y")
97+
98+
val keyWidth = getFloat("key_width")
99+
100+
val keyboards = getStringList("keyboards")
101+
102+
val labelTextSize = getInt("label_text_size")
103+
104+
val labelFont = getStringList("label_font")
105+
106+
val latinFont = getStringList("latin_font")
107+
108+
val latinLocale = getString("latin_locale")
109+
110+
val locale = getString("locale")
111+
112+
val keyboardHeight = getInt("keyboard_height")
113+
114+
val keyboardHeightLand = getInt("keyboard_height_land")
115+
116+
val previewFont = getStringList("preview_font")
117+
118+
val previewHeight = getInt("preview_height")
119+
120+
val previewOffset = getInt("preview_offset")
121+
122+
val previewTextSize = getInt("preview_text_size")
123+
124+
val proximityCorrection = getBoolean("proximity_correction")
125+
126+
val resetASCIIMode = getBoolean("reset_ascii_mode")
127+
128+
val roundCorner = getInt("round_corner")
129+
130+
val shadowRadius = getFloat("shadow_radius")
131+
132+
val speechOpenccConfig = getString("speech_opencc_config")
133+
134+
val symbolFont = getStringList("symbol_font")
135+
136+
val symbolTextSize = getInt("symbol_text_size")
137+
138+
val textFont = getStringList("text_font")
139+
140+
val textSize = getInt("text_size")
141+
142+
val verticalCorrection = getInt("vertical_correction")
143+
144+
val verticalGap = getInt("vertical_gap")
145+
146+
val longTextFont = getStringList("long_text_font")
147+
148+
val backgroundFolder = getString("background_folder")
149+
150+
val keyIntTextBorder = getInt("key_long_text_border")
151+
152+
val enterLabelMode = getInt("enter_label_mode")
153+
154+
val enterLabels = EnterLabelStyleMapper((getObject("enter_labels")?.configMap)).map()
155+
156+
return GeneralStyle(
157+
autoCaps,
158+
backgroundDimAmount,
159+
candidateBorder,
160+
candidateBorderRound,
161+
candidateFont,
162+
candidatePadding,
163+
candidateSpacing,
164+
candidateTextSize,
165+
candidateUseCursor,
166+
candidateViewHeight,
167+
colorScheme,
168+
commentFont,
169+
commentHeight,
170+
commentOnTop,
171+
commentPosition,
172+
commentTextSize,
173+
hanbFont,
174+
horizontal,
175+
horizontalGap,
176+
keyboardPadding,
177+
keyboardPaddingLeft,
178+
keyboardPaddingRight,
179+
keyboardPaddingBottom,
180+
keyboardPaddingLand,
181+
keyboardPaddingLandBottom,
182+
layout,
183+
window,
184+
liquidKeyboardWindow,
185+
keyFont,
186+
keyBorder,
187+
keyHeight,
188+
keyLongTextSize,
189+
keyTextSize,
190+
keyTextOffsetX,
191+
keyTextOffsetY,
192+
keySymbolOffsetX,
193+
keySymbolOffsetY,
194+
keyHintOffsetX,
195+
keyHintOffsetY,
196+
keyPressOffsetX,
197+
keyPressOffsetY,
198+
keyWidth,
199+
keyboards,
200+
labelTextSize,
201+
labelFont,
202+
latinFont,
203+
latinLocale,
204+
locale,
205+
keyboardHeight,
206+
keyboardHeightLand,
207+
previewFont,
208+
previewHeight,
209+
previewOffset,
210+
previewTextSize,
211+
proximityCorrection,
212+
resetASCIIMode,
213+
roundCorner,
214+
shadowRadius,
215+
speechOpenccConfig,
216+
symbolFont,
217+
symbolTextSize,
218+
textFont,
219+
textSize,
220+
verticalCorrection,
221+
verticalGap,
222+
longTextFont,
223+
backgroundFolder,
224+
keyIntTextBorder,
225+
enterLabelMode,
226+
enterLabels,
227+
)
228+
}
229+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.osfans.trime.data.theme.mapper
2+
3+
import com.osfans.trime.data.theme.model.Layout
4+
import com.osfans.trime.util.config.ConfigItem
5+
6+
class LayoutStyleMapper(
7+
style: Map<String, ConfigItem?>?,
8+
) : Mapper(style) {
9+
fun map(): Layout {
10+
val position = getString("position")
11+
12+
val minLength = getInt("min_length")
13+
14+
val maxLength = getInt("max_length")
15+
16+
val stickyLines = getInt("sticky_lines")
17+
18+
val stickyLinesLand = getInt("sticky_lines_land")
19+
20+
val maxEntries = getInt("max_entries")
21+
22+
val minCheck = getInt("min_check")
23+
24+
val allPhrases = getBoolean("all_phrases")
25+
26+
val border = getInt("border")
27+
28+
val maxWidth = getInt("max_width")
29+
30+
val maxHeight = getInt("max_height")
31+
32+
val minWidth = getInt("min_width")
33+
34+
val minHeight = getInt("min_height")
35+
36+
val marginX = getInt("margin_x")
37+
38+
val marginY = getInt("margin_y")
39+
40+
val marginBottom = getInt("margin_bottom")
41+
42+
val lineSpacing = getInt("line_spacing")
43+
44+
val lineSpacingMultiplier = getFloat("line_spacing_multiplier")
45+
46+
val realMargin = getInt("real_margin")
47+
48+
val spacing = getInt("spacing")
49+
50+
val roundCorner = getInt("round_corner")
51+
52+
val alpha = getInt("alpha")
53+
val elevation = getInt("elevation")
54+
val movable = getString("movable")
55+
56+
return Layout(
57+
position,
58+
minLength,
59+
maxLength,
60+
stickyLines,
61+
stickyLinesLand,
62+
maxEntries,
63+
minCheck,
64+
allPhrases,
65+
border,
66+
maxWidth,
67+
maxHeight,
68+
minWidth,
69+
minHeight,
70+
marginX,
71+
marginY,
72+
marginBottom,
73+
lineSpacing,
74+
lineSpacingMultiplier,
75+
realMargin,
76+
spacing,
77+
roundCorner,
78+
alpha,
79+
elevation,
80+
movable,
81+
)
82+
}
83+
}

0 commit comments

Comments
 (0)