Skip to content

Commit

Permalink
selection color bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Masoud Ashrafzadeh committed Feb 23, 2020
1 parent 67cd0f1 commit b7d38ef
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cardentry/src/main/java/com/sma6871/cardentry/CardEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class CardEntry : AppCompatEditText {
private val spaceSize
get() = getCharSize(" ")
private var spaceCount = 0
private val mSpace
get() = spaceCount * spaceSize
private val mSpace: Float by lazy { spaceCount * spaceSize }

private val mPartLength
get() = maxLength / partCount
private val mPartSize
get() = mCharSize * mPartLength

private val mPartSize: Float by lazy { mCharSize * mPartLength }

private var mLineSpacing = toPxF(12)
private var mLineSpacingAnimated = toPxF(12)

Expand Down Expand Up @@ -76,6 +76,10 @@ class CardEntry : AppCompatEditText {
}
var oldText = ""

private val partNumbersCount:Int by lazy {
maxLength/partCount
}

private fun String.getChunked(): String {
return replace(" ", "").chunked(4).joinToString(separator = spaces)
}
Expand Down Expand Up @@ -243,7 +247,7 @@ class CardEntry : AppCompatEditText {

private fun copySelectedNumberWithoutSpaces() {
val clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val copiedText = text?.substring(selectionStart until selectionEnd)?.replace(" ", "")
val copiedText = text?.substring(selectionStart until selectionEnd)?.replace(" ", "")
clipboardManager.setPrimaryClip(ClipData.newPlainText(copiedText, copiedText))
}

Expand Down Expand Up @@ -333,7 +337,9 @@ class CardEntry : AppCompatEditText {
}

private fun drawNumber(canvas: Canvas, text: CharSequence, i: Int, middle: Float, top: Int, animated: Boolean) {
val isSelected = i in selectionStart until selectionEnd
val diff = spaceCount * (selectionStart / (spaceCount + partNumbersCount))
val diffEnd = spaceCount * (selectionEnd / (spaceCount + partNumbersCount))
val isSelected = i in selectionStart - diff until selectionEnd - diffEnd
if (animated) {
paint.alpha = animatedAlpha
} else {
Expand Down

0 comments on commit b7d38ef

Please sign in to comment.