From 6b5d4e75071b322bb644ebc6de0893d4702ada39 Mon Sep 17 00:00:00 2001
From: Kelvin <kelvin@futo.org>
Date: Fri, 19 Jan 2024 19:44:52 +0100
Subject: [PATCH] Fix nullable

---
 .../fragment/mainactivity/main/VideoDetailView.kt         | 8 ++++----
 .../java/com/futo/platformplayer/states/StateHistory.kt   | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt
index 1c0f1df0..0d252376 100644
--- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt
+++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt
@@ -859,11 +859,11 @@ class VideoDetailView : ConstraintLayout {
 
 
     private val _historyIndexLock = Mutex(false);
-    suspend fun getHistoryIndex(video: IPlatformVideo): DBHistory.Index = withContext(Dispatchers.IO){
+    suspend fun getHistoryIndex(video: IPlatformVideo): DBHistory.Index? = withContext(Dispatchers.IO){
         _historyIndexLock.withLock {
             val current = _historyIndex;
             if(current == null || current.url != video.url) {
-                val index = StateHistory.instance.getHistoryByVideo(video, true)!!;
+                val index = StateHistory.instance.getHistoryByVideo(video, true);
                 _historyIndex = index;
                 return@withContext index;
             }
@@ -1390,7 +1390,7 @@ class VideoDetailView : ConstraintLayout {
 
         if (video !is TutorialFragment.TutorialVideo) {
             fragment.lifecycleScope.launch(Dispatchers.IO) {
-                val historyItem = getHistoryIndex(videoDetail);
+                val historyItem = getHistoryIndex(videoDetail) ?: return@launch;
 
                 withContext(Dispatchers.Main) {
                     _historicalPosition = StateHistory.instance.updateHistoryPosition(video,  historyItem,false, (toResume.toFloat() / 1000.0f).toLong());
@@ -2252,7 +2252,7 @@ class VideoDetailView : ConstraintLayout {
         if (updateHistory && (_lastPositionSaveTime == -1L || currentTime - _lastPositionSaveTime > 5000)) {
             if (v !is TutorialFragment.TutorialVideo) {
                 fragment.lifecycleScope.launch(Dispatchers.IO) {
-                    val history = getHistoryIndex(v);
+                    val history = getHistoryIndex(v) ?: return@launch;
                     StateHistory.instance.updateHistoryPosition(v, history, true, (positionMilliseconds.toFloat() / 1000.0f).toLong());
                 }
             }
diff --git a/app/src/main/java/com/futo/platformplayer/states/StateHistory.kt b/app/src/main/java/com/futo/platformplayer/states/StateHistory.kt
index 2beaf40a..9f9ef81f 100644
--- a/app/src/main/java/com/futo/platformplayer/states/StateHistory.kt
+++ b/app/src/main/java/com/futo/platformplayer/states/StateHistory.kt
@@ -106,7 +106,7 @@ class StateHistory {
             if(result == null)
                 UIDialogs.toast("History creation failed?\nNo history tracking..");
         }
-        return null;
+        return result;
     }
 
     fun removeHistory(url: String) {
-- 
GitLab