Skip to content

Commit

Permalink
feat: add textLength and convert companion object to enum class TextL…
Browse files Browse the repository at this point in the history
…engthType
  • Loading branch information
iamageo committed Feb 11, 2024
1 parent d2c1799 commit f731c0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MainActivity : AppCompatActivity() {

private fun setupBasicView() {
val anotherReadMore: AnotherReadMore = AnotherReadMore.Builder()
.textLength(3, AnotherReadMore.TextLengthType.TYPE_LINE)
.moreLabel("mais")
.lessLabel("menos")
.build()
Expand Down
21 changes: 12 additions & 9 deletions library/src/main/java/com/iamageo/library/AnotherReadMore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import android.view.ViewGroup.MarginLayoutParams
import android.widget.TextView

class AnotherReadMore(
private val textLength: Int = 0,
private val textLengthType: Int = 0,
private val textLength: Int = 100,
private val textLengthType: TextLengthType = TextLengthType.TYPE_CHARACTER,
private val moreLabel: String? = null,
private val lessLabel: String? = null,
private val moreLabelColor: Int,
Expand All @@ -36,7 +36,7 @@ class AnotherReadMore(
)

fun addReadMoreTo(textView: TextView, text: CharSequence) {
if (textLengthType == TYPE_CHARACTER) {
if (textLengthType == TextLengthType.TYPE_CHARACTER) {
if (text.length <= textLength) {
textView.text = text
return
Expand All @@ -47,7 +47,7 @@ class AnotherReadMore(
}
textView.post(Runnable {
var textLengthNew = textLength
if (textLengthType == TYPE_LINE) {
if (textLengthType == TextLengthType.TYPE_LINE) {
if (textView.layout.lineCount <= textLength) {
textView.text = text
return@Runnable
Expand Down Expand Up @@ -134,7 +134,7 @@ class AnotherReadMore(

var textLength = 100
private set
var textLengthType = TYPE_CHARACTER
var textLengthType = TextLengthType.TYPE_CHARACTER
private set
var moreLabel = "mais"
private set
Expand All @@ -147,7 +147,10 @@ class AnotherReadMore(
var underlineVisible: Boolean = true
private set

fun textLengthType(type: Int) = apply { textLengthType = type }
fun textLength(length: Int, type: TextLengthType) = apply {
this.textLength = length
this.textLengthType = type
}
fun moreLabel(more: String) = apply { moreLabel = more }
fun lessLabel(less: String) = apply { lessLabel = less }
fun moreLabelColor(color: Int) = apply { moreLabelColor = color }
Expand All @@ -157,9 +160,9 @@ class AnotherReadMore(
fun build() = AnotherReadMore(this)
}

companion object {
const val TYPE_LINE = 1
const val TYPE_CHARACTER = 2
enum class TextLengthType {
TYPE_LINE,
TYPE_CHARACTER
}

}

0 comments on commit f731c0c

Please sign in to comment.