-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Создан модуль corbind-material. Добавлены ивенты AppBarLayoutOffsetCh…
…anges
- Loading branch information
1 parent
39805de
commit efb1a0f
Showing
6 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'org.jetbrains.kotlin.android' | ||
|
||
kotlin { | ||
experimental { | ||
coroutines "enable" | ||
} | ||
} | ||
|
||
android { | ||
|
||
compileSdkVersion buildConfig.compileSdk | ||
defaultConfig { | ||
minSdkVersion buildConfig.minSdk | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
api project(':corbind') | ||
|
||
api deps.googleMaterial | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="ru.ldralighieri.corbind.material" /> |
68 changes: 68 additions & 0 deletions
68
...nd-material/src/main/kotlin/ru/ldralighieri/corbind/material/AppBarLayoutOffsetChanges.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package ru.ldralighieri.corbind.material | ||
|
||
import com.google.android.material.appbar.AppBarLayout | ||
import kotlinx.coroutines.experimental.CoroutineScope | ||
import kotlinx.coroutines.experimental.Dispatchers | ||
import kotlinx.coroutines.experimental.channels.Channel | ||
import kotlinx.coroutines.experimental.channels.ReceiveChannel | ||
import kotlinx.coroutines.experimental.channels.actor | ||
import kotlinx.coroutines.experimental.channels.produce | ||
import kotlinx.coroutines.experimental.coroutineScope | ||
|
||
// ----------------------------------------------------------------------------------------------- | ||
|
||
|
||
fun AppBarLayout.offsetChanges( | ||
scope: CoroutineScope, | ||
action: suspend (Int) -> Unit | ||
) { | ||
val events = scope.actor<Int>(Dispatchers.Main, Channel.CONFLATED) { | ||
for (offset in channel) action(offset) | ||
} | ||
|
||
val listener = listener(events::offer) | ||
addOnOffsetChangedListener(listener) | ||
events.invokeOnClose { removeOnOffsetChangedListener(listener) } | ||
} | ||
|
||
suspend fun AppBarLayout.offsetChanges( | ||
action: suspend (Int) -> Unit | ||
) = coroutineScope { | ||
val events = actor<Int>(Dispatchers.Main, Channel.CONFLATED) { | ||
for (offset in channel) action(offset) | ||
} | ||
|
||
val listener = listener(events::offer) | ||
addOnOffsetChangedListener(listener) | ||
events.invokeOnClose { removeOnOffsetChangedListener(listener) } | ||
} | ||
|
||
|
||
// ----------------------------------------------------------------------------------------------- | ||
|
||
|
||
fun AppBarLayout.offsetChanges( | ||
scope: CoroutineScope | ||
): ReceiveChannel<Int> = scope.produce(Dispatchers.Main, Channel.CONFLATED) { | ||
|
||
val listener = listener(::offer) | ||
addOnOffsetChangedListener(listener) | ||
invokeOnClose { removeOnOffsetChangedListener(listener) } | ||
} | ||
|
||
suspend fun AppBarLayout.offsetChanges(): ReceiveChannel<Int> = coroutineScope { | ||
|
||
produce<Int>(Dispatchers.Main, Channel.CONFLATED) { | ||
val listener = listener(::offer) | ||
addOnOffsetChangedListener(listener) | ||
invokeOnClose { removeOnOffsetChangedListener(listener) } | ||
} | ||
} | ||
|
||
|
||
// ----------------------------------------------------------------------------------------------- | ||
|
||
|
||
private fun listener( | ||
emitter: (Int) -> Boolean | ||
) = AppBarLayout.OnOffsetChangedListener { _, verticalOffset -> emitter(verticalOffset) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
rootProject.name = 'Corbind' | ||
|
||
include ':corbind' | ||
include ':corbind-core' | ||
include ':corbind-appcompat' | ||
include ':corbind-viewpager' | ||
include ':corbind-swiperefreshlayout' | ||
include ':corbind-core' | ||
include ':corbind-drawerlayout' | ||
include ':corbind-leanback' | ||
include ':corbind-material' | ||
include ':corbind-swiperefreshlayout' | ||
include ':corbind-viewpager' |