Skip to content

Commit

Permalink
line fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LikhanovD committed Oct 22, 2020
1 parent 17ae3d6 commit 9d1d4ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
24 changes: 11 additions & 13 deletions phonemask/src/main/java/ru/vvdev/phonemask/ui/PhoneView.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.vvdev.phonemask.ui

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
Expand All @@ -12,7 +11,6 @@ import android.widget.ImageView
import android.widget.LinearLayout
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatEditText
import androidx.core.content.res.getColorOrThrow
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
Expand All @@ -39,7 +37,7 @@ class PhoneView @JvmOverloads constructor(

var defaultCode = ""
var flagEnabled = true
var lineColor: Int? = null
var lineVisible = true
attrs?.let {
val a = context.theme.obtainStyledAttributes(
attrs,
Expand All @@ -52,20 +50,20 @@ class PhoneView @JvmOverloads constructor(
""
}

flagEnabled = try{
flagEnabled = try {
a.getBoolean(R.styleable.PhoneView_flagEnabled, true)
}catch (e: Exception){
} catch (e: Exception) {
true
}

lineColor = try{
a.getColorOrThrow(R.styleable.PhoneView_lineColor)
}catch (e: Exception){
null
lineVisible = try {
a.getBoolean(R.styleable.PhoneView_lineVisible, true)
} catch (e: Exception) {
true
}
}

editText = initEditText(lineColor)
editText = initEditText(lineVisible)
countryFlag = initFlag()

phoneTextWatcher = PhoneTextWatcher(
Expand All @@ -74,7 +72,7 @@ class PhoneView @JvmOverloads constructor(
defaultCode
)
editText.addTextChangedListener(phoneTextWatcher)
if(flagEnabled) addView(countryFlag)
if (flagEnabled) addView(countryFlag)
addView(editText)
}

Expand All @@ -100,12 +98,12 @@ class PhoneView @JvmOverloads constructor(
}
}

private fun initEditText(color: Int?) =
private fun initEditText(lineVisible: Boolean) =
AppCompatEditText(context).apply {
layoutParams = LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply {
setMargins(16, 0, 0, 0)
}
color?.let { setBackgroundResource(it) }
if (!lineVisible) setBackgroundResource(android.R.color.transparent)
}

private fun initFlag() =
Expand Down
2 changes: 1 addition & 1 deletion phonemask/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<declare-styleable name="PhoneView">
<attr name="defaultCode" format="string" />
<attr name="flagEnabled" format="boolean" />
<attr name="lineColor" format="color" />
<attr name="lineVisible" format="boolean" />
</declare-styleable>
</resources>

0 comments on commit 9d1d4ea

Please sign in to comment.