Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: controls to order queue by date, uploader or views #4371

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.databinding.QueueBottomSheetBinding
import com.github.libretube.ui.adapters.PlayingQueueAdapter
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
import com.github.libretube.util.PlayingQueue
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.lang.IllegalArgumentException

class PlayingQueueSheet : ExpandedBottomSheet() {
private lateinit var binding: QueueBottomSheetBinding
Expand Down Expand Up @@ -76,6 +79,9 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
.filterIndexed { index, _ -> index == currentIndex })
adapter.notifyDataSetChanged()
}
binding.sort.setOnClickListener {
showSortDialog()
}

binding.bottomControls.setOnClickListener {
dialog?.dismiss()
Expand Down Expand Up @@ -113,4 +119,24 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
val itemTouchHelper = ItemTouchHelper(callback)
itemTouchHelper.attachToRecyclerView(binding.optionsRecycler)
}

@SuppressLint("NotifyDataSetChanged")
private fun showSortDialog() {
val sortOptions = listOf(R.string.creation_date, R.string.most_views, R.string.uploader_name)
.map { requireContext().getString(it) }
.toTypedArray()
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.sort_by)
.setItems(sortOptions) { _, index ->
val newQueue = when (index) {
0 -> PlayingQueue.getStreams().sortedBy { it.uploaded }
1 -> PlayingQueue.getStreams().sortedBy { it.views }.reversed()
2 -> PlayingQueue.getStreams().sortedBy { it.uploaderName }
else -> throw IllegalArgumentException()
}
PlayingQueue.setStreams(newQueue)
binding.optionsRecycler.adapter?.notifyDataSetChanged()
}
.show()
}
}
17 changes: 13 additions & 4 deletions app/src/main/res/layout/queue_bottom_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
android:background="@drawable/rounded_ripple"
android:padding="10dp">

<ImageView
android:id="@+id/repeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="5dp"
android:src="@drawable/ic_repeat" />

<ImageView
android:id="@+id/shuffle"
android:layout_width="wrap_content"
Expand All @@ -56,22 +65,22 @@
android:src="@drawable/ic_reverse" />

<ImageView
android:id="@+id/repeat"
android:id="@+id/add_to_playlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="5dp"
android:src="@drawable/ic_repeat" />
android:src="@drawable/ic_playlist_add" />

<ImageView
android:id="@+id/add_to_playlist"
android:id="@+id/sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="5dp"
android:src="@drawable/ic_playlist_add" />
android:src="@drawable/ic_sort" />

<ImageView
android:id="@+id/clear_queue"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@
<string name="visibility">Visibility</string>
<string name="visibility_public">Public</string>
<string name="visibility_unlisted">Unlisted</string>
<string name="sort_by">Sort by</string>
<string name="uploader_name">Uploader name</string>

<!-- Backup & Restore Settings -->
<string name="import_subscriptions_from">Import subscriptions from</string>
Expand Down