-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GridLayoutManager is buggy - https://issuetracker.google.com/issues/37067220: it randomly loses or incorrectly assigns focus when being scrolled via direction-based navigation. This commit reimplements onFocusSearchFailed() on top of scrollBy() to work around that problem. Ordinary touch-based navigation should not be affected.
- Loading branch information
Alexander
committed
Oct 7, 2019
1 parent
40e4839
commit 3c4d62c
Showing
7 changed files
with
140 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/src/main/java/org/schabi/newpipe/views/FixedGridLayoutManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) Eltex ltd 2019 <[email protected]> | ||
* FixedGridLayoutManager.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.util.AttributeSet; | ||
import android.view.FocusFinder; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.recyclerview.widget.GridLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
// Version of GridLayoutManager that works around https://issuetracker.google.com/issues/37067220 | ||
public class FixedGridLayoutManager extends GridLayoutManager { | ||
public FixedGridLayoutManager(Context context, int spanCount) { | ||
super(context, spanCount); | ||
} | ||
|
||
public FixedGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
} | ||
|
||
public FixedGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) { | ||
super(context, spanCount, orientation, reverseLayout); | ||
} | ||
|
||
@Override | ||
public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state) { | ||
FocusFinder ff = FocusFinder.getInstance(); | ||
|
||
View result = ff.findNextFocus((ViewGroup) focused.getParent(), focused, focusDirection); | ||
if (result != null) { | ||
return super.onFocusSearchFailed(focused, focusDirection, recycler, state); | ||
} | ||
|
||
if (focusDirection == View.FOCUS_DOWN) { | ||
scrollVerticallyBy(10, recycler, state); | ||
return null; | ||
} | ||
|
||
return super.onFocusSearchFailed(focused, focusDirection, recycler, state); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
app/src/main/java/org/schabi/newpipe/views/NewPipeRecyclerView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (C) Eltex ltd 2019 <[email protected]> | ||
* NewPipeRecyclerView.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.util.AttributeSet; | ||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
public class NewPipeRecyclerView extends RecyclerView { | ||
private static final String TAG = "FixedRecyclerView"; | ||
|
||
public NewPipeRecyclerView(@NonNull Context context) { | ||
super(context); | ||
} | ||
|
||
public NewPipeRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public NewPipeRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
} | ||
|
||
@Override | ||
public View focusSearch(int direction) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public View focusSearch(View focused, int direction) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean dispatchUnhandledMove(View focused, int direction) { | ||
View found = super.focusSearch(focused, direction); | ||
if (found != null) { | ||
found.requestFocus(direction); | ||
return true; | ||
} | ||
|
||
if (direction == View.FOCUS_UP) { | ||
if (canScrollVertically(-1)) { | ||
scrollBy(0, -10); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return super.dispatchUnhandledMove(focused, direction); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters