From 08780eade8c7df5a948252dabd84cbd43d298734 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Mon, 20 Jul 2020 11:25:36 +0200 Subject: [PATCH] remove scrolling from notification options bar (#1858) --- .../util/AppBarLayoutNoEmptyScrollBehavior.kt | 74 ------------------- .../fragment_timeline_notifications.xml | 6 +- .../fragment_timeline_notifications.xml | 6 +- 3 files changed, 4 insertions(+), 82 deletions(-) delete mode 100644 app/src/main/java/com/keylesspalace/tusky/util/AppBarLayoutNoEmptyScrollBehavior.kt diff --git a/app/src/main/java/com/keylesspalace/tusky/util/AppBarLayoutNoEmptyScrollBehavior.kt b/app/src/main/java/com/keylesspalace/tusky/util/AppBarLayoutNoEmptyScrollBehavior.kt deleted file mode 100644 index a6bbac80..00000000 --- a/app/src/main/java/com/keylesspalace/tusky/util/AppBarLayoutNoEmptyScrollBehavior.kt +++ /dev/null @@ -1,74 +0,0 @@ -/* Copyright 2019 Joel Pyska - * - * This file is a part of Tusky. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Tusky 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 Tusky; if not, - * see . */ - -package com.keylesspalace.tusky.util - -import android.content.Context -import android.util.AttributeSet -import android.view.MotionEvent -import com.google.android.material.appbar.AppBarLayout -import androidx.coordinatorlayout.widget.CoordinatorLayout -import android.view.View -import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView - - -/** - * Disable AppBar scroll if content view empty or don't need to scroll - */ -class AppBarLayoutNoEmptyScrollBehavior : AppBarLayout.Behavior { - - constructor() : super() - - constructor (context: Context, attrs: AttributeSet) : super(context, attrs) - - private fun isRecyclerViewScrollable(appBar: AppBarLayout, recyclerView: RecyclerView?): Boolean { - if (recyclerView == null) - return false - var recyclerViewHeight = recyclerView.height // Height includes RecyclerView plus AppBarLayout at same level - val appCompatHeight = appBar.height - recyclerViewHeight -= appCompatHeight - - return recyclerView.computeVerticalScrollRange() > recyclerViewHeight - } - - override fun onStartNestedScroll(parent: CoordinatorLayout, child: AppBarLayout, directTargetChild: View, target: View, nestedScrollAxes: Int, type: Int): Boolean { - return if (isRecyclerViewScrollable(child, getRecyclerView(parent))) { - super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes, type) - } else false - } - - override fun onTouchEvent(parent: CoordinatorLayout, child: AppBarLayout, ev: MotionEvent): Boolean { - //Prevent scroll on app bar drag - return if (child.isShown && !isRecyclerViewScrollable(child, getRecyclerView(parent))) - true - else - super.onTouchEvent(parent, child, ev) - } - - private fun getRecyclerView(parent: ViewGroup): RecyclerView? { - for (i in 0 until parent.childCount) { - val child = parent.getChildAt(i) - if (child is RecyclerView) - return child - else if (child is ViewGroup) { - val childRecyclerView = getRecyclerView(child) - if (childRecyclerView is RecyclerView) - return childRecyclerView - } - } - return null - } -} \ No newline at end of file diff --git a/app/src/main/res/layout-sw640dp/fragment_timeline_notifications.xml b/app/src/main/res/layout-sw640dp/fragment_timeline_notifications.xml index e39998bf..da5a204b 100644 --- a/app/src/main/res/layout-sw640dp/fragment_timeline_notifications.xml +++ b/app/src/main/res/layout-sw640dp/fragment_timeline_notifications.xml @@ -17,15 +17,13 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorSurface" - app:elevation="0dp" - app:layout_behavior="com.keylesspalace.tusky.util.AppBarLayoutNoEmptyScrollBehavior"> + app:elevation="0dp"> + android:orientation="horizontal">