Cleanup with Kotlin extension functions
This commit is contained in:
parent
fc4f0396a4
commit
e0f345b616
37 changed files with 183 additions and 291 deletions
|
@ -15,24 +15,24 @@ package code.name.monkey.retromusic.views
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.core.content.withStyledAttributes
|
||||
import code.name.monkey.retromusic.R
|
||||
import com.bumptech.glide.Glide
|
||||
|
||||
/** @author Hemanth S (h4h13).
|
||||
*/
|
||||
class NetworkImageView : CircularImageView {
|
||||
constructor(context: Context) : super(context) {
|
||||
init(context, null)
|
||||
}
|
||||
class NetworkImageView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) :
|
||||
CircularImageView(context, attrs, defStyleAttr) {
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
|
||||
init(context, attrs)
|
||||
}
|
||||
|
||||
constructor(
|
||||
context: Context, attrs: AttributeSet?, defStyleAttr: Int
|
||||
) : super(context, attrs, defStyleAttr) {
|
||||
init(context, attrs)
|
||||
init {
|
||||
context.withStyledAttributes(attrs, R.styleable.NetworkImageView, 0, 0) {
|
||||
val url = getString(R.styleable.NetworkImageView_url_link)
|
||||
setImageUrl(context, url!!)
|
||||
}
|
||||
}
|
||||
|
||||
fun setImageUrl(imageUrl: String) {
|
||||
|
@ -46,12 +46,4 @@ class NetworkImageView : CircularImageView {
|
|||
.placeholder(R.drawable.ic_account)
|
||||
.into(this)
|
||||
}
|
||||
|
||||
private fun init(context: Context, attributeSet: AttributeSet?) {
|
||||
val attributes =
|
||||
context.obtainStyledAttributes(attributeSet, R.styleable.NetworkImageView, 0, 0)
|
||||
val url = attributes.getString(R.styleable.NetworkImageView_url_link)
|
||||
setImageUrl(context, url!!)
|
||||
attributes.recycle()
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ package code.name.monkey.retromusic.views
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.core.content.withStyledAttributes
|
||||
import code.name.monkey.retromusic.R
|
||||
import com.google.android.material.imageview.ShapeableImageView
|
||||
import com.google.android.material.shape.CornerFamily
|
||||
|
@ -29,13 +30,12 @@ class RetroShapeableImageView @JvmOverloads constructor(
|
|||
|
||||
|
||||
init {
|
||||
val typedArray =
|
||||
context.obtainStyledAttributes(attrs, R.styleable.RetroShapeableImageView, defStyle, -1)
|
||||
addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
|
||||
val radius = width / 2f
|
||||
shapeAppearanceModel = ShapeAppearanceModel().withCornerSize(radius)
|
||||
context.withStyledAttributes(attrs, R.styleable.RetroShapeableImageView, defStyle, -1) {
|
||||
addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
|
||||
val radius = width / 2f
|
||||
shapeAppearanceModel = ShapeAppearanceModel().withCornerSize(radius)
|
||||
}
|
||||
}
|
||||
typedArray.recycle()
|
||||
}
|
||||
|
||||
private fun updateCornerSize(cornerSize: Float) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue