From baf45d711092bb811656be1b70357877ff52ecf2 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Tue, 18 Jun 2024 23:48:44 +0200 Subject: [PATCH 1/7] Fix focus listener not being invoked for parent if a child RecyclerView has no listener attached --- .../tests/focus/NestedFocusListenerTest.kt | 27 +++++++++++++++++++ .../layoutmanager/PivotSelector.kt | 8 ++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/focus/NestedFocusListenerTest.kt b/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/focus/NestedFocusListenerTest.kt index e7d0ca49..bbfdefef 100644 --- a/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/focus/NestedFocusListenerTest.kt +++ b/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/focus/NestedFocusListenerTest.kt @@ -19,6 +19,9 @@ package com.rubensousa.dpadrecyclerview.test.tests.focus import androidx.core.view.get import androidx.fragment.app.testing.FragmentScenario import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.test.espresso.Espresso +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withTagValue import com.google.common.truth.Truth.assertThat import com.rubensousa.dpadrecyclerview.DpadRecyclerView import com.rubensousa.dpadrecyclerview.test.TestNestedListFragment @@ -29,7 +32,10 @@ import com.rubensousa.dpadrecyclerview.testfixtures.DpadFocusEvent import com.rubensousa.dpadrecyclerview.testfixtures.recording.ScreenRecorderRule import com.rubensousa.dpadrecyclerview.testing.KeyEvents import com.rubensousa.dpadrecyclerview.testing.R +import com.rubensousa.dpadrecyclerview.testing.actions.DpadRecyclerViewActions import com.rubensousa.dpadrecyclerview.testing.rules.DisableIdleTimeoutRule +import org.hamcrest.Matchers +import org.hamcrest.core.AllOf.allOf import org.junit.Before import org.junit.Rule import org.junit.Test @@ -127,6 +133,27 @@ class NestedFocusListenerTest { } } + @Test + fun testParentRecyclerViewStillReceivesFocusIfChildHasNoListener() { + // given + val focusEvents = 6 + Espresso.onView( + allOf( + withId(com.rubensousa.dpadrecyclerview.test.R.id.nestedRecyclerView), + withTagValue(Matchers.`is`(0)) + ) + ).perform(DpadRecyclerViewActions.execute("Clear listener") { recyclerView -> + recyclerView.clearOnViewFocusedListeners() + }) + + // when + KeyEvents.pressRight(times = focusEvents - 1) + waitForIdleScrollState() + + // then + assertThat(getParentFocusEvents()).hasSize(focusEvents) + } + private fun getChildFocusEvents(): List { var events = listOf() fragmentScenario.onFragment { fragment -> diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotSelector.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotSelector.kt index a5badcaa..c7926f77 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotSelector.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotSelector.kt @@ -106,8 +106,8 @@ internal class PivotSelector( fun focus(view: View) { view.requestFocus() - // Exit early if there's no one listening for focus events - if (focusListeners.isEmpty() || isRetainingFocus) { + // Do not notify listeners if we are retaining focus + if (isRetainingFocus) { return } val currentRecyclerView = recyclerView ?: return @@ -213,10 +213,6 @@ internal class PivotSelector( return max(0, min(itemCount - 1, position)) } - fun onLayoutChildren(state: RecyclerView.State) { - - } - fun onLayoutCompleted() { if (isSelectionUpdatePending) { isSelectionUpdatePending = false From 235d4d24621353d50fa87859996c3d4db7ef3c32 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Tue, 18 Jun 2024 23:54:45 +0200 Subject: [PATCH 2/7] Bump to 1.3.0-beta02 --- docs/changelog.md | 8 ++++++++ gradle.properties | 2 +- mkdocs.yml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 68dbb68e..906cc213 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,14 @@ ## Version 1.3.0 +### 1.3.0-beta02 + +2024-06-19 + +#### Bug fixes + +- Fixed `OnViewFocusedListener` not working correctly for a parent RecyclerView when a nested RecyclerView doesn't have a listener registered ([#229](https://github.com/rubensousa/DpadRecyclerView/pull/229)) + ### 1.3.0-beta01 2024-06-17 diff --git a/gradle.properties b/gradle.properties index 21387c72..52babd32 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,4 +22,4 @@ kotlin.code.style=official # thereby reducing the size of the R class for that library android.nonTransitiveRClass=true android.enableR8.fullMode=true -LIBRARY_VERSION=1.3.0-beta01 \ No newline at end of file +LIBRARY_VERSION=1.3.0-beta02 \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 2fddc5c3..7f027445 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,7 +24,7 @@ theme: extra: dpadrecyclerview: - version: '1.3.0-beta01' + version: '1.3.0-beta02' social: - icon: 'fontawesome/brands/github' link: 'https://github.com/rubensousa/DpadRecyclerView' From 0324cbd4232ecb7d52f9c80236c243d4296c0a0a Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Tue, 18 Jun 2024 23:58:49 +0200 Subject: [PATCH 3/7] Remove unused method call --- .../dpadrecyclerview/layoutmanager/PivotLayoutManager.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutManager.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutManager.kt index b6f5a237..f6353f62 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutManager.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutManager.kt @@ -139,7 +139,6 @@ class PivotLayoutManager(properties: Properties) : RecyclerView.LayoutManager(), // If we have focus, save it temporarily since the views will change and we might lose it hadFocusBeforeLayout = hasFocus() scroller.cancelSmoothScroller() - pivotSelector.onLayoutChildren(state) pivotLayout.onLayoutChildren(recycler, state) layoutCompletedListener?.onLayoutCompleted(state) } From 4436ac58fece0a786b15d29faaf0bcc0b52ac537 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Wed, 19 Jun 2024 00:05:50 +0200 Subject: [PATCH 4/7] Include popular android tv sdk versions for UI tests --- .github/workflows/pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a4927daf..a7f4c855 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -49,7 +49,7 @@ jobs: matrix: arch: [ x86 ] target: [ android-tv ] - api-level: [27] + api-level: [22, 25, 27, 28, 29, 30, 31] profile: [tv_1080p] steps: - name: checkout @@ -120,7 +120,7 @@ jobs: ./gradlew --build-cache dpadrecyclerview-compose:connectedDebugAndroidTest ./gradlew --build-cache sample:connectedDebugAndroidTest ./gradlew --build-cache dpadrecyclerview-testing:connectedDebugAndroidTest - ./gradlew --build-cache dpadrecyclerview:connectedDebugAndroidTest --info + ./gradlew --build-cache dpadrecyclerview:connectedDebugAndroidTest - name: Upload artifacts uses: actions/upload-artifact@v3 From abbacd280093453bd04160afe21d4f83ac4195aa Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Wed, 19 Jun 2024 00:46:03 +0200 Subject: [PATCH 5/7] Create avd cache for all api levels after pushing --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index d05eeddf..414469cb 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -45,7 +45,7 @@ jobs: matrix: arch: [ x86 ] target: [ android-tv ] - api-level: [27] + api-level: [22, 25, 27, 28, 29, 30, 31] profile: [tv_1080p] steps: - name: checkout From 8d5e356b7dce830f7a8196982f65089c847def72 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Wed, 19 Jun 2024 00:58:20 +0200 Subject: [PATCH 6/7] Revert version bump --- docs/changelog.md | 8 -------- gradle.properties | 2 +- mkdocs.yml | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 906cc213..68dbb68e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,14 +2,6 @@ ## Version 1.3.0 -### 1.3.0-beta02 - -2024-06-19 - -#### Bug fixes - -- Fixed `OnViewFocusedListener` not working correctly for a parent RecyclerView when a nested RecyclerView doesn't have a listener registered ([#229](https://github.com/rubensousa/DpadRecyclerView/pull/229)) - ### 1.3.0-beta01 2024-06-17 diff --git a/gradle.properties b/gradle.properties index 52babd32..21387c72 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,4 +22,4 @@ kotlin.code.style=official # thereby reducing the size of the R class for that library android.nonTransitiveRClass=true android.enableR8.fullMode=true -LIBRARY_VERSION=1.3.0-beta02 \ No newline at end of file +LIBRARY_VERSION=1.3.0-beta01 \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 7f027445..2fddc5c3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,7 +24,7 @@ theme: extra: dpadrecyclerview: - version: '1.3.0-beta02' + version: '1.3.0-beta01' social: - icon: 'fontawesome/brands/github' link: 'https://github.com/rubensousa/DpadRecyclerView' From d3f57da6827004916531088ac180f731cf1b06d8 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Wed, 19 Jun 2024 00:59:12 +0200 Subject: [PATCH 7/7] Run tests in single api for now --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a7f4c855..c6b8d4bb 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -49,7 +49,7 @@ jobs: matrix: arch: [ x86 ] target: [ android-tv ] - api-level: [22, 25, 27, 28, 29, 30, 31] + api-level: [27] profile: [tv_1080p] steps: - name: checkout