This commit is contained in:
Bnyro 2022-08-13 23:19:07 +02:00
parent 6da00f912e
commit 7eb83716c5
2 changed files with 82 additions and 69 deletions

View File

@ -89,7 +89,10 @@ class MainActivity : BaseActivity() {
if (!ConnectionHelper.isNetworkAvailable(this)) {
val noInternetIntent = Intent(this, NoInternetActivity::class.java)
startActivity(noInternetIntent)
} else {
finish()
return
}
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
@ -158,7 +161,6 @@ class MainActivity : BaseActivity() {
}
binding.toolbar.title = ThemeHelper.getStyledAppName(this)
}
/**
* handle error logs

View File

@ -3,6 +3,8 @@ package com.github.libretube.database
import com.github.libretube.obj.Streams
import com.github.libretube.obj.WatchHistoryItem
import com.github.libretube.obj.WatchPosition
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.toID
object DatabaseHelper {
@ -19,6 +21,15 @@ object DatabaseHelper {
)
Thread {
DatabaseHolder.database.watchHistoryDao().insertAll(watchHistoryItem)
val maxHistorySize = PreferenceHelper.getString(PreferenceKeys.WATCH_HISTORY_SIZE, "unlimited")
if (maxHistorySize == "unlimited") return@Thread
// delete the first watch history entry if the limit is reached
val watchHistory = DatabaseHolder.database.watchHistoryDao().getAll()
if (watchHistory.size > maxHistorySize.toInt()) {
DatabaseHolder.database.watchHistoryDao()
.delete(watchHistory.first())
}
}.start()
}