diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Toolbar.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Toolbar.kt new file mode 100644 index 000000000..05ad9c7f1 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Toolbar.kt @@ -0,0 +1,14 @@ +package org.koitharu.kotatsu.core.util.ext + +import androidx.annotation.DrawableRes +import androidx.appcompat.widget.Toolbar + +fun Toolbar.setNavigationIconSafe(@DrawableRes iconRes: Int, retry: Boolean = true) { + try { + setNavigationIcon(iconRes) + } catch (e: IllegalStateException) { + if (retry) { + post { setNavigationIconSafe(iconRes, retry = false) } + } + } +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt index 323a0d797..e41b998d2 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt @@ -43,6 +43,7 @@ import org.koitharu.kotatsu.core.util.ext.measureHeight import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent import org.koitharu.kotatsu.core.util.ext.setNavigationBarTransparentCompat +import org.koitharu.kotatsu.core.util.ext.setNavigationIconSafe import org.koitharu.kotatsu.core.util.ext.textAndVisible import org.koitharu.kotatsu.databinding.ActivityDetailsBinding import org.koitharu.kotatsu.details.service.MangaPrefetchService @@ -211,7 +212,7 @@ class DetailsActivity : } if (isExpanded) { toolbar.addMenuProvider(chaptersMenuProvider) - toolbar.setNavigationIcon(materialR.drawable.abc_ic_clear_material) + toolbar.setNavigationIconSafe(materialR.drawable.abc_ic_clear_material) } else { toolbar.removeMenuProvider(chaptersMenuProvider) toolbar.navigationIcon = null diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/widget/recent/RecentListFactory.kt b/app/src/main/kotlin/org/koitharu/kotatsu/widget/recent/RecentListFactory.kt index 83266be1e..18c62cb85 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/widget/recent/RecentListFactory.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/widget/recent/RecentListFactory.kt @@ -48,7 +48,7 @@ class RecentListFactory( override fun getViewAt(position: Int): RemoteViews { val views = RemoteViews(context.packageName, R.layout.item_recent) - val item = dataSet[position] + val item = dataSet.getOrNull(position) ?: return views runCatching { coil.executeBlocking( ImageRequest.Builder(context) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/widget/shelf/ShelfListFactory.kt b/app/src/main/kotlin/org/koitharu/kotatsu/widget/shelf/ShelfListFactory.kt index fb914916f..14e15b967 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/widget/shelf/ShelfListFactory.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/widget/shelf/ShelfListFactory.kt @@ -58,7 +58,7 @@ class ShelfListFactory( override fun getViewAt(position: Int): RemoteViews { val views = RemoteViews(context.packageName, R.layout.item_shelf) - val item = dataSet[position] + val item = dataSet.getOrNull(position) ?: return views views.setTextViewText(R.id.textView_title, item.title) runCatching { coil.executeBlocking(