mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-07 10:00:31 +05:30
commit
60e34e3a6f
@ -5,9 +5,10 @@ import android.view.LayoutInflater
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.libretube.databinding.VideoRowBinding
|
import com.github.libretube.databinding.WatchHistoryRowBinding
|
||||||
import com.github.libretube.dialogs.VideoOptionsDialog
|
import com.github.libretube.dialogs.VideoOptionsDialog
|
||||||
import com.github.libretube.obj.WatchHistoryItem
|
import com.github.libretube.obj.WatchHistoryItem
|
||||||
|
import com.github.libretube.preferences.PreferenceHelper
|
||||||
import com.github.libretube.util.ConnectionHelper
|
import com.github.libretube.util.ConnectionHelper
|
||||||
import com.github.libretube.util.NavigationHelper
|
import com.github.libretube.util.NavigationHelper
|
||||||
import com.github.libretube.util.setWatchProgressLength
|
import com.github.libretube.util.setWatchProgressLength
|
||||||
@ -19,15 +20,9 @@ class WatchHistoryAdapter(
|
|||||||
RecyclerView.Adapter<WatchHistoryViewHolder>() {
|
RecyclerView.Adapter<WatchHistoryViewHolder>() {
|
||||||
private val TAG = "WatchHistoryAdapter"
|
private val TAG = "WatchHistoryAdapter"
|
||||||
|
|
||||||
fun clear() {
|
|
||||||
val size = watchHistory.size
|
|
||||||
watchHistory.clear()
|
|
||||||
notifyItemRangeRemoved(0, size)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchHistoryViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchHistoryViewHolder {
|
||||||
val layoutInflater = LayoutInflater.from(parent.context)
|
val layoutInflater = LayoutInflater.from(parent.context)
|
||||||
val binding = VideoRowBinding.inflate(layoutInflater, parent, false)
|
val binding = WatchHistoryRowBinding.inflate(layoutInflater, parent, false)
|
||||||
return WatchHistoryViewHolder(binding)
|
return WatchHistoryViewHolder(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +40,12 @@ class WatchHistoryAdapter(
|
|||||||
NavigationHelper.navigateChannel(root.context, video.uploaderUrl)
|
NavigationHelper.navigateChannel(root.context, video.uploaderUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteBTN.setOnClickListener {
|
||||||
|
PreferenceHelper.removeFromWatchHistory(video.videoId!!)
|
||||||
|
watchHistory.removeAt(position)
|
||||||
|
notifyItemRemoved(position)
|
||||||
|
}
|
||||||
|
|
||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
NavigationHelper.navigateVideo(root.context, video.videoId)
|
NavigationHelper.navigateVideo(root.context, video.videoId)
|
||||||
}
|
}
|
||||||
@ -63,5 +64,5 @@ class WatchHistoryAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WatchHistoryViewHolder(val binding: VideoRowBinding) :
|
class WatchHistoryViewHolder(val binding: WatchHistoryRowBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root)
|
RecyclerView.ViewHolder(binding.root)
|
||||||
|
@ -27,12 +27,12 @@ class WatchHistoryFragment : Fragment() {
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val watchHistory = PreferenceHelper.getWatchHistory()
|
val watchHistory = PreferenceHelper.getWatchHistory()
|
||||||
|
|
||||||
|
if (watchHistory.isNotEmpty()) {
|
||||||
val watchHistoryAdapter = WatchHistoryAdapter(watchHistory, childFragmentManager)
|
val watchHistoryAdapter = WatchHistoryAdapter(watchHistory, childFragmentManager)
|
||||||
binding.watchHistoryRecView.adapter = watchHistoryAdapter
|
binding.watchHistoryRecView.adapter = watchHistoryAdapter
|
||||||
|
binding.historyEmpty.visibility = View.GONE
|
||||||
binding.clearHistory.setOnClickListener {
|
binding.watchHistoryRecView.visibility = View.VISIBLE
|
||||||
PreferenceHelper.removePreference("watch_history")
|
|
||||||
watchHistoryAdapter.clear()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reverse order
|
// reverse order
|
||||||
|
@ -25,38 +25,10 @@ object PreferenceHelper {
|
|||||||
editor = settings.edit()
|
editor = settings.edit()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setString(key: String?, value: String?) {
|
|
||||||
editor.putString(key, value)
|
|
||||||
editor.apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setInt(key: String?, value: Int) {
|
|
||||||
editor.putInt(key, value)
|
|
||||||
editor.apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setLong(key: String?, value: Long) {
|
|
||||||
editor.putLong(key, value)
|
|
||||||
editor.apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setBoolean(key: String?, value: Boolean) {
|
|
||||||
editor.putBoolean(key, value)
|
|
||||||
editor.apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getString(key: String?, defValue: String?): String {
|
fun getString(key: String?, defValue: String?): String {
|
||||||
return settings.getString(key, defValue)!!
|
return settings.getString(key, defValue)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getInt(key: String?, defValue: Int): Int {
|
|
||||||
return settings.getInt(key, defValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getLong(key: String?, defValue: Long): Long {
|
|
||||||
return settings.getLong(key, defValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getBoolean(key: String?, defValue: Boolean): Boolean {
|
fun getBoolean(key: String?, defValue: Boolean): Boolean {
|
||||||
return settings.getBoolean(key, defValue)
|
return settings.getBoolean(key, defValue)
|
||||||
}
|
}
|
||||||
@ -153,7 +125,7 @@ object PreferenceHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addToWatchHistory(videoId: String, streams: Streams) {
|
fun addToWatchHistory(videoId: String, streams: Streams) {
|
||||||
val mapper = ObjectMapper()
|
removeFromWatchHistory(videoId)
|
||||||
|
|
||||||
val watchHistoryItem = WatchHistoryItem(
|
val watchHistoryItem = WatchHistoryItem(
|
||||||
videoId,
|
videoId,
|
||||||
@ -166,21 +138,30 @@ object PreferenceHelper {
|
|||||||
streams.duration
|
streams.duration
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val mapper = ObjectMapper()
|
||||||
val watchHistory = getWatchHistory()
|
val watchHistory = getWatchHistory()
|
||||||
|
|
||||||
// delete entries that have the same videoId
|
|
||||||
var indexToRemove: Int? = null
|
|
||||||
watchHistory.forEachIndexed { index, item ->
|
|
||||||
if (item.videoId == videoId) indexToRemove = index
|
|
||||||
}
|
|
||||||
if (indexToRemove != null) watchHistory.removeAt(indexToRemove!!)
|
|
||||||
|
|
||||||
watchHistory += watchHistoryItem
|
watchHistory += watchHistoryItem
|
||||||
|
|
||||||
val json = mapper.writeValueAsString(watchHistory)
|
val json = mapper.writeValueAsString(watchHistory)
|
||||||
editor.putString("watch_history", json).apply()
|
editor.putString("watch_history", json).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun removeFromWatchHistory(videoId: String) {
|
||||||
|
val mapper = ObjectMapper()
|
||||||
|
val watchHistory = getWatchHistory()
|
||||||
|
|
||||||
|
var indexToRemove: Int? = null
|
||||||
|
watchHistory.forEachIndexed { index, item ->
|
||||||
|
if (item.videoId == videoId) indexToRemove = index
|
||||||
|
}
|
||||||
|
if (indexToRemove != null) {
|
||||||
|
watchHistory.removeAt(indexToRemove!!)
|
||||||
|
val json = mapper.writeValueAsString(watchHistory)
|
||||||
|
editor.putString("watch_history", json).commit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getWatchHistory(): ArrayList<WatchHistoryItem> {
|
fun getWatchHistory(): ArrayList<WatchHistoryItem> {
|
||||||
val mapper = ObjectMapper()
|
val mapper = ObjectMapper()
|
||||||
|
|
||||||
|
@ -97,8 +97,7 @@
|
|||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:layout_marginEnd="10dp"
|
android:layout_marginEnd="10dp"
|
||||||
android:layout_marginBottom="15dp"
|
android:layout_marginBottom="15dp"
|
||||||
android:autoLink="web"
|
android:autoLink="web" />
|
||||||
android:text="" />
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -264,7 +264,6 @@
|
|||||||
android:layout_toEndOf="@+id/player_channelImage"
|
android:layout_toEndOf="@+id/player_channelImage"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:text=""
|
|
||||||
android:textSize="15sp" />
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text=""
|
|
||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
@ -1,34 +1,29 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/history_empty"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<ImageView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="100dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="100dp"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:paddingHorizontal="8dp">
|
android:src="@drawable/ic_history" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginHorizontal="10dp"
|
||||||
android:text="@string/watch_history"
|
android:gravity="center"
|
||||||
android:textSize="16sp" />
|
android:text="@string/history_empty"
|
||||||
|
android:textSize="20sp"
|
||||||
<ImageView
|
android:textStyle="bold" />
|
||||||
android:id="@+id/clearHistory"
|
|
||||||
android:layout_width="16dp"
|
|
||||||
android:layout_height="16dp"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginRight="5dp"
|
|
||||||
android:src="@drawable/ic_reset" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
@ -36,8 +31,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="8dp"
|
android:layout_margin="8dp"
|
||||||
android:nestedScrollingEnabled="false" />
|
android:nestedScrollingEnabled="false"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
</LinearLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</ScrollView>
|
|
@ -42,7 +42,6 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:text=""
|
|
||||||
app:layout_constraintEnd_toStartOf="@+id/delete_playlist"
|
app:layout_constraintEnd_toStartOf="@+id/delete_playlist"
|
||||||
app:layout_constraintStart_toEndOf="@+id/card_playlist_thumbnail"
|
app:layout_constraintStart_toEndOf="@+id/card_playlist_thumbnail"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
@ -52,8 +51,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:text=""
|
app:layout_constraintEnd_toStartOf="@id/delete_playlist"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/card_playlist_thumbnail"
|
app:layout_constraintStart_toEndOf="@+id/card_playlist_thumbnail"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/playlist_title" />
|
app:layout_constraintTop_toBottomOf="@+id/playlist_title" />
|
||||||
|
|
||||||
|
129
app/src/main/res/layout/watch_history_row.xml
Normal file
129
app/src/main/res/layout/watch_history_row.xml
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
<?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" />
|
||||||
|
|
||||||
|
<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"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="4dp"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:background="@android:color/holo_red_dark" />
|
||||||
|
|
||||||
|
</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" />
|
||||||
|
|
||||||
|
<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_info" />
|
||||||
|
|
||||||
|
<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>
|
@ -266,4 +266,5 @@
|
|||||||
<string name="worst_quality">Worst quality</string>
|
<string name="worst_quality">Worst quality</string>
|
||||||
<string name="default_subtitle_language">Default subtitle language</string>
|
<string name="default_subtitle_language">Default subtitle language</string>
|
||||||
<string name="irreversible">Are you sure? This can\'t be undone!</string>
|
<string name="irreversible">Are you sure? This can\'t be undone!</string>
|
||||||
|
<string name="history_empty">History is empty.</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user