Merge pull request #4323 from Bnyro/master

feat: support for video tags
This commit is contained in:
Bnyro 2023-07-29 16:59:20 +02:00 committed by GitHub
commit 801c454790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 0 deletions

View File

@ -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<String>) :
RecyclerView.Adapter<VideoTagsViewHolder>() {
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()
}
}
}
}

View File

@ -93,6 +93,7 @@ import com.github.libretube.obj.VideoResolution
import com.github.libretube.parcelable.PlayerData import com.github.libretube.parcelable.PlayerData
import com.github.libretube.services.DownloadService import com.github.libretube.services.DownloadService
import com.github.libretube.ui.activities.MainActivity 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.ChaptersAdapter
import com.github.libretube.ui.adapters.VideosAdapter import com.github.libretube.ui.adapters.VideosAdapter
import com.github.libretube.ui.dialogs.AddToPlaylistDialog 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.license)}: ${streams.license}\n" +
"${context?.getString(R.string.visibility)}: $visibility" "${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 { binding.playerChannel.setOnClickListener {
val activity = view?.context as MainActivity val activity = view?.context as MainActivity
val bundle = bundleOf(IntentData.channelId to streams.uploaderUrl) val bundle = bundleOf(IntentData.channelId to streams.uploaderUrl)

View File

@ -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)

View File

@ -132,6 +132,11 @@
android:textIsSelectable="true" android:textIsSelectable="true"
android:textSize="14sp" /> android:textSize="14sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tags_recycler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout> </LinearLayout>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="3dp">
<TextView
android:id="@+id/tag_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginVertical="6dp"
tools:text="Gaming" />
</com.google.android.material.card.MaterialCardView>
</FrameLayout>