Skip to content

Commit 26fcab4

Browse files
committed
Fixed crash in arrayText if one of texts is .empty(). Added isEmpty() to TextBuilder
1 parent 673a1e2 commit 26fcab4

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

app/src/main/java/omega_r/com/omegatypesexample/MainActivity.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ import android.os.Bundle
88
import android.widget.ImageView
99
import android.widget.TextView
1010
import androidx.core.content.res.ResourcesCompat
11-
import com.omega_r.libs.omegatypes.Color
12-
import com.omega_r.libs.omegatypes.Text
13-
import com.omega_r.libs.omegatypes.TextStyle
11+
import com.omega_r.libs.omegatypes.*
1412
import com.omega_r.libs.omegatypes.file.File
1513
import com.omega_r.libs.omegatypes.file.from
1614
import com.omega_r.libs.omegatypes.image.*
17-
import com.omega_r.libs.omegatypes.join
1815
import kotlinx.coroutines.Dispatchers
1916
import kotlinx.coroutines.launch
2017
import kotlinx.coroutines.withContext
@@ -31,16 +28,20 @@ class MainActivity : BaseActivity() {
3128
super.onCreate(savedInstanceState)
3229

3330
setContentView(R.layout.activity_main)
34-
val text = Text.from("test ") +
35-
Text.from(
31+
val text = TextBuilder()
32+
.append(Text.empty())
33+
.append(Text.from("test "))
34+
.append(Text.from(
3635
R.string.hello_world,
3736
Text.from(R.string.app_name),
3837
textStyle = TextStyle.font(ResourcesCompat.getFont(this, R.font.noto_sans_regular)!!)
39-
) +
40-
Text.from(
38+
))
39+
.append(Text.from(
4140
" SEMI BOLD",
4241
textStyle = TextStyle.font(ResourcesCompat.getFont(this, R.font.noto_sans_semi_bold)!!)
43-
)
42+
))
43+
.toText()
44+
4445
text.applyTo(exampleTextView) // or exampleTextView.setText(text)
4546

4647
val list = listOf(Text.from("1", TextStyle.color(Color.fromAttribute(R.attr.colorAccent))), Text.from("2", TextStyle.color(Color.fromAttribute(R.attr.colorAccent))), Text.from("3"))

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ buildscript {
1212
jcenter()
1313
}
1414
dependencies {
15-
classpath 'com.android.tools.build:gradle:3.4.1'
15+
classpath 'com.android.tools.build:gradle:3.6.3'
1616
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1717
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1818
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed May 29 11:12:26 MSK 2019
1+
#Tue Apr 21 10:08:25 MSK 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

omegatypes/src/main/java/com/omega_r/libs/omegatypes/Text.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ open class Text(protected val defaultTextStyle: TextStyle?) : Serializable, Text
297297
val stringBuilder = SpannableStringBuilder()
298298
val newTextStyle = defaultTextStyle + textStyle
299299
for (text in texts) {
300-
stringBuilder.append(text.getCharSequence(context, newTextStyle))
300+
text.getCharSequence(context, newTextStyle)?.let { textCharSequence ->
301+
stringBuilder.append(textCharSequence)
302+
}
301303
}
302304
return stringBuilder
303305
}

omegatypes/src/main/java/com/omega_r/libs/omegatypes/TextBuilder.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ class TextBuilder(capacity: Int) : Serializable {
4848
return Text.from(list)
4949
}
5050

51+
fun isEmpty(): Boolean {
52+
for (text in list) {
53+
if (!text.isEmpty()) {
54+
return false
55+
}
56+
}
57+
return true
58+
}
59+
5160
override fun equals(other: Any?): Boolean {
5261
if (this === other) return true
5362
if (javaClass != other?.javaClass) return false

0 commit comments

Comments
 (0)