Code refactor
This commit is contained in:
parent
54b037c0c1
commit
cf3db7a76b
2 changed files with 35 additions and 3 deletions
|
@ -18,13 +18,16 @@ import android.app.Dialog
|
|||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.widget.Button
|
||||
import android.widget.CheckBox
|
||||
import android.widget.SeekBar
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.*
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
|
@ -163,4 +166,22 @@ fun TextInputEditText.accentColor() {
|
|||
|
||||
fun AppCompatImageView.accentColor(): Int {
|
||||
return ThemeStore.accentColor(context)
|
||||
}
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
fun Drawable.tint(@ColorInt color: Int): Drawable {
|
||||
val tintedDrawable = DrawableCompat.wrap(this).mutate()
|
||||
DrawableCompat.setTint(this, color)
|
||||
return tintedDrawable
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
fun Drawable.tint(context: Context, @ColorRes color: Int): Drawable {
|
||||
return tint(context.getColorCompat(color))
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun Context.getColorCompat(@ColorRes colorRes: Int): Int {
|
||||
return ContextCompat.getColor(this, colorRes)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,15 @@ package code.name.monkey.retromusic.extensions
|
|||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.PowerManager
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.IntegerRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
|
@ -73,4 +76,12 @@ fun Fragment.showToast(@StringRes stringRes: Int) {
|
|||
|
||||
fun Fragment.showToast(message: String) {
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
fun Context.getDrawableCompat(@DrawableRes drawableRes: Int): Drawable {
|
||||
return AppCompatResources.getDrawable(this, drawableRes)!!
|
||||
}
|
||||
|
||||
fun Fragment.getDrawableCompat(@DrawableRes drawableRes: Int): Drawable {
|
||||
return AppCompatResources.getDrawable(requireContext(), drawableRes)!!
|
||||
}
|
Loading…
Reference in a new issue