Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
LDRAlighieri committed Aug 31, 2020
2 parents ee01694 + 2e9eae9 commit d1361f5
Showing 26 changed files with 887 additions and 47 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,24 @@
# ChangeLog


## Version 1.4.0

* New: Bindings list:
* Google "material" library bindings:
* `corbind-material`:
* `Slider`:
* `touches`
* `valueChanges`
* `valueChangeEvents`
* `RangeSlider`:
* `touches`
* `valuesChanges`
* `valuesChangeEvents`
* Update: Kotlin modules dependency to v1.4.0.
* Update: Kotlin coroutines modules dependency to v1.3.9.
* Update: Material components dependency to v1.2.0.


## Version 1.3.2

* Update: Kotlin modules dependency to v1.3.72.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![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.3.72-blue.svg)](https://kotlinlang.org)
[![Kotlin Coroutines Version](https://img.shields.io/badge/Coroutines-v1.3.5-blue.svg)](https://kotlinlang.org/docs/reference/coroutines-overview.html)
[![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.4.0-blue.svg)](https://kotlinlang.org)
[![Kotlin Coroutines Version](https://img.shields.io/badge/Coroutines-v1.3.9-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)
@@ -23,26 +23,26 @@ This library is for Android applications only. Help you to transform Android UI

Platform bindings:
```groovy
implementation 'ru.ldralighieri.corbind:corbind:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind:1.4.0'
```

AndroidX library bindings:
```groovy
implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-core:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-leanback:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-navigation:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-recyclerview:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-slidingpanelayout:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-viewpager:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-viewpager2:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.4.0'
implementation 'ru.ldralighieri.corbind:corbind-core:1.4.0'
implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.4.0'
implementation 'ru.ldralighieri.corbind:corbind-leanback:1.4.0'
implementation 'ru.ldralighieri.corbind:corbind-navigation:1.4.0'
implementation 'ru.ldralighieri.corbind:corbind-recyclerview:1.4.0'
implementation 'ru.ldralighieri.corbind:corbind-slidingpanelayout:1.4.0'
implementation 'ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.4.0'
implementation 'ru.ldralighieri.corbind:corbind-viewpager:1.4.0'
implementation 'ru.ldralighieri.corbind:corbind-viewpager2:1.4.0'
```

Google 'material' library bindings:
```groovy
implementation 'ru.ldralighieri.corbind:corbind-material:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-material:1.4.0'
```

Snapshot build:
@@ -52,7 +52,7 @@ repositories {
}
dependencies {
implementation 'ru.ldralighieri.corbind:{module}:1.3.3-SNAPSHOT'
implementation 'ru.ldralighieri.corbind:{module}:1.4.1-SNAPSHOT'
}
```

30 changes: 15 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -18,22 +18,22 @@ buildscript {

ext {
versions = [
'kotlin': '1.3.72',
'kotlin_coroutines': '1.3.5',
'android_gradle': '3.6.3',
'kotlin': '1.4.0',
'kotlin_coroutines': '1.3.9',
'android_gradle': '4.0.1',
'androidx': [
'core': '1.2.0',
'core': '1.3.1',
'annotation': '1.1.0',
'appcompat': '1.1.0',
'drawerlayout': '1.0.0',
'appcompat': '1.2.0',
'drawerlayout': '1.1.0',
'leanback': '1.0.0',
'navigation': '2.2.2',
'navigation': '2.3.0',
'recycler_view': '1.1.0',
'slidingpane_layout': '1.0.0',
'swiperefresh_layout': '1.0.0',
'slidingpane_layout': '1.1.0',
'swiperefresh_layout': '1.1.0',
'viewpager': '1.0.0',
'viewpager2': '1.0.0',
'material': '1.1.0'
'material': '1.2.0'
],
'ktlint': '0.33.0',
'dokka': '0.10.1'
@@ -96,9 +96,9 @@ buildscript {


plugins {
id "com.diffplug.gradle.spotless" version "3.28.1"
id 'com.github.ben-manes.versions' version '0.28.0'
id "io.gitlab.arturbosch.detekt" version "1.8.0"
id "com.diffplug.spotless" version "5.3.0"
id 'com.github.ben-manes.versions' version '0.29.0'
id "io.gitlab.arturbosch.detekt" version "1.12.0"
}


@@ -124,7 +124,7 @@ subprojects {
group = GROUP
version = VERSION_NAME

apply plugin: 'com.diffplug.gradle.spotless'
apply plugin: 'com.diffplug.spotless'
spotless {
kotlin {
target "**/*.kt"
@@ -149,7 +149,7 @@ subprojects {


detekt {
toolVersion = "1.8.0"
toolVersion = "1.12.0"

failFast = false
buildUponDefaultConfig = true
2 changes: 1 addition & 1 deletion corbind-appcompat/README.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
To add androidx appcompat bindings, import `corbind-appcompat` module:

```groovy
implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.4.0'
```

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

```groovy
implementation 'ru.ldralighieri.corbind:corbind-core:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-core:1.4.0'
```

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

```groovy
implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.4.0'
```

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

```groovy
implementation 'ru.ldralighieri.corbind:corbind-leanback:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-leanback:1.4.0'
```

## List of extensions
8 changes: 7 additions & 1 deletion corbind-material/README.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
To add material bindings, import `corbind-material` module:

```groovy
implementation 'ru.ldralighieri.corbind:corbind-material:1.3.2'
implementation 'ru.ldralighieri.corbind:corbind-material:1.4.0'
```

## List of extensions
@@ -27,6 +27,12 @@ Component | Extension | Description
  | `negativeClicks` | Called when the user clicks the cancel button.
  | `positiveClicks` | Called when the user confirms a valid selection.
**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.
**RangeSlider** | `valuesChanges` | Called a range slider's value is changed. This is called for all existing values to check all the current values use.
**RangeSlider** | `valuesChangeEvents` | A more advanced version of the `valuesChanges`.
**Slider** | `touches` | Called when a slider's touch event is being started/stopped.
**Slider** | `valueChanges` | Called a slider's value is changed.
**Slider** | `valueChangeEvents` | A more advanced version of the `valuesChanges`.
**Snackbar** | `dismisses` | Called when the given Snackbar has been dismissed, either through a time-out, having been manually dismissed, or an action being clicked.
  | `shown` | Called when the given Snackbar is visible.
**View**<br>(SwipeDismissBehavior) | `dismisses` | Called when view has been dismissed via swiping.
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright 2020 Vladimir Raupov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ru.ldralighieri.corbind.material

import androidx.annotation.CheckResult
import com.google.android.material.slider.RangeSlider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.isActive
import ru.ldralighieri.corbind.corbindReceiveChannel
import ru.ldralighieri.corbind.safeOffer

/**
* Perform an action on touch tracking events for [RangeSlider].
*
* @param scope Root coroutine scope
* @param capacity Capacity of the channel's buffer (no buffer by default)
* @param action An action to perform
*/
fun RangeSlider.touches(
scope: CoroutineScope,
capacity: Int = Channel.RENDEZVOUS,
action: suspend (Boolean) -> Unit
) {
val events = scope.actor<Boolean>(Dispatchers.Main.immediate, capacity) {
for (event in channel) action(event)
}

val listener = listener(scope, events::offer)
addOnSliderTouchListener(listener)
events.invokeOnClose { removeOnSliderTouchListener(listener) }
}

/**
* Perform an action on touch tracking events for [RangeSlider], inside new [CoroutineScope].
*
* @param capacity Capacity of the channel's buffer (no buffer by default)
* @param action An action to perform
*/
suspend fun RangeSlider.touches(
capacity: Int = Channel.RENDEZVOUS,
action: suspend (Boolean) -> Unit
) = coroutineScope {
touches(this, capacity, action)
}

/**
* Create a channel of touch tracking events for [RangeSlider].
*
* Example:
*
* ```
* launch {
* rangeSlider.touches(scope)
* .consumeEach { /* handle touch tracking event */ }
* }
* ```
*
* @param scope Root coroutine scope
* @param capacity Capacity of the channel's buffer (no buffer by default)
*/
@CheckResult
fun RangeSlider.touches(
scope: CoroutineScope,
capacity: Int = Channel.RENDEZVOUS
): ReceiveChannel<Boolean> = corbindReceiveChannel(capacity) {
val listener = listener(scope, ::safeOffer)
addOnSliderTouchListener(listener)
invokeOnClose { removeOnSliderTouchListener(listener) }
}

/**
* Create a flow of touch tracking events for [RangeSlider].
*
* Examples:
*
* ```
* rangeSlider.touches()
* .onEach { /* handle touch tracking event */ }
* .launchIn(scope)
* ```
*/
@CheckResult
fun RangeSlider.touches(): Flow<Boolean> = channelFlow {
val listener = listener(this, ::offer)
addOnSliderTouchListener(listener)
awaitClose { removeOnSliderTouchListener(listener) }
}

@CheckResult
private fun listener(
scope: CoroutineScope,
emitter: (Boolean) -> Unit
) = object : RangeSlider.OnSliderTouchListener {

override fun onStartTrackingTouch(slider: RangeSlider) { onEvent(true) }
override fun onStopTrackingTouch(slider: RangeSlider) { onEvent(false) }

private fun onEvent(event: Boolean) {
if (scope.isActive) { emitter(event) }
}
}
Loading

0 comments on commit d1361f5

Please sign in to comment.