mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Merge pull request #4442 from Bnyro/master
feat: move playlists sort order to library tab
This commit is contained in:
commit
2f707778a5
@ -47,8 +47,11 @@ object PlaylistsHelper {
|
||||
)
|
||||
}
|
||||
}
|
||||
sortPlaylists(playlists)
|
||||
}
|
||||
|
||||
when (
|
||||
private fun sortPlaylists(playlists: List<Playlists>): List<Playlists> {
|
||||
return when (
|
||||
PreferenceHelper.getString(PreferenceKeys.PLAYLISTS_ORDER, "creation_date")
|
||||
) {
|
||||
"creation_date" -> playlists
|
||||
@ -56,7 +59,6 @@ object PlaylistsHelper {
|
||||
"alphabetic" -> playlists.sortedBy { it.name?.lowercase() }
|
||||
"alphabetic_reversed" -> playlists.sortedBy { it.name?.lowercase() }
|
||||
.reversed()
|
||||
|
||||
else -> playlists
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.PlaylistsHelper
|
||||
import com.github.libretube.api.obj.Playlists
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.databinding.FragmentLibraryBinding
|
||||
import com.github.libretube.db.DatabaseHolder
|
||||
@ -31,6 +32,7 @@ import com.github.libretube.ui.adapters.PlaylistBookmarkAdapter
|
||||
import com.github.libretube.ui.adapters.PlaylistsAdapter
|
||||
import com.github.libretube.ui.dialogs.CreatePlaylistDialog
|
||||
import com.github.libretube.ui.models.PlayerViewModel
|
||||
import com.github.libretube.ui.sheets.BaseBottomSheet
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@ -95,6 +97,20 @@ class LibraryFragment : Fragment() {
|
||||
fetchPlaylists()
|
||||
}.show(childFragmentManager, CreatePlaylistDialog::class.java.name)
|
||||
}
|
||||
|
||||
binding.sortTV.setOnClickListener {
|
||||
val sortOptions = resources.getStringArray(R.array.playlistSortingOptions)
|
||||
val sortOptionValues = resources.getStringArray(R.array.playlistSortingOptionsValues)
|
||||
|
||||
BaseBottomSheet().apply {
|
||||
setSimpleItems(sortOptions.toList()) { index ->
|
||||
binding.sortTV.text = sortOptions[index]
|
||||
val value = sortOptionValues[index]
|
||||
PreferenceHelper.putString(PreferenceKeys.PLAYLISTS_ORDER, value)
|
||||
fetchPlaylists()
|
||||
}
|
||||
}.show(childFragmentManager)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
@ -143,26 +159,32 @@ class LibraryFragment : Fragment() {
|
||||
binding.playlistRefresh.isRefreshing = false
|
||||
|
||||
if (playlists.isNotEmpty()) {
|
||||
val playlistsAdapter = PlaylistsAdapter(
|
||||
playlists.toMutableList(),
|
||||
PlaylistsHelper.getPrivatePlaylistType()
|
||||
)
|
||||
|
||||
// listen for playlists to become deleted
|
||||
playlistsAdapter.registerAdapterDataObserver(object :
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
_binding?.nothingHere?.isVisible = playlistsAdapter.itemCount == 0
|
||||
super.onItemRangeRemoved(positionStart, itemCount)
|
||||
}
|
||||
})
|
||||
|
||||
binding.nothingHere.isGone = true
|
||||
binding.playlistRecView.adapter = playlistsAdapter
|
||||
showPlaylists(playlists)
|
||||
} else {
|
||||
binding.nothingHere.isVisible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showPlaylists(playlists: List<Playlists>) {
|
||||
val binding = _binding ?: return
|
||||
|
||||
val playlistsAdapter = PlaylistsAdapter(
|
||||
playlists.toMutableList(),
|
||||
PlaylistsHelper.getPrivatePlaylistType()
|
||||
)
|
||||
|
||||
// listen for playlists to become deleted
|
||||
playlistsAdapter.registerAdapterDataObserver(object :
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
_binding?.nothingHere?.isVisible = playlistsAdapter.itemCount == 0
|
||||
super.onItemRangeRemoved(positionStart, itemCount)
|
||||
}
|
||||
})
|
||||
|
||||
binding.nothingHere.isGone = true
|
||||
binding.playlistRecView.adapter = playlistsAdapter
|
||||
}
|
||||
}
|
||||
|
@ -78,14 +78,32 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:text="@string/playlists"
|
||||
android:textAlignment="viewStart"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:text="@string/playlists"
|
||||
android:textAlignment="viewStart"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sortTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawablePadding="5dp"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:text="@string/creation_date"
|
||||
android:textSize="16sp"
|
||||
app:drawableEndCompat="@drawable/ic_sort" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/nothing_here"
|
||||
|
@ -103,16 +103,4 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/misc">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="creation_date"
|
||||
android:entries="@array/playlistSortingOptions"
|
||||
android:entryValues="@array/playlistSortingOptionsValues"
|
||||
android:icon="@drawable/ic_filter"
|
||||
app:key="playlists_order"
|
||||
app:title="@string/playlists_order" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user