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 { deleteBTN.setOnClickListener {
PreferenceHelper.removeFromWatchHistory(video.videoId!!) PreferenceHelper.removeFromWatchHistory(video.videoId!!)
watchHistory.removeAt(position) watchHistory.removeAt(position)
notifyItemRemoved(position) notifyDataSetChanged()
} }
root.setOnClickListener { root.setOnClickListener {

View File

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

View File

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