diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/util/WindowInsetsDelegate.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/util/WindowInsetsDelegate.kt index aa3ce78d1..ce0bd79a1 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/util/WindowInsetsDelegate.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/util/WindowInsetsDelegate.kt @@ -7,6 +7,7 @@ import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import java.util.LinkedList +@Deprecated("") class WindowInsetsDelegate : OnApplyWindowInsetsListener, View.OnLayoutChangeListener { @JvmField diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt index 719ac2135..1ea3b999f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt @@ -6,6 +6,7 @@ import androidx.annotation.DrawableRes import coil3.network.HttpException import com.davemorrissey.labs.subscaleview.decoder.ImageDecodeException import okhttp3.Response +import okhttp3.internal.http2.StreamResetException import okio.FileNotFoundException import okio.IOException import okio.ProtocolException @@ -195,7 +196,6 @@ fun Throwable.isReportable(): Boolean { || this is WrongPasswordException || this is TooManyRequestExceptions || this is HttpStatusException - || this is SocketException ) { return false } @@ -203,7 +203,10 @@ fun Throwable.isReportable(): Boolean { } fun Throwable.isNetworkError(): Boolean { - return this is UnknownHostException || this is SocketTimeoutException + return this is UnknownHostException + || this is SocketTimeoutException + || this is StreamResetException + || this is SocketException } fun Throwable.report(silent: Boolean = false) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt index 43570c7f7..adf6e5062 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt @@ -82,6 +82,8 @@ class ChaptersPagesSheet : BaseAdaptiveSheet(), Actio viewModel.onError.observeEvent(viewLifecycleOwner, SnackbarErrorObserver(binding.pager, this)) viewModel.onActionDone.observeEvent(viewLifecycleOwner, ReversibleActionObserver(binding.pager, null)) viewModel.onDownloadStarted.observeEvent(viewLifecycleOwner, DownloadStartedObserver(binding.pager)) + } else { + PeekHeightController(arrayOf(binding.headerBar, binding.toolbar)).attach() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/PeekHeightController.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/PeekHeightController.kt new file mode 100644 index 000000000..fbf13f3f3 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/PeekHeightController.kt @@ -0,0 +1,62 @@ +package org.koitharu.kotatsu.details.ui.pager + +import android.view.View +import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.view.OnApplyWindowInsetsListener +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.ancestors +import com.google.android.material.bottomsheet.BottomSheetBehavior + +class PeekHeightController( + private val views: Array, +) : View.OnLayoutChangeListener, OnApplyWindowInsetsListener { + + private var behavior: BottomSheetBehavior<*>? = null + + fun attach() { + behavior = findBehavior() ?: return + views.forEach { v -> + v.addOnLayoutChangeListener(this) + } + ViewCompat.setOnApplyWindowInsetsListener(views.first(), this) + } + + override fun onLayoutChange( + v: View?, + left: Int, + top: Int, + right: Int, + bottom: Int, + oldLeft: Int, + oldTop: Int, + oldRight: Int, + oldBottom: Int + ) { + if (top != oldTop || bottom != oldBottom) { + updatePeekHeight() + } + } + + override fun onApplyWindowInsets( + v: View, + insets: WindowInsetsCompat + ): WindowInsetsCompat { + updatePeekHeight() + return insets + } + + private fun updatePeekHeight() { + behavior?.peekHeight = views.sumOf { it.height } + getBottomInset() + } + + private fun getBottomInset(): Int = ViewCompat.getRootWindowInsets(views.first()) + ?.getInsets(WindowInsetsCompat.Type.navigationBars()) + ?.bottom ?: 0 + + private fun findBehavior(): BottomSheetBehavior<*>? { + return views.first().ancestors.firstNotNullOfOrNull { + ((it as? View)?.layoutParams as? CoordinatorLayout.LayoutParams)?.behavior as? BottomSheetBehavior<*> + } + } +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/bookmarks/BookmarksFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/bookmarks/BookmarksFragment.kt index 5c201c9b5..5168255cb 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/bookmarks/BookmarksFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/bookmarks/BookmarksFragment.kt @@ -9,6 +9,7 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.view.ActionMode import androidx.core.graphics.Insets +import androidx.core.view.updatePadding import androidx.fragment.app.viewModels import androidx.recyclerview.widget.GridLayoutManager import coil3.ImageLoader @@ -115,7 +116,13 @@ class BookmarksFragment : BaseFragment(), super.onDestroyView() } - override fun onWindowInsetsChanged(insets: Insets) = Unit + override fun onWindowInsetsChanged(insets: Insets) { + with (viewBinding ?: return) { + recyclerView.updatePadding( + bottom = insets.bottom + ) + } + } override fun onItemClick(item: Bookmark, view: View) { if (selectionController?.onItemClick(item.pageId) == true) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt index 32ed1edb3..f40e95d0a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import androidx.core.graphics.Insets import androidx.core.view.isGone import androidx.core.view.isVisible +import androidx.core.view.updatePadding import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.chip.Chip @@ -129,7 +130,13 @@ class ChaptersFragment : viewModel.setSelectedBranch(data.titleText) } - override fun onWindowInsetsChanged(insets: Insets) = Unit + override fun onWindowInsetsChanged(insets: Insets) { + with (viewBinding ?: return) { + recyclerViewChapters.updatePadding( + bottom = insets.bottom + ) + } + } private fun onChaptersChanged(list: List) { val adapter = chaptersAdapter ?: return diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/pages/PagesFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/pages/PagesFragment.kt index 73c709830..d82f06e2e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/pages/PagesFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/pages/PagesFragment.kt @@ -12,6 +12,7 @@ import androidx.collection.ArraySet import androidx.core.graphics.Insets import androidx.core.view.isInvisible import androidx.core.view.isVisible +import androidx.core.view.updatePadding import androidx.fragment.app.viewModels import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -142,7 +143,13 @@ class PagesFragment : super.onDestroyView() } - override fun onWindowInsetsChanged(insets: Insets) = Unit + override fun onWindowInsetsChanged(insets: Insets) { + with (viewBinding ?: return) { + recyclerView.updatePadding( + bottom = insets.bottom + ) + } + } override fun onItemClick(item: PageThumbnail, view: View) { if (selectionController?.onItemClick(item.page.id) == true) { diff --git a/app/src/main/res/layout/activity_details.xml b/app/src/main/res/layout/activity_details.xml index 6b5a38641..52d0cda9f 100644 --- a/app/src/main/res/layout/activity_details.xml +++ b/app/src/main/res/layout/activity_details.xml @@ -315,6 +315,7 @@ app:behavior_hideable="false" app:behavior_peekHeight="@dimen/details_bs_peek_height" app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" + app:paddingBottomSystemWindowInsets="false" tools:layout="@layout/sheet_chapters_pages" />