diff --git a/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt index 00b4fffcf..99ec74415 100644 --- a/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt @@ -9,11 +9,12 @@ class UpdatesRepositoryImpl( private val databaseHandler: DatabaseHandler, ) : UpdatesRepository { - override suspend fun awaitWithRead(read: Boolean, after: Long): List { + override suspend fun awaitWithRead(read: Boolean, after: Long, limit: Long): List { return databaseHandler.awaitList { updatesViewQueries.getUpdatesByReadStatus( read = read, after = after, + limit = limit, mapper = updateWithRelationMapper, ) } @@ -25,11 +26,12 @@ class UpdatesRepositoryImpl( } } - override fun subscribeWithRead(read: Boolean, after: Long): Flow> { + override fun subscribeWithRead(read: Boolean, after: Long, limit: Long): Flow> { return databaseHandler.subscribeToList { updatesViewQueries.getUpdatesByReadStatus( read = read, after = after, + limit = limit, mapper = updateWithRelationMapper, ) } diff --git a/data/src/main/sqldelight/tachiyomi/view/updatesView.sq b/data/src/main/sqldelight/tachiyomi/view/updatesView.sq index 6e9fd95c2..5fdd3ea75 100644 --- a/data/src/main/sqldelight/tachiyomi/view/updatesView.sq +++ b/data/src/main/sqldelight/tachiyomi/view/updatesView.sq @@ -30,4 +30,5 @@ getUpdatesByReadStatus: SELECT * FROM updatesView WHERE read = :read -AND dateUpload > :after; \ No newline at end of file +AND dateUpload > :after +LIMIT :limit; \ No newline at end of file diff --git a/domain/src/main/java/tachiyomi/domain/updates/interactor/GetUpdates.kt b/domain/src/main/java/tachiyomi/domain/updates/interactor/GetUpdates.kt index 0c1ac5f83..b3c6481d5 100644 --- a/domain/src/main/java/tachiyomi/domain/updates/interactor/GetUpdates.kt +++ b/domain/src/main/java/tachiyomi/domain/updates/interactor/GetUpdates.kt @@ -10,7 +10,7 @@ class GetUpdates( ) { suspend fun await(read: Boolean, after: Long): List { - return repository.awaitWithRead(read, after) + return repository.awaitWithRead(read, after, limit = 500) } fun subscribe(calendar: Calendar): Flow> { @@ -18,6 +18,6 @@ class GetUpdates( } fun subscribe(read: Boolean, after: Long): Flow> { - return repository.subscribeWithRead(read, after) + return repository.subscribeWithRead(read, after, limit = 500) } } diff --git a/domain/src/main/java/tachiyomi/domain/updates/repository/UpdatesRepository.kt b/domain/src/main/java/tachiyomi/domain/updates/repository/UpdatesRepository.kt index 0856b4b9f..3b583ea90 100644 --- a/domain/src/main/java/tachiyomi/domain/updates/repository/UpdatesRepository.kt +++ b/domain/src/main/java/tachiyomi/domain/updates/repository/UpdatesRepository.kt @@ -5,9 +5,9 @@ import tachiyomi.domain.updates.model.UpdatesWithRelations interface UpdatesRepository { - suspend fun awaitWithRead(read: Boolean, after: Long): List + suspend fun awaitWithRead(read: Boolean, after: Long, limit: Long): List fun subscribeAll(after: Long, limit: Long): Flow> - fun subscribeWithRead(read: Boolean, after: Long): Flow> + fun subscribeWithRead(read: Boolean, after: Long, limit: Long): Flow> } diff --git a/presentation-widget/src/main/java/tachiyomi/presentation/widget/UpdatesGridGlanceWidget.kt b/presentation-widget/src/main/java/tachiyomi/presentation/widget/UpdatesGridGlanceWidget.kt index 9d7794b56..4275d08f0 100644 --- a/presentation-widget/src/main/java/tachiyomi/presentation/widget/UpdatesGridGlanceWidget.kt +++ b/presentation-widget/src/main/java/tachiyomi/presentation/widget/UpdatesGridGlanceWidget.kt @@ -36,14 +36,14 @@ import tachiyomi.presentation.widget.util.appWidgetBackgroundRadius import tachiyomi.presentation.widget.util.calculateRowAndColumnCount import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import uy.kohesive.injekt.injectLazy import java.util.Calendar import java.util.Date -class UpdatesGridGlanceWidget : GlanceAppWidget() { - - private val app: Application by injectLazy() - private val preferences: SecurityPreferences by injectLazy() +class UpdatesGridGlanceWidget( + private val context: Context = Injekt.get(), + private val getUpdates: GetUpdates = Injekt.get(), + private val preferences: SecurityPreferences = Injekt.get(), +) : GlanceAppWidget() { private var data: List>? = null @@ -63,23 +63,22 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() { } } - private suspend fun loadData(list: List? = null) { - withIOContext { - val manager = GlanceAppWidgetManager(app) - val ids = manager.getGlanceIds(this@UpdatesGridGlanceWidget::class.java) - if (ids.isEmpty()) return@withIOContext + private suspend fun loadData() { + val manager = GlanceAppWidgetManager(context) + val ids = manager.getGlanceIds(this@UpdatesGridGlanceWidget::class.java) + if (ids.isEmpty()) return - val processList = list - ?: Injekt.get().await( - read = false, - after = DateLimit.timeInMillis, - ) + withIOContext { + val updates = getUpdates.await( + read = false, + after = DateLimit.timeInMillis, + ) val (rowCount, columnCount) = ids .flatMap { manager.getAppWidgetSizes(it) } .maxBy { it.height.value * it.width.value } .calculateRowAndColumnCount() - data = prepareList(processList, rowCount * columnCount) + data = prepareList(updates, rowCount * columnCount) } } @@ -87,12 +86,12 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() { // Resize to cover size val widthPx = CoverWidth.value.toInt().dpToPx val heightPx = CoverHeight.value.toInt().dpToPx - val roundPx = app.resources.getDimension(R.dimen.appwidget_inner_radius) + val roundPx = context.resources.getDimension(R.dimen.appwidget_inner_radius) return processList .distinctBy { it.mangaId } .take(take) .map { updatesView -> - val request = ImageRequest.Builder(app) + val request = ImageRequest.Builder(context) .data( MangaCover( mangaId = updatesView.mangaId, @@ -114,7 +113,7 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() { } } .build() - Pair(updatesView.mangaId, app.imageLoader.executeBlocking(request).drawable?.toBitmap()) + Pair(updatesView.mangaId, context.imageLoader.executeBlocking(request).drawable?.toBitmap()) } }