database: move databases to feature modules

Move all databases to their respective feature modules. This makes
things a bit easier to work with.
This commit is contained in:
OxygenCobalt 2021-08-15 15:49:02 -06:00
parent c5b1293a90
commit 267578d606
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
9 changed files with 18 additions and 39 deletions

View file

@ -1,29 +0,0 @@
/*
* Copyright (c) 2021 Auxio Project
* DatabaseUtils.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.database
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
/**
* Shortcut for querying all items in a database and running [block] with the cursor returned.
* Will not run if the cursor is null.
*/
fun <R> SQLiteDatabase.queryAll(tableName: String, block: (Cursor) -> R) =
query(tableName, null, null, null, null, null, null)?.use(block)

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.database
package org.oxycblt.auxio.music
import android.content.ContentValues
import android.content.Context
@ -25,6 +25,7 @@ import android.database.sqlite.SQLiteOpenHelper
import androidx.core.database.sqlite.transaction
import org.oxycblt.auxio.logD
import org.oxycblt.auxio.ui.assertBackgroundThread
import org.oxycblt.auxio.ui.queryAll
/**
* Database for storing blacklisted paths.

View file

@ -27,7 +27,6 @@ import android.provider.MediaStore.Audio.Genres
import android.provider.MediaStore.Audio.Media
import androidx.core.database.getStringOrNull
import org.oxycblt.auxio.R
import org.oxycblt.auxio.database.BlacklistDatabase
import org.oxycblt.auxio.logD
/**

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.database
package org.oxycblt.auxio.playback.state
/**
* A database entity that stores a compressed variant of the current playback state.

View file

@ -16,13 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.database
package org.oxycblt.auxio.playback.state
import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import androidx.core.database.sqlite.transaction
import org.oxycblt.auxio.ui.queryAll
import org.oxycblt.auxio.logD
import org.oxycblt.auxio.ui.assertBackgroundThread

View file

@ -21,9 +21,6 @@ package org.oxycblt.auxio.playback.state
import android.content.Context
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.oxycblt.auxio.database.PlaybackState
import org.oxycblt.auxio.database.PlaybackStateDatabase
import org.oxycblt.auxio.database.QueueItem
import org.oxycblt.auxio.logD
import org.oxycblt.auxio.logE
import org.oxycblt.auxio.music.Album

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.database
package org.oxycblt.auxio.playback.state
/**
* A database entity that stores a simplified representation of a song in a queue.

View file

@ -27,7 +27,7 @@ import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.oxycblt.auxio.database.BlacklistDatabase
import org.oxycblt.auxio.music.BlacklistDatabase
/**
* ViewModel that acts as a wrapper around [BlacklistDatabase], allowing for the addition/removal

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2021 Auxio Project
* InterfaceUtils.kt is part of Auxio.
* AndroidUtils.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,6 +25,8 @@ import android.content.Intent
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.content.res.Resources
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.graphics.drawable.AnimatedVectorDrawable
import android.graphics.drawable.Drawable
import android.os.Build
@ -198,6 +200,14 @@ fun Context.newMainIntent(): PendingIntent {
)
}
/**
* Shortcut for querying all items in a database and running [block] with the cursor returned.
* Will not run if the cursor is null.
*/
fun <R> SQLiteDatabase.queryAll(tableName: String, block: (Cursor) -> R) =
query(tableName, null, null, null, null, null, null)?.use(block)
/**
* Assert that we are on a background thread.
*/