all: fix merge junk

This commit is contained in:
Alexander Capehart 2023-07-25 17:40:53 -06:00
parent 816ab04252
commit ed08559b94
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 45 additions and 188 deletions

View file

@ -192,7 +192,7 @@ class AlbumDetailFragment :
override fun onShuffle() { override fun onShuffle() {
playbackModel.shuffle(unlikelyToBeNull(detailModel.currentAlbum.value)) playbackModel.shuffle(unlikelyToBeNull(detailModel.currentAlbum.value))
} }
override fun onOpenSortMenu() { override fun onOpenSortMenu() {
findNavController().navigateSafe(AlbumDetailFragmentDirections.sort()) findNavController().navigateSafe(AlbumDetailFragmentDirections.sort())
} }

View file

@ -1,88 +0,0 @@
/*
* Copyright (c) 2023 Auxio Project
* SortAdapter.kt is part of Auxio.
*
* This program 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 program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.list.sort
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import org.oxycblt.auxio.databinding.ItemSortModeBinding
import org.oxycblt.auxio.list.Sort
import org.oxycblt.auxio.list.adapter.FlexibleListAdapter
import org.oxycblt.auxio.util.inflater
class SortAdapter(var selectedMode: Sort.Mode) :
FlexibleListAdapter<Sort.Mode, SortModeViewHolder>(SortModeViewHolder.DIFF_CALLBACK) {
var currentlySelected = selectedMode
private set
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
SortModeViewHolder.from(parent)
override fun onBindViewHolder(holder: SortModeViewHolder, position: Int) {
throw NotImplementedError()
}
override fun onBindViewHolder(holder: SortModeViewHolder, position: Int, payload: List<Any>) {
val mode = getItem(position)
if (payload.isEmpty()) {
holder.bind(mode)
}
holder.setSelected(mode == currentlySelected)
}
fun setSelected(mode: Sort.Mode) {
if (mode == currentlySelected) return
val oldMode = currentList.indexOf(currentlySelected)
val newMode = currentList.indexOf(mode)
currentlySelected = selectedMode
notifyItemChanged(oldMode, PAYLOAD_SELECTION_CHANGED)
notifyItemChanged(newMode, PAYLOAD_SELECTION_CHANGED)
}
private companion object {
val PAYLOAD_SELECTION_CHANGED = Any()
}
}
class SortModeViewHolder private constructor(private val binding: ItemSortModeBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(mode: Sort.Mode) {
// TODO: Add names to sort.mode
binding.sortRadio.text = mode.toString()
}
fun setSelected(selected: Boolean) {
binding.sortRadio.isChecked = selected
}
companion object {
fun from(parent: View) =
SortModeViewHolder(ItemSortModeBinding.inflate(parent.context.inflater))
val DIFF_CALLBACK =
object : DiffUtil.ItemCallback<Sort.Mode>() {
override fun areItemsTheSame(oldItem: Sort.Mode, newItem: Sort.Mode) =
oldItem == newItem
override fun areContentsTheSame(oldItem: Sort.Mode, newItem: Sort.Mode) =
oldItem == newItem
}
}
}

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2023 Auxio Project * Copyright (c) 2023 Auxio Project
* MenuDialogFragment.kt is part of Auxio. * SortDialog.kt is part of Auxio.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -16,126 +16,74 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.oxycblt.auxio.list.menu package org.oxycblt.auxio.list.sort
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MenuInflater import androidx.core.view.updatePadding
import android.view.MenuItem
import androidx.appcompat.view.menu.MenuBuilder
import androidx.core.view.children
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import org.oxycblt.auxio.databinding.DialogMenuBinding import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.DialogSortBinding
import org.oxycblt.auxio.list.ClickableListListener import org.oxycblt.auxio.list.ClickableListListener
import org.oxycblt.auxio.list.ListViewModel import org.oxycblt.auxio.list.Sort
import org.oxycblt.auxio.list.Menu
import org.oxycblt.auxio.list.adapter.UpdateInstructions import org.oxycblt.auxio.list.adapter.UpdateInstructions
import org.oxycblt.auxio.ui.ViewBindingBottomSheetDialogFragment import org.oxycblt.auxio.ui.ViewBindingBottomSheetDialogFragment
import org.oxycblt.auxio.util.collectImmediately import org.oxycblt.auxio.util.systemBarInsetsCompat
import org.oxycblt.auxio.util.logD
/** abstract class SortDialog :
* A [ViewBindingBottomSheetDialogFragment] that displays basic music information and a series of ViewBindingBottomSheetDialogFragment<DialogSortBinding>(), ClickableListListener<Sort.Mode> {
* options. private val modeAdapter = SortModeAdapter(this)
*
* @author Alexander Capehart (OxygenCobalt)
*
* TODO: Extend the amount of music info shown in the dialog
*/
abstract class MenuDialogFragment<M : Menu> :
ViewBindingBottomSheetDialogFragment<DialogMenuBinding>(), ClickableListListener<MenuItem> {
protected abstract val menuModel: MenuViewModel
protected abstract val listModel: ListViewModel
private val menuAdapter = MenuItemAdapter(@Suppress("LeakingThis") this)
abstract val parcel: Menu.Parcel abstract fun getInitialSort(): Sort
/** abstract fun applyChosenSort(sort: Sort)
* Get the options to disable in the context of the currently shown [M].
*
* @param menu The currently-shown menu [M].
*/
abstract fun getDisabledItemIds(menu: M): Set<Int>
/** abstract fun getModeChoices(): List<Sort.Mode>
* Update the displayed information about the currently shown [M].
*
* @param binding The [DialogMenuBinding] to bind information to.
* @param menu The currently-shown menu [M].
*/
abstract fun updateMenu(binding: DialogMenuBinding, menu: M)
/** override fun onCreateBinding(inflater: LayoutInflater) = DialogSortBinding.inflate(inflater)
* Forward the clicked [MenuItem] to it's corresponding handler in another module.
*
* @param item The [MenuItem] that was clicked.
* @param menu The currently-shown menu [M].
*/
abstract fun onClick(item: MenuItem, menu: M)
override fun onCreateBinding(inflater: LayoutInflater) = DialogMenuBinding.inflate(inflater) override fun onBindingCreated(binding: DialogSortBinding, savedInstanceState: Bundle?) {
override fun onBindingCreated(binding: DialogMenuBinding, savedInstanceState: Bundle?) {
super.onBindingCreated(binding, savedInstanceState) super.onBindingCreated(binding, savedInstanceState)
// --- UI SETUP --- // --- UI SETUP ---
binding.menuName.isSelected = true binding.root.setOnApplyWindowInsetsListener { v, insets ->
binding.menuInfo.isSelected = true v.updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
binding.menuOptionRecycler.apply { insets
adapter = menuAdapter
itemAnimator = null
} }
// --- VIEWMODEL SETUP --- binding.sortModeRecycler.adapter = modeAdapter
listModel.menu.consume()
menuModel.setMenu(parcel)
collectImmediately(menuModel.currentMenu, this::updateMenu)
}
override fun onDestroyBinding(binding: DialogMenuBinding) { binding.sortCancel.setOnClickListener { dismiss() }
super.onDestroyBinding(binding)
binding.menuName.isSelected = false
binding.menuInfo.isSelected = false
binding.menuOptionRecycler.adapter = null
}
private fun updateMenu(menu: Menu?) { binding.sortSave.setOnClickListener {
if (menu == null) { val initial = getInitialSort()
logD("No menu to show, navigating away") // FIXME: This won't work for the playlist sort dialog.
findNavController().navigateUp() val mode = modeAdapter.currentMode ?: initial.mode
return val direction =
when (binding.sortDirectionGroup.checkedButtonId) {
R.id.sort_direction_asc -> Sort.Direction.ASCENDING
R.id.sort_direction_dsc -> Sort.Direction.DESCENDING
else -> initial.direction
}
applyChosenSort(Sort(mode, direction))
dismiss()
} }
@Suppress("UNCHECKED_CAST") val casted = menu as? M // --- STATE SETUP ---
check(casted != null) { "Unexpected menu instance ${menu::class.simpleName}" } val initial = getInitialSort()
// We need to inflate the menu on every menu update since it might have changed modeAdapter.update(getModeChoices(), UpdateInstructions.Diff)
// what options are available (ex. if an artist with no songs has had new songs added). modeAdapter.setSelected(initial.mode)
// Since we don't have (and don't want) a dummy view to inflate this menu, just
// depend on the AndroidX Toolbar internal API and hope for the best.
@SuppressLint("RestrictedApi") val builder = MenuBuilder(requireContext())
MenuInflater(requireContext()).inflate(casted.res, builder)
// Disable any menu options as specified by the impl val directionId =
val disabledIds = getDisabledItemIds(casted) when (initial.direction) {
val visible = Sort.Direction.ASCENDING -> R.id.sort_direction_asc
builder.children.mapTo(mutableListOf()) { Sort.Direction.DESCENDING -> R.id.sort_direction_dsc
it.isEnabled = !disabledIds.contains(it.itemId)
it
} }
menuAdapter.update(visible, UpdateInstructions.Diff) binding.sortDirectionGroup.check(directionId)
// Delegate to impl how to show music
updateMenu(requireBinding(), casted)
} }
final override fun onClick(item: MenuItem, viewHolder: RecyclerView.ViewHolder) { override fun onClick(item: Sort.Mode, viewHolder: RecyclerView.ViewHolder) {
// All option selections close the dialog currently. modeAdapter.setSelected(item)
// TODO: This should change if the app is 100% migrated to menu dialogs
findNavController().navigateUp()
// Delegate to impl on how to handle items
@Suppress("UNCHECKED_CAST") onClick(item, menuModel.currentMenu.value as M)
} }
} }

View file

@ -210,9 +210,6 @@
<action <action
android:id="@+id/play_from_genre" android:id="@+id/play_from_genre"
app:destination="@id/play_from_genre_dialog" /> app:destination="@id/play_from_genre_dialog" />
<action
android:id="@+id/sort"
app:destination="@id/sort_dialog" />
</fragment> </fragment>
<dialog <dialog