Fix crash on widgets update

This commit is contained in:
Koitharu
2022-08-01 17:00:00 +03:00
parent 8faacab53a
commit f342cd6b56
3 changed files with 10 additions and 11 deletions

View File

@@ -73,7 +73,7 @@ class KotatsuApp : Application() {
appWidgetModule, appWidgetModule,
suggestionsModule, suggestionsModule,
shikimoriModule, shikimoriModule,
bookmarksModule, bookmarksModule
) )
} }
} }
@@ -91,8 +91,7 @@ class KotatsuApp : Application() {
ReportField.PHONE_MODEL, ReportField.PHONE_MODEL,
ReportField.CRASH_CONFIGURATION, ReportField.CRASH_CONFIGURATION,
ReportField.STACK_TRACE, ReportField.STACK_TRACE,
ReportField.CUSTOM_DATA, ReportField.SHARED_PREFERENCES
ReportField.SHARED_PREFERENCES,
) )
dialog { dialog {
text = getString(R.string.crash_text) text = getString(R.string.crash_text)

View File

@@ -15,12 +15,13 @@ import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.domain.MangaIntent import org.koitharu.kotatsu.base.domain.MangaIntent
import org.koitharu.kotatsu.history.domain.HistoryRepository import org.koitharu.kotatsu.history.domain.HistoryRepository
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.util.replaceWith
import org.koitharu.kotatsu.utils.ext.requireBitmap import org.koitharu.kotatsu.utils.ext.requireBitmap
class RecentListFactory( class RecentListFactory(
private val context: Context, private val context: Context,
private val historyRepository: HistoryRepository, private val historyRepository: HistoryRepository,
private val coil: ImageLoader private val coil: ImageLoader,
) : RemoteViewsService.RemoteViewsFactory { ) : RemoteViewsService.RemoteViewsFactory {
private val dataSet = ArrayList<Manga>() private val dataSet = ArrayList<Manga>()
@@ -29,7 +30,7 @@ class RecentListFactory(
) )
private val coverSize = Size( private val coverSize = Size(
context.resources.getDimensionPixelSize(R.dimen.widget_cover_width), 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 override fun onCreate() = Unit
@@ -39,9 +40,8 @@ class RecentListFactory(
override fun getItemId(position: Int) = dataSet[position].id override fun getItemId(position: Int) = dataSet[position].id
override fun onDataSetChanged() { override fun onDataSetChanged() {
dataSet.clear()
val data = runBlocking { historyRepository.getList(0, 10) } val data = runBlocking { historyRepository.getList(0, 10) }
dataSet.addAll(data) dataSet.replaceWith(data)
} }
override fun hasStableIds() = true override fun hasStableIds() = true

View File

@@ -16,6 +16,7 @@ import org.koitharu.kotatsu.base.domain.MangaIntent
import org.koitharu.kotatsu.core.prefs.AppWidgetConfig import org.koitharu.kotatsu.core.prefs.AppWidgetConfig
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.util.replaceWith
import org.koitharu.kotatsu.utils.ext.requireBitmap import org.koitharu.kotatsu.utils.ext.requireBitmap
class ShelfListFactory( class ShelfListFactory(
@@ -32,7 +33,7 @@ class ShelfListFactory(
) )
private val coverSize = Size( private val coverSize = Size(
context.resources.getDimensionPixelSize(R.dimen.widget_cover_width), 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 override fun onCreate() = Unit
@@ -42,7 +43,6 @@ class ShelfListFactory(
override fun getItemId(position: Int) = dataSet[position].id override fun getItemId(position: Int) = dataSet[position].id
override fun onDataSetChanged() { override fun onDataSetChanged() {
dataSet.clear()
val data = runBlocking { val data = runBlocking {
val category = config.categoryId val category = config.categoryId
if (category == 0L) { if (category == 0L) {
@@ -51,7 +51,7 @@ class ShelfListFactory(
favouritesRepository.getManga(category) favouritesRepository.getManga(category)
} }
} }
dataSet.addAll(data) dataSet.replaceWith(data)
} }
override fun hasStableIds() = true override fun hasStableIds() = true
@@ -85,4 +85,4 @@ class ShelfListFactory(
override fun getViewTypeCount() = 1 override fun getViewTypeCount() = 1
override fun onDestroy() = Unit override fun onDestroy() = Unit
} }