From 3dc8af4ceff70c442122e11e200ac6e1f7939dca Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 14 Aug 2022 09:59:05 +0200 Subject: [PATCH] cleanup --- .../main/java/com/github/libretube/MyApp.kt | 2 +- .../adapters/SearchHistoryAdapter.kt | 6 ++--- .../libretube/adapters/WatchHistoryAdapter.kt | 4 ++-- .../libretube/{database => db}/AppDatabase.kt | 14 +++++++----- .../{database => db}/DatabaseHelper.kt | 22 +++++++++---------- .../{database => db}/DatabaseHolder.kt | 6 ++--- .../{database => db/dao}/CustomInstanceDao.kt | 4 ++-- .../{database => db/dao}/SearchHistoryDao.kt | 4 ++-- .../{database => db/dao}/WatchHistoryDao.kt | 4 ++-- .../{database => db/dao}/WatchPositionDao.kt | 4 ++-- .../libretube/{ => db}/obj/CustomInstance.kt | 2 +- .../{ => db}/obj/SearchHistoryItem.kt | 2 +- .../{ => db}/obj/WatchHistoryItem.kt | 2 +- .../libretube/{ => db}/obj/WatchPosition.kt | 2 +- .../libretube/dialogs/CustomInstanceDialog.kt | 6 ++--- .../github/libretube/dialogs/ShareDialog.kt | 6 ++--- .../extensions/SetWatchProgressLength.kt | 4 ++-- .../libretube/fragments/PlayerFragment.kt | 6 ++--- .../libretube/fragments/SearchFragment.kt | 4 ++-- .../fragments/SearchResultFragment.kt | 6 ++--- .../fragments/WatchHistoryFragment.kt | 6 ++--- .../libretube/preferences/HistorySettings.kt | 8 +++---- .../libretube/preferences/InstanceSettings.kt | 8 +++---- .../libretube/preferences/PreferenceHelper.kt | 7 +----- 24 files changed, 69 insertions(+), 70 deletions(-) rename app/src/main/java/com/github/libretube/{database => db}/AppDatabase.kt (60%) rename app/src/main/java/com/github/libretube/{database => db}/DatabaseHelper.kt (66%) rename app/src/main/java/com/github/libretube/{database => db}/DatabaseHolder.kt (74%) rename app/src/main/java/com/github/libretube/{database => db/dao}/CustomInstanceDao.kt (85%) rename app/src/main/java/com/github/libretube/{database => db/dao}/SearchHistoryDao.kt (85%) rename app/src/main/java/com/github/libretube/{database => db/dao}/WatchHistoryDao.kt (88%) rename app/src/main/java/com/github/libretube/{database => db/dao}/WatchPositionDao.kt (87%) rename app/src/main/java/com/github/libretube/{ => db}/obj/CustomInstance.kt (88%) rename app/src/main/java/com/github/libretube/{ => db}/obj/SearchHistoryItem.kt (82%) rename app/src/main/java/com/github/libretube/{ => db}/obj/WatchHistoryItem.kt (93%) rename app/src/main/java/com/github/libretube/{ => db}/obj/WatchPosition.kt (87%) diff --git a/app/src/main/java/com/github/libretube/MyApp.kt b/app/src/main/java/com/github/libretube/MyApp.kt index 0cdeaa035..1b864c5f2 100644 --- a/app/src/main/java/com/github/libretube/MyApp.kt +++ b/app/src/main/java/com/github/libretube/MyApp.kt @@ -9,7 +9,7 @@ import android.os.StrictMode import android.os.StrictMode.VmPolicy import androidx.work.ExistingPeriodicWorkPolicy 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.PreferenceKeys import com.github.libretube.util.ExceptionHandler diff --git a/app/src/main/java/com/github/libretube/adapters/SearchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchHistoryAdapter.kt index a0b75f2a3..4db969d87 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchHistoryAdapter.kt @@ -4,9 +4,9 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.widget.SearchView import androidx.recyclerview.widget.RecyclerView -import com.github.libretube.database.DatabaseHolder 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( private var historyList: List, @@ -32,7 +32,7 @@ class SearchHistoryAdapter( deleteHistory.setOnClickListener { historyList -= historyQuery Thread { - DatabaseHolder.database.searchHistoryDao().delete( + DatabaseHolder.db.searchHistoryDao().delete( SearchHistoryItem(query = historyQuery) ) }.start() diff --git a/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt index afddaa614..ff7ba1042 100644 --- a/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt @@ -4,11 +4,11 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView -import com.github.libretube.database.DatabaseHelper 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.extensions.setFormattedDuration -import com.github.libretube.obj.WatchHistoryItem import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.NavigationHelper import com.github.libretube.util.setWatchProgressLength diff --git a/app/src/main/java/com/github/libretube/database/AppDatabase.kt b/app/src/main/java/com/github/libretube/db/AppDatabase.kt similarity index 60% rename from app/src/main/java/com/github/libretube/database/AppDatabase.kt rename to app/src/main/java/com/github/libretube/db/AppDatabase.kt index 4899271af..e919953ea 100644 --- a/app/src/main/java/com/github/libretube/database/AppDatabase.kt +++ b/app/src/main/java/com/github/libretube/db/AppDatabase.kt @@ -1,11 +1,15 @@ -package com.github.libretube.database +package com.github.libretube.db import androidx.room.Database import androidx.room.RoomDatabase -import com.github.libretube.obj.CustomInstance -import com.github.libretube.obj.SearchHistoryItem -import com.github.libretube.obj.WatchHistoryItem -import com.github.libretube.obj.WatchPosition +import com.github.libretube.db.dao.CustomInstanceDao +import com.github.libretube.db.dao.SearchHistoryDao +import com.github.libretube.db.dao.WatchHistoryDao +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( entities = [ diff --git a/app/src/main/java/com/github/libretube/database/DatabaseHelper.kt b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt similarity index 66% rename from app/src/main/java/com/github/libretube/database/DatabaseHelper.kt rename to app/src/main/java/com/github/libretube/db/DatabaseHelper.kt index 84dc1aac9..d56c6e94f 100644 --- a/app/src/main/java/com/github/libretube/database/DatabaseHelper.kt +++ b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt @@ -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.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 @@ -20,15 +20,15 @@ object DatabaseHelper { streams.duration ) Thread { - DatabaseHolder.database.watchHistoryDao().insertAll(watchHistoryItem) + DatabaseHolder.db.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() + val watchHistory = DatabaseHolder.db.watchHistoryDao().getAll() if (watchHistory.size > maxHistorySize.toInt()) { - DatabaseHolder.database.watchHistoryDao() + DatabaseHolder.db.watchHistoryDao() .delete(watchHistory.first()) } }.start() @@ -36,8 +36,8 @@ object DatabaseHelper { fun removeFromWatchHistory(index: Int) { Thread { - DatabaseHolder.database.watchHistoryDao().delete( - DatabaseHolder.database.watchHistoryDao().getAll()[index] + DatabaseHolder.db.watchHistoryDao().delete( + DatabaseHolder.db.watchHistoryDao().getAll()[index] ) }.start() } @@ -48,14 +48,14 @@ object DatabaseHelper { position ) Thread { - DatabaseHolder.database.watchPositionDao().insertAll(watchPosition) + DatabaseHolder.db.watchPositionDao().insertAll(watchPosition) }.start() } fun removeWatchPosition(videoId: String) { Thread { - DatabaseHolder.database.watchPositionDao().delete( - DatabaseHolder.database.watchPositionDao().findById(videoId) + DatabaseHolder.db.watchPositionDao().delete( + DatabaseHolder.db.watchPositionDao().findById(videoId) ) }.start() } diff --git a/app/src/main/java/com/github/libretube/database/DatabaseHolder.kt b/app/src/main/java/com/github/libretube/db/DatabaseHolder.kt similarity index 74% rename from app/src/main/java/com/github/libretube/database/DatabaseHolder.kt rename to app/src/main/java/com/github/libretube/db/DatabaseHolder.kt index 401f95260..2d92fdbcc 100644 --- a/app/src/main/java/com/github/libretube/database/DatabaseHolder.kt +++ b/app/src/main/java/com/github/libretube/db/DatabaseHolder.kt @@ -1,14 +1,14 @@ -package com.github.libretube.database +package com.github.libretube.db import android.content.Context import androidx.room.Room import com.github.libretube.DATABASE_NAME object DatabaseHolder { - lateinit var database: AppDatabase + lateinit var db: AppDatabase fun initializeDatabase(context: Context) { - database = Room.databaseBuilder( + db = Room.databaseBuilder( context, AppDatabase::class.java, DATABASE_NAME diff --git a/app/src/main/java/com/github/libretube/database/CustomInstanceDao.kt b/app/src/main/java/com/github/libretube/db/dao/CustomInstanceDao.kt similarity index 85% rename from app/src/main/java/com/github/libretube/database/CustomInstanceDao.kt rename to app/src/main/java/com/github/libretube/db/dao/CustomInstanceDao.kt index 287abf699..182db494e 100644 --- a/app/src/main/java/com/github/libretube/database/CustomInstanceDao.kt +++ b/app/src/main/java/com/github/libretube/db/dao/CustomInstanceDao.kt @@ -1,11 +1,11 @@ -package com.github.libretube.database +package com.github.libretube.db.dao import androidx.room.Dao import androidx.room.Delete import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.github.libretube.obj.CustomInstance +import com.github.libretube.db.obj.CustomInstance @Dao interface CustomInstanceDao { diff --git a/app/src/main/java/com/github/libretube/database/SearchHistoryDao.kt b/app/src/main/java/com/github/libretube/db/dao/SearchHistoryDao.kt similarity index 85% rename from app/src/main/java/com/github/libretube/database/SearchHistoryDao.kt rename to app/src/main/java/com/github/libretube/db/dao/SearchHistoryDao.kt index 865d670c8..4556d4a13 100644 --- a/app/src/main/java/com/github/libretube/database/SearchHistoryDao.kt +++ b/app/src/main/java/com/github/libretube/db/dao/SearchHistoryDao.kt @@ -1,11 +1,11 @@ -package com.github.libretube.database +package com.github.libretube.db.dao import androidx.room.Dao import androidx.room.Delete import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.github.libretube.obj.SearchHistoryItem +import com.github.libretube.db.obj.SearchHistoryItem @Dao interface SearchHistoryDao { diff --git a/app/src/main/java/com/github/libretube/database/WatchHistoryDao.kt b/app/src/main/java/com/github/libretube/db/dao/WatchHistoryDao.kt similarity index 88% rename from app/src/main/java/com/github/libretube/database/WatchHistoryDao.kt rename to app/src/main/java/com/github/libretube/db/dao/WatchHistoryDao.kt index 6ac076fd4..dfa5b732a 100644 --- a/app/src/main/java/com/github/libretube/database/WatchHistoryDao.kt +++ b/app/src/main/java/com/github/libretube/db/dao/WatchHistoryDao.kt @@ -1,11 +1,11 @@ -package com.github.libretube.database +package com.github.libretube.db.dao import androidx.room.Dao import androidx.room.Delete import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.github.libretube.obj.WatchHistoryItem +import com.github.libretube.db.obj.WatchHistoryItem @Dao interface WatchHistoryDao { diff --git a/app/src/main/java/com/github/libretube/database/WatchPositionDao.kt b/app/src/main/java/com/github/libretube/db/dao/WatchPositionDao.kt similarity index 87% rename from app/src/main/java/com/github/libretube/database/WatchPositionDao.kt rename to app/src/main/java/com/github/libretube/db/dao/WatchPositionDao.kt index d48e79bd1..09ec247ac 100644 --- a/app/src/main/java/com/github/libretube/database/WatchPositionDao.kt +++ b/app/src/main/java/com/github/libretube/db/dao/WatchPositionDao.kt @@ -1,11 +1,11 @@ -package com.github.libretube.database +package com.github.libretube.db.dao import androidx.room.Dao import androidx.room.Delete import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.github.libretube.obj.WatchPosition +import com.github.libretube.db.obj.WatchPosition @Dao interface WatchPositionDao { diff --git a/app/src/main/java/com/github/libretube/obj/CustomInstance.kt b/app/src/main/java/com/github/libretube/db/obj/CustomInstance.kt similarity index 88% rename from app/src/main/java/com/github/libretube/obj/CustomInstance.kt rename to app/src/main/java/com/github/libretube/db/obj/CustomInstance.kt index 110e63ac8..189b24a79 100644 --- a/app/src/main/java/com/github/libretube/obj/CustomInstance.kt +++ b/app/src/main/java/com/github/libretube/db/obj/CustomInstance.kt @@ -1,4 +1,4 @@ -package com.github.libretube.obj +package com.github.libretube.db.obj import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/github/libretube/obj/SearchHistoryItem.kt b/app/src/main/java/com/github/libretube/db/obj/SearchHistoryItem.kt similarity index 82% rename from app/src/main/java/com/github/libretube/obj/SearchHistoryItem.kt rename to app/src/main/java/com/github/libretube/db/obj/SearchHistoryItem.kt index eecb040a9..6a7d0d3c2 100644 --- a/app/src/main/java/com/github/libretube/obj/SearchHistoryItem.kt +++ b/app/src/main/java/com/github/libretube/db/obj/SearchHistoryItem.kt @@ -1,4 +1,4 @@ -package com.github.libretube.obj +package com.github.libretube.db.obj import androidx.room.Entity import androidx.room.PrimaryKey diff --git a/app/src/main/java/com/github/libretube/obj/WatchHistoryItem.kt b/app/src/main/java/com/github/libretube/db/obj/WatchHistoryItem.kt similarity index 93% rename from app/src/main/java/com/github/libretube/obj/WatchHistoryItem.kt rename to app/src/main/java/com/github/libretube/db/obj/WatchHistoryItem.kt index a395ba903..c5fed1b1b 100644 --- a/app/src/main/java/com/github/libretube/obj/WatchHistoryItem.kt +++ b/app/src/main/java/com/github/libretube/db/obj/WatchHistoryItem.kt @@ -1,4 +1,4 @@ -package com.github.libretube.obj +package com.github.libretube.db.obj import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/github/libretube/obj/WatchPosition.kt b/app/src/main/java/com/github/libretube/db/obj/WatchPosition.kt similarity index 87% rename from app/src/main/java/com/github/libretube/obj/WatchPosition.kt rename to app/src/main/java/com/github/libretube/db/obj/WatchPosition.kt index 73b56e51e..bf6a77396 100644 --- a/app/src/main/java/com/github/libretube/obj/WatchPosition.kt +++ b/app/src/main/java/com/github/libretube/db/obj/WatchPosition.kt @@ -1,4 +1,4 @@ -package com.github.libretube.obj +package com.github.libretube.db.obj import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt index fa37fd9fd..48b1f0039 100644 --- a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt @@ -5,9 +5,9 @@ import android.os.Bundle import android.widget.Toast import androidx.fragment.app.DialogFragment import com.github.libretube.R -import com.github.libretube.database.DatabaseHolder 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.google.android.material.dialog.MaterialAlertDialogBuilder import java.net.URL @@ -42,7 +42,7 @@ class CustomInstanceDialog : DialogFragment() { URL(customInstance.frontendUrl).toURI() Thread { - DatabaseHolder.database.customInstanceDao().insertAll(customInstance) + DatabaseHolder.db.customInstanceDao().insertAll(customInstance) }.start() activity?.recreate() diff --git a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt index 01616e7e6..398239287 100644 --- a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt @@ -7,9 +7,9 @@ import androidx.fragment.app.DialogFragment import com.github.libretube.PIPED_FRONTEND_URL import com.github.libretube.R 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.obj.CustomInstance import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceKeys import com.google.android.material.dialog.MaterialAlertDialogBuilder @@ -76,7 +76,7 @@ class ShareDialog( // get the api urls of the other custom instances var customInstances = listOf() Thread { - customInstances = DatabaseHolder.database.customInstanceDao().getAll() + customInstances = DatabaseHolder.db.customInstanceDao().getAll() }.await() // return the custom instance frontend url if available diff --git a/app/src/main/java/com/github/libretube/extensions/SetWatchProgressLength.kt b/app/src/main/java/com/github/libretube/extensions/SetWatchProgressLength.kt index 9d63f6481..f0689deda 100644 --- a/app/src/main/java/com/github/libretube/extensions/SetWatchProgressLength.kt +++ b/app/src/main/java/com/github/libretube/extensions/SetWatchProgressLength.kt @@ -3,7 +3,7 @@ package com.github.libretube.util import android.view.View import android.view.ViewTreeObserver import android.widget.LinearLayout -import com.github.libretube.database.DatabaseHolder +import com.github.libretube.db.DatabaseHolder import com.github.libretube.extensions.await /** @@ -15,7 +15,7 @@ fun View?.setWatchProgressLength(videoId: String, duration: Long) { Thread { try { - progress = DatabaseHolder.database.watchPositionDao().findById(videoId).position + progress = DatabaseHolder.db.watchPositionDao().findById(videoId).position } catch (e: Exception) { progress = null } diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 8ade71ca4..3d7d64e4e 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -40,11 +40,11 @@ import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.api.CronetHelper import com.github.libretube.api.RetrofitInstance 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.ExoStyledPlayerControlViewBinding 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.DownloadDialog import com.github.libretube.dialogs.ShareDialog @@ -941,7 +941,7 @@ class PlayerFragment : BaseFragment() { var position: Long? = null Thread { try { - position = DatabaseHolder.database.watchPositionDao().findById(videoId!!).position + position = DatabaseHolder.db.watchPositionDao().findById(videoId!!).position } catch (e: Exception) { position = null } diff --git a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt index b520d6deb..3e65e37d7 100644 --- a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt @@ -12,8 +12,8 @@ import com.github.libretube.activities.MainActivity import com.github.libretube.adapters.SearchHistoryAdapter import com.github.libretube.adapters.SearchSuggestionsAdapter import com.github.libretube.api.RetrofitInstance -import com.github.libretube.database.DatabaseHolder import com.github.libretube.databinding.FragmentSearchBinding +import com.github.libretube.db.DatabaseHolder import com.github.libretube.extensions.BaseFragment import com.github.libretube.extensions.TAG import com.github.libretube.extensions.await @@ -92,7 +92,7 @@ class SearchFragment() : BaseFragment() { private fun showHistory() { var historyList = listOf() Thread { - val history = DatabaseHolder.database.searchHistoryDao().getAll() + val history = DatabaseHolder.db.searchHistoryDao().getAll() historyList = history.map { it.query } }.await() if (historyList.isNotEmpty()) { diff --git a/app/src/main/java/com/github/libretube/fragments/SearchResultFragment.kt b/app/src/main/java/com/github/libretube/fragments/SearchResultFragment.kt index ad8cd74bb..8019812e9 100644 --- a/app/src/main/java/com/github/libretube/fragments/SearchResultFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SearchResultFragment.kt @@ -10,12 +10,12 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.R import com.github.libretube.adapters.SearchAdapter import com.github.libretube.api.RetrofitInstance -import com.github.libretube.database.DatabaseHolder 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.TAG import com.github.libretube.extensions.await -import com.github.libretube.obj.SearchHistoryItem import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.util.hideKeyboard @@ -136,7 +136,7 @@ class SearchResultFragment : BaseFragment() { PreferenceHelper.getBoolean(PreferenceKeys.SEARCH_HISTORY_TOGGLE, true) if (searchHistoryEnabled && query != "") { Thread { - DatabaseHolder.database.searchHistoryDao().insertAll( + DatabaseHolder.db.searchHistoryDao().insertAll( SearchHistoryItem( query = query ) 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 3c602b86c..4ef54c47c 100644 --- a/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt @@ -8,11 +8,11 @@ import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.github.libretube.adapters.WatchHistoryAdapter -import com.github.libretube.database.DatabaseHolder 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.await -import com.github.libretube.obj.WatchHistoryItem class WatchHistoryFragment : BaseFragment() { private lateinit var binding: FragmentWatchHistoryBinding @@ -32,7 +32,7 @@ class WatchHistoryFragment : BaseFragment() { var watchHistory = listOf() Thread { - watchHistory = DatabaseHolder.database.watchHistoryDao().getAll() + watchHistory = DatabaseHolder.db.watchHistoryDao().getAll() }.await() if (watchHistory.isEmpty()) return diff --git a/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt b/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt index 699e89cc5..640bbf880 100644 --- a/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt @@ -4,7 +4,7 @@ import android.os.Bundle import androidx.preference.Preference import com.github.libretube.R 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.google.android.material.dialog.MaterialAlertDialogBuilder @@ -20,7 +20,7 @@ class HistorySettings : MaterialPreferenceFragment() { val clearHistory = findPreference(PreferenceKeys.CLEAR_SEARCH_HISTORY) clearHistory?.setOnPreferenceClickListener { showClearDialog(R.string.clear_history) { - DatabaseHolder.database.searchHistoryDao().deleteAll() + DatabaseHolder.db.searchHistoryDao().deleteAll() } true } @@ -29,7 +29,7 @@ class HistorySettings : MaterialPreferenceFragment() { val clearWatchHistory = findPreference(PreferenceKeys.CLEAR_WATCH_HISTORY) clearWatchHistory?.setOnPreferenceClickListener { showClearDialog(R.string.clear_history) { - DatabaseHolder.database.watchHistoryDao().deleteAll() + DatabaseHolder.db.watchHistoryDao().deleteAll() } true } @@ -38,7 +38,7 @@ class HistorySettings : MaterialPreferenceFragment() { val clearWatchPositions = findPreference(PreferenceKeys.CLEAR_WATCH_POSITIONS) clearWatchPositions?.setOnPreferenceClickListener { showClearDialog(R.string.reset_watch_positions) { - DatabaseHolder.database.watchPositionDao().deleteAll() + DatabaseHolder.db.watchPositionDao().deleteAll() } true } diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt index b23dc06e1..ddf4cf02e 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -13,13 +13,13 @@ import androidx.preference.SwitchPreferenceCompat import com.github.libretube.R import com.github.libretube.activities.SettingsActivity 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.DeleteAccountDialog import com.github.libretube.dialogs.LoginDialog import com.github.libretube.dialogs.LogoutDialog import com.github.libretube.extensions.await -import com.github.libretube.obj.CustomInstance import com.github.libretube.util.ImportHelper import com.github.libretube.util.PermissionHelper import com.github.libretube.views.MaterialPreferenceFragment @@ -106,7 +106,7 @@ class InstanceSettings : MaterialPreferenceFragment() { val clearCustomInstances = findPreference(PreferenceKeys.CLEAR_CUSTOM_INSTANCES) clearCustomInstances?.setOnPreferenceClickListener { Thread { - DatabaseHolder.database.customInstanceDao().deleteAll() + DatabaseHolder.db.customInstanceDao().deleteAll() }.await() activity?.recreate() true @@ -161,7 +161,7 @@ class InstanceSettings : MaterialPreferenceFragment() { lifecycleScope.launchWhenCreated { var customInstances = listOf() Thread { - customInstances = DatabaseHolder.database.customInstanceDao().getAll() + customInstances = DatabaseHolder.db.customInstanceDao().getAll() }.await() val instanceNames = arrayListOf() diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt index e2707e844..9fe00b195 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt @@ -7,9 +7,6 @@ import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.ObjectMapper object PreferenceHelper { - - private lateinit var prefContext: Context - /** * for normal preferences */ @@ -28,9 +25,7 @@ object PreferenceHelper { * set the context that is being used to access the shared preferences */ fun setContext(context: Context) { - prefContext = context - - settings = getDefaultSharedPreferences(prefContext) + settings = getDefaultSharedPreferences(context) editor = settings.edit() authSettings = getAuthenticationPreferences(context)