Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tunjid committed Apr 19, 2021
1 parent 03a2096 commit cfe4d54
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
67 changes: 67 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Core [Unreleased]

### Added

- Added `doOnEveryEvent` as shorthand for adding a `LifeCycleObserver`

## ViewPager2 [Unreleased]

### Added

- `FragmentListAdapter` for easy and efficient management of `Fragment` instances in a `FragmentStateAdapter`

## Core [1.3.1]

### Fixed

- Fixed callback of service being bound in `HardServiceConnection` firing before the `Service` has been assigned to it's `var`

## Navigation [1.2.1]

### Added

- Allowed `MultiStackNavigator` to have different back stack types as defined by
``` kotlin
sealed class BackStackType {
object UniqueEntries : BackStackType()
object Unlimited : BackStackType()
data class Restricted(val count: Int) : BackStackType()
}
```

## View [1.2.0]

### Changed

- Maintenance update, bumped core androidx versions

## RecyclerView [1.2.0]

### Added

- `RecyclerViewMultiScroller` to synchronize scrolling of multiple `RecyclerView` instances

## Material [1.0.4]

### Changed

- Maintenance update, bumped core androidx versions

## Communications [1.0.0]

### Changed

- Initial release

## SavedState [1.0.1]

### Changed

- Maintenance update, bumped core androidx versions
14 changes: 14 additions & 0 deletions viewpager2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ViewPager2

### FragmentListAdapter

Allows for efficient display `Fragments` in a `ViewPager2` by using `DiffUtil` to diff changes in
the adapter. Extensions are available for both `Fragment` and `FragmentActivity` types.

There are 1 main building blocks:

1. `FragmentTab` a type that represents a `Fragment` in the `ViewPager2`, it's purpose is to map to
a `Fragment` and uniquely identify a it by it's contents, you want to use a `data` class to
implement this, or at the very least a class with stable `equals` and `hashcode` implementations.

With that, updating the `ViewPager2` is as simple as `FragmentListAdapter.submitList(newTabs)`.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import androidx.recyclerview.widget.AsyncListDiffer
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.tunjid.androidx.recyclerview.diff.DiffAdapterCallback

/**
* Represents a type that maps to a `Fragment`. You want to use a data class for this, or at the
* very least a class that has stable implementations of [Any.equals] and [Any.hashCode].
*/
interface FragmentTab {
fun title(res: Resources): CharSequence
fun createFragment(): Fragment
}

// We use toString to avoid hash code collisions for data classes, which are calculated purely based
// on constructor arguments, not on class name. This means that different data classes with the same
// argument have colliding hash codes
val FragmentTab.itemId: Long get() = toString().hashCode().toLong()
// Uniquely identify tabs by hashing fully qualified name along with their contents
private val FragmentTab.itemId: Long get() = "${this.javaClass.name}-${hashCode()}".hashCode().toLong()

fun <T : FragmentTab> Fragment.fragmentListAdapterOf(
initialTabs: List<T>? = null,
Expand All @@ -31,6 +33,7 @@ fun <T : FragmentTab> Fragment.fragmentListAdapterOf(
resources = this.resources
)

@Suppress("unused")
fun <T : FragmentTab> FragmentActivity.fragmentListAdapterOf(
initialTabs: List<T>? = null,
lifecycle: Lifecycle = this.lifecycle
Expand Down

0 comments on commit cfe4d54

Please sign in to comment.