Skip to content

Commit

Permalink
remove context and fix StringIndexOutOfBoundsException
Browse files Browse the repository at this point in the history
  • Loading branch information
iamageo committed Jun 3, 2023
1 parent 851aec1 commit 35b6412
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.util.*
internal class SimpleAnotherAdapter internal constructor(private val context: Context) :
RecyclerView.Adapter<SimpleAnotherAdapter.ViewHolder>() {

private val readMoreOption: AnotherReadMore = AnotherReadMore.Builder(context)
private val readMoreOption: AnotherReadMore = AnotherReadMore.Builder()
.build()

internal class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
Expand Down
8 changes: 3 additions & 5 deletions library/src/main/java/com/iamageo/library/AnotherReadMore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import android.view.ViewGroup.MarginLayoutParams
import android.widget.TextView

class AnotherReadMore(
var context: Context? = null,
val textLength: Int = 0,
val textLengthType: Int = 0,
val moreLabel: String? = null,
val lessLabel: String? = null,
) {

private constructor(builder: Builder) : this(
builder.context,
builder.textLength,
builder.textLengthType,
builder.moreLabel,
Expand All @@ -48,9 +46,10 @@ class AnotherReadMore(
return@Runnable
}
val lp = textView.layoutParams as MarginLayoutParams
val endLine = (textLength - 1).coerceAtMost(textView.layout.lineCount - 1);
val subString = text.toString().substring(
textView.layout.getLineStart(0),
textView.layout.getLineEnd(textLength - 1)
textView.layout.getLineEnd(endLine)
)
textLengthNew = subString.length - (moreLabel!!.length + 4 + lp.rightMargin / 6)
}
Expand Down Expand Up @@ -99,8 +98,7 @@ class AnotherReadMore(
textView.movementMethod = LinkMovementMethod.getInstance()
}

class Builder(c: Context) {
val context: Context = c
class Builder() {

var textLength = 100
private set
Expand Down

0 comments on commit 35b6412

Please sign in to comment.