Kotlin code refactor
Refactor dialogs
This commit is contained in:
parent
d7aae9270e
commit
a5cc0572a8
21 changed files with 371 additions and 384 deletions
|
@ -14,6 +14,7 @@
|
|||
|
||||
package code.name.monkey.retromusic.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
|
@ -62,4 +63,14 @@ fun AppCompatActivity.replaceFragment(
|
|||
}
|
||||
commit()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> Activity.extra(key: String, default: T? = null) = lazy {
|
||||
val value = intent?.extras?.get(key)
|
||||
if (value is T) value else default
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> Activity.extraNotNull(key: String, default: T? = null) = lazy {
|
||||
val value = intent?.extras?.get(key)
|
||||
requireNotNull(if (value is T) value else default) { key }
|
||||
}
|
|
@ -18,6 +18,8 @@ import android.app.Dialog
|
|||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.widget.CheckBox
|
||||
import android.widget.SeekBar
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.fragment.app.Fragment
|
||||
|
@ -65,3 +67,14 @@ fun Fragment.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
|
|||
|
||||
fun Dialog.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
|
||||
ATHUtil.resolveColor(context, attr, fallBackColor)
|
||||
|
||||
|
||||
fun CheckBox.addAccentColor() {
|
||||
buttonTintList = ColorStateList.valueOf(ThemeStore.accentColor(context))
|
||||
}
|
||||
|
||||
fun SeekBar.addAccentColor() {
|
||||
val colorState = ColorStateList.valueOf(ThemeStore.accentColor(context))
|
||||
progressTintList = colorState
|
||||
thumbTintList = colorState
|
||||
}
|
|
@ -26,3 +26,14 @@ fun Context.isSystemDarkModeEnabled(): Boolean {
|
|||
(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||
return isBatterySaverEnabled or isDarkModeEnabled
|
||||
}
|
||||
|
||||
|
||||
inline fun <reified T : Any> Fragment.extra(key: String, default: T? = null) = lazy {
|
||||
val value = arguments?.get(key)
|
||||
if (value is T) value else default
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> Fragment.extraNotNull(key: String, default: T? = null) = lazy {
|
||||
val value = arguments?.get(key)
|
||||
requireNotNull(if (value is T) value else default) { key }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue