From 17626419a2ab96359f86949f58ffd860313c0e19 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 13 Aug 2022 20:11:56 +0200 Subject: [PATCH] bug fixes --- app/build.gradle | 3 +++ .../com/github/libretube/database/DatabaseHelper.kt | 4 +++- .../github/libretube/fragments/WatchHistoryFragment.kt | 10 +++++++++- .../java/com/github/libretube/obj/WatchHistoryItem.kt | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c2270bbd7..8b156c10f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,6 +4,7 @@ plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-android-extensions' + id 'kotlin-kapt' } android { @@ -74,6 +75,8 @@ android { dependencies { //debugImplementation libs.square.leakcanary + kapt "androidx.room:room-compiler:2.4.3" + implementation libs.androidx.appcompat implementation libs.androidx.constraintlayout implementation libs.androidx.legacySupport diff --git a/app/src/main/java/com/github/libretube/database/DatabaseHelper.kt b/app/src/main/java/com/github/libretube/database/DatabaseHelper.kt index 92031a2e0..1585f3797 100644 --- a/app/src/main/java/com/github/libretube/database/DatabaseHelper.kt +++ b/app/src/main/java/com/github/libretube/database/DatabaseHelper.kt @@ -16,6 +16,8 @@ object DatabaseHelper { streams.thumbnailUrl, streams.duration ) - DatabaseHolder.database.watchHistoryDao().insertAll(watchHistoryItem) + Thread { + DatabaseHolder.database.watchHistoryDao().insertAll(watchHistoryItem) + }.start() } } diff --git a/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt b/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt index ad3c45a13..a3471392f 100644 --- a/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt @@ -11,6 +11,8 @@ import com.github.libretube.adapters.WatchHistoryAdapter import com.github.libretube.database.DatabaseHolder import com.github.libretube.databinding.FragmentWatchHistoryBinding import com.github.libretube.extensions.BaseFragment +import com.github.libretube.obj.WatchHistoryItem +import kotlinx.coroutines.runBlocking class WatchHistoryFragment : BaseFragment() { private val TAG = "WatchHistoryFragment" @@ -28,7 +30,13 @@ class WatchHistoryFragment : BaseFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val watchHistory = DatabaseHolder.database.watchHistoryDao().getAll() + var watchHistory = listOf() + + val thread = Thread { + watchHistory = DatabaseHolder.database.watchHistoryDao().getAll() + } + thread.start() + thread.join() if (watchHistory.isEmpty()) return diff --git a/app/src/main/java/com/github/libretube/obj/WatchHistoryItem.kt b/app/src/main/java/com/github/libretube/obj/WatchHistoryItem.kt index e4cffc9e4..a395ba903 100644 --- a/app/src/main/java/com/github/libretube/obj/WatchHistoryItem.kt +++ b/app/src/main/java/com/github/libretube/obj/WatchHistoryItem.kt @@ -6,7 +6,7 @@ import androidx.room.PrimaryKey @Entity(tableName = "watchHistoryItem") data class WatchHistoryItem( - @PrimaryKey val videoId: String? = null, + @PrimaryKey val videoId: String = "", @ColumnInfo val title: String? = null, @ColumnInfo val uploadDate: String? = null, @ColumnInfo val uploader: String? = null,