From 1263f74a9b231b7ed9013bf936a448ee446d1bef Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Mon, 12 Aug 2019 13:13:42 +0200
Subject: [PATCH] Fixes scrolling in chat editor

---
 .../util/ui/FixedNestingScrollView.kt         | 42 +++++++++++++++++++
 app/src/main/res/layout/layout_editor.xml     | 21 ++++------
 2 files changed, 51 insertions(+), 12 deletions(-)
 create mode 100644 app/src/main/java/de/kuschku/quasseldroid/util/ui/FixedNestingScrollView.kt

diff --git a/app/src/main/java/de/kuschku/quasseldroid/util/ui/FixedNestingScrollView.kt b/app/src/main/java/de/kuschku/quasseldroid/util/ui/FixedNestingScrollView.kt
new file mode 100644
index 000000000..1709a028b
--- /dev/null
+++ b/app/src/main/java/de/kuschku/quasseldroid/util/ui/FixedNestingScrollView.kt
@@ -0,0 +1,42 @@
+/*
+ * Quasseldroid - Quassel client for Android
+ *
+ * Copyright (c) 2019 Janne Mareike Koschinski
+ * Copyright (c) 2019 The Quassel Project
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3 as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package de.kuschku.quasseldroid.util.ui
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.MotionEvent
+import androidx.core.widget.NestedScrollView
+
+class FixedNestingScrollView : NestedScrollView {
+  constructor(context: Context) :
+    super(context)
+
+  constructor(context: Context, attrs: AttributeSet?) :
+    super(context, attrs)
+
+  constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
+    super(context, attrs, defStyleAttr)
+
+  override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
+    if (!canScrollVertically(-1))
+      return false
+    return super.onInterceptTouchEvent(ev)
+  }
+}
diff --git a/app/src/main/res/layout/layout_editor.xml b/app/src/main/res/layout/layout_editor.xml
index 8a316d8c2..39910170a 100644
--- a/app/src/main/res/layout/layout_editor.xml
+++ b/app/src/main/res/layout/layout_editor.xml
@@ -31,9 +31,10 @@
     android:layout_weight="1"
     android:orientation="vertical">
 
-    <androidx.constraintlayout.widget.ConstraintLayout
+    <LinearLayout
       android:layout_width="match_parent"
-      android:layout_height="match_parent">
+      android:layout_height="match_parent"
+      android:orientation="horizontal">
 
       <androidx.appcompat.widget.AppCompatImageButton
         android:id="@+id/tab_complete"
@@ -50,15 +51,11 @@
         app:srcCompat="@drawable/ic_tab"
         app:tint="?attr/colorTextSecondary" />
 
-      <ScrollView
+      <de.kuschku.quasseldroid.util.ui.FixedNestingScrollView
         android:id="@+id/chatline_scroller"
-        android:layout_width="0dp"
-        android:layout_height="0dp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toStartOf="@+id/send"
-        app:layout_constraintHorizontal_bias="1.0"
-        app:layout_constraintStart_toEndOf="@+id/tab_complete"
-        app:layout_constraintTop_toTopOf="parent">
+        android:layout_width="0dip"
+        android:layout_height="match_parent"
+        android:layout_weight="1">
 
         <de.kuschku.quasseldroid.ui.chat.input.RichEditText
           android:id="@+id/chatline"
@@ -77,7 +74,7 @@
           android:paddingBottom="8dp"
           android:textColor="?attr/colorForeground"
           android:textSize="16sp" />
-      </ScrollView>
+      </de.kuschku.quasseldroid.util.ui.FixedNestingScrollView>
 
       <androidx.appcompat.widget.AppCompatImageButton
         android:id="@+id/send"
@@ -95,7 +92,7 @@
         app:srcCompat="@drawable/ic_send"
         app:tint="?attr/colorAccent"
         tools:ignore="UnusedAttribute" />
-    </androidx.constraintlayout.widget.ConstraintLayout>
+    </LinearLayout>
 
     <androidx.recyclerview.widget.RecyclerView
       android:id="@+id/autocomplete_list"
-- 
GitLab