mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
watch history adapter
This commit is contained in:
parent
e9226313f4
commit
321887933b
@ -0,0 +1,42 @@
|
|||||||
|
package com.github.libretube.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.obj.WatchHistoryItem
|
||||||
|
import com.squareup.picasso.Picasso
|
||||||
|
|
||||||
|
class WatchHistoryAdapter(
|
||||||
|
private val watchHistory: List<WatchHistoryItem>
|
||||||
|
) :
|
||||||
|
RecyclerView.Adapter<WatchHistoryViewHolder>() {
|
||||||
|
private val TAG = "WatchHistoryAdapter"
|
||||||
|
private lateinit var binding: WatchHistoryRowBinding
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchHistoryViewHolder {
|
||||||
|
val layoutInflater = LayoutInflater.from(parent.context)
|
||||||
|
binding = WatchHistoryRowBinding.inflate(layoutInflater, parent, false)
|
||||||
|
return WatchHistoryViewHolder(binding.root)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: WatchHistoryViewHolder, position: Int) {
|
||||||
|
val video = watchHistory[position]
|
||||||
|
binding.apply {
|
||||||
|
videoTitle.text = video.title
|
||||||
|
channelName.text = video.uploader
|
||||||
|
Picasso.get().load(video.thumbnailUrl).into(thumbnail)
|
||||||
|
Picasso.get().load(video.uploaderAvatar).into(channelImage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return watchHistory.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class WatchHistoryViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||||
|
init {
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,10 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.github.libretube.adapters.WatchHistoryAdapter
|
||||||
import com.github.libretube.databinding.FragmentWatchHistoryBinding
|
import com.github.libretube.databinding.FragmentWatchHistoryBinding
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
|
|
||||||
class WatchHistoryFragment : Fragment() {
|
class WatchHistoryFragment : Fragment() {
|
||||||
private val TAG = "WatchHistoryFragment"
|
private val TAG = "WatchHistoryFragment"
|
||||||
@ -22,5 +25,9 @@ class WatchHistoryFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
val watchHistory = PreferenceHelper.getWatchHistory(requireContext())
|
||||||
|
binding.watchHistoryRecView.adapter = WatchHistoryAdapter(watchHistory)
|
||||||
|
binding.watchHistoryRecView.layoutManager = LinearLayoutManager(view.context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ data class WatchHistoryItem(
|
|||||||
val title: String?,
|
val title: String?,
|
||||||
val uploadDate: String?,
|
val uploadDate: String?,
|
||||||
val uploader: String?,
|
val uploader: String?,
|
||||||
|
val uploaderAvatar: String?,
|
||||||
val uploaderUrl: String?,
|
val uploaderUrl: String?,
|
||||||
val thumbnailUrl: String?,
|
val thumbnailUrl: String?,
|
||||||
val duration: Int?
|
val duration: Int?
|
||||||
|
@ -137,6 +137,7 @@ object PreferenceHelper {
|
|||||||
streams.uploadDate,
|
streams.uploadDate,
|
||||||
streams.uploader,
|
streams.uploader,
|
||||||
streams.uploaderUrl?.replace("/channel/", ""),
|
streams.uploaderUrl?.replace("/channel/", ""),
|
||||||
|
streams.uploaderAvatar,
|
||||||
streams.thumbnailUrl,
|
streams.thumbnailUrl,
|
||||||
streams.duration
|
streams.duration
|
||||||
)
|
)
|
||||||
|
106
app/src/main/res/layout/watch_history_row.xml
Normal file
106
app/src/main/res/layout/watch_history_row.xml
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<?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/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" />
|
||||||
|
|
||||||
|
<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/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/video_title"
|
||||||
|
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/thumbnail_card"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/video_views"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/thumbnail_card"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/video_title" />
|
||||||
|
|
||||||
|
<de.hdodenhof.circleimageview.CircleImageView
|
||||||
|
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_views" />
|
||||||
|
|
||||||
|
<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_views" />
|
||||||
|
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -79,7 +79,7 @@
|
|||||||
<string name="okay">OK</string>
|
<string name="okay">OK</string>
|
||||||
<string name="history">History</string>
|
<string name="history">History</string>
|
||||||
<string name="search_history">Search History</string>
|
<string name="search_history">Search History</string>
|
||||||
<string name="clear_history">Clear search history</string>
|
<string name="clear_history">Clear history</string>
|
||||||
<string name="music_songs">YT Music Songs</string>
|
<string name="music_songs">YT Music Songs</string>
|
||||||
<string name="music_videos">YT Music Videos</string>
|
<string name="music_videos">YT Music Videos</string>
|
||||||
<string name="music_albums">YT Music Albums</string>
|
<string name="music_albums">YT Music Albums</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user