Merge pull request #2584 from Bnyro/master

Unify similar layouts for watch history, playlists and videos
This commit is contained in:
Bnyro 2023-01-04 19:09:44 +01:00 committed by GitHub
commit fe06b47eb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 241 deletions

View File

@ -9,7 +9,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.api.PlaylistsHelper
import com.github.libretube.api.obj.StreamItem
import com.github.libretube.databinding.PlaylistRowBinding
import com.github.libretube.databinding.VideoRowBinding
import com.github.libretube.enums.PlaylistType
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toID
@ -43,17 +43,18 @@ class PlaylistAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = PlaylistRowBinding.inflate(layoutInflater, parent, false)
val binding = VideoRowBinding.inflate(layoutInflater, parent, false)
return PlaylistViewHolder(binding)
}
override fun onBindViewHolder(holder: PlaylistViewHolder, position: Int) {
val streamItem = videoFeed[position]
holder.binding.apply {
playlistTitle.text = streamItem.title
playlistDescription.text = streamItem.uploaderName
videoTitle.text = streamItem.title
videoInfo.text = streamItem.uploaderName
channelImage.visibility = View.GONE
thumbnailDuration.setFormattedDuration(streamItem.duration!!)
ImageHelper.loadImage(streamItem.thumbnail, playlistThumbnail)
ImageHelper.loadImage(streamItem.thumbnail, thumbnail)
root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, streamItem.url, playlistId)
}
@ -68,9 +69,13 @@ class PlaylistAdapter(
true
}
channelContainer.setOnClickListener {
streamItem.url?.toID()?.let { NavigationHelper.navigateChannel(root.context, it) }
}
if (playlistType != PlaylistType.PUBLIC) {
deletePlaylist.visibility = View.VISIBLE
deletePlaylist.setOnClickListener {
deleteVideo.visibility = View.VISIBLE
deleteVideo.setOnClickListener {
removeFromPlaylist(root.context, position)
}
}

View File

@ -1,9 +1,10 @@
package com.github.libretube.ui.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.WatchHistoryRowBinding
import com.github.libretube.databinding.VideoRowBinding
import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.extensions.query
@ -32,7 +33,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)
}
@ -50,7 +51,8 @@ class WatchHistoryAdapter(
NavigationHelper.navigateChannel(root.context, video.uploaderUrl)
}
deleteBTN.setOnClickListener {
deleteVideo.visibility = View.VISIBLE
deleteVideo.setOnClickListener {
removeFromWatchHistory(position)
}

View File

@ -1,8 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.PlaylistRowBinding
import com.github.libretube.databinding.VideoRowBinding
class PlaylistViewHolder(
val binding: PlaylistRowBinding
val binding: VideoRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -1,8 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.WatchHistoryRowBinding
import com.github.libretube.databinding.VideoRowBinding
class WatchHistoryViewHolder(
val binding: WatchHistoryRowBinding
val binding: VideoRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -1,103 +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"
style="@style/ItemRow">
<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/playlist_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp">
<TextView
android:id="@+id/thumbnail_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingVertical="2dp"
android:textColor="@color/duration_text_color"
android:textSize="11sp"
tools:text="05:36" />
</androidx.cardview.widget.CardView>
<View
android:id="@+id/watch_progress"
style="@style/WatchProgress" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<TextView
android:id="@+id/playlist_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:maxLines="2"
app:layout_constraintEnd_toStartOf="@+id/delete_playlist"
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
app:layout_constraintTop_toTopOf="parent"
tools:text="Playlist Name" />
<TextView
android:id="@+id/playlist_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:maxLines="2"
app:layout_constraintEnd_toStartOf="@+id/delete_playlist"
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
app:layout_constraintTop_toBottomOf="@+id/playlist_title"
tools:text="Description" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/delete_playlist"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:padding="8dp"
android:src="@drawable/ic_delete"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/roundedImageViewRounded" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -74,7 +74,7 @@
android:layout_marginStart="8dp"
android:ellipsize="end"
android:maxLines="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@id/delete_video"
app:layout_constraintStart_toEndOf="@id/thumbnail_card"
app:layout_constraintTop_toTopOf="parent" />
@ -116,4 +116,16 @@
</LinearLayout>
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/delete_video"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:padding="8dp"
android:src="@drawable/ic_delete"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/roundedImageViewRounded" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,123 +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"
style="@style/ItemRow">
<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/thumbnail_card"
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/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp">
<TextView
android:id="@+id/thumbnail_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingVertical="2dp"
android:textColor="@color/duration_text_color"
android:textSize="11sp"
tools:text="05:36" />
</androidx.cardview.widget.CardView>
<View
android:id="@+id/watch_progress"
style="@style/WatchProgress" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<TextView
android:id="@+id/video_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ellipsize="end"
android:maxLines="2"
app:layout_constraintEnd_toStartOf="@id/deleteBTN"
app:layout_constraintStart_toEndOf="@id/thumbnail_card"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/video_info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toStartOf="@id/deleteBTN"
app:layout_constraintStart_toEndOf="@id/thumbnail_card"
app:layout_constraintTop_toBottomOf="@id/video_title" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/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/video_info"
app:shapeAppearance="@style/CircleImageView" />
<TextView
android:id="@+id/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/channel_image"
app:layout_constraintTop_toBottomOf="@id/video_info" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/deleteBTN"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:padding="8dp"
android:src="@drawable/ic_delete"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/roundedImageViewRounded" />
</androidx.constraintlayout.widget.ConstraintLayout>