Limit amount of updates loaded for widget
Probably fixes #9868 (cherry picked from commit 87530f506e16db3d5c9ed89740c324ebd464117f) # Conflicts: # domain/src/main/java/tachiyomi/domain/updates/interactor/GetUpdates.kt
This commit is contained in:
parent
e776d455f5
commit
511979045f
@ -11,11 +11,12 @@ class UpdatesRepositoryImpl(
|
|||||||
private val databaseHandler: DatabaseHandler,
|
private val databaseHandler: DatabaseHandler,
|
||||||
) : UpdatesRepository {
|
) : UpdatesRepository {
|
||||||
|
|
||||||
override suspend fun awaitWithRead(read: Boolean, after: Long): List<UpdatesWithRelations> {
|
override suspend fun awaitWithRead(read: Boolean, after: Long, limit: Long): List<UpdatesWithRelations> {
|
||||||
return databaseHandler.awaitList {
|
return databaseHandler.awaitList {
|
||||||
updatesViewQueries.getUpdatesByReadStatus(
|
updatesViewQueries.getUpdatesByReadStatus(
|
||||||
read = read,
|
read = read,
|
||||||
after = after,
|
after = after,
|
||||||
|
limit = limit,
|
||||||
mapper = updateWithRelationMapper,
|
mapper = updateWithRelationMapper,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -30,11 +31,12 @@ class UpdatesRepositoryImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun subscribeWithRead(read: Boolean, after: Long): Flow<List<UpdatesWithRelations>> {
|
override fun subscribeWithRead(read: Boolean, after: Long, limit: Long): Flow<List<UpdatesWithRelations>> {
|
||||||
return databaseHandler.subscribeToList {
|
return databaseHandler.subscribeToList {
|
||||||
updatesViewQueries.getUpdatesByReadStatus(
|
updatesViewQueries.getUpdatesByReadStatus(
|
||||||
read = read,
|
read = read,
|
||||||
after = after,
|
after = after,
|
||||||
|
limit = limit,
|
||||||
mapper = updateWithRelationMapper,
|
mapper = updateWithRelationMapper,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,5 @@ getUpdatesByReadStatus:
|
|||||||
SELECT *
|
SELECT *
|
||||||
FROM updatesView
|
FROM updatesView
|
||||||
WHERE read = :read
|
WHERE read = :read
|
||||||
AND dateUpload > :after;
|
AND dateUpload > :after
|
||||||
|
LIMIT :limit;
|
@ -17,7 +17,7 @@ class GetUpdates(
|
|||||||
suspend fun await(read: Boolean, after: Long): List<UpdatesWithRelations> {
|
suspend fun await(read: Boolean, after: Long): List<UpdatesWithRelations> {
|
||||||
// SY -->
|
// SY -->
|
||||||
return flow {
|
return flow {
|
||||||
emit(repository.awaitWithRead(read, after))
|
emit(repository.awaitWithRead(read, after, limit = 500))
|
||||||
}
|
}
|
||||||
.catchNPE()
|
.catchNPE()
|
||||||
.first()
|
.first()
|
||||||
@ -32,7 +32,7 @@ class GetUpdates(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun subscribe(read: Boolean, after: Long): Flow<List<UpdatesWithRelations>> {
|
fun subscribe(read: Boolean, after: Long): Flow<List<UpdatesWithRelations>> {
|
||||||
return repository.subscribeWithRead(read, after)
|
return repository.subscribeWithRead(read, after, limit = 500)
|
||||||
// SY -->
|
// SY -->
|
||||||
.catchNPE()
|
.catchNPE()
|
||||||
// SY <--
|
// SY <--
|
||||||
|
@ -5,9 +5,9 @@ import tachiyomi.domain.updates.model.UpdatesWithRelations
|
|||||||
|
|
||||||
interface UpdatesRepository {
|
interface UpdatesRepository {
|
||||||
|
|
||||||
suspend fun awaitWithRead(read: Boolean, after: Long): List<UpdatesWithRelations>
|
suspend fun awaitWithRead(read: Boolean, after: Long, limit: Long): List<UpdatesWithRelations>
|
||||||
|
|
||||||
fun subscribeAll(after: Long, limit: Long): Flow<List<UpdatesWithRelations>>
|
fun subscribeAll(after: Long, limit: Long): Flow<List<UpdatesWithRelations>>
|
||||||
|
|
||||||
fun subscribeWithRead(read: Boolean, after: Long): Flow<List<UpdatesWithRelations>>
|
fun subscribeWithRead(read: Boolean, after: Long, limit: Long): Flow<List<UpdatesWithRelations>>
|
||||||
}
|
}
|
||||||
|
@ -36,14 +36,14 @@ import tachiyomi.presentation.widget.util.appWidgetBackgroundRadius
|
|||||||
import tachiyomi.presentation.widget.util.calculateRowAndColumnCount
|
import tachiyomi.presentation.widget.util.calculateRowAndColumnCount
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
class UpdatesGridGlanceWidget : GlanceAppWidget() {
|
class UpdatesGridGlanceWidget(
|
||||||
|
private val context: Context = Injekt.get<Application>(),
|
||||||
private val app: Application by injectLazy()
|
private val getUpdates: GetUpdates = Injekt.get(),
|
||||||
private val preferences: SecurityPreferences by injectLazy()
|
private val preferences: SecurityPreferences = Injekt.get(),
|
||||||
|
) : GlanceAppWidget() {
|
||||||
|
|
||||||
private var data: List<Pair<Long, Bitmap?>>? = null
|
private var data: List<Pair<Long, Bitmap?>>? = null
|
||||||
|
|
||||||
@ -63,14 +63,13 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadData(list: List<UpdatesWithRelations>? = null) {
|
private suspend fun loadData() {
|
||||||
withIOContext {
|
val manager = GlanceAppWidgetManager(context)
|
||||||
val manager = GlanceAppWidgetManager(app)
|
|
||||||
val ids = manager.getGlanceIds(this@UpdatesGridGlanceWidget::class.java)
|
val ids = manager.getGlanceIds(this@UpdatesGridGlanceWidget::class.java)
|
||||||
if (ids.isEmpty()) return@withIOContext
|
if (ids.isEmpty()) return
|
||||||
|
|
||||||
val processList = list
|
withIOContext {
|
||||||
?: Injekt.get<GetUpdates>().await(
|
val updates = getUpdates.await(
|
||||||
read = false,
|
read = false,
|
||||||
after = DateLimit.timeInMillis,
|
after = DateLimit.timeInMillis,
|
||||||
)
|
)
|
||||||
@ -79,7 +78,7 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() {
|
|||||||
.maxBy { it.height.value * it.width.value }
|
.maxBy { it.height.value * it.width.value }
|
||||||
.calculateRowAndColumnCount()
|
.calculateRowAndColumnCount()
|
||||||
|
|
||||||
data = prepareList(processList, rowCount * columnCount)
|
data = prepareList(updates, rowCount * columnCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,12 +86,12 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() {
|
|||||||
// Resize to cover size
|
// Resize to cover size
|
||||||
val widthPx = CoverWidth.value.toInt().dpToPx
|
val widthPx = CoverWidth.value.toInt().dpToPx
|
||||||
val heightPx = CoverHeight.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
|
return processList
|
||||||
.distinctBy { it.mangaId }
|
.distinctBy { it.mangaId }
|
||||||
.take(take)
|
.take(take)
|
||||||
.map { updatesView ->
|
.map { updatesView ->
|
||||||
val request = ImageRequest.Builder(app)
|
val request = ImageRequest.Builder(context)
|
||||||
.data(
|
.data(
|
||||||
MangaCover(
|
MangaCover(
|
||||||
mangaId = updatesView.mangaId,
|
mangaId = updatesView.mangaId,
|
||||||
@ -114,7 +113,7 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
Pair(updatesView.mangaId, app.imageLoader.executeBlocking(request).drawable?.toBitmap())
|
Pair(updatesView.mangaId, context.imageLoader.executeBlocking(request).drawable?.toBitmap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user