Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextBuilder improvements #34

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions app/src/main/java/omega_r/com/omegatypesexample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import com.omega_r.libs.omegatypes.Color
import com.omega_r.libs.omegatypes.Text
import com.omega_r.libs.omegatypes.TextStyle
import com.omega_r.libs.omegatypes.*
import com.omega_r.libs.omegatypes.file.File
import com.omega_r.libs.omegatypes.file.from
import com.omega_r.libs.omegatypes.image.*
import com.omega_r.libs.omegatypes.join
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand All @@ -31,16 +28,20 @@ class MainActivity : BaseActivity() {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)
val text = Text.from("test ") +
Text.from(
val text = TextBuilder()
.append(Text.empty())
.append(Text.from("test "))
.append(Text.from(
R.string.hello_world,
Text.from(R.string.app_name),
textStyle = TextStyle.font(ResourcesCompat.getFont(this, R.font.noto_sans_regular)!!)
) +
Text.from(
))
.append(Text.from(
" SEMI BOLD",
textStyle = TextStyle.font(ResourcesCompat.getFont(this, R.font.noto_sans_semi_bold)!!)
)
))
.toText()

text.applyTo(exampleTextView) // or exampleTextView.setText(text)

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"))
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed May 29 11:12:26 MSK 2019
#Tue Apr 21 10:08:25 MSK 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
4 changes: 3 additions & 1 deletion omegatypes/src/main/java/com/omega_r/libs/omegatypes/Text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ open class Text(protected val defaultTextStyle: TextStyle?) : Serializable, Text
val stringBuilder = SpannableStringBuilder()
val newTextStyle = defaultTextStyle + textStyle
for (text in texts) {
stringBuilder.append(text.getCharSequence(context, newTextStyle))
text.getCharSequence(context, newTextStyle)?.let { textCharSequence ->
stringBuilder.append(textCharSequence)
}
}
return stringBuilder
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ class TextBuilder(capacity: Int) : Serializable {
return Text.from(list)
}

fun isEmpty(): Boolean {
for (text in list) {
if (!text.isEmpty()) {
return false
}
}
return true
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
Expand Down