From 0c43d208b9281f8f5ecd3cbb8bc4c8ed8b3fffb2 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 29 Jul 2023 16:59:56 +0200 Subject: [PATCH] feat: support for video tags --- .../ui/activities/VideoTagsAdapter.kt | 33 +++++++++++++++++++ .../libretube/ui/fragments/PlayerFragment.kt | 7 ++++ .../ui/viewholders/VideoTagsViewHolder.kt | 8 +++++ app/src/main/res/layout/fragment_player.xml | 5 +++ app/src/main/res/layout/video_tag_row.xml | 23 +++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 app/src/main/java/com/github/libretube/ui/activities/VideoTagsAdapter.kt create mode 100644 app/src/main/java/com/github/libretube/ui/viewholders/VideoTagsViewHolder.kt create mode 100644 app/src/main/res/layout/video_tag_row.xml diff --git a/app/src/main/java/com/github/libretube/ui/activities/VideoTagsAdapter.kt b/app/src/main/java/com/github/libretube/ui/activities/VideoTagsAdapter.kt new file mode 100644 index 000000000..578469e13 --- /dev/null +++ b/app/src/main/java/com/github/libretube/ui/activities/VideoTagsAdapter.kt @@ -0,0 +1,33 @@ +package com.github.libretube.ui.activities + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.core.os.bundleOf +import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.R +import com.github.libretube.constants.IntentData +import com.github.libretube.databinding.VideoTagRowBinding +import com.github.libretube.ui.viewholders.VideoTagsViewHolder + +class VideoTagsAdapter(private val tags: List) : + RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VideoTagsViewHolder { + val binding = VideoTagRowBinding.inflate(LayoutInflater.from(parent.context)) + return VideoTagsViewHolder(binding) + } + + override fun getItemCount() = tags.size + + override fun onBindViewHolder(holder: VideoTagsViewHolder, position: Int) { + val tag = tags[position] + holder.binding.apply { + tagText.text = tag + root.setOnClickListener { + val mainActivity = root.context as MainActivity + mainActivity.searchView.setQuery(tag, true) + // minimizes the player fragment to the mini player + mainActivity.onBackPressedDispatcher.onBackPressed() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 0a9cc2eb2..e6c8a075e 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -93,6 +93,7 @@ import com.github.libretube.obj.VideoResolution import com.github.libretube.parcelable.PlayerData import com.github.libretube.services.DownloadService import com.github.libretube.ui.activities.MainActivity +import com.github.libretube.ui.activities.VideoTagsAdapter import com.github.libretube.ui.adapters.ChaptersAdapter import com.github.libretube.ui.adapters.VideosAdapter import com.github.libretube.ui.dialogs.AddToPlaylistDialog @@ -996,6 +997,12 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { "${context?.getString(R.string.license)}: ${streams.license}\n" + "${context?.getString(R.string.visibility)}: $visibility" + if (streams.tags.isNotEmpty()) { + binding.tagsRecycler.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) + binding.tagsRecycler.adapter = VideoTagsAdapter(streams.tags) + } + binding.tagsRecycler.isVisible = streams.tags.isNotEmpty() + binding.playerChannel.setOnClickListener { val activity = view?.context as MainActivity val bundle = bundleOf(IntentData.channelId to streams.uploaderUrl) diff --git a/app/src/main/java/com/github/libretube/ui/viewholders/VideoTagsViewHolder.kt b/app/src/main/java/com/github/libretube/ui/viewholders/VideoTagsViewHolder.kt new file mode 100644 index 000000000..93ec15500 --- /dev/null +++ b/app/src/main/java/com/github/libretube/ui/viewholders/VideoTagsViewHolder.kt @@ -0,0 +1,8 @@ +package com.github.libretube.ui.viewholders + +import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.databinding.VideoTagRowBinding + +class VideoTagsViewHolder( + val binding: VideoTagRowBinding +): RecyclerView.ViewHolder(binding.root) diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 28263a0aa..76d1093d0 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -132,6 +132,11 @@ android:textIsSelectable="true" android:textSize="14sp" /> + + + + + + + + + + + \ No newline at end of file