Fix scrolling comments list

AppBarLayout mostly gets it, but we still need to uphold our own part -
expanding it back after focus returns to it
This commit is contained in:
Alexander 2019-09-20 16:02:16 +07:00 committed by Alexander--
parent eeeeeef3a7
commit eaa1179572
3 changed files with 94 additions and 1 deletions

View file

@ -34,6 +34,7 @@ import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.OnClickGesture;
import org.schabi.newpipe.util.StateSaver;
import org.schabi.newpipe.util.StreamDialogEntry;
import org.schabi.newpipe.views.SuperScrollLayoutManager;
import java.util.List;
import java.util.Queue;
@ -147,7 +148,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
}
protected RecyclerView.LayoutManager getListLayoutManager() {
return new LinearLayoutManager(activity);
return new SuperScrollLayoutManager(activity);
}
protected RecyclerView.LayoutManager getGridLayoutManager() {

View file

@ -0,0 +1,53 @@
/*
* Copyright (C) Eltex ltd 2019 <eltex@eltex-co.ru>
* SuperScrollLayoutManager.java is part of NewPipe.
*
* NewPipe 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.
*
* NewPipe 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 NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
package org.schabi.newpipe.views;
import android.content.Context;
import android.graphics.Rect;
import android.view.FocusFinder;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public final class SuperScrollLayoutManager extends LinearLayoutManager {
private final Rect handy = new Rect();
public SuperScrollLayoutManager(Context context) {
super(context);
}
@Override
public boolean requestChildRectangleOnScreen(@NonNull RecyclerView parent, @NonNull View child, @NonNull Rect rect, boolean immediate, boolean focusedChildVisible) {
if (!parent.isInTouchMode()) {
// only activate when in directional navigation mode (Android TV etc) fine grained
// touch scrolling is better served by nested scroll system
if (!focusedChildVisible || getFocusedChild() == child) {
handy.set(rect);
parent.offsetDescendantRectToMyCoords(child, handy);
parent.requestRectangleOnScreen(handy, immediate);
}
}
return super.requestChildRectangleOnScreen(parent, child, rect, immediate, focusedChildVisible);
}
}