Fix nullable

This commit is contained in:
Kelvin 2024-01-19 19:44:52 +01:00
commit 45830a63ff
2 changed files with 5 additions and 5 deletions

View file

@ -859,11 +859,11 @@ class VideoDetailView : ConstraintLayout {
private val _historyIndexLock = Mutex(false); 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 { _historyIndexLock.withLock {
val current = _historyIndex; val current = _historyIndex;
if(current == null || current.url != video.url) { if(current == null || current.url != video.url) {
val index = StateHistory.instance.getHistoryByVideo(video, true)!!; val index = StateHistory.instance.getHistoryByVideo(video, true);
_historyIndex = index; _historyIndex = index;
return@withContext index; return@withContext index;
} }
@ -1390,7 +1390,7 @@ class VideoDetailView : ConstraintLayout {
if (video !is TutorialFragment.TutorialVideo) { if (video !is TutorialFragment.TutorialVideo) {
fragment.lifecycleScope.launch(Dispatchers.IO) { fragment.lifecycleScope.launch(Dispatchers.IO) {
val historyItem = getHistoryIndex(videoDetail); val historyItem = getHistoryIndex(videoDetail) ?: return@launch;
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
_historicalPosition = StateHistory.instance.updateHistoryPosition(video, historyItem,false, (toResume.toFloat() / 1000.0f).toLong()); _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 (updateHistory && (_lastPositionSaveTime == -1L || currentTime - _lastPositionSaveTime > 5000)) {
if (v !is TutorialFragment.TutorialVideo) { if (v !is TutorialFragment.TutorialVideo) {
fragment.lifecycleScope.launch(Dispatchers.IO) { 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()); StateHistory.instance.updateHistoryPosition(v, history, true, (positionMilliseconds.toFloat() / 1000.0f).toLong());
} }
} }

View file

@ -106,7 +106,7 @@ class StateHistory {
if(result == null) if(result == null)
UIDialogs.toast("History creation failed?\nNo history tracking.."); UIDialogs.toast("History creation failed?\nNo history tracking..");
} }
return null; return result;
} }
fun removeHistory(url: String) { fun removeHistory(url: String) {