Fix null safety
This commit is contained in:
parent
fdee056ade
commit
20e71f355a
16 changed files with 40 additions and 67 deletions
|
@ -380,11 +380,15 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
|
||||||
|
|
||||||
private fun setupLyricsView() {
|
private fun setupLyricsView() {
|
||||||
lyricsView.apply {
|
lyricsView.apply {
|
||||||
val context = activity!!
|
setCurrentPlayLineColor(ThemeStore.accentColor(requireContext()))
|
||||||
setCurrentPlayLineColor(ThemeStore.accentColor(context))
|
setIndicatorTextColor(ThemeStore.accentColor(requireContext()))
|
||||||
setIndicatorTextColor(ThemeStore.accentColor(context))
|
setCurrentIndicateLineTextColor(
|
||||||
setCurrentIndicateLineTextColor(resolveColor(activity, attr.textColorPrimary))
|
resolveColor(
|
||||||
setNoLrcTextColor(resolveColor(activity, attr.textColorPrimary))
|
requireContext(),
|
||||||
|
attr.textColorPrimary
|
||||||
|
)
|
||||||
|
)
|
||||||
|
setNoLrcTextColor(resolveColor(requireContext(), attr.textColorPrimary))
|
||||||
setOnPlayIndicatorLineListener(object : LrcView.OnPlayIndicatorLineListener {
|
setOnPlayIndicatorLineListener(object : LrcView.OnPlayIndicatorLineListener {
|
||||||
override fun onPlay(time: Long, content: String) {
|
override fun onPlay(time: Long, content: String) {
|
||||||
MusicPlayerRemote.seekTo(time.toInt())
|
MusicPlayerRemote.seekTo(time.toInt())
|
||||||
|
|
|
@ -56,9 +56,7 @@ class DeletePlaylistDialog : DialogFragment() {
|
||||||
message(text = content)
|
message(text = content)
|
||||||
negativeButton(android.R.string.cancel)
|
negativeButton(android.R.string.cancel)
|
||||||
positiveButton(R.string.action_delete) {
|
positiveButton(R.string.action_delete) {
|
||||||
if (activity == null)
|
PlaylistsUtil.deletePlaylists(requireContext(), playlists)
|
||||||
return@positiveButton
|
|
||||||
PlaylistsUtil.deletePlaylists(activity!!, playlists)
|
|
||||||
}
|
}
|
||||||
negativeButton(android.R.string.cancel)
|
negativeButton(android.R.string.cancel)
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ class AdaptivePlaybackControlsFragment : AbsPlayerControlsFragment() {
|
||||||
override fun setDark(color: Int) {
|
override fun setDark(color: Int) {
|
||||||
if (ColorUtil.isColorLight(
|
if (ColorUtil.isColorLight(
|
||||||
ATHUtil.resolveColor(
|
ATHUtil.resolveColor(
|
||||||
context,
|
requireContext(),
|
||||||
android.R.attr.windowBackground
|
android.R.attr.windowBackground
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -113,7 +113,7 @@ class CardPlaybackControlsFragment : AbsPlayerControlsFragment() {
|
||||||
|
|
||||||
if (ColorUtil.isColorLight(
|
if (ColorUtil.isColorLight(
|
||||||
ATHUtil.resolveColor(
|
ATHUtil.resolveColor(
|
||||||
context,
|
requireContext(),
|
||||||
android.R.attr.windowBackground
|
android.R.attr.windowBackground
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -39,7 +39,7 @@ class FitFragment : AbsPlayerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toolbarIconColor(): Int {
|
override fun toolbarIconColor(): Int {
|
||||||
return ATHUtil.resolveColor(context, R.attr.colorControlNormal)
|
return ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onColorChanged(color: Int) {
|
override fun onColorChanged(color: Int) {
|
||||||
|
|
|
@ -113,11 +113,11 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setDark(color: Int) {
|
override fun setDark(color: Int) {
|
||||||
val colorBg = ATHUtil.resolveColor(activity, android.R.attr.colorBackground)
|
val colorBg = ATHUtil.resolveColor(requireContext(), android.R.attr.colorBackground)
|
||||||
if (ColorUtil.isColorLight(colorBg)) {
|
if (ColorUtil.isColorLight(colorBg)) {
|
||||||
lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(activity, true)
|
lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(requireContext(), true)
|
||||||
lastDisabledPlaybackControlsColor =
|
lastDisabledPlaybackControlsColor =
|
||||||
MaterialValueHelper.getSecondaryDisabledTextColor(activity, true)
|
MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true)
|
||||||
} else {
|
} else {
|
||||||
lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(activity, false)
|
lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(activity, false)
|
||||||
lastDisabledPlaybackControlsColor =
|
lastDisabledPlaybackControlsColor =
|
||||||
|
|
|
@ -14,7 +14,6 @@ import code.name.monkey.appthemehelper.util.TintHelper
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.extensions.hide
|
import code.name.monkey.retromusic.extensions.hide
|
||||||
import code.name.monkey.retromusic.extensions.ripAlpha
|
import code.name.monkey.retromusic.extensions.ripAlpha
|
||||||
import code.name.monkey.retromusic.extensions.setRange
|
|
||||||
import code.name.monkey.retromusic.extensions.show
|
import code.name.monkey.retromusic.extensions.show
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment
|
import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
|
@ -79,16 +78,18 @@ class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setDark(color: Int) {
|
override fun setDark(color: Int) {
|
||||||
val colorBg = ATHUtil.resolveColor(activity, android.R.attr.colorBackground)
|
val colorBg = ATHUtil.resolveColor(requireContext(), android.R.attr.colorBackground)
|
||||||
val isDark = ColorUtil.isColorLight(colorBg)
|
val isDark = ColorUtil.isColorLight(colorBg)
|
||||||
if (isDark) {
|
if (isDark) {
|
||||||
lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(activity, true)
|
lastPlaybackControlsColor =
|
||||||
|
MaterialValueHelper.getSecondaryTextColor(requireContext(), true)
|
||||||
lastDisabledPlaybackControlsColor =
|
lastDisabledPlaybackControlsColor =
|
||||||
MaterialValueHelper.getSecondaryDisabledTextColor(activity, true)
|
MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true)
|
||||||
} else {
|
} else {
|
||||||
lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(activity, false)
|
lastPlaybackControlsColor =
|
||||||
|
MaterialValueHelper.getPrimaryTextColor(requireContext(), false)
|
||||||
lastDisabledPlaybackControlsColor =
|
lastDisabledPlaybackControlsColor =
|
||||||
MaterialValueHelper.getPrimaryDisabledTextColor(activity, false)
|
MaterialValueHelper.getPrimaryDisabledTextColor(requireContext(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
val colorFinal = if (PreferenceUtil.getInstance(requireContext()).adaptiveColor) {
|
val colorFinal = if (PreferenceUtil.getInstance(requireContext()).adaptiveColor) {
|
||||||
|
|
|
@ -100,7 +100,7 @@ class FlatPlayerFragment : AbsPlayerFragment() {
|
||||||
return if (PreferenceUtil.getInstance(requireContext()).adaptiveColor)
|
return if (PreferenceUtil.getInstance(requireContext()).adaptiveColor)
|
||||||
MaterialValueHelper.getPrimaryTextColor(requireContext(), isLight)
|
MaterialValueHelper.getPrimaryTextColor(requireContext(), isLight)
|
||||||
else
|
else
|
||||||
ATHUtil.resolveColor(context, R.attr.colorControlNormal)
|
ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onColorChanged(color: Int) {
|
override fun onColorChanged(color: Int) {
|
||||||
|
|
|
@ -128,7 +128,7 @@ class FullPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca
|
||||||
|
|
||||||
private fun setUpPlayerToolbar() {
|
private fun setUpPlayerToolbar() {
|
||||||
playerToolbar.apply {
|
playerToolbar.apply {
|
||||||
setNavigationOnClickListener { activity!!.onBackPressed() }
|
setNavigationOnClickListener { requireActivity().onBackPressed() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ class PlayerFragment : AbsPlayerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toolbarIconColor(): Int {
|
override fun toolbarIconColor(): Int {
|
||||||
return ATHUtil.resolveColor(context, R.attr.colorControlNormal)
|
return ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onColorChanged(color: Int) {
|
override fun onColorChanged(color: Int) {
|
||||||
|
@ -80,7 +80,7 @@ class PlayerFragment : AbsPlayerFragment() {
|
||||||
|
|
||||||
ToolbarContentTintHelper.colorizeToolbar(
|
ToolbarContentTintHelper.colorizeToolbar(
|
||||||
playerToolbar,
|
playerToolbar,
|
||||||
ATHUtil.resolveColor(context, R.attr.colorControlNormal),
|
ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal),
|
||||||
requireActivity()
|
requireActivity()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ class PlayerFragment : AbsPlayerFragment() {
|
||||||
|
|
||||||
ToolbarContentTintHelper.colorizeToolbar(
|
ToolbarContentTintHelper.colorizeToolbar(
|
||||||
playerToolbar,
|
playerToolbar,
|
||||||
ATHUtil.resolveColor(context, R.attr.colorControlNormal),
|
ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal),
|
||||||
requireActivity()
|
requireActivity()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ class SimplePlayerFragment : AbsPlayerFragment() {
|
||||||
playerToolbar.setOnMenuItemClickListener(this)
|
playerToolbar.setOnMenuItemClickListener(this)
|
||||||
ToolbarContentTintHelper.colorizeToolbar(
|
ToolbarContentTintHelper.colorizeToolbar(
|
||||||
playerToolbar,
|
playerToolbar,
|
||||||
ATHUtil.resolveColor(context, R.attr.colorControlNormal),
|
ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal),
|
||||||
requireActivity()
|
requireActivity()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,10 +74,10 @@ class AlbumCoverStylePreferenceDialog : PreferenceDialogFragmentCompat(),
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
@SuppressLint("InflateParams") val view =
|
@SuppressLint("InflateParams") val view =
|
||||||
LayoutInflater.from(activity)
|
LayoutInflater.from(requireContext())
|
||||||
.inflate(R.layout.preference_dialog_now_playing_screen, null)
|
.inflate(R.layout.preference_dialog_now_playing_screen, null)
|
||||||
val viewPager = view.findViewById<ViewPager>(R.id.now_playing_screen_view_pager)
|
val viewPager = view.findViewById<ViewPager>(R.id.now_playing_screen_view_pager)
|
||||||
viewPager.adapter = AlbumCoverStyleAdapter(activity!!)
|
viewPager.adapter = AlbumCoverStyleAdapter(requireContext())
|
||||||
viewPager.addOnPageChangeListener(this)
|
viewPager.addOnPageChangeListener(this)
|
||||||
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
||||||
viewPager.currentItem = PreferenceUtil.getInstance(requireContext()).albumCoverStyle.ordinal
|
viewPager.currentItem = PreferenceUtil.getInstance(requireContext()).albumCoverStyle.ordinal
|
||||||
|
|
|
@ -82,7 +82,7 @@ class NowPlayingScreenPreferenceDialog : PreferenceDialogFragmentCompat(),
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val view = LayoutInflater.from(activity)
|
val view = LayoutInflater.from(requireContext())
|
||||||
.inflate(R.layout.preference_dialog_now_playing_screen, null)
|
.inflate(R.layout.preference_dialog_now_playing_screen, null)
|
||||||
val viewPager = view.findViewById<ViewPager>(R.id.now_playing_screen_view_pager)
|
val viewPager = view.findViewById<ViewPager>(R.id.now_playing_screen_view_pager)
|
||||||
?: throw IllegalStateException("Dialog view must contain a ViewPager with id 'now_playing_screen_view_pager'")
|
?: throw IllegalStateException("Dialog view must contain a ViewPager with id 'now_playing_screen_view_pager'")
|
||||||
|
@ -101,7 +101,7 @@ class NowPlayingScreenPreferenceDialog : PreferenceDialogFragmentCompat(),
|
||||||
val result =
|
val result =
|
||||||
getString(nowPlayingScreen.titleRes) + " theme is Pro version feature."
|
getString(nowPlayingScreen.titleRes) + " theme is Pro version feature."
|
||||||
Toast.makeText(context, result, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, result, Toast.LENGTH_SHORT).show()
|
||||||
NavigationUtil.goToProVersion(activity!!)
|
NavigationUtil.goToProVersion(requireContext())
|
||||||
} else {
|
} else {
|
||||||
PreferenceUtil.getInstance(requireContext()).nowPlayingScreen = nowPlayingScreen
|
PreferenceUtil.getInstance(requireContext()).nowPlayingScreen = nowPlayingScreen
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,25 +13,12 @@ object ATHUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun resolveColor(context: Context?, @AttrRes attr: Int, fallback: Int = 0): Int {
|
fun resolveColor(context: Context, @AttrRes attr: Int, fallback: Int = 0): Int {
|
||||||
val a = context!!.theme.obtainStyledAttributes(intArrayOf(attr))
|
val a = context.theme.obtainStyledAttributes(intArrayOf(attr))
|
||||||
try {
|
try {
|
||||||
return a.getColor(0, fallback)
|
return a.getColor(0, fallback)
|
||||||
} finally {
|
} finally {
|
||||||
a.recycle()
|
a.recycle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun inClassPath(clsName: String): Class<*> {
|
|
||||||
try {
|
|
||||||
return Class.forName(clsName)
|
|
||||||
} catch (t: Throwable) {
|
|
||||||
throw IllegalStateException(
|
|
||||||
String.format(
|
|
||||||
"%s is not in your class path! You must include the associated library.",
|
|
||||||
clsName
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,22 +0,0 @@
|
||||||
package code.name.monkey.appthemehelper.util
|
|
||||||
|
|
||||||
import android.graphics.drawable.ColorDrawable
|
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.graphics.drawable.TransitionDrawable
|
|
||||||
import androidx.annotation.ColorInt
|
|
||||||
|
|
||||||
object DrawableUtil {
|
|
||||||
|
|
||||||
fun createTransitionDrawable(@ColorInt startColor: Int, @ColorInt endColor: Int): TransitionDrawable {
|
|
||||||
return createTransitionDrawable(ColorDrawable(startColor), ColorDrawable(endColor))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createTransitionDrawable(start: Drawable, end: Drawable): TransitionDrawable {
|
|
||||||
val drawables = arrayOfNulls<Drawable>(2)
|
|
||||||
|
|
||||||
drawables[0] = start
|
|
||||||
drawables[1] = end
|
|
||||||
|
|
||||||
return TransitionDrawable(drawables)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,6 +10,7 @@ import com.google.android.material.textfield.TextInputLayout
|
||||||
object MaterialUtil {
|
object MaterialUtil {
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
|
@JvmStatic
|
||||||
fun setTint(
|
fun setTint(
|
||||||
button: MaterialButton, background: Boolean = true,
|
button: MaterialButton, background: Boolean = true,
|
||||||
color: Int = ThemeStore.accentColor(button.context)
|
color: Int = ThemeStore.accentColor(button.context)
|
||||||
|
@ -37,6 +38,8 @@ object MaterialUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmOverloads
|
||||||
|
@JvmStatic
|
||||||
fun setTint(textInputLayout: TextInputLayout, background: Boolean = true) {
|
fun setTint(textInputLayout: TextInputLayout, background: Boolean = true) {
|
||||||
val context = textInputLayout.context
|
val context = textInputLayout.context
|
||||||
val accentColor = ThemeStore.accentColor(context)
|
val accentColor = ThemeStore.accentColor(context)
|
||||||
|
@ -52,6 +55,8 @@ object MaterialUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmOverloads
|
||||||
|
@JvmStatic
|
||||||
fun setTint(
|
fun setTint(
|
||||||
button: DialogActionButton,
|
button: DialogActionButton,
|
||||||
color: Int = ThemeStore.accentColor(button.context),
|
color: Int = ThemeStore.accentColor(button.context),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue