diff --git a/app/src/main/java/org/oxycblt/auxio/detail/DetailAppBarLayout.kt b/app/src/main/java/org/oxycblt/auxio/detail/DetailAppBarLayout.kt index d486fa109..ae1325daf 100644 --- a/app/src/main/java/org/oxycblt/auxio/detail/DetailAppBarLayout.kt +++ b/app/src/main/java/org/oxycblt/auxio/detail/DetailAppBarLayout.kt @@ -44,9 +44,6 @@ import org.oxycblt.auxio.util.lazyReflectedField * and thus scrolling past them should make the toolbar show the name in order to give context on * where the user currently is. * - * This task should nominally be accomplished with CollapsingToolbarLayout, but I have not figured - * out how to get that working sensibly yet. - * * @author Alexander Capehart (OxygenCobalt) */ class DetailAppBarLayout diff --git a/app/src/main/java/org/oxycblt/auxio/list/recycler/ViewHolders.kt b/app/src/main/java/org/oxycblt/auxio/list/recycler/ViewHolders.kt index 62fffeb54..7119a163c 100644 --- a/app/src/main/java/org/oxycblt/auxio/list/recycler/ViewHolders.kt +++ b/app/src/main/java/org/oxycblt/auxio/list/recycler/ViewHolders.kt @@ -24,10 +24,8 @@ import org.oxycblt.auxio.IntegerTable import org.oxycblt.auxio.R import org.oxycblt.auxio.databinding.ItemHeaderBinding import org.oxycblt.auxio.databinding.ItemParentBinding -import org.oxycblt.auxio.databinding.ItemPickerChoiceBinding import org.oxycblt.auxio.databinding.ItemSongBinding import org.oxycblt.auxio.list.BasicHeader -import org.oxycblt.auxio.list.ClickableListListener import org.oxycblt.auxio.list.SelectableListListener import org.oxycblt.auxio.list.adapter.SelectionIndicatorAdapter import org.oxycblt.auxio.list.adapter.SimpleDiffCallback @@ -352,53 +350,3 @@ class BasicHeaderViewHolder private constructor(private val binding: ItemHeaderB } } } - -/** - * A [DialogRecyclerView.ViewHolder] that displays a smaller variant of a typical [T] item, for use - * in choice dialogs. Use [from] to create an instance. - * - * @author Alexander Capehart (OxygenCobalt) - * - * TODO: Unwind this into specific impls - */ -class ChoiceViewHolder -private constructor(private val binding: ItemPickerChoiceBinding) : - DialogRecyclerView.ViewHolder(binding.root) { - /** - * Bind new data to this instance. - * - * @param music The new [T] to bind. - * @param listener A [ClickableListListener] to bind interactions to. - */ - fun bind(music: T, listener: ClickableListListener) { - listener.bind(music, this) - // ImageGroup is not generic, so we must downcast to specific types for now. - when (music) { - is Song -> binding.pickerImage.bind(music) - is Album -> binding.pickerImage.bind(music) - is Artist -> binding.pickerImage.bind(music) - is Genre -> binding.pickerImage.bind(music) - is Playlist -> binding.pickerImage.bind(music) - } - binding.pickerName.text = music.name.resolve(binding.context) - } - - companion object { - - /** - * Create a new instance. - * - * @param parent The parent to inflate this instance from. - * @return A new instance. - */ - fun from(parent: View) = - ChoiceViewHolder(ItemPickerChoiceBinding.inflate(parent.context.inflater)) - - /** Get a comparator that can be used with DiffUtil. */ - fun diffCallback() = - object : SimpleDiffCallback() { - override fun areContentsTheSame(oldItem: T, newItem: T) = - oldItem.name == newItem.name - } - } -} diff --git a/app/src/main/java/org/oxycblt/auxio/music/picker/AddToPlaylistDialog.kt b/app/src/main/java/org/oxycblt/auxio/music/picker/AddToPlaylistDialog.kt index e1058d1b5..dc3ceb556 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/picker/AddToPlaylistDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/picker/AddToPlaylistDialog.kt @@ -29,7 +29,7 @@ import androidx.recyclerview.widget.ConcatAdapter import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint import org.oxycblt.auxio.R -import org.oxycblt.auxio.databinding.DialogMusicPickerBinding +import org.oxycblt.auxio.databinding.DialogMusicChoicesBinding import org.oxycblt.auxio.list.ClickableListListener import org.oxycblt.auxio.music.MusicViewModel import org.oxycblt.auxio.music.Song @@ -44,7 +44,7 @@ import org.oxycblt.auxio.util.showToast */ @AndroidEntryPoint class AddToPlaylistDialog : - ViewBindingDialogFragment(), + ViewBindingDialogFragment(), ClickableListListener, NewPlaylistFooterAdapter.Listener { private val musicModel: MusicViewModel by activityViewModels() @@ -60,12 +60,12 @@ class AddToPlaylistDialog : } override fun onCreateBinding(inflater: LayoutInflater) = - DialogMusicPickerBinding.inflate(inflater) + DialogMusicChoicesBinding.inflate(inflater) - override fun onBindingCreated(binding: DialogMusicPickerBinding, savedInstanceState: Bundle?) { + override fun onBindingCreated(binding: DialogMusicChoicesBinding, savedInstanceState: Bundle?) { super.onBindingCreated(binding, savedInstanceState) - binding.pickerChoiceRecycler.apply { + binding.choiceRecycler.apply { itemAnimator = null adapter = ConcatAdapter(choiceAdapter, footerAdapter) } @@ -76,9 +76,9 @@ class AddToPlaylistDialog : collectImmediately(pickerModel.playlistChoices, ::updatePlaylistChoices) } - override fun onDestroyBinding(binding: DialogMusicPickerBinding) { + override fun onDestroyBinding(binding: DialogMusicChoicesBinding) { super.onDestroyBinding(binding) - binding.pickerChoiceRecycler.adapter = null + binding.choiceRecycler.adapter = null } override fun onClick(item: PlaylistChoice, viewHolder: RecyclerView.ViewHolder) { diff --git a/app/src/main/java/org/oxycblt/auxio/navigation/picker/ArtistNavigationChoiceAdapter.kt b/app/src/main/java/org/oxycblt/auxio/navigation/picker/ArtistNavigationChoiceAdapter.kt new file mode 100644 index 000000000..a397ec23b --- /dev/null +++ b/app/src/main/java/org/oxycblt/auxio/navigation/picker/ArtistNavigationChoiceAdapter.kt @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023 Auxio Project + * ArtistNavigationChoiceAdapter.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 . + */ + +package org.oxycblt.auxio.navigation.picker + +import android.view.View +import android.view.ViewGroup +import org.oxycblt.auxio.databinding.ItemPickerChoiceBinding +import org.oxycblt.auxio.list.ClickableListListener +import org.oxycblt.auxio.list.adapter.FlexibleListAdapter +import org.oxycblt.auxio.list.adapter.SimpleDiffCallback +import org.oxycblt.auxio.list.recycler.DialogRecyclerView +import org.oxycblt.auxio.music.Artist +import org.oxycblt.auxio.util.context +import org.oxycblt.auxio.util.inflater + +/** + * A [FlexibleListAdapter] that displays a list of [Artist] navigation choices, for use with + * [NavigateToArtistDialog]. + * + * @param listener A [ClickableListListener] to bind interactions to. + */ +class ArtistNavigationChoiceAdapter(private val listener: ClickableListListener) : + FlexibleListAdapter( + ArtistNavigationChoiceViewHolder.DIFF_CALLBACK) { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = + ArtistNavigationChoiceViewHolder.from(parent) + + override fun onBindViewHolder(holder: ArtistNavigationChoiceViewHolder, position: Int) { + holder.bind(getItem(position), listener) + } +} + +/** + * A [DialogRecyclerView.ViewHolder] that displays a smaller variant of a typical [Artist] item, for + * use [ArtistNavigationChoiceAdapter]. Use [from] to create an instance. + * + * @author Alexander Capehart (OxygenCobalt) + */ +class ArtistNavigationChoiceViewHolder +private constructor(private val binding: ItemPickerChoiceBinding) : + DialogRecyclerView.ViewHolder(binding.root) { + /** + * Bind new data to this instance. + * + * @param artist The new [Artist] to bind. + * @param listener A [ClickableListListener] to bind interactions to. + */ + fun bind(artist: Artist, listener: ClickableListListener) { + listener.bind(artist, this) + binding.pickerImage.bind(artist) + binding.pickerName.text = artist.name.resolve(binding.context) + } + + companion object { + + /** + * Create a new instance. + * + * @param parent The parent to inflate this instance from. + * @return A new instance. + */ + fun from(parent: View) = + ArtistNavigationChoiceViewHolder( + ItemPickerChoiceBinding.inflate(parent.context.inflater)) + + /** A comparator that can be used with DiffUtil. */ + val DIFF_CALLBACK = + object : SimpleDiffCallback() { + override fun areContentsTheSame(oldItem: Artist, newItem: Artist) = + oldItem.name == newItem.name + } + } +} diff --git a/app/src/main/java/org/oxycblt/auxio/navigation/picker/NavigateToArtistDialog.kt b/app/src/main/java/org/oxycblt/auxio/navigation/picker/NavigateToArtistDialog.kt index 1d3f83543..a8614af77 100644 --- a/app/src/main/java/org/oxycblt/auxio/navigation/picker/NavigateToArtistDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/navigation/picker/NavigateToArtistDialog.kt @@ -20,7 +20,6 @@ package org.oxycblt.auxio.navigation.picker import android.os.Bundle import android.view.LayoutInflater -import android.view.ViewGroup import androidx.appcompat.app.AlertDialog import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels @@ -29,11 +28,9 @@ import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint import org.oxycblt.auxio.R -import org.oxycblt.auxio.databinding.DialogMusicPickerBinding +import org.oxycblt.auxio.databinding.DialogMusicChoicesBinding import org.oxycblt.auxio.list.ClickableListListener -import org.oxycblt.auxio.list.adapter.FlexibleListAdapter import org.oxycblt.auxio.list.adapter.UpdateInstructions -import org.oxycblt.auxio.list.recycler.ChoiceViewHolder import org.oxycblt.auxio.music.Artist import org.oxycblt.auxio.navigation.NavigationViewModel import org.oxycblt.auxio.ui.ViewBindingDialogFragment @@ -46,25 +43,25 @@ import org.oxycblt.auxio.util.collectImmediately */ @AndroidEntryPoint class NavigateToArtistDialog : - ViewBindingDialogFragment(), ClickableListListener { + ViewBindingDialogFragment(), ClickableListListener { private val navigationModel: NavigationViewModel by activityViewModels() private val pickerModel: NavigationPickerViewModel by viewModels() // Information about what artists to show choices for is initially within the navigation // arguments as UIDs, as that is the only safe way to parcel an artist. private val args: NavigateToArtistDialogArgs by navArgs() - private val choiceAdapter = ArtistChoiceAdapter(this) + private val choiceAdapter = ArtistNavigationChoiceAdapter(this) override fun onConfigDialog(builder: AlertDialog.Builder) { builder.setTitle(R.string.lbl_artists).setNegativeButton(R.string.lbl_cancel, null) } override fun onCreateBinding(inflater: LayoutInflater) = - DialogMusicPickerBinding.inflate(inflater) + DialogMusicChoicesBinding.inflate(inflater) - override fun onBindingCreated(binding: DialogMusicPickerBinding, savedInstanceState: Bundle?) { + override fun onBindingCreated(binding: DialogMusicChoicesBinding, savedInstanceState: Bundle?) { super.onBindingCreated(binding, savedInstanceState) - binding.pickerChoiceRecycler.apply { + binding.choiceRecycler.apply { itemAnimator = null adapter = choiceAdapter } @@ -79,7 +76,7 @@ class NavigateToArtistDialog : } } - override fun onDestroyBinding(binding: DialogMusicPickerBinding) { + override fun onDestroyBinding(binding: DialogMusicChoicesBinding) { super.onDestroyBinding(binding) choiceAdapter } @@ -89,16 +86,4 @@ class NavigateToArtistDialog : navigationModel.exploreNavigateTo(item) findNavController().navigateUp() } - - private class ArtistChoiceAdapter(private val listener: ClickableListListener) : - FlexibleListAdapter>(ChoiceViewHolder.diffCallback()) { - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ChoiceViewHolder = ChoiceViewHolder.from(parent) - - override fun onBindViewHolder(holder: ChoiceViewHolder, position: Int) { - holder.bind(getItem(position), listener) - } - } } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/picker/ArtistPlaybackChoiceAdapter.kt b/app/src/main/java/org/oxycblt/auxio/playback/picker/ArtistPlaybackChoiceAdapter.kt new file mode 100644 index 000000000..be8bed183 --- /dev/null +++ b/app/src/main/java/org/oxycblt/auxio/playback/picker/ArtistPlaybackChoiceAdapter.kt @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2023 Auxio Project + * ArtistPlaybackChoiceAdapter.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 . + */ + +package org.oxycblt.auxio.playback.picker + +import android.view.View +import android.view.ViewGroup +import org.oxycblt.auxio.databinding.ItemPickerChoiceBinding +import org.oxycblt.auxio.list.ClickableListListener +import org.oxycblt.auxio.list.adapter.FlexibleListAdapter +import org.oxycblt.auxio.list.adapter.SimpleDiffCallback +import org.oxycblt.auxio.list.recycler.DialogRecyclerView +import org.oxycblt.auxio.music.Artist +import org.oxycblt.auxio.util.context +import org.oxycblt.auxio.util.inflater + +/** + * A [FlexibleListAdapter] that displays a list of [Artist] playback choices, for use with + * [PlayFromArtistDialog]. + * + * @param listener A [ClickableListListener] to bind interactions to. + */ +class ArtistPlaybackChoiceAdapter(private val listener: ClickableListListener) : + FlexibleListAdapter( + ArtistPlaybackChoiceViewHolder.DIFF_CALLBACK) { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = + ArtistPlaybackChoiceViewHolder.from(parent) + + override fun onBindViewHolder(holder: ArtistPlaybackChoiceViewHolder, position: Int) { + holder.bind(getItem(position), listener) + } +} + +/** + * A [DialogRecyclerView.ViewHolder] that displays a smaller variant of a typical [Artist] item, for + * use [ArtistPlaybackChoiceAdapter]. Use [from] to create an instance. + * + * @author Alexander Capehart (OxygenCobalt) + */ +class ArtistPlaybackChoiceViewHolder +private constructor(private val binding: ItemPickerChoiceBinding) : + DialogRecyclerView.ViewHolder(binding.root) { + /** + * Bind new data to this instance. + * + * @param artist The new [Artist] to bind. + * @param listener A [ClickableListListener] to bind interactions to. + */ + fun bind(artist: Artist, listener: ClickableListListener) { + listener.bind(artist, this) + binding.pickerImage.bind(artist) + binding.pickerName.text = artist.name.resolve(binding.context) + } + + companion object { + + /** + * Create a new instance. + * + * @param parent The parent to inflate this instance from. + * @return A new instance. + */ + fun from(parent: View) = + ArtistPlaybackChoiceViewHolder(ItemPickerChoiceBinding.inflate(parent.context.inflater)) + + /** A comparator that can be used with DiffUtil. */ + val DIFF_CALLBACK = + object : SimpleDiffCallback() { + override fun areContentsTheSame(oldItem: Artist, newItem: Artist) = + oldItem.name == newItem.name + } + } +} diff --git a/app/src/main/java/org/oxycblt/auxio/playback/picker/GenrePlaybackChoiceAdapter.kt b/app/src/main/java/org/oxycblt/auxio/playback/picker/GenrePlaybackChoiceAdapter.kt new file mode 100644 index 000000000..f5fdbf970 --- /dev/null +++ b/app/src/main/java/org/oxycblt/auxio/playback/picker/GenrePlaybackChoiceAdapter.kt @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2023 Auxio Project + * GenrePlaybackChoiceAdapter.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 . + */ + +package org.oxycblt.auxio.playback.picker + +import android.view.View +import android.view.ViewGroup +import org.oxycblt.auxio.databinding.ItemPickerChoiceBinding +import org.oxycblt.auxio.list.ClickableListListener +import org.oxycblt.auxio.list.adapter.FlexibleListAdapter +import org.oxycblt.auxio.list.adapter.SimpleDiffCallback +import org.oxycblt.auxio.list.recycler.DialogRecyclerView +import org.oxycblt.auxio.music.Genre +import org.oxycblt.auxio.util.context +import org.oxycblt.auxio.util.inflater + +/** + * A [FlexibleListAdapter] that displays a list of [Genre] playback choices, for use with + * [PlayFromGenreDialog]. + * + * @param listener A [ClickableListListener] to bind interactions to. + */ +class GenrePlaybackChoiceAdapter(private val listener: ClickableListListener) : + FlexibleListAdapter( + GenrePlaybackChoiceViewHolder.DIFF_CALLBACK) { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = + GenrePlaybackChoiceViewHolder.from(parent) + + override fun onBindViewHolder(holder: GenrePlaybackChoiceViewHolder, position: Int) { + holder.bind(getItem(position), listener) + } +} + +/** + * A [DialogRecyclerView.ViewHolder] that displays a smaller variant of a typical [Genre] item, for + * use [GenrePlaybackChoiceAdapter]. Use [from] to create an instance. + * + * @author Alexander Capehart (OxygenCobalt) + */ +class GenrePlaybackChoiceViewHolder +private constructor(private val binding: ItemPickerChoiceBinding) : + DialogRecyclerView.ViewHolder(binding.root) { + /** + * Bind new data to this instance. + * + * @param artist The new [Genre] to bind. + * @param listener A [ClickableListListener] to bind interactions to. + */ + fun bind(artist: Genre, listener: ClickableListListener) { + listener.bind(artist, this) + binding.pickerImage.bind(artist) + binding.pickerName.text = artist.name.resolve(binding.context) + } + + companion object { + + /** + * Create a new instance. + * + * @param parent The parent to inflate this instance from. + * @return A new instance. + */ + fun from(parent: View) = + GenrePlaybackChoiceViewHolder(ItemPickerChoiceBinding.inflate(parent.context.inflater)) + + /** A comparator that can be used with DiffUtil. */ + val DIFF_CALLBACK = + object : SimpleDiffCallback() { + override fun areContentsTheSame(oldItem: Genre, newItem: Genre) = + oldItem.name == newItem.name + } + } +} diff --git a/app/src/main/java/org/oxycblt/auxio/playback/picker/PlayFromArtistDialog.kt b/app/src/main/java/org/oxycblt/auxio/playback/picker/PlayFromArtistDialog.kt index d0907c39f..0d477bd8d 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/picker/PlayFromArtistDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/picker/PlayFromArtistDialog.kt @@ -20,7 +20,6 @@ package org.oxycblt.auxio.playback.picker import android.os.Bundle import android.view.LayoutInflater -import android.view.ViewGroup import androidx.appcompat.app.AlertDialog import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels @@ -29,11 +28,9 @@ import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint import org.oxycblt.auxio.R -import org.oxycblt.auxio.databinding.DialogMusicPickerBinding +import org.oxycblt.auxio.databinding.DialogMusicChoicesBinding import org.oxycblt.auxio.list.ClickableListListener -import org.oxycblt.auxio.list.adapter.FlexibleListAdapter import org.oxycblt.auxio.list.adapter.UpdateInstructions -import org.oxycblt.auxio.list.recycler.ChoiceViewHolder import org.oxycblt.auxio.music.Artist import org.oxycblt.auxio.playback.PlaybackViewModel import org.oxycblt.auxio.ui.ViewBindingDialogFragment @@ -47,25 +44,25 @@ import org.oxycblt.auxio.util.unlikelyToBeNull */ @AndroidEntryPoint class PlayFromArtistDialog : - ViewBindingDialogFragment(), ClickableListListener { + ViewBindingDialogFragment(), ClickableListListener { private val playbackModel: PlaybackViewModel by activityViewModels() private val pickerModel: PlaybackPickerViewModel by viewModels() // Information about what Song to show choices for is initially within the navigation arguments // as UIDs, as that is the only safe way to parcel a Song. private val args: PlayFromArtistDialogArgs by navArgs() - private val choiceAdapter = ArtistChoiceAdapter(this) + private val choiceAdapter = ArtistPlaybackChoiceAdapter(this) override fun onConfigDialog(builder: AlertDialog.Builder) { builder.setTitle(R.string.lbl_artists).setNegativeButton(R.string.lbl_cancel, null) } override fun onCreateBinding(inflater: LayoutInflater) = - DialogMusicPickerBinding.inflate(inflater) + DialogMusicChoicesBinding.inflate(inflater) - override fun onBindingCreated(binding: DialogMusicPickerBinding, savedInstanceState: Bundle?) { + override fun onBindingCreated(binding: DialogMusicChoicesBinding, savedInstanceState: Bundle?) { super.onBindingCreated(binding, savedInstanceState) - binding.pickerChoiceRecycler.apply { + binding.choiceRecycler.apply { itemAnimator = null adapter = choiceAdapter } @@ -80,7 +77,7 @@ class PlayFromArtistDialog : } } - override fun onDestroyBinding(binding: DialogMusicPickerBinding) { + override fun onDestroyBinding(binding: DialogMusicChoicesBinding) { super.onDestroyBinding(binding) choiceAdapter } @@ -91,16 +88,4 @@ class PlayFromArtistDialog : playbackModel.playFromArtist(song, item) findNavController().navigateUp() } - - private class ArtistChoiceAdapter(private val listener: ClickableListListener) : - FlexibleListAdapter>(ChoiceViewHolder.diffCallback()) { - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ChoiceViewHolder = ChoiceViewHolder.from(parent) - - override fun onBindViewHolder(holder: ChoiceViewHolder, position: Int) { - holder.bind(getItem(position), listener) - } - } } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/picker/PlayFromGenreDialog.kt b/app/src/main/java/org/oxycblt/auxio/playback/picker/PlayFromGenreDialog.kt index 21c81aa25..0b8914dc2 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/picker/PlayFromGenreDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/picker/PlayFromGenreDialog.kt @@ -20,7 +20,6 @@ package org.oxycblt.auxio.playback.picker import android.os.Bundle import android.view.LayoutInflater -import android.view.ViewGroup import androidx.appcompat.app.AlertDialog import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels @@ -29,11 +28,9 @@ import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint import org.oxycblt.auxio.R -import org.oxycblt.auxio.databinding.DialogMusicPickerBinding +import org.oxycblt.auxio.databinding.DialogMusicChoicesBinding import org.oxycblt.auxio.list.ClickableListListener -import org.oxycblt.auxio.list.adapter.FlexibleListAdapter import org.oxycblt.auxio.list.adapter.UpdateInstructions -import org.oxycblt.auxio.list.recycler.ChoiceViewHolder import org.oxycblt.auxio.music.Genre import org.oxycblt.auxio.playback.PlaybackViewModel import org.oxycblt.auxio.ui.ViewBindingDialogFragment @@ -47,25 +44,25 @@ import org.oxycblt.auxio.util.unlikelyToBeNull */ @AndroidEntryPoint class PlayFromGenreDialog : - ViewBindingDialogFragment(), ClickableListListener { + ViewBindingDialogFragment(), ClickableListListener { private val playbackModel: PlaybackViewModel by activityViewModels() private val pickerModel: PlaybackPickerViewModel by viewModels() // Information about what Song to show choices for is initially within the navigation arguments // as UIDs, as that is the only safe way to parcel a Song. private val args: PlayFromGenreDialogArgs by navArgs() - private val choiceAdapter = GenreChoiceAdapter(this) + private val choiceAdapter = GenrePlaybackChoiceAdapter(this) override fun onConfigDialog(builder: AlertDialog.Builder) { builder.setTitle(R.string.lbl_genres).setNegativeButton(R.string.lbl_cancel, null) } override fun onCreateBinding(inflater: LayoutInflater) = - DialogMusicPickerBinding.inflate(inflater) + DialogMusicChoicesBinding.inflate(inflater) - override fun onBindingCreated(binding: DialogMusicPickerBinding, savedInstanceState: Bundle?) { + override fun onBindingCreated(binding: DialogMusicChoicesBinding, savedInstanceState: Bundle?) { super.onBindingCreated(binding, savedInstanceState) - binding.pickerChoiceRecycler.apply { + binding.choiceRecycler.apply { itemAnimator = null adapter = choiceAdapter } @@ -80,7 +77,7 @@ class PlayFromGenreDialog : } } - override fun onDestroyBinding(binding: DialogMusicPickerBinding) { + override fun onDestroyBinding(binding: DialogMusicChoicesBinding) { super.onDestroyBinding(binding) choiceAdapter } @@ -91,14 +88,4 @@ class PlayFromGenreDialog : playbackModel.playFromGenre(song, item) findNavController().navigateUp() } - - private class GenreChoiceAdapter(private val listener: ClickableListListener) : - FlexibleListAdapter>(ChoiceViewHolder.diffCallback()) { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChoiceViewHolder = - ChoiceViewHolder.from(parent) - - override fun onBindViewHolder(holder: ChoiceViewHolder, position: Int) { - holder.bind(getItem(position), listener) - } - } } diff --git a/app/src/main/res/layout/dialog_music_picker.xml b/app/src/main/res/layout/dialog_music_choices.xml similarity index 76% rename from app/src/main/res/layout/dialog_music_picker.xml rename to app/src/main/res/layout/dialog_music_choices.xml index 8c1d82ee3..64c36ada8 100644 --- a/app/src/main/res/layout/dialog_music_picker.xml +++ b/app/src/main/res/layout/dialog_music_choices.xml @@ -1,9 +1,8 @@ - + tools:layout="@layout/dialog_music_choices"> @@ -81,7 +81,7 @@ android:id="@+id/play_from_artist_dialog" android:name="org.oxycblt.auxio.playback.picker.PlayFromArtistDialog" android:label="play_from_artist_dialog" - tools:layout="@layout/dialog_music_picker"> + tools:layout="@layout/dialog_music_choices"> @@ -91,7 +91,7 @@ android:id="@+id/play_from_genre_dialog" android:name="org.oxycblt.auxio.playback.picker.PlayFromGenreDialog" android:label="play_from_genre_dialog" - tools:layout="@layout/dialog_music_picker"> + tools:layout="@layout/dialog_music_choices">