Fix unwanted touch events when chapters sheet is collapsed

devel
Koitharu 6 months ago
parent c8a8203c39
commit 464f24e9f0
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -0,0 +1,22 @@
package org.koitharu.kotatsu.core.ui.widgets
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.FrameLayout
class TouchBlockLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
) : FrameLayout(context, attrs) {
var isTouchEventsAllowed = true
override fun onInterceptTouchEvent(
ev: MotionEvent?
): Boolean = if (isTouchEventsAllowed) {
super.onInterceptTouchEvent(ev)
} else {
true
}
}

@ -99,10 +99,11 @@ class ChaptersPagesSheet : BaseAdaptiveSheet<SheetChaptersPagesBinding>(),
override fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat = insets override fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat = insets
override fun onStateChanged(sheet: View, newState: Int) { override fun onStateChanged(sheet: View, newState: Int) {
if (newState == STATE_DRAGGING || newState == STATE_SETTLING) { val binding = viewBinding ?: return
return binding.layoutTouchBlock.isTouchEventsAllowed = newState != STATE_COLLAPSED
} if (newState == STATE_DRAGGING || newState == STATE_SETTLING) {
val binding = viewBinding ?: return return
}
val isActionModeStarted = actionModeDelegate?.isActionModeStarted == true val isActionModeStarted = actionModeDelegate?.isActionModeStarted == true
binding.toolbar.menuView?.isVisible = newState == STATE_EXPANDED && !isActionModeStarted binding.toolbar.menuView?.isVisible = newState == STATE_EXPANDED && !isActionModeStarted
binding.splitButtonRead.isVisible = newState != STATE_EXPANDED && !isActionModeStarted binding.splitButtonRead.isVisible = newState != STATE_EXPANDED && !isActionModeStarted

@ -1,82 +1,88 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetHeaderBar <org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetHeaderBar
android:id="@+id/headerBar" android:id="@+id/headerBar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:title="@string/chapters" /> app:title="@string/chapters" />
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:baselineAligned="false" android:baselineAligned="false"
android:orientation="horizontal"> android:orientation="horizontal">
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/tabs" android:id="@+id/tabs"
style="?tabSecondaryStyle" style="?tabSecondaryStyle"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
android:layout_weight="1" android:layout_weight="1"
android:background="@null" android:background="@null"
app:tabGravity="start" app:tabGravity="start"
app:tabIndicator="@drawable/bg_tab_pill" app:tabIndicator="@drawable/bg_tab_pill"
app:tabIndicatorAnimationMode="fade" app:tabIndicatorAnimationMode="fade"
app:tabIndicatorColor="?colorSurfaceDim" app:tabIndicatorColor="?colorSurfaceDim"
app:tabIndicatorFullWidth="true" app:tabIndicatorFullWidth="true"
app:tabIndicatorGravity="stretch" app:tabIndicatorGravity="stretch"
app:tabInlineLabel="true" app:tabInlineLabel="true"
app:tabMinWidth="0dp" app:tabMinWidth="0dp"
app:tabMode="scrollable" app:tabMode="scrollable"
app:tabUnboundedRipple="true" /> app:tabUnboundedRipple="true" />
<com.google.android.material.button.MaterialSplitButton <com.google.android.material.button.MaterialSplitButton
android:id="@+id/split_button_read" android:id="@+id/split_button_read"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical" android:layout_gravity="end|center_vertical"
android:paddingTop="0dp" android:paddingTop="0dp"
android:paddingBottom="0dp"> android:paddingBottom="0dp">
<Button <Button
android:id="@+id/button_read" android:id="@+id/button_read"
style="?materialSplitButtonLeadingFilledStyle" style="?materialSplitButtonLeadingFilledStyle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minWidth="@dimen/read_button_min_width" android:minWidth="@dimen/read_button_min_width"
android:text="@string/read" /> android:text="@string/read" />
<Button <Button
android:id="@+id/button_read_menu" android:id="@+id/button_read_menu"
style="?materialSplitButtonIconFilledStyle" style="?materialSplitButtonIconFilledStyle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:contentDescription="@string/show_menu" android:contentDescription="@string/show_menu"
app:icon="?expandCollapseIndicator" app:icon="?expandCollapseIndicator"
app:toggleCheckedStateOnClick="false" /> app:toggleCheckedStateOnClick="false" />
</com.google.android.material.button.MaterialSplitButton> </com.google.android.material.button.MaterialSplitButton>
</LinearLayout> </LinearLayout>
</com.google.android.material.appbar.MaterialToolbar> </com.google.android.material.appbar.MaterialToolbar>
<androidx.viewpager2.widget.ViewPager2 <org.koitharu.kotatsu.core.ui.widgets.TouchBlockLayout
android:id="@+id/pager" android:id="@+id/layout_touchBlock"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</org.koitharu.kotatsu.core.ui.widgets.TouchBlockLayout>
</LinearLayout> </LinearLayout>

Loading…
Cancel
Save