mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-19 16:45:20 +01:00
Code refactor
This commit is contained in:
parent
a8f0867c9d
commit
5394f94973
96 changed files with 384 additions and 1068 deletions
|
@ -37,7 +37,7 @@ import code.name.monkey.retromusic.extensions.colorControlNormal
|
|||
import code.name.monkey.retromusic.fragments.AlbumCoverStyle
|
||||
import code.name.monkey.retromusic.fragments.AlbumCoverStyle.*
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtilKT
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.bumptech.glide.Glide
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
@ -77,7 +77,7 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(),
|
|||
viewPager.adapter = AlbumCoverStyleAdapter(requireContext())
|
||||
viewPager.addOnPageChangeListener(this)
|
||||
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
||||
viewPager.currentItem = PreferenceUtilKT.albumCoverStyle.ordinal
|
||||
viewPager.currentItem = PreferenceUtil.albumCoverStyle.ordinal
|
||||
|
||||
return MaterialAlertDialogBuilder(requireActivity(),
|
||||
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert)
|
||||
|
@ -89,7 +89,7 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(),
|
|||
Toast.makeText(context, result, Toast.LENGTH_SHORT).show()
|
||||
NavigationUtil.goToProVersion(requireActivity())
|
||||
} else {
|
||||
PreferenceUtilKT.albumCoverStyle = coverStyle
|
||||
PreferenceUtil.albumCoverStyle = coverStyle
|
||||
}
|
||||
}
|
||||
.setView(view)
|
||||
|
@ -164,5 +164,5 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(),
|
|||
}
|
||||
|
||||
private fun isAlbumCoverStyle(style: AlbumCoverStyle): Boolean {
|
||||
return (!App.isProVersion() && (style == CIRCLE || style == CARD || style == FULL_CARD))
|
||||
return (!App.isProVersion() && (style == Circle || style == Card || style == FullCard))
|
||||
}
|
|
@ -31,7 +31,7 @@ import code.name.monkey.retromusic.R
|
|||
import code.name.monkey.retromusic.adapter.CategoryInfoAdapter
|
||||
import code.name.monkey.retromusic.extensions.colorControlNormal
|
||||
import code.name.monkey.retromusic.model.CategoryInfo
|
||||
import code.name.monkey.retromusic.util.PreferenceUtilKT
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
|
||||
|
@ -57,7 +57,7 @@ class LibraryPreferenceDialog : DialogFragment() {
|
|||
.inflate(R.layout.preference_dialog_library_categories, null)
|
||||
|
||||
val categoryAdapter = CategoryInfoAdapter()
|
||||
categoryAdapter.categoryInfos = PreferenceUtilKT.libraryCategory
|
||||
categoryAdapter.categoryInfos = PreferenceUtil.libraryCategory
|
||||
val recyclerView = view.findViewById<RecyclerView>(R.id.recycler_view)
|
||||
recyclerView.layoutManager = LinearLayoutManager(activity)
|
||||
recyclerView.adapter = categoryAdapter
|
||||
|
@ -72,7 +72,7 @@ class LibraryPreferenceDialog : DialogFragment() {
|
|||
.setNeutralButton(
|
||||
R.string.reset_action
|
||||
) { _, _ ->
|
||||
categoryAdapter.categoryInfos = PreferenceUtilKT.defaultCategories
|
||||
categoryAdapter.categoryInfos = PreferenceUtil.defaultCategories
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(
|
||||
|
@ -88,7 +88,7 @@ class LibraryPreferenceDialog : DialogFragment() {
|
|||
Toast.makeText(context, "Not more than 5 items", Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
PreferenceUtilKT.libraryCategory = categories
|
||||
PreferenceUtil.libraryCategory = categories
|
||||
}
|
||||
|
||||
private fun getSelected(categories: List<CategoryInfo>): Int {
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
package code.name.monkey.retromusic.preferences
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.content.res.TypedArray
|
||||
import android.os.Bundle
|
||||
import android.util.AttributeSet
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||
import androidx.core.graphics.BlendModeCompat.SRC_IN
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.PreferenceDialogFragmentCompat
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.extensions.colorControlNormal
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class MaterialListPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = -1,
|
||||
defStyleRes: Int = -1
|
||||
) : ListPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
private val mLayoutRes = R.layout.ate_preference_list
|
||||
|
||||
init {
|
||||
icon?.colorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
|
||||
context.colorControlNormal(),
|
||||
SRC_IN
|
||||
)
|
||||
}
|
||||
|
||||
override fun getDialogLayoutResource(): Int {
|
||||
return mLayoutRes
|
||||
}
|
||||
|
||||
override fun onGetDefaultValue(a: TypedArray, index: Int): String {
|
||||
// Default value from attribute. Fallback value is set to 0.
|
||||
return a.getString(index)!!
|
||||
}
|
||||
|
||||
fun setCustomValue(any: Any) {
|
||||
when (any) {
|
||||
is String -> persistString(any)
|
||||
is Int -> persistInt(any)
|
||||
is Boolean -> persistBoolean(any)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val materialListPreference = preference as MaterialListPreference
|
||||
val entries = arguments?.getStringArrayList(EXTRA_ENTRIES)
|
||||
val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES)
|
||||
val position: Int = arguments?.getInt(EXTRA_POSITION) ?: 0
|
||||
/* materialDialog = MaterialDialog(requireContext())
|
||||
.title(text = materialListPreference.title.toString())
|
||||
.positiveButton(R.string.set)
|
||||
.listItemsSingleChoice(
|
||||
items = entries,
|
||||
initialSelection = position,
|
||||
waitForPositiveButton = true
|
||||
) { _, index, _ ->
|
||||
entriesValues?.let {
|
||||
materialListPreference.callChangeListener(it[index])
|
||||
materialListPreference.setCustomValue(it[index])
|
||||
}
|
||||
entries?.let {
|
||||
materialListPreference.summary = it[index]
|
||||
val value = materialListPreference.entryValues[index].toString()
|
||||
if (materialListPreference.callChangeListener(value)) {
|
||||
materialListPreference.value = value
|
||||
}
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
materialDialog.getActionButton(WhichButton.POSITIVE)
|
||||
.updateTextColor(ThemeStore.accentColor(requireContext()))
|
||||
return materialDialog*/
|
||||
return MaterialAlertDialogBuilder(requireContext()).create()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
materialDialog.dismiss()
|
||||
}
|
||||
|
||||
private lateinit var materialDialog: MaterialDialog
|
||||
|
||||
override fun onDialogClosed(positiveResult: Boolean) {
|
||||
if (positiveResult) {
|
||||
materialDialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val EXTRA_KEY = "key"
|
||||
private const val EXTRA_TITLE = "title"
|
||||
private const val EXTRA_POSITION = "position"
|
||||
private const val EXTRA_ENTRIES = "extra_entries"
|
||||
private const val EXTRA_ENTRIES_VALUES = "extra_entries_values"
|
||||
|
||||
fun newInstance(listPreference: ListPreference): MaterialListPreferenceDialog {
|
||||
val entries = listPreference.entries.toList() as ArrayList<String>
|
||||
val entriesValues = listPreference.entryValues.toList() as ArrayList<String>
|
||||
val position = listPreference.findIndexOfValue(listPreference.value)
|
||||
val args = Bundle()
|
||||
args.putString(ARG_KEY, listPreference.key)
|
||||
args.putString(EXTRA_TITLE, listPreference.title.toString())
|
||||
args.putInt(EXTRA_POSITION, position)
|
||||
args.putStringArrayList(EXTRA_ENTRIES, entries)
|
||||
args.putStringArrayList(EXTRA_ENTRIES_VALUES, entriesValues)
|
||||
val fragment = MaterialListPreferenceDialog()
|
||||
fragment.arguments = args
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ import code.name.monkey.retromusic.extensions.colorControlNormal
|
|||
import code.name.monkey.retromusic.fragments.NowPlayingScreen
|
||||
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtilKT
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.bumptech.glide.Glide
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
@ -84,7 +84,7 @@ class NowPlayingScreenPreferenceDialog : DialogFragment(), ViewPager.OnPageChang
|
|||
viewPager.adapter = NowPlayingScreenAdapter(requireContext())
|
||||
viewPager.addOnPageChangeListener(this)
|
||||
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
||||
viewPager.currentItem = PreferenceUtilKT.nowPlayingScreen.ordinal
|
||||
viewPager.currentItem = PreferenceUtil.nowPlayingScreen.ordinal
|
||||
|
||||
return MaterialAlertDialogBuilder(
|
||||
requireContext(),
|
||||
|
@ -100,7 +100,7 @@ class NowPlayingScreenPreferenceDialog : DialogFragment(), ViewPager.OnPageChang
|
|||
Toast.makeText(context, result, Toast.LENGTH_SHORT).show()
|
||||
NavigationUtil.goToProVersion(requireContext())
|
||||
} else {
|
||||
PreferenceUtilKT.nowPlayingScreen = nowPlayingScreen
|
||||
PreferenceUtil.nowPlayingScreen = nowPlayingScreen
|
||||
}
|
||||
}
|
||||
.setView(view)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue