mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
cleanup
This commit is contained in:
parent
e1b078ecd8
commit
3dc8af4cef
@ -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
|
||||
|
@ -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<String>,
|
||||
@ -32,7 +32,7 @@ class SearchHistoryAdapter(
|
||||
deleteHistory.setOnClickListener {
|
||||
historyList -= historyQuery
|
||||
Thread {
|
||||
DatabaseHolder.database.searchHistoryDao().delete(
|
||||
DatabaseHolder.db.searchHistoryDao().delete(
|
||||
SearchHistoryItem(query = historyQuery)
|
||||
)
|
||||
}.start()
|
||||
|
@ -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
|
||||
|
@ -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 = [
|
@ -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()
|
||||
}
|
@ -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
|
@ -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 {
|
@ -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 {
|
@ -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 {
|
@ -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 {
|
@ -1,4 +1,4 @@
|
||||
package com.github.libretube.obj
|
||||
package com.github.libretube.db.obj
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
@ -1,4 +1,4 @@
|
||||
package com.github.libretube.obj
|
||||
package com.github.libretube.db.obj
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
@ -1,4 +1,4 @@
|
||||
package com.github.libretube.obj
|
||||
package com.github.libretube.db.obj
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
@ -1,4 +1,4 @@
|
||||
package com.github.libretube.obj
|
||||
package com.github.libretube.db.obj
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
@ -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()
|
||||
|
@ -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<CustomInstance>()
|
||||
Thread {
|
||||
customInstances = DatabaseHolder.database.customInstanceDao().getAll()
|
||||
customInstances = DatabaseHolder.db.customInstanceDao().getAll()
|
||||
}.await()
|
||||
|
||||
// return the custom instance frontend url if available
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<String>()
|
||||
Thread {
|
||||
val history = DatabaseHolder.database.searchHistoryDao().getAll()
|
||||
val history = DatabaseHolder.db.searchHistoryDao().getAll()
|
||||
historyList = history.map { it.query }
|
||||
}.await()
|
||||
if (historyList.isNotEmpty()) {
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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<WatchHistoryItem>()
|
||||
|
||||
Thread {
|
||||
watchHistory = DatabaseHolder.database.watchHistoryDao().getAll()
|
||||
watchHistory = DatabaseHolder.db.watchHistoryDao().getAll()
|
||||
}.await()
|
||||
|
||||
if (watchHistory.isEmpty()) return
|
||||
|
@ -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<Preference>(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<Preference>(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<Preference>(PreferenceKeys.CLEAR_WATCH_POSITIONS)
|
||||
clearWatchPositions?.setOnPreferenceClickListener {
|
||||
showClearDialog(R.string.reset_watch_positions) {
|
||||
DatabaseHolder.database.watchPositionDao().deleteAll()
|
||||
DatabaseHolder.db.watchPositionDao().deleteAll()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
@ -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<Preference>(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<CustomInstance>()
|
||||
Thread {
|
||||
customInstances = DatabaseHolder.database.customInstanceDao().getAll()
|
||||
customInstances = DatabaseHolder.db.customInstanceDao().getAll()
|
||||
}.await()
|
||||
|
||||
val instanceNames = arrayListOf<String>()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user