Migrate History screen database calls to SQLDelight (#6933)

* Migrate History screen database call to SQLDelight

- Move all migrations to SQLDelight
- Move all tables to SQLDelight

Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com>

* Changes from review comments

* Add adapters to database

* Remove logging of database version in App

* Change query name for paging source queries

* Update migrations

* Make SQLite Callback handle migration

- To ensure it updates the database

* Use SQLDelight Schema version for Callback database version

Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com>
This commit is contained in:
Andreas
2022-04-21 21:45:56 +02:00
committed by GitHub
parent 6c1565a7d4
commit b1f46ed830
62 changed files with 1069 additions and 570 deletions

View File

@@ -9,7 +9,6 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import eu.kanade.tachiyomi.data.database.models.Manga
enum class MangaCoverAspect(val ratio: Float) {
SQUARE(1f / 1f),
@@ -19,13 +18,13 @@ enum class MangaCoverAspect(val ratio: Float) {
@Composable
fun MangaCover(
modifier: Modifier = Modifier,
manga: Manga,
data: String?,
aspect: MangaCoverAspect,
contentDescription: String = "",
shape: Shape = RoundedCornerShape(4.dp)
) {
AsyncImage(
model = manga,
model = data,
contentDescription = contentDescription,
modifier = modifier
.aspectRatio(aspect.ratio)

View File

@@ -1,6 +1,7 @@
package eu.kanade.presentation.history
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@@ -42,13 +43,13 @@ import androidx.core.text.buildSpannedString
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.items
import eu.kanade.domain.history.model.HistoryWithRelations
import eu.kanade.presentation.components.EmptyScreen
import eu.kanade.presentation.components.MangaCover
import eu.kanade.presentation.components.MangaCoverAspect
import eu.kanade.presentation.theme.TachiyomiTheme
import eu.kanade.presentation.util.horizontalPadding
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.recent.history.HistoryPresenter
import eu.kanade.tachiyomi.ui.recent.history.UiModel
@@ -71,9 +72,9 @@ val chapterFormatter = DecimalFormat(
fun HistoryScreen(
composeView: ComposeView,
presenter: HistoryPresenter,
onClickItem: (MangaChapterHistory) -> Unit,
onClickResume: (MangaChapterHistory) -> Unit,
onClickDelete: (MangaChapterHistory, Boolean) -> Unit,
onClickItem: (HistoryWithRelations) -> Unit,
onClickResume: (HistoryWithRelations) -> Unit,
onClickDelete: (HistoryWithRelations, Boolean) -> Unit,
) {
val nestedSrollInterop = rememberNestedScrollInteropConnection(composeView)
TachiyomiTheme {
@@ -104,16 +105,16 @@ fun HistoryScreen(
@Composable
fun HistoryContent(
history: LazyPagingItems<UiModel>,
onClickItem: (MangaChapterHistory) -> Unit,
onClickResume: (MangaChapterHistory) -> Unit,
onClickDelete: (MangaChapterHistory, Boolean) -> Unit,
onClickItem: (HistoryWithRelations) -> Unit,
onClickResume: (HistoryWithRelations) -> Unit,
onClickDelete: (HistoryWithRelations, Boolean) -> Unit,
preferences: PreferencesHelper = Injekt.get(),
nestedScroll: NestedScrollConnection
) {
val relativeTime: Int = remember { preferences.relativeTime().get() }
val dateFormat: DateFormat = remember { preferences.dateFormat() }
val (removeState, setRemoveState) = remember { mutableStateOf<MangaChapterHistory?>(null) }
val (removeState, setRemoveState) = remember { mutableStateOf<HistoryWithRelations?>(null) }
val scrollState = rememberLazyListState()
LazyColumn(
@@ -132,7 +133,7 @@ fun HistoryContent(
dateFormat = dateFormat
)
}
is UiModel.History -> {
is UiModel.Item -> {
val value = item.item
HistoryItem(
modifier = Modifier.animateItemPlacement(),
@@ -189,7 +190,7 @@ fun HistoryHeader(
@Composable
fun HistoryItem(
modifier: Modifier = Modifier,
history: MangaChapterHistory,
history: HistoryWithRelations,
onClickItem: () -> Unit,
onClickResume: () -> Unit,
onClickDelete: () -> Unit,
@@ -203,7 +204,7 @@ fun HistoryItem(
) {
MangaCover(
modifier = Modifier.fillMaxHeight(),
manga = history.manga,
data = history.thumbnailUrl,
aspect = MangaCoverAspect.COVER
)
Column(
@@ -215,7 +216,7 @@ fun HistoryItem(
color = MaterialTheme.colorScheme.onSurface,
)
Text(
text = history.manga.title,
text = history.title,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
style = textStyle.copy(fontWeight = FontWeight.SemiBold)
@@ -223,15 +224,15 @@ fun HistoryItem(
Row {
Text(
text = buildSpannedString {
if (history.chapter.chapter_number > -1) {
if (history.chapterNumber > -1) {
append(
stringResource(
R.string.history_prefix,
chapterFormatter.format(history.chapter.chapter_number)
chapterFormatter.format(history.chapterNumber)
)
)
}
append(Date(history.history.last_read).toTimestampString())
append(history.readAt?.toTimestampString())
}.toString(),
modifier = Modifier.padding(top = 2.dp),
style = textStyle
@@ -270,14 +271,22 @@ fun RemoveHistoryDialog(
Column {
Text(text = stringResource(id = R.string.dialog_with_checkbox_remove_description))
Row(
modifier = Modifier.toggleable(value = removeEverything, onValueChange = removeEverythingState),
modifier = Modifier
.padding(top = 16.dp)
.toggleable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
value = removeEverything,
onValueChange = removeEverythingState
),
verticalAlignment = Alignment.CenterVertically
) {
Checkbox(
checked = removeEverything,
onCheckedChange = removeEverythingState,
onCheckedChange = null,
)
Text(
modifier = Modifier.padding(start = 4.dp),
text = stringResource(id = R.string.dialog_with_checkbox_reset)
)
}