Skip to content

Commit b1bc377

Browse files
committed
added customizable delimeters
1 parent e699b6f commit b1bc377

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
app:endText="@string/app_name"
2020
app:endTextStyle="underline"
2121
app:endTextFontFamily="@font/noto_sans_medium"
22-
app:includeTextSpace="true"
22+
app:startDelimiter=" "
23+
app:endDelimiter="\n"
2324
app:layout_constraintBottom_toBottomOf="parent"
2425
app:layout_constraintLeft_toLeftOf="parent"
2526
app:layout_constraintRight_toRightOf="parent"

omegaviwslibs/src/main/java/com/omega_r/libs/views/OmegaTextView.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ open class OmegaTextView @JvmOverloads constructor(
4747

4848
}
4949

50-
var spaceText: Text? = null
50+
var startSpaceText: Text? = null
51+
set(value) {
52+
field = value
53+
updateAllText()
54+
}
55+
56+
var endSpaceText: Text? = null
5157
set(value) {
5258
field = value
5359
updateAllText()
@@ -103,9 +109,14 @@ open class OmegaTextView @JvmOverloads constructor(
103109
R.styleable.OmegaTextView_endTextFontFamily -> {
104110
obtainFont(intoStyle = endTextStyle, typedArray = a, attr = attr)
105111
}
106-
R.styleable.OmegaTextView_includeTextSpace -> {
107-
if (a.getBoolean(attr, false)) {
108-
spaceText = Text.from(" ")
112+
R.styleable.OmegaTextView_startDelimiter -> {
113+
a.getString(attr)?.let {
114+
startSpaceText = Text.from(it)
115+
}
116+
}
117+
R.styleable.OmegaTextView_endDelimiter -> {
118+
a.getString(attr)?.let {
119+
endSpaceText = Text.from(it)
109120
}
110121
}
111122

@@ -141,7 +152,7 @@ open class OmegaTextView @JvmOverloads constructor(
141152

142153
private fun updateAllText(force: Boolean = false) {
143154
if (initData || force) {
144-
val allText = (startText + startTextStyle) + spaceText + text + spaceText + (endText + endTextStyle)
155+
val allText = (startText + startTextStyle) + startSpaceText + text + endSpaceText + (endText + endTextStyle)
145156
super.setText(allText?.getCharSequence(context), BufferType.NORMAL)
146157
}
147158
}

omegaviwslibs/src/main/res/values/attrs.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
<attr name="startTextFontFamily" />
2828
<attr name="endTextFontFamily" />
2929

30-
<attr name="includeTextSpace" format="boolean"/>
30+
<attr name="startDelimiter" format="string" />
31+
<attr name="endDelimiter" format="string" />
3132

3233
</declare-styleable>
3334

0 commit comments

Comments
 (0)