-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8836e2c
commit 7b1d632
Showing
30 changed files
with
459 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/src/main/kotlin/nl/ndat/tvlauncher/data/DatabaseContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package nl.ndat.tvlauncher.data | ||
|
||
import android.content.Context | ||
import app.cash.sqldelight.ColumnAdapter | ||
import app.cash.sqldelight.EnumColumnAdapter | ||
import app.cash.sqldelight.TransactionWithReturn | ||
import app.cash.sqldelight.TransactionWithoutReturn | ||
import app.cash.sqldelight.driver.android.AndroidSqliteDriver | ||
import nl.ndat.tvlauncher.data.sqldelight.Channel | ||
import nl.ndat.tvlauncher.data.sqldelight.ChannelProgram | ||
import nl.ndat.tvlauncher.data.sqldelight.Database | ||
import nl.ndat.tvlauncher.data.sqldelight.Input | ||
|
||
class DatabaseContainer( | ||
context: Context | ||
) { | ||
companion object { | ||
const val DB_FILE = "data.db" | ||
} | ||
|
||
private val driver = AndroidSqliteDriver(Database.Schema, context, DB_FILE) | ||
private val database = Database( | ||
driver = driver, | ||
ChannelAdapter = Channel.Adapter( | ||
typeAdapter = EnumColumnAdapter(), | ||
), | ||
ChannelProgramAdapter = ChannelProgram.Adapter( | ||
weightAdapter = IntColumnAdapter(), | ||
typeAdapter = EnumColumnAdapter(), | ||
posterArtAspectRatioAdapter = EnumColumnAdapter(), | ||
lastPlaybackPositionMillisAdapter = IntColumnAdapter(), | ||
durationMillisAdapter = IntColumnAdapter(), | ||
itemCountAdapter = IntColumnAdapter(), | ||
interactionTypeAdapter = EnumColumnAdapter(), | ||
), | ||
InputAdapter = Input.Adapter( | ||
typeAdapter = EnumColumnAdapter() | ||
), | ||
) | ||
|
||
val apps = database.appQueries | ||
val inputs = database.inputQueries | ||
val channels = database.channelQueries | ||
val channelPrograms = database.channelProgramQueries | ||
|
||
fun transaction(body: TransactionWithoutReturn.() -> Unit) = database.transaction { body() } | ||
fun <T> transactionForResult(body: TransactionWithReturn<T>.() -> T) = database.transactionWithResult { body() } | ||
} | ||
|
||
class IntColumnAdapter : ColumnAdapter<Int, Long> { | ||
override fun decode(databaseValue: Long): Int = databaseValue.toInt() | ||
override fun encode(value: Int): Long = value.toLong() | ||
} |
43 changes: 0 additions & 43 deletions
43
app/src/main/kotlin/nl/ndat/tvlauncher/data/SharedDatabase.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
app/src/main/kotlin/nl/ndat/tvlauncher/data/dao/ChannelDao.kt
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
app/src/main/kotlin/nl/ndat/tvlauncher/data/dao/ChannelProgramDao.kt
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
app/src/main/kotlin/nl/ndat/tvlauncher/data/dao/InputDao.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
app/src/main/kotlin/nl/ndat/tvlauncher/data/entity/Channel.kt
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
app/src/main/kotlin/nl/ndat/tvlauncher/data/entity/ChannelProgram.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.