From f342cd6b5668b5cb868e27507b80650e1c9cd163 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 1 Aug 2022 17:00:00 +0300 Subject: [PATCH] Fix crash on widgets update --- app/src/main/java/org/koitharu/kotatsu/KotatsuApp.kt | 5 ++--- .../koitharu/kotatsu/widget/recent/RecentListFactory.kt | 8 ++++---- .../org/koitharu/kotatsu/widget/shelf/ShelfListFactory.kt | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/koitharu/kotatsu/KotatsuApp.kt b/app/src/main/java/org/koitharu/kotatsu/KotatsuApp.kt index fcbc79742..23b3df2c6 100644 --- a/app/src/main/java/org/koitharu/kotatsu/KotatsuApp.kt +++ b/app/src/main/java/org/koitharu/kotatsu/KotatsuApp.kt @@ -73,7 +73,7 @@ class KotatsuApp : Application() { appWidgetModule, suggestionsModule, shikimoriModule, - bookmarksModule, + bookmarksModule ) } } @@ -91,8 +91,7 @@ class KotatsuApp : Application() { ReportField.PHONE_MODEL, ReportField.CRASH_CONFIGURATION, ReportField.STACK_TRACE, - ReportField.CUSTOM_DATA, - ReportField.SHARED_PREFERENCES, + ReportField.SHARED_PREFERENCES ) dialog { text = getString(R.string.crash_text) diff --git a/app/src/main/java/org/koitharu/kotatsu/widget/recent/RecentListFactory.kt b/app/src/main/java/org/koitharu/kotatsu/widget/recent/RecentListFactory.kt index 04c25f382..eec01cb41 100644 --- a/app/src/main/java/org/koitharu/kotatsu/widget/recent/RecentListFactory.kt +++ b/app/src/main/java/org/koitharu/kotatsu/widget/recent/RecentListFactory.kt @@ -15,12 +15,13 @@ import org.koitharu.kotatsu.R import org.koitharu.kotatsu.base.domain.MangaIntent import org.koitharu.kotatsu.history.domain.HistoryRepository import org.koitharu.kotatsu.parsers.model.Manga +import org.koitharu.kotatsu.parsers.util.replaceWith import org.koitharu.kotatsu.utils.ext.requireBitmap class RecentListFactory( private val context: Context, private val historyRepository: HistoryRepository, - private val coil: ImageLoader + private val coil: ImageLoader, ) : RemoteViewsService.RemoteViewsFactory { private val dataSet = ArrayList() @@ -29,7 +30,7 @@ class RecentListFactory( ) private val coverSize = Size( context.resources.getDimensionPixelSize(R.dimen.widget_cover_width), - context.resources.getDimensionPixelSize(R.dimen.widget_cover_height), + context.resources.getDimensionPixelSize(R.dimen.widget_cover_height) ) override fun onCreate() = Unit @@ -39,9 +40,8 @@ class RecentListFactory( override fun getItemId(position: Int) = dataSet[position].id override fun onDataSetChanged() { - dataSet.clear() val data = runBlocking { historyRepository.getList(0, 10) } - dataSet.addAll(data) + dataSet.replaceWith(data) } override fun hasStableIds() = true diff --git a/app/src/main/java/org/koitharu/kotatsu/widget/shelf/ShelfListFactory.kt b/app/src/main/java/org/koitharu/kotatsu/widget/shelf/ShelfListFactory.kt index 1676e5a49..edb2eb417 100644 --- a/app/src/main/java/org/koitharu/kotatsu/widget/shelf/ShelfListFactory.kt +++ b/app/src/main/java/org/koitharu/kotatsu/widget/shelf/ShelfListFactory.kt @@ -16,6 +16,7 @@ import org.koitharu.kotatsu.base.domain.MangaIntent import org.koitharu.kotatsu.core.prefs.AppWidgetConfig import org.koitharu.kotatsu.favourites.domain.FavouritesRepository import org.koitharu.kotatsu.parsers.model.Manga +import org.koitharu.kotatsu.parsers.util.replaceWith import org.koitharu.kotatsu.utils.ext.requireBitmap class ShelfListFactory( @@ -32,7 +33,7 @@ class ShelfListFactory( ) private val coverSize = Size( context.resources.getDimensionPixelSize(R.dimen.widget_cover_width), - context.resources.getDimensionPixelSize(R.dimen.widget_cover_height), + context.resources.getDimensionPixelSize(R.dimen.widget_cover_height) ) override fun onCreate() = Unit @@ -42,7 +43,6 @@ class ShelfListFactory( override fun getItemId(position: Int) = dataSet[position].id override fun onDataSetChanged() { - dataSet.clear() val data = runBlocking { val category = config.categoryId if (category == 0L) { @@ -51,7 +51,7 @@ class ShelfListFactory( favouritesRepository.getManga(category) } } - dataSet.addAll(data) + dataSet.replaceWith(data) } override fun hasStableIds() = true @@ -85,4 +85,4 @@ class ShelfListFactory( override fun getViewTypeCount() = 1 override fun onDestroy() = Unit -} +} \ No newline at end of file