Add blacklist UI
Add a UI for the blacklist functionality.
This commit is contained in:
@@ -163,7 +163,7 @@ class PlaybackStateDatabase(context: Context) :
|
||||
|
||||
var position = 0
|
||||
|
||||
// Try to write out the entirety of the queue. Failed inserts will be skipped.
|
||||
// Try to write out the entirety of the queue.
|
||||
while (position < queueItems.size) {
|
||||
var i = position
|
||||
|
||||
|
||||
@@ -93,18 +93,6 @@ abstract class DetailFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Since there is no elevation when the scroll position is zero, dont show
|
||||
// the overscroll indicator.
|
||||
addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
overScrollMode = if (computeVerticalScrollOffset() == 0) {
|
||||
View.OVER_SCROLL_NEVER
|
||||
} else {
|
||||
View.OVER_SCROLL_IF_CONTENT_SCROLLS
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentSettingsBinding
|
||||
import org.oxycblt.auxio.settings.ui.AboutDialog
|
||||
|
||||
@@ -22,12 +21,8 @@ class SettingsFragment : Fragment() {
|
||||
val binding = FragmentSettingsBinding.inflate(inflater)
|
||||
|
||||
binding.settingsToolbar.setOnMenuItemClickListener {
|
||||
if (it.itemId == R.id.action_open_about) {
|
||||
AboutDialog().show(childFragmentManager, TAG_ABOUT_DIALOG)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
AboutDialog().show(childFragmentManager, TAG_ABOUT_DIALOG)
|
||||
true
|
||||
}
|
||||
|
||||
return binding.root
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.recycler.DisplayMode
|
||||
import org.oxycblt.auxio.settings.blacklist.BlacklistDialog
|
||||
import org.oxycblt.auxio.settings.ui.AccentDialog
|
||||
import org.oxycblt.auxio.ui.Accent
|
||||
|
||||
@@ -123,12 +124,19 @@ class SettingsListFragment : PreferenceFragmentCompat() {
|
||||
}
|
||||
}
|
||||
|
||||
SettingsManager.Keys.KEY_DEBUG_SAVE -> {
|
||||
SettingsManager.Keys.KEY_SAVE_STATE -> {
|
||||
onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
playbackModel.savePlaybackState(requireContext())
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
SettingsManager.Keys.KEY_BLACKLIST -> {
|
||||
onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
BlacklistDialog().show(childFragmentManager, TAG_ACCENT_DIALOG)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +231,8 @@ class SettingsManager private constructor(context: Context) :
|
||||
|
||||
const val KEY_LIBRARY_SORT_MODE = "KEY_LIBRARY_SORT_MODE"
|
||||
const val KEY_SEARCH_FILTER_MODE = "KEY_SEARCH"
|
||||
const val KEY_DEBUG_SAVE = "KEY_SAVE_STATE"
|
||||
const val KEY_SAVE_STATE = "KEY_SAVE_STATE"
|
||||
const val KEY_BLACKLIST = "KEY_BLACKLIST"
|
||||
|
||||
@Deprecated("Use the new KEY_ACCENT instead.")
|
||||
const val KEY_ACCENT_OLD = "KEY_ACCENT"
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.oxycblt.auxio.settings.blacklist
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.WhichButton
|
||||
import com.afollestad.materialdialogs.actions.setActionButtonEnabled
|
||||
import com.afollestad.materialdialogs.files.folderChooser
|
||||
import com.afollestad.materialdialogs.files.selectedFolder
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentBlacklistBinding
|
||||
import org.oxycblt.auxio.ui.createToast
|
||||
import java.io.File
|
||||
|
||||
class BlacklistDialog : BottomSheetDialogFragment() {
|
||||
private val blacklistModel: BlacklistViewModel by activityViewModels()
|
||||
|
||||
override fun getTheme() = R.style.Theme_BottomSheetFix
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val binding = FragmentBlacklistBinding.inflate(inflater)
|
||||
|
||||
val adapter = BlacklistEntryAdapter { path ->
|
||||
blacklistModel.removePath(path)
|
||||
}
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
binding.blacklistRecycler.adapter = adapter
|
||||
binding.blacklistAdd.setOnClickListener {
|
||||
MaterialDialog(requireActivity()).show {
|
||||
positiveButton(R.string.label_add) {
|
||||
onFolderSelected()
|
||||
}
|
||||
|
||||
negativeButton()
|
||||
|
||||
folderChooser(
|
||||
requireContext(),
|
||||
initialDirectory = File(Environment.getExternalStorageDirectory().absolutePath),
|
||||
waitForPositiveButton = false,
|
||||
emptyTextRes = R.string.error_no_dirs
|
||||
)
|
||||
|
||||
// Still need to force-reenable the positive button even after flagging the
|
||||
// disabling as false when setting up the file chooser
|
||||
// Gotta love third-party libraries
|
||||
setActionButtonEnabled(WhichButton.POSITIVE, true)
|
||||
}
|
||||
}
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
blacklistModel.paths.observe(viewLifecycleOwner) { paths ->
|
||||
adapter.submitList(paths)
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private fun MaterialDialog.onFolderSelected() {
|
||||
selectedFolder()?.absolutePath?.let { path ->
|
||||
// Due to how Auxio's navigation flow works, dont allow the main root directory
|
||||
// to be excluded, as that would lead to the user being stuck at the "No Music Found"
|
||||
// error.
|
||||
if (path == Environment.getExternalStorageDirectory().absolutePath) {
|
||||
getString(R.string.error_folder_would_brick_app)
|
||||
.createToast(requireContext())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
blacklistModel.addPath(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.oxycblt.auxio.settings.blacklist
|
||||
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.databinding.ItemBlacklistEntryBinding
|
||||
import org.oxycblt.auxio.ui.inflater
|
||||
|
||||
class BlacklistEntryAdapter(
|
||||
private val onClear: (String) -> Unit
|
||||
) : RecyclerView.Adapter<BlacklistEntryAdapter.ViewHolder>() {
|
||||
private var paths = mutableListOf<String>()
|
||||
|
||||
override fun getItemCount() = paths.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(ItemBlacklistEntryBinding.inflate(parent.context.inflater))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(paths[position])
|
||||
}
|
||||
|
||||
fun submitList(newPaths: MutableList<String>) {
|
||||
paths = newPaths
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemBlacklistEntryBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
binding.root.layoutParams = RecyclerView.LayoutParams(
|
||||
RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
}
|
||||
|
||||
fun bind(path: String) {
|
||||
binding.blacklistTitle.text = path
|
||||
binding.blacklistTitle.requestLayout()
|
||||
binding.blacklistClear.setOnClickListener {
|
||||
onClear(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.oxycblt.auxio.settings.blacklist
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class BlacklistViewModel : ViewModel() {
|
||||
private val mPaths = MutableLiveData(mutableListOf<String>())
|
||||
val paths: LiveData<MutableList<String>> get() = mPaths
|
||||
|
||||
fun addPath(path: String) {
|
||||
if (mPaths.value!!.contains(path)) {
|
||||
return
|
||||
}
|
||||
|
||||
mPaths.value!!.add(path)
|
||||
|
||||
mPaths.value = mPaths.value
|
||||
}
|
||||
|
||||
fun removePath(path: String) {
|
||||
mPaths.value!!.remove(path)
|
||||
|
||||
mPaths.value = mPaths.value
|
||||
}
|
||||
}
|
||||
@@ -57,9 +57,9 @@ fun TextView.setTextColorResource(@ColorRes color: Int) {
|
||||
*/
|
||||
fun MaterialButton.applyAccents(highlighted: Boolean) {
|
||||
if (highlighted) {
|
||||
backgroundTintList = Accent.get().color.toStateList(context)
|
||||
backgroundTintList = Accent.get().getStateList(context)
|
||||
} else {
|
||||
setTextColor(Accent.get().color.toColor(context))
|
||||
setTextColorResource(Accent.get().color)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user