Fix null safety

main
h4h13 2020-03-01 20:07:32 +05:30
parent fdee056ade
commit 20e71f355a
16 changed files with 40 additions and 67 deletions

View File

@ -380,11 +380,15 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
private fun setupLyricsView() {
lyricsView.apply {
val context = activity!!
setCurrentPlayLineColor(ThemeStore.accentColor(context))
setIndicatorTextColor(ThemeStore.accentColor(context))
setCurrentIndicateLineTextColor(resolveColor(activity, attr.textColorPrimary))
setNoLrcTextColor(resolveColor(activity, attr.textColorPrimary))
setCurrentPlayLineColor(ThemeStore.accentColor(requireContext()))
setIndicatorTextColor(ThemeStore.accentColor(requireContext()))
setCurrentIndicateLineTextColor(
resolveColor(
requireContext(),
attr.textColorPrimary
)
)
setNoLrcTextColor(resolveColor(requireContext(), attr.textColorPrimary))
setOnPlayIndicatorLineListener(object : LrcView.OnPlayIndicatorLineListener {
override fun onPlay(time: Long, content: String) {
MusicPlayerRemote.seekTo(time.toInt())

View File

@ -56,9 +56,7 @@ class DeletePlaylistDialog : DialogFragment() {
message(text = content)
negativeButton(android.R.string.cancel)
positiveButton(R.string.action_delete) {
if (activity == null)
return@positiveButton
PlaylistsUtil.deletePlaylists(activity!!, playlists)
PlaylistsUtil.deletePlaylists(requireContext(), playlists)
}
negativeButton(android.R.string.cancel)
}

View File

@ -106,7 +106,7 @@ class AdaptivePlaybackControlsFragment : AbsPlayerControlsFragment() {
override fun setDark(color: Int) {
if (ColorUtil.isColorLight(
ATHUtil.resolveColor(
context,
requireContext(),
android.R.attr.windowBackground
)
)

View File

@ -113,7 +113,7 @@ class CardPlaybackControlsFragment : AbsPlayerControlsFragment() {
if (ColorUtil.isColorLight(
ATHUtil.resolveColor(
context,
requireContext(),
android.R.attr.windowBackground
)
)

View File

@ -39,7 +39,7 @@ class FitFragment : AbsPlayerFragment() {
}
override fun toolbarIconColor(): Int {
return ATHUtil.resolveColor(context, R.attr.colorControlNormal)
return ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal)
}
override fun onColorChanged(color: Int) {

View File

@ -113,11 +113,11 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() {
}
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)) {
lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(activity, true)
lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(requireContext(), true)
lastDisabledPlaybackControlsColor =
MaterialValueHelper.getSecondaryDisabledTextColor(activity, true)
MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true)
} else {
lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(activity, false)
lastDisabledPlaybackControlsColor =

View File

@ -14,7 +14,6 @@ import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.hide
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.fragments.base.AbsPlayerControlsFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
@ -79,16 +78,18 @@ class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback {
}
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)
if (isDark) {
lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(activity, true)
lastPlaybackControlsColor =
MaterialValueHelper.getSecondaryTextColor(requireContext(), true)
lastDisabledPlaybackControlsColor =
MaterialValueHelper.getSecondaryDisabledTextColor(activity, true)
MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true)
} else {
lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(activity, false)
lastPlaybackControlsColor =
MaterialValueHelper.getPrimaryTextColor(requireContext(), false)
lastDisabledPlaybackControlsColor =
MaterialValueHelper.getPrimaryDisabledTextColor(activity, false)
MaterialValueHelper.getPrimaryDisabledTextColor(requireContext(), false)
}
val colorFinal = if (PreferenceUtil.getInstance(requireContext()).adaptiveColor) {

View File

@ -100,7 +100,7 @@ class FlatPlayerFragment : AbsPlayerFragment() {
return if (PreferenceUtil.getInstance(requireContext()).adaptiveColor)
MaterialValueHelper.getPrimaryTextColor(requireContext(), isLight)
else
ATHUtil.resolveColor(context, R.attr.colorControlNormal)
ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal)
}
override fun onColorChanged(color: Int) {

View File

@ -128,7 +128,7 @@ class FullPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca
private fun setUpPlayerToolbar() {
playerToolbar.apply {
setNavigationOnClickListener { activity!!.onBackPressed() }
setNavigationOnClickListener { requireActivity().onBackPressed() }
}
}

View File

@ -70,7 +70,7 @@ class PlayerFragment : AbsPlayerFragment() {
}
override fun toolbarIconColor(): Int {
return ATHUtil.resolveColor(context, R.attr.colorControlNormal)
return ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal)
}
override fun onColorChanged(color: Int) {
@ -80,7 +80,7 @@ class PlayerFragment : AbsPlayerFragment() {
ToolbarContentTintHelper.colorizeToolbar(
playerToolbar,
ATHUtil.resolveColor(context, R.attr.colorControlNormal),
ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal),
requireActivity()
)
@ -131,7 +131,7 @@ class PlayerFragment : AbsPlayerFragment() {
ToolbarContentTintHelper.colorizeToolbar(
playerToolbar,
ATHUtil.resolveColor(context, R.attr.colorControlNormal),
ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal),
requireActivity()
)
}

View File

@ -96,7 +96,7 @@ class SimplePlayerFragment : AbsPlayerFragment() {
playerToolbar.setOnMenuItemClickListener(this)
ToolbarContentTintHelper.colorizeToolbar(
playerToolbar,
ATHUtil.resolveColor(context, R.attr.colorControlNormal),
ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal),
requireActivity()
)
}

View File

@ -74,10 +74,10 @@ class AlbumCoverStylePreferenceDialog : PreferenceDialogFragmentCompat(),
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
@SuppressLint("InflateParams") val view =
LayoutInflater.from(activity)
LayoutInflater.from(requireContext())
.inflate(R.layout.preference_dialog_now_playing_screen, null)
val viewPager = view.findViewById<ViewPager>(R.id.now_playing_screen_view_pager)
viewPager.adapter = AlbumCoverStyleAdapter(activity!!)
viewPager.adapter = AlbumCoverStyleAdapter(requireContext())
viewPager.addOnPageChangeListener(this)
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
viewPager.currentItem = PreferenceUtil.getInstance(requireContext()).albumCoverStyle.ordinal

View File

@ -82,7 +82,7 @@ class NowPlayingScreenPreferenceDialog : PreferenceDialogFragmentCompat(),
}
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)
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'")
@ -101,7 +101,7 @@ class NowPlayingScreenPreferenceDialog : PreferenceDialogFragmentCompat(),
val result =
getString(nowPlayingScreen.titleRes) + " theme is Pro version feature."
Toast.makeText(context, result, Toast.LENGTH_SHORT).show()
NavigationUtil.goToProVersion(activity!!)
NavigationUtil.goToProVersion(requireContext())
} else {
PreferenceUtil.getInstance(requireContext()).nowPlayingScreen = nowPlayingScreen
}

View File

@ -13,25 +13,12 @@ object ATHUtil {
}
@JvmOverloads
fun resolveColor(context: Context?, @AttrRes attr: Int, fallback: Int = 0): Int {
val a = context!!.theme.obtainStyledAttributes(intArrayOf(attr))
fun resolveColor(context: Context, @AttrRes attr: Int, fallback: Int = 0): Int {
val a = context.theme.obtainStyledAttributes(intArrayOf(attr))
try {
return a.getColor(0, fallback)
} finally {
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
)
)
}
}
}

View File

@ -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)
}
}

View File

@ -10,6 +10,7 @@ import com.google.android.material.textfield.TextInputLayout
object MaterialUtil {
@JvmOverloads
@JvmStatic
fun setTint(
button: MaterialButton, background: Boolean = true,
color: Int = ThemeStore.accentColor(button.context)
@ -37,6 +38,8 @@ object MaterialUtil {
}
}
@JvmOverloads
@JvmStatic
fun setTint(textInputLayout: TextInputLayout, background: Boolean = true) {
val context = textInputLayout.context
val accentColor = ThemeStore.accentColor(context)
@ -52,6 +55,8 @@ object MaterialUtil {
}
}
@JvmOverloads
@JvmStatic
fun setTint(
button: DialogActionButton,
color: Int = ThemeStore.accentColor(button.context),