This commit is contained in:
Bnyro 2022-08-14 09:59:05 +02:00
parent e1b078ecd8
commit 3dc8af4cef
24 changed files with 69 additions and 70 deletions

View File

@ -9,7 +9,7 @@ import android.os.StrictMode
import android.os.StrictMode.VmPolicy import android.os.StrictMode.VmPolicy
import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.ExistingPeriodicWorkPolicy
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.database.DatabaseHolder import com.github.libretube.db.DatabaseHolder
import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.ExceptionHandler import com.github.libretube.util.ExceptionHandler

View File

@ -4,9 +4,9 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.database.DatabaseHolder
import com.github.libretube.databinding.SearchhistoryRowBinding import com.github.libretube.databinding.SearchhistoryRowBinding
import com.github.libretube.obj.SearchHistoryItem import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.SearchHistoryItem
class SearchHistoryAdapter( class SearchHistoryAdapter(
private var historyList: List<String>, private var historyList: List<String>,
@ -32,7 +32,7 @@ class SearchHistoryAdapter(
deleteHistory.setOnClickListener { deleteHistory.setOnClickListener {
historyList -= historyQuery historyList -= historyQuery
Thread { Thread {
DatabaseHolder.database.searchHistoryDao().delete( DatabaseHolder.db.searchHistoryDao().delete(
SearchHistoryItem(query = historyQuery) SearchHistoryItem(query = historyQuery)
) )
}.start() }.start()

View File

@ -4,11 +4,11 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.database.DatabaseHelper
import com.github.libretube.databinding.WatchHistoryRowBinding import com.github.libretube.databinding.WatchHistoryRowBinding
import com.github.libretube.db.DatabaseHelper
import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.dialogs.VideoOptionsDialog import com.github.libretube.dialogs.VideoOptionsDialog
import com.github.libretube.extensions.setFormattedDuration import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.obj.WatchHistoryItem
import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.ConnectionHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.setWatchProgressLength import com.github.libretube.util.setWatchProgressLength

View File

@ -1,11 +1,15 @@
package com.github.libretube.database package com.github.libretube.db
import androidx.room.Database import androidx.room.Database
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import com.github.libretube.obj.CustomInstance import com.github.libretube.db.dao.CustomInstanceDao
import com.github.libretube.obj.SearchHistoryItem import com.github.libretube.db.dao.SearchHistoryDao
import com.github.libretube.obj.WatchHistoryItem import com.github.libretube.db.dao.WatchHistoryDao
import com.github.libretube.obj.WatchPosition import com.github.libretube.db.dao.WatchPositionDao
import com.github.libretube.db.obj.CustomInstance
import com.github.libretube.db.obj.SearchHistoryItem
import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.db.obj.WatchPosition
@Database( @Database(
entities = [ entities = [

View File

@ -1,8 +1,8 @@
package com.github.libretube.database package com.github.libretube.db
import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.db.obj.WatchPosition
import com.github.libretube.obj.Streams 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.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.toID import com.github.libretube.util.toID
@ -20,15 +20,15 @@ object DatabaseHelper {
streams.duration streams.duration
) )
Thread { Thread {
DatabaseHolder.database.watchHistoryDao().insertAll(watchHistoryItem) DatabaseHolder.db.watchHistoryDao().insertAll(watchHistoryItem)
val maxHistorySize = val maxHistorySize =
PreferenceHelper.getString(PreferenceKeys.WATCH_HISTORY_SIZE, "unlimited") PreferenceHelper.getString(PreferenceKeys.WATCH_HISTORY_SIZE, "unlimited")
if (maxHistorySize == "unlimited") return@Thread if (maxHistorySize == "unlimited") return@Thread
// delete the first watch history entry if the limit is reached // delete the first watch history entry if the limit is reached
val watchHistory = DatabaseHolder.database.watchHistoryDao().getAll() val watchHistory = DatabaseHolder.db.watchHistoryDao().getAll()
if (watchHistory.size > maxHistorySize.toInt()) { if (watchHistory.size > maxHistorySize.toInt()) {
DatabaseHolder.database.watchHistoryDao() DatabaseHolder.db.watchHistoryDao()
.delete(watchHistory.first()) .delete(watchHistory.first())
} }
}.start() }.start()
@ -36,8 +36,8 @@ object DatabaseHelper {
fun removeFromWatchHistory(index: Int) { fun removeFromWatchHistory(index: Int) {
Thread { Thread {
DatabaseHolder.database.watchHistoryDao().delete( DatabaseHolder.db.watchHistoryDao().delete(
DatabaseHolder.database.watchHistoryDao().getAll()[index] DatabaseHolder.db.watchHistoryDao().getAll()[index]
) )
}.start() }.start()
} }
@ -48,14 +48,14 @@ object DatabaseHelper {
position position
) )
Thread { Thread {
DatabaseHolder.database.watchPositionDao().insertAll(watchPosition) DatabaseHolder.db.watchPositionDao().insertAll(watchPosition)
}.start() }.start()
} }
fun removeWatchPosition(videoId: String) { fun removeWatchPosition(videoId: String) {
Thread { Thread {
DatabaseHolder.database.watchPositionDao().delete( DatabaseHolder.db.watchPositionDao().delete(
DatabaseHolder.database.watchPositionDao().findById(videoId) DatabaseHolder.db.watchPositionDao().findById(videoId)
) )
}.start() }.start()
} }

View File

@ -1,14 +1,14 @@
package com.github.libretube.database package com.github.libretube.db
import android.content.Context import android.content.Context
import androidx.room.Room import androidx.room.Room
import com.github.libretube.DATABASE_NAME import com.github.libretube.DATABASE_NAME
object DatabaseHolder { object DatabaseHolder {
lateinit var database: AppDatabase lateinit var db: AppDatabase
fun initializeDatabase(context: Context) { fun initializeDatabase(context: Context) {
database = Room.databaseBuilder( db = Room.databaseBuilder(
context, context,
AppDatabase::class.java, AppDatabase::class.java,
DATABASE_NAME DATABASE_NAME

View File

@ -1,11 +1,11 @@
package com.github.libretube.database package com.github.libretube.db.dao
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Delete import androidx.room.Delete
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import com.github.libretube.obj.CustomInstance import com.github.libretube.db.obj.CustomInstance
@Dao @Dao
interface CustomInstanceDao { interface CustomInstanceDao {

View File

@ -1,11 +1,11 @@
package com.github.libretube.database package com.github.libretube.db.dao
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Delete import androidx.room.Delete
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import com.github.libretube.obj.SearchHistoryItem import com.github.libretube.db.obj.SearchHistoryItem
@Dao @Dao
interface SearchHistoryDao { interface SearchHistoryDao {

View File

@ -1,11 +1,11 @@
package com.github.libretube.database package com.github.libretube.db.dao
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Delete import androidx.room.Delete
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import com.github.libretube.obj.WatchHistoryItem import com.github.libretube.db.obj.WatchHistoryItem
@Dao @Dao
interface WatchHistoryDao { interface WatchHistoryDao {

View File

@ -1,11 +1,11 @@
package com.github.libretube.database package com.github.libretube.db.dao
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Delete import androidx.room.Delete
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import com.github.libretube.obj.WatchPosition import com.github.libretube.db.obj.WatchPosition
@Dao @Dao
interface WatchPositionDao { interface WatchPositionDao {

View File

@ -1,4 +1,4 @@
package com.github.libretube.obj package com.github.libretube.db.obj
import androidx.room.ColumnInfo import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity

View File

@ -1,4 +1,4 @@
package com.github.libretube.obj package com.github.libretube.db.obj
import androidx.room.Entity import androidx.room.Entity
import androidx.room.PrimaryKey import androidx.room.PrimaryKey

View File

@ -1,4 +1,4 @@
package com.github.libretube.obj package com.github.libretube.db.obj
import androidx.room.ColumnInfo import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity

View File

@ -1,4 +1,4 @@
package com.github.libretube.obj package com.github.libretube.db.obj
import androidx.room.ColumnInfo import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity

View File

@ -5,9 +5,9 @@ import android.os.Bundle
import android.widget.Toast import android.widget.Toast
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.database.DatabaseHolder
import com.github.libretube.databinding.DialogCustomInstanceBinding import com.github.libretube.databinding.DialogCustomInstanceBinding
import com.github.libretube.obj.CustomInstance import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.CustomInstance
import com.github.libretube.util.ThemeHelper import com.github.libretube.util.ThemeHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.net.URL import java.net.URL
@ -42,7 +42,7 @@ class CustomInstanceDialog : DialogFragment() {
URL(customInstance.frontendUrl).toURI() URL(customInstance.frontendUrl).toURI()
Thread { Thread {
DatabaseHolder.database.customInstanceDao().insertAll(customInstance) DatabaseHolder.db.customInstanceDao().insertAll(customInstance)
}.start() }.start()
activity?.recreate() activity?.recreate()

View File

@ -7,9 +7,9 @@ import androidx.fragment.app.DialogFragment
import com.github.libretube.PIPED_FRONTEND_URL import com.github.libretube.PIPED_FRONTEND_URL
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.YOUTUBE_FRONTEND_URL import com.github.libretube.YOUTUBE_FRONTEND_URL
import com.github.libretube.database.DatabaseHolder import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.CustomInstance
import com.github.libretube.extensions.await import com.github.libretube.extensions.await
import com.github.libretube.obj.CustomInstance
import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.preferences.PreferenceKeys
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -76,7 +76,7 @@ class ShareDialog(
// get the api urls of the other custom instances // get the api urls of the other custom instances
var customInstances = listOf<CustomInstance>() var customInstances = listOf<CustomInstance>()
Thread { Thread {
customInstances = DatabaseHolder.database.customInstanceDao().getAll() customInstances = DatabaseHolder.db.customInstanceDao().getAll()
}.await() }.await()
// return the custom instance frontend url if available // return the custom instance frontend url if available

View File

@ -3,7 +3,7 @@ package com.github.libretube.util
import android.view.View import android.view.View
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.widget.LinearLayout import android.widget.LinearLayout
import com.github.libretube.database.DatabaseHolder import com.github.libretube.db.DatabaseHolder
import com.github.libretube.extensions.await import com.github.libretube.extensions.await
/** /**
@ -15,7 +15,7 @@ fun View?.setWatchProgressLength(videoId: String, duration: Long) {
Thread { Thread {
try { try {
progress = DatabaseHolder.database.watchPositionDao().findById(videoId).position progress = DatabaseHolder.db.watchPositionDao().findById(videoId).position
} catch (e: Exception) { } catch (e: Exception) {
progress = null progress = null
} }

View File

@ -40,11 +40,11 @@ import com.github.libretube.adapters.TrendingAdapter
import com.github.libretube.api.CronetHelper import com.github.libretube.api.CronetHelper
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.database.DatabaseHelper
import com.github.libretube.database.DatabaseHolder
import com.github.libretube.databinding.DoubleTapOverlayBinding import com.github.libretube.databinding.DoubleTapOverlayBinding
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.databinding.FragmentPlayerBinding import com.github.libretube.databinding.FragmentPlayerBinding
import com.github.libretube.db.DatabaseHelper
import com.github.libretube.db.DatabaseHolder
import com.github.libretube.dialogs.AddToPlaylistDialog import com.github.libretube.dialogs.AddToPlaylistDialog
import com.github.libretube.dialogs.DownloadDialog import com.github.libretube.dialogs.DownloadDialog
import com.github.libretube.dialogs.ShareDialog import com.github.libretube.dialogs.ShareDialog
@ -941,7 +941,7 @@ class PlayerFragment : BaseFragment() {
var position: Long? = null var position: Long? = null
Thread { Thread {
try { try {
position = DatabaseHolder.database.watchPositionDao().findById(videoId!!).position position = DatabaseHolder.db.watchPositionDao().findById(videoId!!).position
} catch (e: Exception) { } catch (e: Exception) {
position = null position = null
} }

View File

@ -12,8 +12,8 @@ import com.github.libretube.activities.MainActivity
import com.github.libretube.adapters.SearchHistoryAdapter import com.github.libretube.adapters.SearchHistoryAdapter
import com.github.libretube.adapters.SearchSuggestionsAdapter import com.github.libretube.adapters.SearchSuggestionsAdapter
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.database.DatabaseHolder
import com.github.libretube.databinding.FragmentSearchBinding import com.github.libretube.databinding.FragmentSearchBinding
import com.github.libretube.db.DatabaseHolder
import com.github.libretube.extensions.BaseFragment import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.await import com.github.libretube.extensions.await
@ -92,7 +92,7 @@ class SearchFragment() : BaseFragment() {
private fun showHistory() { private fun showHistory() {
var historyList = listOf<String>() var historyList = listOf<String>()
Thread { Thread {
val history = DatabaseHolder.database.searchHistoryDao().getAll() val history = DatabaseHolder.db.searchHistoryDao().getAll()
historyList = history.map { it.query } historyList = history.map { it.query }
}.await() }.await()
if (historyList.isNotEmpty()) { if (historyList.isNotEmpty()) {

View File

@ -10,12 +10,12 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.adapters.SearchAdapter import com.github.libretube.adapters.SearchAdapter
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.database.DatabaseHolder
import com.github.libretube.databinding.FragmentSearchResultBinding import com.github.libretube.databinding.FragmentSearchResultBinding
import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.SearchHistoryItem
import com.github.libretube.extensions.BaseFragment import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.await import com.github.libretube.extensions.await
import com.github.libretube.obj.SearchHistoryItem
import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.hideKeyboard import com.github.libretube.util.hideKeyboard
@ -136,7 +136,7 @@ class SearchResultFragment : BaseFragment() {
PreferenceHelper.getBoolean(PreferenceKeys.SEARCH_HISTORY_TOGGLE, true) PreferenceHelper.getBoolean(PreferenceKeys.SEARCH_HISTORY_TOGGLE, true)
if (searchHistoryEnabled && query != "") { if (searchHistoryEnabled && query != "") {
Thread { Thread {
DatabaseHolder.database.searchHistoryDao().insertAll( DatabaseHolder.db.searchHistoryDao().insertAll(
SearchHistoryItem( SearchHistoryItem(
query = query query = query
) )

View File

@ -8,11 +8,11 @@ import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.adapters.WatchHistoryAdapter import com.github.libretube.adapters.WatchHistoryAdapter
import com.github.libretube.database.DatabaseHolder
import com.github.libretube.databinding.FragmentWatchHistoryBinding import com.github.libretube.databinding.FragmentWatchHistoryBinding
import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.extensions.BaseFragment import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.await import com.github.libretube.extensions.await
import com.github.libretube.obj.WatchHistoryItem
class WatchHistoryFragment : BaseFragment() { class WatchHistoryFragment : BaseFragment() {
private lateinit var binding: FragmentWatchHistoryBinding private lateinit var binding: FragmentWatchHistoryBinding
@ -32,7 +32,7 @@ class WatchHistoryFragment : BaseFragment() {
var watchHistory = listOf<WatchHistoryItem>() var watchHistory = listOf<WatchHistoryItem>()
Thread { Thread {
watchHistory = DatabaseHolder.database.watchHistoryDao().getAll() watchHistory = DatabaseHolder.db.watchHistoryDao().getAll()
}.await() }.await()
if (watchHistory.isEmpty()) return if (watchHistory.isEmpty()) return

View File

@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.preference.Preference import androidx.preference.Preference
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity import com.github.libretube.activities.SettingsActivity
import com.github.libretube.database.DatabaseHolder import com.github.libretube.db.DatabaseHolder
import com.github.libretube.views.MaterialPreferenceFragment import com.github.libretube.views.MaterialPreferenceFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -20,7 +20,7 @@ class HistorySettings : MaterialPreferenceFragment() {
val clearHistory = findPreference<Preference>(PreferenceKeys.CLEAR_SEARCH_HISTORY) val clearHistory = findPreference<Preference>(PreferenceKeys.CLEAR_SEARCH_HISTORY)
clearHistory?.setOnPreferenceClickListener { clearHistory?.setOnPreferenceClickListener {
showClearDialog(R.string.clear_history) { showClearDialog(R.string.clear_history) {
DatabaseHolder.database.searchHistoryDao().deleteAll() DatabaseHolder.db.searchHistoryDao().deleteAll()
} }
true true
} }
@ -29,7 +29,7 @@ class HistorySettings : MaterialPreferenceFragment() {
val clearWatchHistory = findPreference<Preference>(PreferenceKeys.CLEAR_WATCH_HISTORY) val clearWatchHistory = findPreference<Preference>(PreferenceKeys.CLEAR_WATCH_HISTORY)
clearWatchHistory?.setOnPreferenceClickListener { clearWatchHistory?.setOnPreferenceClickListener {
showClearDialog(R.string.clear_history) { showClearDialog(R.string.clear_history) {
DatabaseHolder.database.watchHistoryDao().deleteAll() DatabaseHolder.db.watchHistoryDao().deleteAll()
} }
true true
} }
@ -38,7 +38,7 @@ class HistorySettings : MaterialPreferenceFragment() {
val clearWatchPositions = findPreference<Preference>(PreferenceKeys.CLEAR_WATCH_POSITIONS) val clearWatchPositions = findPreference<Preference>(PreferenceKeys.CLEAR_WATCH_POSITIONS)
clearWatchPositions?.setOnPreferenceClickListener { clearWatchPositions?.setOnPreferenceClickListener {
showClearDialog(R.string.reset_watch_positions) { showClearDialog(R.string.reset_watch_positions) {
DatabaseHolder.database.watchPositionDao().deleteAll() DatabaseHolder.db.watchPositionDao().deleteAll()
} }
true true
} }

View File

@ -13,13 +13,13 @@ import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity import com.github.libretube.activities.SettingsActivity
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.database.DatabaseHolder import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.CustomInstance
import com.github.libretube.dialogs.CustomInstanceDialog import com.github.libretube.dialogs.CustomInstanceDialog
import com.github.libretube.dialogs.DeleteAccountDialog import com.github.libretube.dialogs.DeleteAccountDialog
import com.github.libretube.dialogs.LoginDialog import com.github.libretube.dialogs.LoginDialog
import com.github.libretube.dialogs.LogoutDialog import com.github.libretube.dialogs.LogoutDialog
import com.github.libretube.extensions.await import com.github.libretube.extensions.await
import com.github.libretube.obj.CustomInstance
import com.github.libretube.util.ImportHelper import com.github.libretube.util.ImportHelper
import com.github.libretube.util.PermissionHelper import com.github.libretube.util.PermissionHelper
import com.github.libretube.views.MaterialPreferenceFragment import com.github.libretube.views.MaterialPreferenceFragment
@ -106,7 +106,7 @@ class InstanceSettings : MaterialPreferenceFragment() {
val clearCustomInstances = findPreference<Preference>(PreferenceKeys.CLEAR_CUSTOM_INSTANCES) val clearCustomInstances = findPreference<Preference>(PreferenceKeys.CLEAR_CUSTOM_INSTANCES)
clearCustomInstances?.setOnPreferenceClickListener { clearCustomInstances?.setOnPreferenceClickListener {
Thread { Thread {
DatabaseHolder.database.customInstanceDao().deleteAll() DatabaseHolder.db.customInstanceDao().deleteAll()
}.await() }.await()
activity?.recreate() activity?.recreate()
true true
@ -161,7 +161,7 @@ class InstanceSettings : MaterialPreferenceFragment() {
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
var customInstances = listOf<CustomInstance>() var customInstances = listOf<CustomInstance>()
Thread { Thread {
customInstances = DatabaseHolder.database.customInstanceDao().getAll() customInstances = DatabaseHolder.db.customInstanceDao().getAll()
}.await() }.await()
val instanceNames = arrayListOf<String>() val instanceNames = arrayListOf<String>()

View File

@ -7,9 +7,6 @@ import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
object PreferenceHelper { object PreferenceHelper {
private lateinit var prefContext: Context
/** /**
* for normal preferences * for normal preferences
*/ */
@ -28,9 +25,7 @@ object PreferenceHelper {
* set the context that is being used to access the shared preferences * set the context that is being used to access the shared preferences
*/ */
fun setContext(context: Context) { fun setContext(context: Context) {
prefContext = context settings = getDefaultSharedPreferences(context)
settings = getDefaultSharedPreferences(prefContext)
editor = settings.edit() editor = settings.edit()
authSettings = getAuthenticationPreferences(context) authSettings = getAuthenticationPreferences(context)