mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-19 08:35:20 +01:00
implemented dynamic tabs
This commit is contained in:
parent
0c23f313b6
commit
67ea2a40a9
39 changed files with 871 additions and 162 deletions
|
@ -33,7 +33,6 @@ import code.name.monkey.retromusic.fragments.AlbumCoverStyle
|
|||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import com.bumptech.glide.Glide
|
||||
|
||||
|
@ -131,14 +130,8 @@ class AlbumCoverStylePreferenceDialog : PreferenceDialogFragmentCompat(), ViewPa
|
|||
companion object {
|
||||
val TAG: String = AlbumCoverStylePreferenceDialog::class.java.simpleName
|
||||
|
||||
private const val EXTRA_KEY = "key"
|
||||
|
||||
fun newInstance(key: String): AlbumCoverStylePreferenceDialog {
|
||||
val args = Bundle()
|
||||
args.putString(EXTRA_KEY, key)
|
||||
val fragment = AlbumCoverStylePreferenceDialog()
|
||||
fragment.arguments = args
|
||||
return fragment
|
||||
fun newInstance(): AlbumCoverStylePreferenceDialog {
|
||||
return AlbumCoverStylePreferenceDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.util.AttributeSet
|
|||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.preference.DialogPreference
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.dialogs.BlacklistFolderChooserDialog
|
||||
import code.name.monkey.retromusic.providers.BlacklistStore
|
||||
|
@ -32,7 +33,7 @@ import com.afollestad.materialdialogs.list.listItems
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class BlacklistPreference : DialogPreference {
|
||||
class BlacklistPreference : ATEDialogPreference {
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* 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.graphics.PorterDuff
|
||||
import android.os.Bundle
|
||||
import android.util.AttributeSet
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference
|
||||
import code.name.monkey.retromusic.adapter.CategoryInfoAdapter
|
||||
import code.name.monkey.retromusic.model.CategoryInfo
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import java.util.*
|
||||
|
||||
|
||||
class LibraryPreference : ATEDialogPreference {
|
||||
constructor(context: Context) : super(context) {}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {}
|
||||
|
||||
init {
|
||||
icon?.setColorFilter(ThemeStore.textColorSecondary(context), PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
}
|
||||
|
||||
class LibraryPreferenceDialog : DialogFragment() {
|
||||
lateinit var adapter: CategoryInfoAdapter
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val view = activity!!.layoutInflater.inflate(code.name.monkey.retromusic.R.layout.preference_dialog_library_categories, null)
|
||||
|
||||
val categoryInfos: List<CategoryInfo>
|
||||
if (savedInstanceState != null) {
|
||||
categoryInfos = savedInstanceState.getParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES)
|
||||
} else {
|
||||
categoryInfos = PreferenceUtil.getInstance().getLibraryCategoryInfos()
|
||||
}
|
||||
adapter = CategoryInfoAdapter(categoryInfos)
|
||||
|
||||
val recyclerView = view.findViewById<RecyclerView>(code.name.monkey.retromusic.R.id.recycler_view)
|
||||
recyclerView.layoutManager = LinearLayoutManager(activity)
|
||||
recyclerView.adapter = adapter
|
||||
|
||||
adapter.attachToRecyclerView(recyclerView)
|
||||
|
||||
|
||||
return MaterialDialog(context!!, BottomSheet())
|
||||
.title(code.name.monkey.retromusic.R.string.library_categories)
|
||||
.customView(view = view)
|
||||
.positiveButton(android.R.string.ok) {
|
||||
updateCategories(adapter.categoryInfos)
|
||||
dismiss()
|
||||
}
|
||||
.negativeButton(android.R.string.cancel) {
|
||||
dismiss()
|
||||
}
|
||||
.neutralButton(code.name.monkey.retromusic.R.string.reset_action) {
|
||||
adapter.categoryInfos = PreferenceUtil.getInstance().defaultLibraryCategoryInfos
|
||||
}
|
||||
.noAutoDismiss()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES, ArrayList(adapter.categoryInfos))
|
||||
}
|
||||
|
||||
private fun updateCategories(categories: List<CategoryInfo>) {
|
||||
if (getSelected(categories) == 0) return
|
||||
if (getSelected(categories) > 5) {
|
||||
Toast.makeText(context, "Not more than 5 items", Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
PreferenceUtil.getInstance().libraryCategoryInfos = categories
|
||||
}
|
||||
|
||||
private fun getSelected(categories: List<CategoryInfo>): Int {
|
||||
var selected = 0
|
||||
for (categoryInfo in categories) {
|
||||
if (categoryInfo.visible)
|
||||
selected++
|
||||
}
|
||||
return selected
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance(): LibraryPreferenceDialog {
|
||||
return LibraryPreferenceDialog()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -124,14 +124,10 @@ class NowPlayingScreenPreferenceDialog : PreferenceDialogFragmentCompat(), ViewP
|
|||
}
|
||||
|
||||
companion object {
|
||||
private const val EXTRA_KEY = "key"
|
||||
|
||||
fun newInstance(key: String): NowPlayingScreenPreferenceDialog {
|
||||
val args = Bundle()
|
||||
args.putString(EXTRA_KEY, key)
|
||||
val fragment = NowPlayingScreenPreferenceDialog()
|
||||
fragment.arguments = args
|
||||
return fragment
|
||||
|
||||
fun newInstance(): NowPlayingScreenPreferenceDialog {
|
||||
return NowPlayingScreenPreferenceDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue