Skip to content

Commit

Permalink
Merge branch 'master' into looping_items
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa authored May 24, 2023
2 parents 3572954 + bcb7ac7 commit 9f9b7ae
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 59 deletions.
15 changes: 4 additions & 11 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ See the project website for more information: https://rubensousa.github.io/DpadR

Motivation for this library: https://rubensousa.com/2022/11/08/dpadrecyclerview/

Check the sample app for a complete example of integration of this library:

![sample](https://github.com/rubensousa/DpadRecyclerView/blob/master/assets/sample_cover.png?raw=true)

## Getting started

Add the following dependency to your app's `build.gradle`:
Expand Down Expand Up @@ -37,19 +41,8 @@ Check the official website for more information and recipes: https://rubensousa.
- Supports non smooth scroll changes
- Supports continuous and circular grid focus

## Features missing from Leanback's `BaseGridView`

- Scrolling in secondary direction
- Disabling recycling of children
- Saving and restoring children states: clients can save and restore children on the appropriate RecyclerView.Adapter callbacks
- `setChildrenVisibility`: clients can do this by iterating over the children

## Sample app

Check the sample app for a complete example of integration of this library:

![sample](https://github.com/rubensousa/DpadRecyclerView/blob/master/assets/sample_cover.png?raw=true)

Nested lists:

![nested_lists](https://github.com/rubensousa/DpadRecyclerView/blob/master/assets/sample_nested_lists.png?raw=true)
Expand Down
13 changes: 13 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

## Version 1.0.0

### 1.0.0

2023-05-16

#### New Features

- Added support for API 19 ([#146](https://github.com/rubensousa/DpadRecyclerView/issues/146))
- Added missing XML attribute for parent alignment `app:dpadRecyclerViewParentAlignmentPreferKeylineOverEdge` ([#145](https://github.com/rubensousa/DpadRecyclerView/issues/145))

#### Bug fixes

- Fixed crash when R8 is applied ([#122](https://github.com/rubensousa/DpadRecyclerView/issues/122))

### 1.0.0-rc01

2023-05-07
Expand Down
17 changes: 6 additions & 11 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# DpadRecyclerView

A RecyclerView built for Android TV as a replacement for Leanback's BaseGridView.
A RecyclerView built for Android TV as a replacement for [Leanback's](https://developer.android.com/jetpack/androidx/releases/leanback) BaseGridView.

Proceed to [Getting started](getting_started.md) to start adding `DpadRecyclerView`
to your application.

Motivation for this library is available in my [blog](https://rubensousa.com/2022/11/08/dpadrecyclerview/) in case you're interested.

## Requirements

- minSDK: 21
- Java 8

## New Features compared to Leanback's `BaseGridView`

### Layout
Expand All @@ -27,12 +22,12 @@ Motivation for this library is available in my [blog](https://rubensousa.com/202
- Non smooth scroll changes
- Continuous and circular grid focus

## Features missing from Leanback's `BaseGridView`

- Scrolling in secondary direction
- Disabling recycling of children
- Saving and restoring children states: clients can save and restore children on the appropriate RecyclerView.Adapter callbacks
- `setChildrenVisibility`: clients can do this by iterating over the children
### Upcoming features

- [Looping adapter contents](https://github.com/rubensousa/DpadRecyclerView/issues/20)
- [State saving/restoring helper](https://github.com/rubensousa/DpadRecyclerView/issues/45)
- [Drag and drop helper](https://github.com/rubensousa/DpadRecyclerView/issues/12)


## License
Expand Down
1 change: 1 addition & 0 deletions docs/xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<attr name="dpadRecyclerViewParentAlignmentOffset" format="dimension" />
<attr name="dpadRecyclerViewParentAlignmentFraction" format="float" />
<attr name="dpadRecyclerViewParentAlignmentFractionEnabled" format="boolean" />
<attr name="dpadRecyclerViewParentAlignmentPreferKeylineOverEdge" format="boolean" />
```


Expand Down
2 changes: 1 addition & 1 deletion dpadrecyclerview-test-fixtures/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
compileSdk versions.compileSdkVersion

defaultConfig {
minSdk versions.minSdkVersion
minSdk 19
targetSdk versions.targetSdkVersion

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
3 changes: 2 additions & 1 deletion dpadrecyclerview-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ android {
compileSdk versions.compileSdkVersion

defaultConfig {
minSdk versions.minSdkVersion
minSdk 19
targetSdk versions.targetSdkVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments useTestStorageService: 'true'
testInstrumentationRunnerArguments listener: 'com.rubensousa.dpadrecyclerview.testfixtures.recording.TestRecordingListener'
multiDexEnabled true
}

buildTypes {
Expand Down
3 changes: 0 additions & 3 deletions dpadrecyclerview/api/dpadrecyclerview.api
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ public final class com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutMana
public fun onAddFocusables (Landroidx/recyclerview/widget/RecyclerView;Ljava/util/ArrayList;II)Z
public fun onAttachedToWindow (Landroidx/recyclerview/widget/RecyclerView;)V
public fun onDetachedFromWindow (Landroidx/recyclerview/widget/RecyclerView;Landroidx/recyclerview/widget/RecyclerView$Recycler;)V
public final fun onFocusChanged (Z)V
public fun onInitializeAccessibilityNodeInfo (Landroidx/recyclerview/widget/RecyclerView$Recycler;Landroidx/recyclerview/widget/RecyclerView$State;Landroidx/core/view/accessibility/AccessibilityNodeInfoCompat;)V
public fun onInitializeAccessibilityNodeInfoForItem (Landroidx/recyclerview/widget/RecyclerView$Recycler;Landroidx/recyclerview/widget/RecyclerView$State;Landroid/view/View;Landroidx/core/view/accessibility/AccessibilityNodeInfoCompat;)V
public fun onInterceptFocusSearch (Landroid/view/View;I)Landroid/view/View;
Expand All @@ -420,7 +419,6 @@ public final class com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutMana
public fun onRequestChildFocus (Landroidx/recyclerview/widget/RecyclerView;Landroidx/recyclerview/widget/RecyclerView$State;Landroid/view/View;Landroid/view/View;)Z
public final fun onRequestFocusInDescendants (ILandroid/graphics/Rect;)Z
public fun onRestoreInstanceState (Landroid/os/Parcelable;)V
public final fun onRtlPropertiesChanged ()V
public fun onSaveInstanceState ()Landroid/os/Parcelable;
public fun performAccessibilityAction (Landroidx/recyclerview/widget/RecyclerView$Recycler;Landroidx/recyclerview/widget/RecyclerView$State;ILandroid/os/Bundle;)Z
public final fun removeOnLayoutCompletedListener (Lcom/rubensousa/dpadrecyclerview/DpadRecyclerView$OnLayoutCompletedListener;)V
Expand Down Expand Up @@ -449,7 +447,6 @@ public final class com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutMana
public final fun setOrientation (I)V
public final fun setParentAlignment (Lcom/rubensousa/dpadrecyclerview/ParentAlignment;Z)V
public final fun setRecycleChildrenOnDetach (Z)V
public final fun setRecyclerView (Landroidx/recyclerview/widget/RecyclerView;)V
public final fun setReverseLayout (Z)V
public final fun setScrollEnabled (Z)V
public final fun setSmoothFocusChangesEnabled (Z)V
Expand Down
3 changes: 2 additions & 1 deletion dpadrecyclerview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ android {
compileSdk versions.compileSdkVersion

defaultConfig {
minSdk versions.minSdkVersion
minSdk 19
targetSdk versions.targetSdkVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments useTestStorageService: 'true'
testInstrumentationRunnerArguments listener: 'com.rubensousa.dpadrecyclerview.testfixtures.recording.TestRecordingListener'
multiDexEnabled true
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ open class DpadRecyclerView @JvmOverloads constructor(
// Focus a ViewHolder's view first by default if one exists
descendantFocusability = FOCUS_AFTER_DESCENDANTS

// Typically all RecyclerViews have a fixed size, so this is a safe default
setHasFixedSize(true)

// Call setItemAnimator to set it up
this.itemAnimator = itemAnimator

Expand Down Expand Up @@ -164,11 +161,12 @@ open class DpadRecyclerView @JvmOverloads constructor(
typedArray.getInt(R.styleable.DpadRecyclerView_android_gravity, Gravity.NO_GRAVITY)
)
}
val edge = ParentAlignment.Edge.values()[typedArray.getInt(
R.styleable.DpadRecyclerView_dpadRecyclerViewParentAlignmentEdge,
ParentAlignment.Edge.MIN_MAX.ordinal
)]
val parentAlignment = ParentAlignment(
edge = ParentAlignment.Edge.values()[typedArray.getInt(
R.styleable.DpadRecyclerView_dpadRecyclerViewParentAlignmentEdge,
ParentAlignment.Edge.MIN_MAX.ordinal
)],
edge = edge,
offset = typedArray.getDimensionPixelSize(
R.styleable.DpadRecyclerView_dpadRecyclerViewParentAlignmentOffset,
ViewAlignment.DEFAULT_OFFSET
Expand All @@ -180,7 +178,11 @@ open class DpadRecyclerView @JvmOverloads constructor(
isFractionEnabled = typedArray.getBoolean(
R.styleable.DpadRecyclerView_dpadRecyclerViewParentAlignmentFractionEnabled,
true
)
),
preferKeylineOverEdge = typedArray.getBoolean(
R.styleable.DpadRecyclerView_dpadRecyclerViewParentAlignmentPreferKeylineOverEdge,
edge == ParentAlignment.Edge.MAX
),
)
val childAlignment = ChildAlignment(
offset = typedArray.getDimensionPixelSize(
Expand All @@ -203,7 +205,7 @@ open class DpadRecyclerView @JvmOverloads constructor(
final override fun setLayoutManager(layout: LayoutManager?) {
super.setLayoutManager(layout)
pivotLayoutManager?.removeOnViewHolderSelectedListener(viewHolderTaskExecutor)
pivotLayoutManager?.setRecyclerView(null)
pivotLayoutManager?.updateRecyclerView(null)
if (pivotLayoutManager !== layout) {
pivotLayoutManager?.clearOnLayoutCompletedListeners()
pivotLayoutManager?.clearOnViewHolderSelectedListeners()
Expand All @@ -216,7 +218,7 @@ open class DpadRecyclerView @JvmOverloads constructor(
)
}
if (layout is PivotLayoutManager) {
layout.setRecyclerView(this)
layout.updateRecyclerView(this)
layout.addOnViewHolderSelectedListener(viewHolderTaskExecutor)
pivotLayoutManager = layout
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class PivotLayoutManager(properties: Properties) : RecyclerView.LayoutManager()
}
}

fun onFocusChanged(gainFocus: Boolean) {
internal fun onFocusChanged(gainFocus: Boolean) {
// Do nothing if the user is scrolling via touch events
if (!isScrollingFromTouchEvent) {
focusDispatcher.onFocusChanged(gainFocus)
Expand Down Expand Up @@ -317,8 +317,11 @@ class PivotLayoutManager(properties: Properties) : RecyclerView.LayoutManager()
pivotLayout.onRestoreInstanceState(state)
}

// Configuration methods
fun setRecyclerView(recyclerView: RecyclerView?) {
internal fun onRtlPropertiesChanged() {
requestLayout()
}

internal fun updateRecyclerView(recyclerView: RecyclerView?) {
if (recyclerView == null) {
focusDispatcher.clearParentRecyclerView()
}
Expand All @@ -328,6 +331,16 @@ class PivotLayoutManager(properties: Properties) : RecyclerView.LayoutManager()
pivotSelector.setRecyclerView(recyclerView)
}

internal fun getConfig() = configuration

internal fun setScrollingFromTouchEvent(isTouching: Boolean) {
isScrollingFromTouchEvent = isTouching
}

internal fun removeCurrentViewHolderSelection() {
pivotSelector.removeCurrentViewHolderSelection(clearSelection = isScrollingFromTouchEvent)
}

fun setChildrenDrawingOrderEnabled(enabled: Boolean) {
configuration.setChildDrawingOrderEnabled(enabled)
}
Expand Down Expand Up @@ -483,18 +496,6 @@ class PivotLayoutManager(properties: Properties) : RecyclerView.LayoutManager()

fun getChildAlignment(): ChildAlignment = layoutAlignment.getChildAlignment()

internal fun getConfig() = configuration

internal fun setScrollingFromTouchEvent(isTouching: Boolean) {
isScrollingFromTouchEvent = isTouching
}

internal fun removeCurrentViewHolderSelection() {
pivotSelector.removeCurrentViewHolderSelection(clearSelection = isScrollingFromTouchEvent)
}

// Event methods

fun addOnViewHolderSelectedListener(listener: OnViewHolderSelectedListener) {
pivotSelector.addOnViewHolderSelectedListener(listener)
}
Expand All @@ -507,10 +508,6 @@ class PivotLayoutManager(properties: Properties) : RecyclerView.LayoutManager()
pivotSelector.clearOnViewHolderSelectedListeners()
}

fun onRtlPropertiesChanged() {
requestLayout()
}

fun selectPosition(position: Int, subPosition: Int, smooth: Boolean) {
scroller.scrollToPosition(position, subPosition, smooth)
}
Expand Down
1 change: 1 addition & 0 deletions dpadrecyclerview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<attr name="dpadRecyclerViewParentAlignmentOffset" format="dimension" />
<attr name="dpadRecyclerViewParentAlignmentFraction" format="float" />
<attr name="dpadRecyclerViewParentAlignmentFractionEnabled" format="boolean" />
<attr name="dpadRecyclerViewParentAlignmentPreferKeylineOverEdge" format="dimension" />
<attr name="dpadRecyclerViewFocusableDirection" format="enum">
<enum name="standard" value="0" />
<enum name="circular" value="1" />
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.0-rc01
LIBRARY_VERSION=1.0.0
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ theme:

extra:
dpadrecyclerview:
version: '1.0.0-rc01'
version: '1.0.0'
social:
- icon: 'fontawesome/brands/github'
link: 'https://github.com/rubensousa/DpadRecyclerView'
Expand Down

0 comments on commit 9f9b7ae

Please sign in to comment.