Add setting to hide search in playlist

This commit is contained in:
tomaThomas 2024-10-11 21:26:14 +02:00
parent b9d3ee6ddb
commit b74feda9c8
No known key found for this signature in database
GPG key ID: DEE963DC84059108
7 changed files with 80 additions and 20 deletions

View file

@ -161,4 +161,5 @@ const val CIRCLE_PLAY_BUTTON = "circle_play_button"
const val SWIPE_ANYWHERE_NOW_PLAYING = "swipe_anywhere_now_playing" const val SWIPE_ANYWHERE_NOW_PLAYING = "swipe_anywhere_now_playing"
const val PAUSE_HISTORY = "pause_history" const val PAUSE_HISTORY = "pause_history"
const val MANAGE_AUDIO_FOCUS = "manage_audio_focus" const val MANAGE_AUDIO_FOCUS = "manage_audio_focus"
const val SWIPE_DOWN_DISMISS = "swipe_to_dismiss" const val SWIPE_DOWN_DISMISS = "swipe_to_dismiss"
const val ENABLE_SEARCH_PLAYLIST= "enable_search_playlist"

View file

@ -107,7 +107,7 @@ class OrderablePlaylistSongAdapter(
super.onClick(v) super.onClick(v)
} else { } else {
val position = fullDataSet.indexOf(dataSet.get(layoutPosition)) val position = fullDataSet.indexOf(dataSet.get(layoutPosition))
MusicPlayerRemote.openQueue(fullDataSet, position, true) MusicPlayerRemote.openQueueKeepShuffleMode(fullDataSet, position, true)
} }
} }
@ -167,4 +167,8 @@ class OrderablePlaylistSongAdapter(
} }
notifyDataSetChanged() notifyDataSetChanged()
} }
fun hasSongs(): Boolean {
return itemCount > 0 || (filtered && fullDataSet.size > 0)
}
} }

View file

