-
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
13 changed files
with
2,457 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/osfans/trime/data/theme/mapper/CompositionWindowStyleMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.osfans.trime.data.theme.mapper | ||
|
||
import com.osfans.trime.data.theme.model.CompositionComponent | ||
import com.osfans.trime.util.config.ConfigItem | ||
|
||
class CompositionWindowStyleMapper( | ||
style: Map<String, ConfigItem?>?, | ||
) : Mapper(style) { | ||
fun map(): CompositionComponent { | ||
val start = getString("start") | ||
val move = getString("move") | ||
val end = getString("end") | ||
val composition = getString("composition") | ||
val letterSpacing = getInt("letter_spacing") | ||
val label = getString("label") | ||
val candidate = getString("candidate") | ||
val comment = getString("comment") | ||
val sep = getString("sep") | ||
val align = getString("align") | ||
val whenStr = getString("when") | ||
val click = getString("click") | ||
|
||
return CompositionComponent( | ||
start, | ||
move, | ||
end, | ||
composition, | ||
letterSpacing, | ||
label, | ||
candidate, | ||
comment, | ||
sep, | ||
align, | ||
whenStr, | ||
click, | ||
) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/osfans/trime/data/theme/mapper/EnterLabelStyleMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.osfans.trime.data.theme.mapper | ||
|
||
import com.osfans.trime.data.theme.model.EnterLabel | ||
import com.osfans.trime.util.config.ConfigItem | ||
|
||
class EnterLabelStyleMapper( | ||
style: Map<String, ConfigItem?>?, | ||
) : Mapper(style) { | ||
fun map(): EnterLabel { | ||
val go = getString("go", "go") | ||
val done = getString("done", "done") | ||
val next = getString("next", "next") | ||
val pre = getString("pre", "pre") | ||
val search = getString("search", "search") | ||
val send = getString("send", "send") | ||
val default = getString("default", "Enter") | ||
|
||
return EnterLabel( | ||
go, | ||
done, | ||
next, | ||
pre, | ||
search, | ||
send, | ||
default, | ||
) | ||
} | ||
} |
229 changes: 229 additions & 0 deletions
229
app/src/main/java/com/osfans/trime/data/theme/mapper/GeneralStyleMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
package com.osfans.trime.data.theme.mapper | ||
|
||
import com.osfans.trime.data.theme.model.GeneralStyle | ||
import com.osfans.trime.ime.symbol.CandidateAdapter.CommentPosition | ||
import com.osfans.trime.util.config.ConfigItem | ||
|
||
class GeneralStyleMapper( | ||
style: Map<String, ConfigItem?>?, | ||
) : Mapper(style) { | ||
fun map(): GeneralStyle { | ||
val autoCaps = getString("auto_caps") | ||
|
||
val backgroundDimAmount = getFloat("background_dim_amount") | ||
|
||
val candidateBorder = getInt("candidate_border") | ||
val candidateBorderRound = getInt("candidate_border_round") | ||
|
||
val candidateFont = getStringList("candidate_font") | ||
|
||
val candidatePadding = getInt("candidate_padding") | ||
|
||
val candidateSpacing = getFloat("candidate_spacing") | ||
|
||
val candidateTextSize = getInt("candidate_text_size") | ||
|
||
val candidateUseCursor = getBoolean("candidate_use_cursor") | ||
|
||
val candidateViewHeight = getInt("candidate_view_height") | ||
|
||
val colorScheme = getString("color_scheme") | ||
|
||
val commentFont = getStringList("comment_font") | ||
|
||
val commentHeight = getInt("comment_height") | ||
|
||
val commentOnTop = getBoolean("comment_on_top") | ||
val commentPosition = | ||
runCatching { | ||
val s = getString("comment_position") | ||
CommentPosition.valueOf(s.uppercase()) | ||
}.getOrElse { | ||
CommentPosition.UNKNOWN | ||
} | ||
|
||
val commentTextSize = getInt("comment_text_size") | ||
|
||
val hanbFont = getStringList("hanb_font") | ||
|
||
val horizontal = getBoolean("horizontal") | ||
|
||
val horizontalGap = getInt("horizontal_gap") | ||
|
||
val keyboardPadding = getInt("keyboard_padding") | ||
|
||
val keyboardPaddingLeft = getInt("keyboard_padding_left") | ||
|
||
val keyboardPaddingRight = getInt("keyboard_padding_right") | ||
|
||
val keyboardPaddingBottom = getInt("keyboard_padding_bottom") | ||
|
||
val keyboardPaddingLand = getInt("keyboard_padding_land") | ||
|
||
val keyboardPaddingLandBottom = getInt("keyboard_padding_land_bottom") | ||
|
||
val layout = | ||
getObject("layout").let { | ||
LayoutStyleMapper(it).map() | ||
} | ||
|
||
val window = | ||
(getList("window")).map { | ||
val compositionWindowStyleMapper = CompositionWindowStyleMapper(it.configMap) | ||
compositionWindowStyleMapper.map() | ||
} | ||
val liquidKeyboardWindow = | ||
(getList("liquid_keyboard_window")).map { | ||
val mapper = CompositionWindowStyleMapper(it.configMap) | ||
mapper.map() | ||
} | ||
val keyFont = getStringList("key_font") | ||
val keyBorder = getInt("key_border") | ||
|
||
val keyHeight = getInt("key_height") | ||
|
||
val keyLongTextSize = getInt("key_long_text_size") | ||
|
||
val keyTextSize = getInt("key_text_size") | ||
|
||
val keyTextOffsetX = getInt("key_text_offset_x") | ||
val keyTextOffsetY = getInt("key_text_offset_y") | ||
val keySymbolOffsetX = getInt("key_symbol_offset_x") | ||
val keySymbolOffsetY = getInt("key_symbol_offset_y") | ||
val keyHintOffsetX = getInt("key_hint_offset_x") | ||
val keyHintOffsetY = getInt("key_hint_offset_y") | ||
val keyPressOffsetX = getInt("key_press_offset_x") | ||
val keyPressOffsetY = getInt("key_press_offset_y") | ||
|
||
val keyWidth = getFloat("key_width") | ||
|
||
val keyboards = getStringList("keyboards") | ||
|
||
val labelTextSize = getInt("label_text_size") | ||
|
||
val labelFont = getStringList("label_font") | ||
|
||
val latinFont = getStringList("latin_font") | ||
|
||
val latinLocale = getString("latin_locale") | ||
|
||
val locale = getString("locale") | ||
|
||
val keyboardHeight = getInt("keyboard_height") | ||
|
||
val keyboardHeightLand = getInt("keyboard_height_land") | ||
|
||
val previewFont = getStringList("preview_font") | ||
|
||
val previewHeight = getInt("preview_height") | ||
|
||
val previewOffset = getInt("preview_offset") | ||
|
||
val previewTextSize = getInt("preview_text_size") | ||
|
||
val proximityCorrection = getBoolean("proximity_correction") | ||
|
||
val resetASCIIMode = getBoolean("reset_ascii_mode") | ||
|
||
val roundCorner = getInt("round_corner") | ||
|
||
val shadowRadius = getFloat("shadow_radius") | ||
|
||
val speechOpenccConfig = getString("speech_opencc_config") | ||
|
||
val symbolFont = getStringList("symbol_font") | ||
|
||
val symbolTextSize = getInt("symbol_text_size") | ||
|
||
val textFont = getStringList("text_font") | ||
|
||
val textSize = getInt("text_size") | ||
|
||
val verticalCorrection = getInt("vertical_correction") | ||
|
||
val verticalGap = getInt("vertical_gap") | ||
|
||
val longTextFont = getStringList("long_text_font") | ||
|
||
val backgroundFolder = getString("background_folder") | ||
|
||
val keyIntTextBorder = getInt("key_long_text_border") | ||
|
||
val enterLabelMode = getInt("enter_label_mode") | ||
|
||
val enterLabels = EnterLabelStyleMapper((getObject("enter_labels")?.configMap)).map() | ||
|
||
return GeneralStyle( | ||
autoCaps, | ||
backgroundDimAmount, | ||
candidateBorder, | ||
candidateBorderRound, | ||
candidateFont, | ||
candidatePadding, | ||
candidateSpacing, | ||
candidateTextSize, | ||
candidateUseCursor, | ||
candidateViewHeight, | ||
colorScheme, | ||
commentFont, | ||
commentHeight, | ||
commentOnTop, | ||
commentPosition, | ||
commentTextSize, | ||
hanbFont, | ||
horizontal, | ||
horizontalGap, | ||
keyboardPadding, | ||
keyboardPaddingLeft, | ||
keyboardPaddingRight, | ||
keyboardPaddingBottom, | ||
keyboardPaddingLand, | ||
keyboardPaddingLandBottom, | ||
layout, | ||
window, | ||
liquidKeyboardWindow, | ||
keyFont, | ||
keyBorder, | ||
keyHeight, | ||
keyLongTextSize, | ||
keyTextSize, | ||
keyTextOffsetX, | ||
keyTextOffsetY, | ||
keySymbolOffsetX, | ||
keySymbolOffsetY, | ||
keyHintOffsetX, | ||
keyHintOffsetY, | ||
keyPressOffsetX, | ||
keyPressOffsetY, | ||
keyWidth, | ||
keyboards, | ||
labelTextSize, | ||
labelFont, | ||
latinFont, | ||
latinLocale, | ||
locale, | ||
keyboardHeight, | ||
keyboardHeightLand, | ||
previewFont, | ||
previewHeight, | ||
previewOffset, | ||
previewTextSize, | ||
proximityCorrection, | ||
resetASCIIMode, | ||
roundCorner, | ||
shadowRadius, | ||
speechOpenccConfig, | ||
symbolFont, | ||
symbolTextSize, | ||
textFont, | ||
textSize, | ||
verticalCorrection, | ||
verticalGap, | ||
longTextFont, | ||
backgroundFolder, | ||
keyIntTextBorder, | ||
enterLabelMode, | ||
enterLabels, | ||
) | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
app/src/main/java/com/osfans/trime/data/theme/mapper/LayoutStyleMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.osfans.trime.data.theme.mapper | ||
|
||
import com.osfans.trime.data.theme.model.Layout | ||
import com.osfans.trime.util.config.ConfigItem | ||
|
||
class LayoutStyleMapper( | ||
style: Map<String, ConfigItem?>?, | ||
) : Mapper(style) { | ||
fun map(): Layout { | ||
val position = getString("position") | ||
|
||
val minLength = getInt("min_length") | ||
|
||
val maxLength = getInt("max_length") | ||
|
||
val stickyLines = getInt("sticky_lines") | ||
|
||
val stickyLinesLand = getInt("sticky_lines_land") | ||
|
||
val maxEntries = getInt("max_entries") | ||
|
||
val minCheck = getInt("min_check") | ||
|
||
val allPhrases = getBoolean("all_phrases") | ||
|
||
val border = getInt("border") | ||
|
||
val maxWidth = getInt("max_width") | ||
|
||
val maxHeight = getInt("max_height") | ||
|
||
val minWidth = getInt("min_width") | ||
|
||
val minHeight = getInt("min_height") | ||
|
||
val marginX = getInt("margin_x") | ||
|
||
val marginY = getInt("margin_y") | ||
|
||
val marginBottom = getInt("margin_bottom") | ||
|
||
val lineSpacing = getInt("line_spacing") | ||
|
||
val lineSpacingMultiplier = getFloat("line_spacing_multiplier") | ||
|
||
val realMargin = getInt("real_margin") | ||
|
||
val spacing = getInt("spacing") | ||
|
||
val roundCorner = getInt("round_corner") | ||
|
||
val alpha = getInt("alpha") | ||
val elevation = getInt("elevation") | ||
val movable = getString("movable") | ||
|
||
return Layout( | ||
position, | ||
minLength, | ||
maxLength, | ||
stickyLines, | ||
stickyLinesLand, | ||
maxEntries, | ||
minCheck, | ||
allPhrases, | ||
border, | ||
maxWidth, | ||
maxHeight, | ||
minWidth, | ||
minHeight, | ||
marginX, | ||
marginY, | ||
marginBottom, | ||
lineSpacing, | ||
lineSpacingMultiplier, | ||
realMargin, | ||
spacing, | ||
roundCorner, | ||
alpha, | ||
elevation, | ||
movable, | ||
) | ||
} | ||
} |
Oops, something went wrong.