mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
merge all videoRows into one
This commit is contained in:
parent
c9740a2d5f
commit
9ea9e63ef6
@ -2,10 +2,11 @@ package com.github.libretube.adapters
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.VideoChannelRowBinding
|
||||
import com.github.libretube.databinding.VideoRowBinding
|
||||
import com.github.libretube.dialogs.VideoOptionsDialog
|
||||
import com.github.libretube.obj.StreamItem
|
||||
import com.github.libretube.util.ConnectionHelper
|
||||
@ -29,20 +30,22 @@ class ChannelAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChannelViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val binding = VideoChannelRowBinding.inflate(layoutInflater, parent, false)
|
||||
val binding = VideoRowBinding.inflate(layoutInflater, parent, false)
|
||||
return ChannelViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ChannelViewHolder, position: Int) {
|
||||
val trending = videoFeed[position]
|
||||
holder.binding.apply {
|
||||
channelDescription.text = trending.title
|
||||
channelViews.text =
|
||||
channelImage.visibility = View.GONE
|
||||
channelName.visibility = View.GONE
|
||||
videoTitle.text = trending.title
|
||||
videoInfo.text =
|
||||
trending.views.formatShort() + " • " +
|
||||
DateUtils.getRelativeTimeSpanString(trending.uploaded!!)
|
||||
channelDuration.text =
|
||||
thumbnailDuration.text =
|
||||
DateUtils.formatElapsedTime(trending.duration!!)
|
||||
ConnectionHelper.loadImage(trending.thumbnail, channelThumbnail)
|
||||
ConnectionHelper.loadImage(trending.thumbnail, thumbnail)
|
||||
root.setOnClickListener {
|
||||
NavigationHelper.navigateVideo(root.context, trending.url)
|
||||
}
|
||||
@ -56,4 +59,4 @@ class ChannelAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class ChannelViewHolder(val binding: VideoChannelRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
class ChannelViewHolder(val binding: VideoRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -7,9 +7,9 @@ import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.databinding.ChannelSearchRowBinding
|
||||
import com.github.libretube.databinding.ChannelRowBinding
|
||||
import com.github.libretube.databinding.PlaylistSearchRowBinding
|
||||
import com.github.libretube.databinding.VideoSearchRowBinding
|
||||
import com.github.libretube.databinding.VideoRowBinding
|
||||
import com.github.libretube.dialogs.PlaylistOptionsDialog
|
||||
import com.github.libretube.dialogs.VideoOptionsDialog
|
||||
import com.github.libretube.obj.SearchItem
|
||||
@ -45,10 +45,10 @@ class SearchAdapter(
|
||||
|
||||
return when (viewType) {
|
||||
0 -> SearchViewHolder(
|
||||
VideoSearchRowBinding.inflate(layoutInflater, parent, false)
|
||||
VideoRowBinding.inflate(layoutInflater, parent, false)
|
||||
)
|
||||
1 -> SearchViewHolder(
|
||||
ChannelSearchRowBinding.inflate(layoutInflater, parent, false)
|
||||
ChannelRowBinding.inflate(layoutInflater, parent, false)
|
||||
)
|
||||
2 -> SearchViewHolder(
|
||||
PlaylistSearchRowBinding.inflate(layoutInflater, parent, false)
|
||||
@ -78,26 +78,26 @@ class SearchAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindWatch(item: SearchItem, binding: VideoSearchRowBinding) {
|
||||
private fun bindWatch(item: SearchItem, binding: VideoRowBinding) {
|
||||
binding.apply {
|
||||
ConnectionHelper.loadImage(item.thumbnail, searchThumbnail)
|
||||
ConnectionHelper.loadImage(item.thumbnail, thumbnail)
|
||||
if (item.duration != -1L) {
|
||||
searchThumbnailDuration.text = DateUtils.formatElapsedTime(item.duration!!)
|
||||
thumbnailDuration.text = DateUtils.formatElapsedTime(item.duration!!)
|
||||
} else {
|
||||
searchThumbnailDuration.text = root.context.getString(R.string.live)
|
||||
searchThumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark)
|
||||
thumbnailDuration.text = root.context.getString(R.string.live)
|
||||
thumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
ConnectionHelper.loadImage(item.uploaderAvatar, searchChannelImage)
|
||||
searchDescription.text = item.title
|
||||
ConnectionHelper.loadImage(item.uploaderAvatar, channelImage)
|
||||
videoTitle.text = item.title
|
||||
val viewsString = if (item.views?.toInt() != -1) item.views.formatShort() else ""
|
||||
val uploadDate = if (item.uploadedDate != null) item.uploadedDate else ""
|
||||
searchViews.text =
|
||||
videoInfo.text =
|
||||
if (viewsString != "" && uploadDate != "") {
|
||||
"$viewsString • $uploadDate"
|
||||
} else {
|
||||
viewsString + uploadDate
|
||||
}
|
||||
searchChannelName.text = item.uploaderName
|
||||
channelName.text = item.uploaderName
|
||||
root.setOnClickListener {
|
||||
NavigationHelper.navigateVideo(root.context, item.url)
|
||||
}
|
||||
@ -107,13 +107,13 @@ class SearchAdapter(
|
||||
.show(childFragmentManager, "VideoOptionsDialog")
|
||||
true
|
||||
}
|
||||
searchChannelImage.setOnClickListener {
|
||||
channelImage.setOnClickListener {
|
||||
NavigationHelper.navigateChannel(root.context, item.uploaderUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindChannel(item: SearchItem, binding: ChannelSearchRowBinding) {
|
||||
private fun bindChannel(item: SearchItem, binding: ChannelRowBinding) {
|
||||
binding.apply {
|
||||
ConnectionHelper.loadImage(item.thumbnail, searchChannelImage)
|
||||
searchChannelName.text = item.name
|
||||
@ -132,7 +132,7 @@ class SearchAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSubscribed(channelId: String, token: String, binding: ChannelSearchRowBinding) {
|
||||
private fun isSubscribed(channelId: String, token: String, binding: ChannelRowBinding) {
|
||||
var isSubscribed = false
|
||||
|
||||
// check whether the user subscribed to the channel
|
||||
@ -223,15 +223,15 @@ class SearchAdapter(
|
||||
}
|
||||
|
||||
class SearchViewHolder : RecyclerView.ViewHolder {
|
||||
var videoRowBinding: VideoSearchRowBinding? = null
|
||||
var channelRowBinding: ChannelSearchRowBinding? = null
|
||||
var videoRowBinding: VideoRowBinding? = null
|
||||
var channelRowBinding: ChannelRowBinding? = null
|
||||
var playlistRowBinding: PlaylistSearchRowBinding? = null
|
||||
|
||||
constructor(binding: VideoSearchRowBinding) : super(binding.root) {
|
||||
constructor(binding: VideoRowBinding) : super(binding.root) {
|
||||
videoRowBinding = binding
|
||||
}
|
||||
|
||||
constructor(binding: ChannelSearchRowBinding) : super(binding.root) {
|
||||
constructor(binding: ChannelRowBinding) : super(binding.root) {
|
||||
channelRowBinding = binding
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.WatchHistoryRowBinding
|
||||
import com.github.libretube.databinding.VideoRowBinding
|
||||
import com.github.libretube.dialogs.VideoOptionsDialog
|
||||
import com.github.libretube.obj.WatchHistoryItem
|
||||
import com.github.libretube.util.ConnectionHelper
|
||||
@ -26,7 +26,7 @@ class WatchHistoryAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchHistoryViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val binding = WatchHistoryRowBinding.inflate(layoutInflater, parent, false)
|
||||
val binding = VideoRowBinding.inflate(layoutInflater, parent, false)
|
||||
return WatchHistoryViewHolder(binding)
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ class WatchHistoryAdapter(
|
||||
holder.binding.apply {
|
||||
videoTitle.text = video.title
|
||||
channelName.text = video.uploader
|
||||
uploadDate.text = video.uploadDate
|
||||
videoInfo.text = video.uploadDate
|
||||
thumbnailDuration.text = DateUtils.formatElapsedTime(video.duration?.toLong()!!)
|
||||
ConnectionHelper.loadImage(video.thumbnailUrl, thumbnail)
|
||||
ConnectionHelper.loadImage(video.uploaderAvatar, channelImage)
|
||||
@ -60,5 +60,5 @@ class WatchHistoryAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class WatchHistoryViewHolder(val binding: WatchHistoryRowBinding) :
|
||||
class WatchHistoryViewHolder(val binding: VideoRowBinding) :
|
||||
RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -1,80 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/video_search"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/guideline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_percent=".45" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/card_search_thumbnail"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintDimensionRatio="16:9"
|
||||
app:layout_constraintEnd_toStartOf="@+id/guideline"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
app:strokeWidth="0dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/channel_thumbnail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:srcCompat="@tools:sample/backgrounds/scenic" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="5dp"
|
||||
app:cardBackgroundColor="@color/duration_background_color"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="0dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/channel_duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="6dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingEnd="6dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:textColor="@color/duration_text_color"
|
||||
tools:text="05:36" />
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/channel_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/channel_views"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
|
||||
app:layout_constraintTop_toBottomOf="@+id/channel_description" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -73,7 +73,7 @@
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/upload_date"
|
||||
android:id="@+id/video_info"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
@ -88,7 +88,7 @@
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintStart_toStartOf="@+id/guideline"
|
||||
app:layout_constraintTop_toBottomOf="@id/upload_date" />
|
||||
app:layout_constraintTop_toBottomOf="@id/video_info" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/channel_name"
|
||||
@ -100,7 +100,6 @@
|
||||
android:maxLines="1"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/channel_image"
|
||||
app:layout_constraintTop_toBottomOf="@id/upload_date" />
|
||||
|
||||
app:layout_constraintTop_toBottomOf="@id/video_info" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,106 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/video_search"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/guideline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_percent=".45" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/card_search_thumbnail"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintDimensionRatio="16:9"
|
||||
app:layout_constraintEnd_toStartOf="@+id/guideline"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
app:strokeWidth="0dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/search_thumbnail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:srcCompat="@tools:sample/backgrounds/scenic" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginBottom="3dp"
|
||||
app:cardBackgroundColor="@color/duration_background_color"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="0dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/search_thumbnail_duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="6dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingEnd="6dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:textColor="@color/duration_text_color"
|
||||
android:textSize="11sp"
|
||||
tools:text="05:36" />
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/search_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/search_views"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
|
||||
app:layout_constraintTop_toBottomOf="@+id/search_description" />
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/search_channel_image"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintStart_toStartOf="@+id/guideline"
|
||||
app:layout_constraintTop_toBottomOf="@+id/search_views" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/search_channel_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/search_channel_image"
|
||||
app:layout_constraintTop_toBottomOf="@+id/search_views" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user