@ -30,6 +30,7 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.helper.menu.PlaylistMenuHelper import code.name.monkey.retromusic.helper.menu.PlaylistMenuHelper
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.ThemedFastScroller import code.name.monkey.retromusic.util.ThemedFastScroller
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.google.android.material.shape.MaterialShapeDrawable import com.google.android.material.shape.MaterialShapeDrawable
@ -79,6 +80,7 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
// binding.container.transitionName = playlist.playlistEntity.playlistName // binding.container.transitionName = playlist.playlistEntity.playlistName
setUpRecyclerView() setUpRecyclerView()
setUpSearch()
setupButtons() setupButtons()
viewModel.getPlaylist().observe(viewLifecycleOwner) { playlistWithSongs -> viewModel.getPlaylist().observe(viewLifecycleOwner) { playlistWithSongs ->
playlist = playlistWithSongs playlist = playlistWithSongs
@ -120,6 +122,33 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
} }
} }
private fun setUpSearch() {
if (!PreferenceUtil.enableSearchPlaylist) {
binding.playlistSearchView.visibility = View.GONE
} else {
binding.playlistSearchView.visibility = View.VISIBLE
}
binding.playlistSearchView.addTextChangedListener { text ->
lifecycleScope.launch {
_searchFlow.emit(text)
binding.clearSearch.visibility =
if (text.isNullOrBlank()) View.GONE else View.VISIBLE
}
}
binding.clearSearch.setOnClickListener {
lifecycleScope.launch {
_searchFlow.emit(null)
binding.playlistSearchView.clearText()
binding.clearSearch.visibility = View.GONE
}
}
lifecycleScope.launch {
_searchFlow.debounce(300).collect { text ->
playlistSongAdapter.onFilter(text)
}
}
}
private fun setUpRecyclerView() { private fun setUpRecyclerView() {
playlistSongAdapter = OrderablePlaylistSongAdapter( playlistSongAdapter = OrderablePlaylistSongAdapter(
arguments.extraPlaylistId, arguments.extraPlaylistId,
@ -127,16 +156,6 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
ArrayList(), ArrayList(),
R.layout.item_queue R.layout.item_queue
) )
binding.playlistSearchView.addTextChangedListener { text ->
lifecycleScope.launch {
_searchFlow.emit(text)
}
}
lifecycleScope.launch {
_searchFlow.debounce(300).collect { text ->
playlistSongAdapter.onFilter(text)
}
}
val dragDropManager = RecyclerViewDragDropManager() val dragDropManager = RecyclerViewDragDropManager()
@ -168,8 +187,18 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
} }
private fun checkIsEmpty() { private fun checkIsEmpty() {
binding.empty.isVisible = playlistSongAdapter.itemCount == 0 if (_binding != null) {
binding.emptyText.isVisible = playlistSongAdapter.itemCount == 0 if (playlistSongAdapter.itemCount != 0) {
binding.empty.isVisible = false
} else {
binding.empty.isVisible = true
if (playlistSongAdapter.hasSongs()) {
binding.emptyText.text = getString(R.string.no_search_results)
} else {
binding.emptyText.text = getString(R.string.no_songs)
}
}
}
} }
override fun onDestroy() { override fun onDestroy() {

View file

@ -680,6 +680,9 @@ object PreferenceUtil {
val rememberLastTab: Boolean val rememberLastTab: Boolean
get() = sharedPreferences.getBoolean(REMEMBER_LAST_TAB, true) get() = sharedPreferences.getBoolean(REMEMBER_LAST_TAB, true)
val enableSearchPlaylist: Boolean
get() = sharedPreferences.getBoolean(ENABLE_SEARCH_PLAYLIST, true)
var lastTab: Int var lastTab: Int
get() = sharedPreferences get() = sharedPreferences
.getInt(LAST_USED_TAB, 0) .getInt(LAST_USED_TAB, 0)

View file

@ -35,16 +35,28 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/play_button" app:layout_constraintTop_toBottomOf="@id/play_button"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/clear_search"
android:background="@null" android:background="@null"
android:hint="@string/action_search" android:hint="@string/action_search"
android:inputType="text|textAutoComplete" android:inputType="text|textAutoComplete"
android:paddingStart="16dp" android:padding="12dp"
android:paddingEnd="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:textAppearance="@style/TextViewSubtitle1"> android:textAppearance="@style/TextViewSubtitle1">
</com.google.android.material.textfield.TextInputEditText> </com.google.android.material.textfield.TextInputEditText>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/clear_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?roundSelector"
android:padding="10dp"
android:visibility="gone"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/playlistSearchView"
app:srcCompat="@drawable/ic_close"
app:tint="?attr/colorControlNormal"
tools:visibility="visible" />
<com.google.android.material.imageview.ShapeableImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image" android:id="@+id/image"
android:layout_width="0dp" android:layout_width="0dp"
@ -131,12 +143,13 @@
<LinearLayout <LinearLayout
android:id="@android:id/empty" android:id="@android:id/empty"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_marginTop="30dp"
android:gravity="center" android:gravity="center"
android:orientation="vertical" android:orientation="vertical"
android:visibility="gone" android:visibility="gone"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
tools:visibility="visible"> tools:visibility="visible">
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView

View file

@ -277,6 +277,7 @@
<string name="no_purchase_found">No purchase found.</string> <string name="no_purchase_found">No purchase found.</string>
<string name="no_results">No results</string> <string name="no_results">No results</string>
<string name="no_songs">You have no songs</string> <string name="no_songs">You have no songs</string>
<string name="no_search_results">No search results</string>
<string name="normal">Normal</string> <string name="normal">Normal</string>
<string name="normal_lyrics">Normal lyrics</string> <string name="normal_lyrics">Normal lyrics</string>
<string name="not_listed_in_media_store"><![CDATA[<b>%s</b> is not listed in the media store.]]></string> <string name="not_listed_in_media_store"><![CDATA[<b>%s</b> is not listed in the media store.]]></string>
@ -365,6 +366,7 @@
<string name="pref_summary_open_source_licences">License details for open source software</string> <string name="pref_summary_open_source_licences">License details for open source software</string>
<string name="pref_summary_pause_history">When enabled, newly played songs won\'t show in history</string> <string name="pref_summary_pause_history">When enabled, newly played songs won\'t show in history</string>
<string name="pref_summary_remember_tab">Navigate to the last used tab on start</string> <string name="pref_summary_remember_tab">Navigate to the last used tab on start</string>
<string name="pref_summary_enable_search_playlist">Show a search field in a playlist</string>
<string name="pref_summary_show_lyrics">Display synced lyrics over album cover</string> <string name="pref_summary_show_lyrics">Display synced lyrics over album cover</string>
<string name="pref_summary_suggestions">Show New Music Mix on homescreen</string> <string name="pref_summary_suggestions">Show New Music Mix on homescreen</string>
<string name="pref_summary_swipe_anywhere_now_playing">Enables changing song by swiping anywhere on the now playing screen</string> <string name="pref_summary_swipe_anywhere_now_playing">Enables changing song by swiping anywhere on the now playing screen</string>
@ -412,6 +414,7 @@
<string name="pref_title_open_source_licences">Open source licences</string> <string name="pref_title_open_source_licences">Open source licences</string>
<string name="pref_title_pause_history">Pause history</string> <string name="pref_title_pause_history">Pause history</string>
<string name="pref_title_remember_tab">Remember last tab</string> <string name="pref_title_remember_tab">Remember last tab</string>
<string name="pref_title_enable_search_playlist">Enable search in playlist</string>
<string name="pref_title_show_lyrics">Show lyrics</string> <string name="pref_title_show_lyrics">Show lyrics</string>
<string name="pref_title_suggestions">Show suggestions</string> <string name="pref_title_suggestions">Show suggestions</string>
<string name="pref_title_swipe_anywhere_now_playing">Swipe anywhere to change song</string> <string name="pref_title_swipe_anywhere_now_playing">Swipe anywhere to change song</string>

View file

@ -67,6 +67,13 @@
android:summary="@string/pref_summary_remember_tab" android:summary="@string/pref_summary_remember_tab"
android:title="@string/pref_title_remember_tab" /> android:title="@string/pref_title_remember_tab" />
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="true"
android:key="enable_search_playlist"
android:layout="@layout/list_item_view_switch"
android:summary="@string/pref_summary_enable_search_playlist"
android:title="@string/pref_title_enable_search_playlist" />
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="0" android:defaultValue="0"
android:entries="@array/pref_tab_text_mode_titles" android:entries="@array/pref_tab_text_mode_titles"