Converted PreferencUtil to Kotlin class
This commit is contained in:
parent
df225e179f
commit
e9bd24872f
108 changed files with 1855 additions and 2099 deletions
|
@ -14,8 +14,13 @@
|
|||
|
||||
package code.name.monkey.retromusic.extensions
|
||||
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
|
||||
fun AppCompatActivity.applyToolbar(toolbar: MaterialToolbar) {
|
||||
|
@ -24,3 +29,37 @@ fun AppCompatActivity.applyToolbar(toolbar: MaterialToolbar) {
|
|||
setSupportActionBar(toolbar)
|
||||
}
|
||||
|
||||
fun FragmentActivity?.addFragment(
|
||||
@IdRes idRes: Int = R.id.container,
|
||||
fragment: Fragment,
|
||||
tag: String? = null,
|
||||
addToBackStack: Boolean = false
|
||||
) {
|
||||
val compatActivity = this as? AppCompatActivity ?: return
|
||||
compatActivity.supportFragmentManager.beginTransaction()
|
||||
.apply {
|
||||
add(fragment, tag)
|
||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||
if (addToBackStack) {
|
||||
addToBackStack(null)
|
||||
}
|
||||
commitNow()
|
||||
}
|
||||
}
|
||||
|
||||
fun AppCompatActivity.replaceFragment(
|
||||
@IdRes id: Int = R.id.container,
|
||||
fragment: Fragment,
|
||||
tag: String? = null,
|
||||
addToBackStack: Boolean = false
|
||||
) {
|
||||
val compatActivity = this ?: return
|
||||
compatActivity.supportFragmentManager.beginTransaction()
|
||||
.apply {
|
||||
replace(id, fragment, tag)
|
||||
if (addToBackStack) {
|
||||
addToBackStack(null)
|
||||
}
|
||||
commit()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package code.name.monkey.retromusic.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.os.PowerManager
|
||||
import androidx.annotation.IntegerRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import code.name.monkey.retromusic.util.PreferenceUtilKT
|
||||
|
||||
fun Fragment.getIntRes(@IntegerRes int: Int): Int {
|
||||
return resources.getInteger(int)
|
||||
}
|
||||
|
||||
fun Context.getIntRes(@IntegerRes int: Int): Int {
|
||||
return resources.getInteger(int)
|
||||
}
|
||||
|
||||
val Context.generalThemeValue
|
||||
get() = PreferenceUtilKT.getGeneralThemeValue(isSystemDarkModeEnabled())
|
||||
|
||||
|
||||
fun Context.isSystemDarkModeEnabled(): Boolean {
|
||||
val isBatterySaverEnabled =
|
||||
(getSystemService(Context.POWER_SERVICE) as PowerManager?)?.isPowerSaveMode ?: false
|
||||
val isDarkModeEnabled =
|
||||
(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||
return isBatterySaverEnabled or isDarkModeEnabled
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package code.name.monkey.retromusic.extensions
|
||||
|
||||
import android.content.SharedPreferences
|
||||
|
||||
fun SharedPreferences.getStringOrDefault(key: String, default: String): String {
|
||||
return getString(key, default) ?: default
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue