Merge pull request #925 from Bnyro/master

fix search and watch history
This commit is contained in:
Bnyro 2022-07-30 16:16:07 +02:00 committed by GitHub
commit 3b3ca61df7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -43,7 +43,7 @@ class WatchHistoryAdapter(
deleteBTN.setOnClickListener {
PreferenceHelper.removeFromWatchHistory(video.videoId!!)
watchHistory.removeAt(position)
notifyItemRemoved(position)
notifyDataSetChanged()
}
root.setOnClickListener {

View File

@ -19,7 +19,7 @@ fun View?.setWatchProgressLength(videoId: String, duration: Long) {
positions.forEach {
if (it.videoId == videoId) {
val fullWidth = (parent as LinearLayout).width
newWidth = (fullWidth * (it.position / (duration))) / 1000
if (duration != 0L) newWidth = (fullWidth * (it.position / (duration))) / 1000
return@forEach
}
}

View File

@ -3,6 +3,7 @@ package com.github.libretube.preferences
import android.content.Context
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.libretube.obj.CustomInstance
import com.github.libretube.obj.Streams
@ -86,8 +87,9 @@ object PreferenceHelper {
fun getSearchHistory(): List<String> {
return try {
val set: Set<String> = settings.getStringSet("search_history", LinkedHashSet())!!
set.toList()
val json = settings.getString("search_history", "")!!
val type = object : TypeReference<List<String>>(){}
return mapper.readValue(json, type)
} catch (e: Exception) {
emptyList()
}
@ -118,8 +120,8 @@ object PreferenceHelper {
}
private fun updateSearchHistory(historyList: List<String>) {
val set: Set<String> = LinkedHashSet(historyList)
editor.putStringSet("search_history", set).apply()
val json = mapper.writeValueAsString(historyList)
editor.putString("search_history", json).apply()
}
fun addToWatchHistory(videoId: String, streams: Streams) {