Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
LDRAlighieri committed Jul 2, 2021
2 parents d933c8f + 0cde3e7 commit 8d643de
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 97 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
# ChangeLog


## Version 1.5.2

* Update: `BottomNavigationView` extensions replaced by `NavigationBarView` extensions.
* Update: Kotlin modules dependency to v1.5.20.
* Update: Material components dependency to v1.4.0.
* Update: Minor update of other libraries.


## Version 1.5.1

* Fix: Kotlin coroutines issue 974.
Expand Down
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[![Corbind](logo.svg)](https://ldralighieri.github.io/Corbind)

[![Maven Central](https://img.shields.io/maven-central/v/ru.ldralighieri.corbind/corbind.svg)](https://search.maven.org/search?q=g:ru.ldralighieri.corbind)
[![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.5.0-blue.svg)](https://kotlinlang.org)
[![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.5.20-blue.svg)](https://kotlinlang.org)
[![Kotlin Coroutines Version](https://img.shields.io/badge/Coroutines-v1.5.0-blue.svg)](https://kotlinlang.org/docs/reference/coroutines-overview.html)
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a1c9a1b1d1ce4ca7a201ab93492bf6e0)](https://www.codacy.com/app/LDRAlighieri/Corbind?utm_source=github.com&utm_medium=referral&utm_content=LDRAlighieri/Corbind&utm_campaign=Badge_Grade)
[![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14)

[![Google Dev Library](https://img.shields.io/badge/Featured%20in%20devlibrary.withgoogle.com-Corbind-blue)](https://devlibrary.withgoogle.com/products/android/repos/LDRAlighieri-Corbind)
[![Android Weekly](https://androidweekly.net/issues/issue-377/badge)](https://androidweekly.net/issues/issue-377)

<br>
Expand All @@ -23,28 +25,28 @@ This library is for Android applications only. Help you to transform Android UI

Platform bindings:
```groovy
implementation 'ru.ldralighieri.corbind:corbind:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind:1.5.2'
```

AndroidX library bindings:
```groovy
implementation 'ru.ldralighieri.corbind:corbind-activity:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-core:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-leanback:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-lifecycle:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-navigation:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-recyclerview:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-slidingpanelayout:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-viewpager:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-viewpager2:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-activity:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-core:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-leanback:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-lifecycle:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-navigation:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-recyclerview:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-slidingpanelayout:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-viewpager:1.5.2'
implementation 'ru.ldralighieri.corbind:corbind-viewpager2:1.5.2'
```

Google 'material' library bindings:
```groovy
implementation 'ru.ldralighieri.corbind:corbind-material:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-material:1.5.2'
```

Snapshot build:
Expand All @@ -54,7 +56,7 @@ repositories {
}
dependencies {
implementation 'ru.ldralighieri.corbind:{module}:1.5.2-SNAPSHOT'
implementation 'ru.ldralighieri.corbind:{module}:1.5.3-SNAPSHOT'
}
```

Expand Down Expand Up @@ -139,7 +141,7 @@ If I forgot something or you have any ideas what can be added or corrected, plea
## License

```
Copyright 2019 Vladimir Raupov
Copyright 2019-2021 Vladimir Raupov
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ buildscript {

ext {
versions = [
'kotlin': '1.5.0',
'kotlin': '1.5.20',
'kotlin_coroutines': '1.5.0',
'android_gradle': '4.2.1',
'android_gradle': '4.2.2',
'androidx': [
'core': '1.3.2',
'core': '1.6.0',
'annotation': '1.2.0',
'appcompat': '1.2.0',
'appcompat': '1.3.0',
'drawerlayout': '1.1.1',
'leanback': '1.0.0',
'navigation': '2.3.5',
'recyclerview': '1.2.0',
'recyclerview': '1.2.1',
'slidingpanelayout': '1.1.0',
'swiperefreshlayout': '1.1.0',
'viewpager': '1.0.0',
'viewpager2': '1.0.0',
'lifecycle': '2.3.1',
'activity': '1.2.3'
],
'material': '1.3.0',
'material': '1.4.0',
'ktlint': '0.40.0',
'dokka': '0.10.1'
]
Expand Down Expand Up @@ -99,9 +99,9 @@ buildscript {


plugins {
id "com.diffplug.spotless" version "5.12.5"
id 'com.github.ben-manes.versions' version '0.38.0'
id "io.gitlab.arturbosch.detekt" version "1.17.0"
id "com.diffplug.spotless" version "5.14.0"
id 'com.github.ben-manes.versions' version '0.39.0'
id "io.gitlab.arturbosch.detekt" version "1.17.1"
}


Expand Down
2 changes: 1 addition & 1 deletion corbind-activity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
To add androidx activity bindings, import `corbind-activity` module:

```groovy
implementation 'ru.ldralighieri.corbind:corbind-activity:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-activity:1.5.2'
```

## List of extensions
Expand Down
2 changes: 1 addition & 1 deletion corbind-appcompat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
To add androidx appcompat bindings, import `corbind-appcompat` module:

```groovy
implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.5.2'
```

## List of extensions
Expand Down
2 changes: 1 addition & 1 deletion corbind-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
To add androidx core bindings, import `corbind-core` module:

```groovy
implementation 'ru.ldralighieri.corbind:corbind-core:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-core:1.5.2'
```

## List of extensions
Expand Down
2 changes: 1 addition & 1 deletion corbind-drawerlayout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
To add androidx drawerlayout bindings, import `corbind-drawerlayout` module:

```groovy
implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.5.2'
```

## List of extensions
Expand Down
2 changes: 1 addition & 1 deletion corbind-leanback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
To add androidx leanback bindings, import `corbind-leanback` module:

```groovy
implementation 'ru.ldralighieri.corbind:corbind-leanback:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-leanback:1.5.2'
```

## List of extensions
Expand Down
2 changes: 1 addition & 1 deletion corbind-lifecycle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
To add androidx lifecycle bindings, import `corbind-lifecycle` module:

```groovy
implementation 'ru.ldralighieri.corbind:corbind-lifecycle:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-lifecycle:1.5.2'
```

## List of extensions
Expand Down
6 changes: 3 additions & 3 deletions corbind-material/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
To add material bindings, import `corbind-material` module:

```groovy
implementation 'ru.ldralighieri.corbind:corbind-material:1.5.1'
implementation 'ru.ldralighieri.corbind:corbind-material:1.5.2'
```

## List of extensions

Component | Extension | Description
--|---|--
**AppBarLayout** | `offsetChanges` | Called when the AppBarLayout's layout offset has been changed
**BottomNavigationView** | `itemReselections` | Called when the currently selected item in the bottom navigation menu is selected again.
  | `itemSelections`| Called when an item in the bottom navigation menu is selected.
**View**<br>(BottomSheetBehavior) | `slides` | Called when the bottom sheet is being dragged.
  | `stateChanges` | Called when the bottom sheet changes its state.
**Chip** | `closeIconClicks` | Called when the chip’s close icon is clicked.
Expand All @@ -30,6 +28,8 @@ Component | Extension | Description
  | `dismisses` | Called whenever the time picker is dismissed, no matter how it is dismissed.
  | `negativeClicks` | Called when the user clicks the time picker cancel button.
  | `positiveClicks` | Called when the user confirms a valid selection of the time.
**NavigationBarView** | `itemReselections` | Called when the currently selected navigation item is reselected.
  | `itemSelections`| Called when a navigation item is selected.
**NavigationView** | `itemSelections` | Called when an item in the navigation menu is selected.
**RangeSlider** | `touches` | Called when a range slider's touch event is being started/stopped.
  | `valuesChanges` | Called a range slider's value is changed. This is called for all existing values to check all the current values use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package ru.ldralighieri.corbind.material
import android.view.MenuItem
import androidx.annotation.CheckResult
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.navigation.NavigationBarView
import com.google.android.material.navigationrail.NavigationRailView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
Expand All @@ -32,16 +34,16 @@ import kotlinx.coroutines.isActive
import ru.ldralighieri.corbind.internal.corbindReceiveChannel

/**
* Perform an action on the reselected item in [BottomNavigationView].
* Perform an action on the reselected item in [NavigationBarView].
*
* *Warning:* The created actor uses [BottomNavigationView.setOnNavigationItemReselectedListener].
* Only one actor can be used at a time.
* *Warning:* The created actor uses [NavigationBarView.setOnItemReselectedListener]. Only one actor
* can be used at a time.
*
* @param scope Root coroutine scope
* @param capacity Capacity of the channel's buffer (no buffer by default)
* @param action An action to perform
*/
fun BottomNavigationView.itemReselections(
fun NavigationBarView.itemReselections(
scope: CoroutineScope,
capacity: Int = Channel.RENDEZVOUS,
action: suspend (MenuItem) -> Unit
Expand All @@ -50,37 +52,37 @@ fun BottomNavigationView.itemReselections(
for (item in channel) action(item)
}

setOnNavigationItemReselectedListener(listener(scope, events::trySend))
events.invokeOnClose { setOnNavigationItemReselectedListener(null) }
setOnItemReselectedListener(listener(scope, events::trySend))
events.invokeOnClose { setOnItemReselectedListener(null) }
}

/**
* Perform an action on the reselected item in [BottomNavigationView], inside new [CoroutineScope].
* Perform an action on the reselected item in [NavigationBarView], inside new [CoroutineScope].
*
* *Warning:* The created actor uses [BottomNavigationView.setOnNavigationItemReselectedListener].
* Only one actor can be used at a time.
* *Warning:* The created actor uses [NavigationBarView.setOnItemReselectedListener]. Only one actor
* can be used at a time.
*
* @param capacity Capacity of the channel's buffer (no buffer by default)
* @param action An action to perform
*/
suspend fun BottomNavigationView.itemReselections(
suspend fun NavigationBarView.itemReselections(
capacity: Int = Channel.RENDEZVOUS,
action: suspend (MenuItem) -> Unit
) = coroutineScope {
itemReselections(this, capacity, action)
}

/**
* Create a channel which emits the reselected item in [BottomNavigationView].
* Create a channel which emits the reselected item in [NavigationBarView].
*
* *Warning:* The created channel uses [BottomNavigationView.setOnNavigationItemReselectedListener].
* Only one channel can be used at a time.
* *Warning:* The created channel uses [NavigationBarView.setOnItemReselectedListener]. Only one
* channel can be used at a time.
*
* Example:
*
* ```
* launch {
* absListView.scrollEvents(scope)
* anyNavigationBarView.itemReselections(scope)
* .consumeEach { /* handle reselected item */ }
* }
* ```
Expand All @@ -89,38 +91,38 @@ suspend fun BottomNavigationView.itemReselections(
* @param capacity Capacity of the channel's buffer (no buffer by default)
*/
@CheckResult
fun BottomNavigationView.itemReselections(
fun NavigationBarView.itemReselections(
scope: CoroutineScope,
capacity: Int = Channel.RENDEZVOUS
): ReceiveChannel<MenuItem> = corbindReceiveChannel(capacity) {
setOnNavigationItemReselectedListener(listener(scope, ::trySend))
invokeOnClose { setOnNavigationItemReselectedListener(null) }
setOnItemReselectedListener(listener(scope, ::trySend))
invokeOnClose { setOnItemReselectedListener(null) }
}

/**
* Create a flow which emits the reselected item in [BottomNavigationView].
* Create a flow which emits the reselected item in [NavigationBarView].
*
* *Warning:* The created flow uses [BottomNavigationView.setOnNavigationItemReselectedListener].
* Only one flow can be used at a time.
* *Warning:* The created flow uses [NavigationBarView.setOnItemReselectedListener]. Only one flow
* can be used at a time.
*
* Example:
*
* ```
* bottomNavigationView.itemReselections()
* anyNavigationBarView.itemReselections()
* .onEach { /* handle reselected item */ }
* .launchIn(lifecycleScope) // lifecycle-runtime-ktx
* ```
*/
@CheckResult
fun BottomNavigationView.itemReselections(): Flow<MenuItem> = channelFlow {
setOnNavigationItemReselectedListener(listener(this, ::trySend))
awaitClose { setOnNavigationItemReselectedListener(null) }
fun NavigationBarView.itemReselections(): Flow<MenuItem> = channelFlow {
setOnItemReselectedListener(listener(this, ::trySend))
awaitClose { setOnItemReselectedListener(null) }
}

@CheckResult
private fun listener(
scope: CoroutineScope,
emitter: (MenuItem) -> Unit
) = BottomNavigationView.OnNavigationItemReselectedListener {
) = NavigationBarView.OnItemReselectedListener {
if (scope.isActive) { emitter(it) }
}
Loading

0 comments on commit 8d643de

Please sign in to comment.