New cache system
Refactoring Separation into libraries
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.meloda.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.*
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
|
||||
object ContextExtensions {
|
||||
|
||||
fun Context.drawable(@DrawableRes resId: Int): Drawable? {
|
||||
return ContextCompat.getDrawable(this, resId)
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun Context.color(@ColorRes resId: Int): Int {
|
||||
return ContextCompat.getColor(this, resId)
|
||||
}
|
||||
|
||||
fun Context.font(@FontRes resId: Int): Typeface? {
|
||||
return ResourcesCompat.getFont(this, resId)
|
||||
}
|
||||
|
||||
fun Context.string(@StringRes resId: Int): String {
|
||||
return getString(resId)
|
||||
}
|
||||
|
||||
fun Context.view(resId: Int, root: ViewGroup? = null, attachToRoot: Boolean = false): View {
|
||||
return LayoutInflater.from(this).inflate(resId, root, attachToRoot)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.meloda.extensions
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.annotation.ColorInt
|
||||
|
||||
object DrawableExtensions {
|
||||
|
||||
fun Drawable?.tint(@ColorInt color: Int): Drawable? {
|
||||
this?.setTint(color)
|
||||
return this
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.meloda.extensions
|
||||
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object FloatExtensions {
|
||||
|
||||
fun Float.int(): Int {
|
||||
return roundToInt()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.meloda.extensions
|
||||
|
||||
import java.util.*
|
||||
|
||||
object StringExtensions {
|
||||
|
||||
fun String.lowerCase(): String {
|
||||
return toLowerCase(Locale.getDefault())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.meloda.extensions
|
||||
|
||||
import android.widget.TextView
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
|
||||
object TextViewExtensions {
|
||||
|
||||
fun TextView.clear() {
|
||||
text = ""
|
||||
}
|
||||
|
||||
fun TextInputLayout.clear() {
|
||||
editText?.setText("")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user