diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a91d4fb..e00e8dbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ # ChangeLog +## Version 1.1.2 + +* Update: Kotlin coroutines modules dependency to v1.3.1 +* Update: Android sdk to v29 +* Update: Updated sample +* Fix: Fixed various inaccuracies, refactoring + + ## Version 1.1.0 * New: ViewPager2 module diff --git a/README.md b/README.md index 44f590be..3f2bd22e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![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.50-blue.svg)](https://kotlinlang.org) +[![Kotlin Coroutines Version](https://img.shields.io/badge/Coroutines-v1.3.1-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) @@ -21,25 +22,25 @@ This library is for Android applications only. Help you to transform Android UI Platform bindings: ```groovy -implementation 'ru.ldralighieri.corbind:corbind:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind:1.1.2' ``` AndroidX library bindings: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.1.0' -implementation 'ru.ldralighieri.corbind:corbind-core:1.1.0' -implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.1.0' -implementation 'ru.ldralighieri.corbind:corbind-leanback:1.1.0' -implementation 'ru.ldralighieri.corbind:corbind-recyclerview:1.1.0' -implementation 'ru.ldralighieri.corbind:corbind-slidingpanelayout:1.1.0' -implementation 'ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.1.0' -implementation 'ru.ldralighieri.corbind:corbind-viewpager:1.1.0' -implementation 'ru.ldralighieri.corbind:corbind-viewpager2:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.1.2' +implementation 'ru.ldralighieri.corbind:corbind-core:1.1.2' +implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.1.2' +implementation 'ru.ldralighieri.corbind:corbind-leanback:1.1.2' +implementation 'ru.ldralighieri.corbind:corbind-recyclerview:1.1.2' +implementation 'ru.ldralighieri.corbind:corbind-slidingpanelayout:1.1.2' +implementation 'ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.1.2' +implementation 'ru.ldralighieri.corbind:corbind-viewpager:1.1.2' +implementation 'ru.ldralighieri.corbind:corbind-viewpager2:1.1.2' ``` Google 'material' library bindings: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-material:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-material:1.1.2' ``` diff --git a/build.gradle b/build.gradle index 196970f7..e823fada 100644 --- a/build.gradle +++ b/build.gradle @@ -19,12 +19,12 @@ buildscript { ext { versions = [ 'kotlin' : '1.3.50', - 'kotlin_coroutines' : '1.3.0', + 'kotlin_coroutines' : '1.3.1', 'android_gradle' : '3.5.0', 'androidx' : [ - 'core' : '1.0.2', + 'core' : '1.1.0', 'annotation' : '1.1.0', - 'appcompat' : '1.0.2', + 'appcompat' : '1.1.0', 'drawerlayout' : '1.0.0', 'leanback' : '1.0.0', 'recycler_view' : '1.0.0', @@ -66,9 +66,9 @@ buildscript { ] buildConfig = [ - 'compileSdk': 28, + 'compileSdk': 29, 'minSdk': 14, - 'targetSdk': 28 + 'targetSdk': 29 ] } @@ -95,7 +95,7 @@ buildscript { plugins { id "com.diffplug.gradle.spotless" version "3.24.2" - id 'com.github.ben-manes.versions' version '0.22.0' + id 'com.github.ben-manes.versions' version '0.25.0' id "io.gitlab.arturbosch.detekt" version "1.0.1" } diff --git a/corbind-appcompat/README.md b/corbind-appcompat/README.md index a0400367..7fff60f8 100644 --- a/corbind-appcompat/README.md +++ b/corbind-appcompat/README.md @@ -4,7 +4,7 @@ To add androidx appcompat bindings, import `corbind-appcompat` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.1.2' ``` ## List of extensions diff --git a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ActionMenuViewItemClicks.kt b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ActionMenuViewItemClicks.kt index 49a6624a..ef3f2df6 100644 --- a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ActionMenuViewItemClicks.kt +++ b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ActionMenuViewItemClicks.kt @@ -44,7 +44,6 @@ fun ActionMenuView.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (item in channel) action(item) } @@ -54,7 +53,7 @@ fun ActionMenuView.itemClicks( } /** - * Perform an action on clicked menu item in [ActionMenuView] inside new [CoroutineScope]. + * Perform an action on clicked menu item in [ActionMenuView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,13 +62,7 @@ suspend fun ActionMenuView.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (item in channel) action(item) - } - - setOnMenuItemClickListener(listener(this, events::offer)) - events.invokeOnClose { setOnMenuItemClickListener(null) } + itemClicks(this, capacity, action) } /** diff --git a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/PopupMenuDismisses.kt b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/PopupMenuDismisses.kt index ea8146a0..9e2682b3 100644 --- a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/PopupMenuDismisses.kt +++ b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/PopupMenuDismisses.kt @@ -46,7 +46,6 @@ fun PopupMenu.dismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -56,7 +55,7 @@ fun PopupMenu.dismisses( } /** - * Perform an action on [PopupMenu] dismiss events inside new [CoroutineScope]. + * Perform an action on [PopupMenu] dismiss events, inside new [CoroutineScope]. * * *Warning:* The created actor uses [PopupMenu.setOnDismissListener] to emit dismiss change. * Only one actor can be used for a view at a time. @@ -68,13 +67,7 @@ suspend fun PopupMenu.dismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - setOnDismissListener(listener(this, events::offer)) - events.invokeOnClose { setOnMenuItemClickListener(null) } + dismisses(this, capacity, action) } /** diff --git a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/PopupMenuItemClicks.kt b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/PopupMenuItemClicks.kt index a511dbae..3bf95685 100644 --- a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/PopupMenuItemClicks.kt +++ b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/PopupMenuItemClicks.kt @@ -47,7 +47,6 @@ fun PopupMenu.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (item in channel) action(item) } @@ -57,7 +56,7 @@ fun PopupMenu.itemClicks( } /** - * Perform an action on clicked item in [PopupMenu] inside new [CoroutineScope]. + * Perform an action on clicked item in [PopupMenu], inside new [CoroutineScope]. * * *Warning:* The created actor uses [PopupMenu.setOnMenuItemClickListener] to emit dismiss * change. Only one actor can be used for a view at a time. @@ -69,13 +68,7 @@ suspend fun PopupMenu.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (item in channel) action(item) - } - - setOnMenuItemClickListener(listener(this, events::offer)) - events.invokeOnClose { setOnMenuItemClickListener(null) } + itemClicks(this, capacity, action) } /** diff --git a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/SearchViewQueryTextChangeEvents.kt b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/SearchViewQueryTextChangeEvents.kt index 9db75e8d..0ebb7aa9 100644 --- a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/SearchViewQueryTextChangeEvents.kt +++ b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/SearchViewQueryTextChangeEvents.kt @@ -49,18 +49,17 @@ fun SearchView.queryTextChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (SearchViewQueryTextEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } events.offer(SearchViewQueryTextEvent(this, query, false)) - setOnQueryTextListener(listener(scope = scope, searchView = this, emitter = events::offer)) + setOnQueryTextListener(listener(scope, this, events::offer)) events.invokeOnClose { setOnQueryTextListener(null) } } /** - * Perform an action on [query text events][SearchViewQueryTextEvent] on [SearchView] inside new + * Perform an action on [query text events][SearchViewQueryTextEvent] on [SearchView], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -70,15 +69,7 @@ suspend fun SearchView.queryTextChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (SearchViewQueryTextEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - events.offer(SearchViewQueryTextEvent(this@queryTextChangeEvents, query, false)) - setOnQueryTextListener(listener(scope = this, searchView = this@queryTextChangeEvents, - emitter = events::offer)) - events.invokeOnClose { setOnQueryTextListener(null) } + queryTextChangeEvents(this, capacity, action) } /** diff --git a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/SearchViewQueryTextChanges.kt b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/SearchViewQueryTextChanges.kt index 39a538f4..cabc2e45 100644 --- a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/SearchViewQueryTextChanges.kt +++ b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/SearchViewQueryTextChanges.kt @@ -43,7 +43,6 @@ fun SearchView.queryTextChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (CharSequence) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (chars in channel) action(chars) } @@ -54,7 +53,7 @@ fun SearchView.queryTextChanges( } /** - * Perform an action on character sequences for query text changes on [SearchView] inside new + * Perform an action on character sequences for query text changes on [SearchView], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -64,14 +63,7 @@ suspend fun SearchView.queryTextChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (CharSequence) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (chars in channel) action(chars) - } - - events.offer(query) - setOnQueryTextListener(listener(this, events::offer)) - events.invokeOnClose { setOnQueryTextListener(null) } + queryTextChanges(this, capacity, action) } /** diff --git a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ToolbarItemClicks.kt b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ToolbarItemClicks.kt index 9ae16e91..7d606809 100644 --- a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ToolbarItemClicks.kt +++ b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ToolbarItemClicks.kt @@ -44,7 +44,6 @@ fun Toolbar.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (item in channel) action(item) } @@ -54,7 +53,7 @@ fun Toolbar.itemClicks( } /** - * Perform an action on the clicked item in [Toolbar] menu inside new [CoroutineScope]. + * Perform an action on the clicked item in [Toolbar] menu, inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,13 +62,7 @@ suspend fun Toolbar.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (item in channel) action(item) - } - - setOnMenuItemClickListener(listener(this, events::offer)) - events.invokeOnClose { setOnMenuItemClickListener(null) } + itemClicks(this, capacity, action) } /** diff --git a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ToolbarNavigationClicks.kt b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ToolbarNavigationClicks.kt index 11b4c156..9cf61bcc 100644 --- a/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ToolbarNavigationClicks.kt +++ b/corbind-appcompat/src/main/kotlin/ru/ldralighieri/corbind/appcompat/ToolbarNavigationClicks.kt @@ -47,7 +47,6 @@ fun Toolbar.navigationClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -57,7 +56,7 @@ fun Toolbar.navigationClicks( } /** - * Perform an action on [Toolbar] navigation click events inside new [CoroutineScope]. + * Perform an action on [Toolbar] navigation click events, inside new [CoroutineScope]. * * *Warning:* The created actor uses [Toolbar.setNavigationOnClickListener] to emit clicks. Only * one actor can be used for a view at a time. @@ -69,13 +68,7 @@ suspend fun Toolbar.navigationClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - setNavigationOnClickListener(listener(this, events::offer)) - events.invokeOnClose { setNavigationOnClickListener(null) } + navigationClicks(this, capacity, action) } /** diff --git a/corbind-core/README.md b/corbind-core/README.md index 68b75673..0b11f75c 100644 --- a/corbind-core/README.md +++ b/corbind-core/README.md @@ -4,7 +4,7 @@ To add androidx core bindings, import `corbind-core` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-core:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-core:1.1.2' ``` ## List of extensions diff --git a/corbind-core/src/main/kotlin/ru/ldralighieri/corbind/core/NestedScrollViewScrollChangeEvents.kt b/corbind-core/src/main/kotlin/ru/ldralighieri/corbind/core/NestedScrollViewScrollChangeEvents.kt index c294c332..e453d47d 100644 --- a/corbind-core/src/main/kotlin/ru/ldralighieri/corbind/core/NestedScrollViewScrollChangeEvents.kt +++ b/corbind-core/src/main/kotlin/ru/ldralighieri/corbind/core/NestedScrollViewScrollChangeEvents.kt @@ -44,7 +44,6 @@ fun NestedScrollView.scrollChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewScrollChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -56,7 +55,7 @@ fun NestedScrollView.scrollChangeEvents( } /** - * Perform an action on scroll-change events for [NestedScrollView] inside new [CoroutineScope]. + * Perform an action on scroll-change events for [NestedScrollView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -65,15 +64,7 @@ suspend fun NestedScrollView.scrollChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewScrollChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - setOnScrollChangeListener(listener(this, events::offer)) - events.invokeOnClose { - setOnScrollChangeListener(null as NestedScrollView.OnScrollChangeListener?) - } + scrollChangeEvents(this, capacity, action) } /** diff --git a/corbind-drawerlayout/README.md b/corbind-drawerlayout/README.md index 4a8883e7..1cdbc02a 100644 --- a/corbind-drawerlayout/README.md +++ b/corbind-drawerlayout/README.md @@ -4,7 +4,7 @@ To add androidx drawerlayout bindings, import `corbind-drawerlayout` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.1.2' ``` ## List of extensions diff --git a/corbind-drawerlayout/src/main/kotlin/ru/ldralighieri/corbind/drawerlayout/DrawerLayoutDrawerOpen.kt b/corbind-drawerlayout/src/main/kotlin/ru/ldralighieri/corbind/drawerlayout/DrawerLayoutDrawerOpen.kt index b26f8c50..06ca4d68 100644 --- a/corbind-drawerlayout/src/main/kotlin/ru/ldralighieri/corbind/drawerlayout/DrawerLayoutDrawerOpen.kt +++ b/corbind-drawerlayout/src/main/kotlin/ru/ldralighieri/corbind/drawerlayout/DrawerLayoutDrawerOpen.kt @@ -46,7 +46,6 @@ fun DrawerLayout.drawerOpens( gravity: Int, action: suspend (Boolean) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (open in channel) action(open) } @@ -58,7 +57,7 @@ fun DrawerLayout.drawerOpens( } /** - * Perform an action on the open state of the drawer of [DrawerLayout] inside new [CoroutineScope]. + * Perform an action on the open state of the drawer of [DrawerLayout], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param gravity Gravity of the drawer to check @@ -69,15 +68,7 @@ suspend fun DrawerLayout.drawerOpens( gravity: Int, action: suspend (Boolean) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (open in channel) action(open) - } - - events.offer(isDrawerOpen(gravity)) - val listener = listener(this, gravity, events::offer) - addDrawerListener(listener) - events.invokeOnClose { removeDrawerListener(listener) } + drawerOpens(this, capacity, gravity, action) } /** diff --git a/corbind-leanback/README.md b/corbind-leanback/README.md index 8dcdac1e..34705ee8 100644 --- a/corbind-leanback/README.md +++ b/corbind-leanback/README.md @@ -4,7 +4,7 @@ To add androidx leanback bindings, import `corbind-leanback` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-leanback:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-leanback:1.1.2' ``` ## List of extensions diff --git a/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchBarSearchQueryChangeEvents.kt b/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchBarSearchQueryChangeEvents.kt index bd2f16f4..1a6c5209 100644 --- a/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchBarSearchQueryChangeEvents.kt +++ b/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchBarSearchQueryChangeEvents.kt @@ -63,17 +63,16 @@ fun SearchBar.searchQueryChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (SearchBarSearchQueryEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } - setSearchBarListener(listener(scope = scope, searchBar = this, emitter = events::offer)) + setSearchBarListener(listener(scope, this, events::offer)) events.invokeOnClose { setSearchBarListener(null) } } /** - * Perform an action on [search query events][SearchBarSearchQueryEvent] on [SearchBar] inside new + * Perform an action on [search query events][SearchBarSearchQueryEvent] on [SearchBar], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -83,14 +82,7 @@ suspend fun SearchBar.searchQueryChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (SearchBarSearchQueryEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - setSearchBarListener(listener(scope = this, searchBar = this@searchQueryChangeEvents, - emitter = events::offer)) - events.invokeOnClose { setSearchBarListener(null) } + searchQueryChangeEvents(this, capacity, action) } /** diff --git a/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchBarSearchQueryChanges.kt b/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchBarSearchQueryChanges.kt index 6a54c8ad..3de1aa88 100644 --- a/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchBarSearchQueryChanges.kt +++ b/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchBarSearchQueryChanges.kt @@ -43,7 +43,6 @@ fun SearchBar.searchQueryChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (String) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (query in channel) action(query) } @@ -53,7 +52,7 @@ fun SearchBar.searchQueryChanges( } /** - * Perform an action on String values for search query changes on [SearchBar] inside new + * Perform an action on String values for search query changes on [SearchBar], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -63,13 +62,7 @@ suspend fun SearchBar.searchQueryChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (String) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (query in channel) action(query) - } - - setSearchBarListener(listener(this, events::offer)) - events.invokeOnClose { setSearchBarListener(null) } + searchQueryChanges(this, capacity, action) } /** diff --git a/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchEditTextKeyboardDismisses.kt b/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchEditTextKeyboardDismisses.kt index 9fc9bbbc..7e07429f 100644 --- a/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchEditTextKeyboardDismisses.kt +++ b/corbind-leanback/src/main/kotlin/ru/ldralighieri/corbind/leanback/SearchEditTextKeyboardDismisses.kt @@ -43,7 +43,6 @@ fun SearchEditText.keyboardDismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -53,7 +52,7 @@ fun SearchEditText.keyboardDismisses( } /** - * Perform an action on the keyboard dismiss events from [SearchEditText] inside new + * Perform an action on the keyboard dismiss events from [SearchEditText], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -63,13 +62,7 @@ suspend fun SearchEditText.keyboardDismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - setOnKeyboardDismissListener(listener(this, events::offer)) - events.invokeOnClose { setOnKeyboardDismissListener(null) } + keyboardDismisses(this, capacity, action) } /** diff --git a/corbind-material/README.md b/corbind-material/README.md index 8370f4d5..072eb311 100644 --- a/corbind-material/README.md +++ b/corbind-material/README.md @@ -4,7 +4,7 @@ To add material bindings, import `corbind-material` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-material:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-material:1.1.2' ``` ## List of extensions diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/AppBarLayoutOffsetChanges.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/AppBarLayoutOffsetChanges.kt index 59fde73d..04cb131a 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/AppBarLayoutOffsetChanges.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/AppBarLayoutOffsetChanges.kt @@ -43,7 +43,6 @@ fun AppBarLayout.offsetChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (offset in channel) action(offset) } @@ -54,7 +53,7 @@ fun AppBarLayout.offsetChanges( } /** - * Perform an action on the offset change in [AppBarLayout] inside new [CoroutineScope]. + * Perform an action on the offset change in [AppBarLayout], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,14 +62,7 @@ suspend fun AppBarLayout.offsetChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (offset in channel) action(offset) - } - - val listener = listener(this, events::offer) - addOnOffsetChangedListener(listener) - events.invokeOnClose { removeOnOffsetChangedListener(listener) } + offsetChanges(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomNavigationViewItemSelections.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomNavigationViewItemSelections.kt index 95628716..7bde94de 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomNavigationViewItemSelections.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomNavigationViewItemSelections.kt @@ -44,7 +44,6 @@ fun BottomNavigationView.itemSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (item in channel) action(item) } @@ -55,7 +54,7 @@ fun BottomNavigationView.itemSelections( } /** - * Perform an action on the selected item in [BottomNavigationView] inside new [CoroutineScope]. + * Perform an action on the selected item in [BottomNavigationView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -64,14 +63,7 @@ suspend fun BottomNavigationView.itemSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (item in channel) action(item) - } - - setInitialValue(this@itemSelections, events::offer) - setOnNavigationItemSelectedListener(listener(this, events::offer)) - events.invokeOnClose { setOnNavigationItemSelectedListener(null) } + itemSelections(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomSheetBehaviorSlides.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomSheetBehaviorSlides.kt index 52115099..2c29aec0 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomSheetBehaviorSlides.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomSheetBehaviorSlides.kt @@ -45,7 +45,6 @@ fun View.slides( capacity: Int = Channel.RENDEZVOUS, action: suspend (Float) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (offset in channel) action(offset) } @@ -56,7 +55,7 @@ fun View.slides( } /** - * Perform an action on the slide offset events from [View] on [BottomSheetBehavior] inside new + * Perform an action on the slide offset events from [View] on [BottomSheetBehavior], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -66,14 +65,7 @@ suspend fun View.slides( capacity: Int = Channel.RENDEZVOUS, action: suspend (Float) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (offset in channel) action(offset) - } - - val behavior = getBehavior(this@slides) - behavior.setBottomSheetCallback(callback(this, events::offer)) - events.invokeOnClose { behavior.setBottomSheetCallback(null) } + slides(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomSheetBehaviorStateChanges.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomSheetBehaviorStateChanges.kt index f1c83c71..faaa58ea 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomSheetBehaviorStateChanges.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/BottomSheetBehaviorStateChanges.kt @@ -45,7 +45,6 @@ fun View.stateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (state in channel) action(state) } @@ -56,7 +55,7 @@ fun View.stateChanges( } /** - * Perform an action on the state change events from [View] on [BottomSheetBehavior] inside new + * Perform an action on the state change events from [View] on [BottomSheetBehavior], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -66,14 +65,7 @@ suspend fun View.stateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (state in channel) action(state) - } - - val behavior = getBehavior(this@stateChanges) - behavior.setBottomSheetCallback(callback(this, events::offer)) - events.invokeOnClose { behavior.setBottomSheetCallback(null) } + stateChanges(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/ChipCloseIconClicks.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/ChipCloseIconClicks.kt index 6cb31dad..dd44b818 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/ChipCloseIconClicks.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/ChipCloseIconClicks.kt @@ -47,7 +47,6 @@ fun Chip.closeIconClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -57,7 +56,7 @@ fun Chip.closeIconClicks( } /** - * Perform an action on [Chip] close icon click events inside new [CoroutineScope]. + * Perform an action on [Chip] close icon click events, inside new [CoroutineScope]. * * *Warning:* The created actor uses [Chip.setOnCloseIconClickListener] to emit clicks. Only one * actor can be used for a view at a time. @@ -69,13 +68,7 @@ suspend fun Chip.closeIconClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - setOnCloseIconClickListener(listener(this, events::offer)) - events.invokeOnClose { setOnCloseIconClickListener(null) } + closeIconClicks(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/ChipGroupCheckedChanges.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/ChipGroupCheckedChanges.kt index 516c3562..588626a8 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/ChipGroupCheckedChanges.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/ChipGroupCheckedChanges.kt @@ -48,7 +48,6 @@ fun ChipGroup.checkedChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (checkedId in channel) action(checkedId) } @@ -60,7 +59,7 @@ fun ChipGroup.checkedChanges( } /** - * Perform an action on checked view ID changes in [ChipGroup] inside new [CoroutineScope]. + * Perform an action on checked view ID changes in [ChipGroup], inside new [CoroutineScope]. * * *Warning:* Only in single selection mode * @@ -73,15 +72,7 @@ suspend fun ChipGroup.checkedChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (checkedId in channel) action(checkedId) - } - - checkSelectionMode(this@checkedChanges) - events.offer(checkedChipId) - setOnCheckedChangeListener(listener(this, events::offer)) - events.invokeOnClose { setOnCheckedChangeListener(null) } + checkedChanges(this, capacity, action) } /** @@ -100,7 +91,7 @@ fun ChipGroup.checkedChanges( capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { checkSelectionMode(this@checkedChanges) - offer(checkedChipId) + offerElement(checkedChipId) setOnCheckedChangeListener(listener(scope, ::offerElement)) invokeOnClose { setOnCheckedChangeListener(null) } } diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/NavigationViewItemSelections.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/NavigationViewItemSelections.kt index 060191b6..e9baf1a9 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/NavigationViewItemSelections.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/NavigationViewItemSelections.kt @@ -44,7 +44,6 @@ fun NavigationView.itemSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (item in channel) action(item) } @@ -55,7 +54,7 @@ fun NavigationView.itemSelections( } /** - * Perform an action on the selected item in [NavigationView] inside new [CoroutineScope]. + * Perform an action on the selected item in [NavigationView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -64,14 +63,7 @@ suspend fun NavigationView.itemSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (item in channel) action(item) - } - - setInitialValue(this@itemSelections, events::offer) - setNavigationItemSelectedListener(listener(this, events::offer)) - events.invokeOnClose { setNavigationItemSelectedListener(null) } + itemSelections(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SnackbarDismisses.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SnackbarDismisses.kt index 48498660..d4642ba3 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SnackbarDismisses.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SnackbarDismisses.kt @@ -43,7 +43,6 @@ fun Snackbar.dismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -54,7 +53,7 @@ fun Snackbar.dismisses( } /** - * Perform an action on the dismiss events from [Snackbar] inside new [CoroutineScope]. + * Perform an action on the dismiss events from [Snackbar], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,14 +62,7 @@ suspend fun Snackbar.dismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - val callback = callback(this, events::offer) - addCallback(callback) - events.invokeOnClose { removeCallback(callback) } + dismisses(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SnackbarShown.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SnackbarShown.kt index 3ef9f77b..20b9c7cb 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SnackbarShown.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SnackbarShown.kt @@ -43,7 +43,6 @@ fun Snackbar.shown( capacity: Int = Channel.RENDEZVOUS, action: suspend (Snackbar) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (snackbar in channel) action(snackbar) } @@ -54,7 +53,7 @@ fun Snackbar.shown( } /** - * Perform an action on the show events from [Snackbar] inside new [CoroutineScope]. + * Perform an action on the show events from [Snackbar], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,14 +62,7 @@ suspend fun Snackbar.shown( capacity: Int = Channel.RENDEZVOUS, action: suspend (Snackbar) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (snackbar in channel) action(snackbar) - } - - val callback = callback(this, events::offer) - addCallback(callback) - events.invokeOnClose { removeCallback(callback) } + shown(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SwipeDismissBehaviorDesmisses.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SwipeDismissBehaviorDesmisses.kt index 23a01865..bad85a86 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SwipeDismissBehaviorDesmisses.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SwipeDismissBehaviorDesmisses.kt @@ -45,7 +45,6 @@ fun View.dismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend (View) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (view in channel) action(view) } @@ -56,7 +55,7 @@ fun View.dismisses( } /** - * Perform an action on the dismiss events from [View] on [SwipeDismissBehavior] inside new + * Perform an action on the dismiss events from [View] on [SwipeDismissBehavior], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -66,14 +65,7 @@ suspend fun View.dismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend (View) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (view in channel) action(view) - } - - val behavior = getBehavior(this@dismisses) - behavior.setListener(listener(this, events::offer)) - events.invokeOnClose { behavior.setListener(null) } + dismisses(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SwipeDismissBehaviorDragStateChanges.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SwipeDismissBehaviorDragStateChanges.kt index b3e9a99e..0e5563ca 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SwipeDismissBehaviorDragStateChanges.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/SwipeDismissBehaviorDragStateChanges.kt @@ -45,7 +45,6 @@ fun View.dragStateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (state in channel) action(state) } @@ -56,7 +55,7 @@ fun View.dragStateChanges( } /** - * Perform an action on the drag state change events from [View] on [SwipeDismissBehavior] inside + * Perform an action on the drag state change events from [View] on [SwipeDismissBehavior], inside * new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -66,14 +65,7 @@ suspend fun View.dragStateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (state in channel) action(state) - } - - val behavior = getBehavior(this@dragStateChanges) - behavior.setListener(listener(this, events::offer)) - events.invokeOnClose { behavior.setListener(null) } + dragStateChanges(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/TabLayoutSelectionEvents.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/TabLayoutSelectionEvents.kt index 618ef970..d41e8d87 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/TabLayoutSelectionEvents.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/TabLayoutSelectionEvents.kt @@ -64,20 +64,19 @@ fun TabLayout.selectionEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (TabLayoutSelectionEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } setInitialValue(this, events::offer) - val listener = listener(scope = scope, tabLayout = this, emitter = events::offer) + val listener = listener(scope, this, events::offer) addOnTabSelectedListener(listener) events.invokeOnClose { removeOnTabSelectedListener(listener) } } /** * Perform an action on selection, reselection, and unselection [events][TabLayoutSelectionEvent] - * for the tabs in [TabLayout] inside new [CoroutineScope]. + * for the tabs in [TabLayout], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -86,15 +85,7 @@ suspend fun TabLayout.selectionEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (TabLayoutSelectionEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - setInitialValue(this@selectionEvents, events::offer) - val listener = listener(scope = this, tabLayout = this@selectionEvents, emitter = events::offer) - addOnTabSelectedListener(listener) - events.invokeOnClose { removeOnTabSelectedListener(listener) } + selectionEvents(this, capacity, action) } /** diff --git a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/TabLayoutSelections.kt b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/TabLayoutSelections.kt index 6fffe1c0..a62a9a35 100644 --- a/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/TabLayoutSelections.kt +++ b/corbind-material/src/main/kotlin/ru/ldralighieri/corbind/material/TabLayoutSelections.kt @@ -43,7 +43,6 @@ fun TabLayout.selections( capacity: Int = Channel.RENDEZVOUS, action: suspend (TabLayout.Tab) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (tab in channel) action(tab) } @@ -55,7 +54,7 @@ fun TabLayout.selections( } /** - * Perform an action on the selected tab in [TabLayout] inside new [CoroutineScope]. + * Perform an action on the selected tab in [TabLayout], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -64,15 +63,7 @@ suspend fun TabLayout.selections( capacity: Int = Channel.RENDEZVOUS, action: suspend (TabLayout.Tab) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (tab in channel) action(tab) - } - - setInitialValue(this@selections, events::offer) - val listener = listener(this, events::offer) - addOnTabSelectedListener(listener) - events.invokeOnClose { removeOnTabSelectedListener(listener) } + selections(this, capacity, action) } /** diff --git a/corbind-recyclerview/README.md b/corbind-recyclerview/README.md index 04dbb7a8..b7ad0dd0 100644 --- a/corbind-recyclerview/README.md +++ b/corbind-recyclerview/README.md @@ -4,7 +4,7 @@ To add androidx recyclerview bindings, import `corbind-recyclerview` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-recyclerview:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-recyclerview:1.1.2' ``` ## List of extensions diff --git a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerAdapterDataChanges.kt b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerAdapterDataChanges.kt index 10812109..17014e11 100644 --- a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerAdapterDataChanges.kt +++ b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerAdapterDataChanges.kt @@ -43,19 +43,18 @@ fun > T.dataChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (T) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (adapter in channel) action(adapter) } events.offer(this) - val dataObserver = observer(scope = scope, adapter = this, emitter = events::offer) + val dataObserver = observer(scope, this, events::offer) registerAdapterDataObserver(dataObserver) events.invokeOnClose { unregisterAdapterDataObserver(dataObserver) } } /** - * Perform an action on data change events for [RecyclerView.Adapter] inside new [CoroutineScope]. + * Perform an action on data change events for [RecyclerView.Adapter], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -64,15 +63,7 @@ suspend fun > T.dataChange capacity: Int = Channel.RENDEZVOUS, action: suspend (T) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (adapter in channel) action(adapter) - } - - events.offer(this@dataChanges) - val dataObserver = observer(scope = this, adapter = this@dataChanges, emitter = events::offer) - registerAdapterDataObserver(dataObserver) - events.invokeOnClose { unregisterAdapterDataObserver(dataObserver) } + dataChanges(this, capacity, action) } /** diff --git a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewChildAttachStateChangeEvents.kt b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewChildAttachStateChangeEvents.kt index c104a97b..00d681c4 100644 --- a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewChildAttachStateChangeEvents.kt +++ b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewChildAttachStateChangeEvents.kt @@ -60,19 +60,18 @@ fun RecyclerView.childAttachStateChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (RecyclerViewChildAttachStateChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } - val listener = listener(scope = scope, recyclerView = this, emitter = events::offer) + val listener = listener(scope, this, events::offer) addOnChildAttachStateChangeListener(listener) events.invokeOnClose { removeOnChildAttachStateChangeListener(listener) } } /** * Perform an action on [child attach state change events][RecyclerViewChildAttachStateChangeEvent] - * on [RecyclerView] inside new [CoroutineScope]. + * on [RecyclerView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -81,15 +80,7 @@ suspend fun RecyclerView.childAttachStateChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (RecyclerViewChildAttachStateChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - val listener = listener(scope = this, recyclerView = this@childAttachStateChangeEvents, - emitter = events::offer) - addOnChildAttachStateChangeListener(listener) - events.invokeOnClose { removeOnChildAttachStateChangeListener(listener) } + childAttachStateChangeEvents(this, capacity, action) } /** diff --git a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewFlingEvents.kt b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewFlingEvents.kt index 99a445a7..e918775e 100644 --- a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewFlingEvents.kt +++ b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewFlingEvents.kt @@ -49,17 +49,16 @@ fun RecyclerView.flingEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (RecyclerViewFlingEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } - onFlingListener = listener(scope = scope, recyclerView = this, emitter = events::offer) + onFlingListener = listener(scope, this, events::offer) events.invokeOnClose { onFlingListener = null } } /** - * Perform an action on [fling events][RecyclerViewFlingEvent] on [RecyclerView] inside new + * Perform an action on [fling events][RecyclerViewFlingEvent] on [RecyclerView], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -69,14 +68,7 @@ suspend fun RecyclerView.flingEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (RecyclerViewFlingEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - onFlingListener = listener(scope = this, recyclerView = this@flingEvents, - emitter = events::offer) - events.invokeOnClose { onFlingListener = null } + flingEvents(this, capacity, action) } /** diff --git a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewScrollEvents.kt b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewScrollEvents.kt index c1306f69..99d595ff 100644 --- a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewScrollEvents.kt +++ b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewScrollEvents.kt @@ -49,7 +49,6 @@ fun RecyclerView.scrollEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (RecyclerViewScrollEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -60,7 +59,7 @@ fun RecyclerView.scrollEvents( } /** - * Perform an action on [scroll events][RecyclerViewScrollEvent] on [RecyclerView] inside new + * Perform an action on [scroll events][RecyclerViewScrollEvent] on [RecyclerView], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -70,14 +69,7 @@ suspend fun RecyclerView.scrollEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (RecyclerViewScrollEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - val scrollListener = listener(this, events::offer) - addOnScrollListener(scrollListener) - events.invokeOnClose { removeOnScrollListener(scrollListener) } + scrollEvents(this, capacity, action) } /** diff --git a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewScrollStateChanges.kt b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewScrollStateChanges.kt index 04596f4e..5bb8e2ca 100644 --- a/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewScrollStateChanges.kt +++ b/corbind-recyclerview/src/main/kotlin/ru/ldralighieri/corbind/recyclerview/RecyclerViewScrollStateChanges.kt @@ -43,7 +43,6 @@ fun RecyclerView.scrollStateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (state in channel) action(state) } @@ -54,7 +53,7 @@ fun RecyclerView.scrollStateChanges( } /** - * Perform an action on scroll state changes on [RecyclerView] inside new [CoroutineScope]. + * Perform an action on scroll state changes on [RecyclerView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,14 +62,7 @@ suspend fun RecyclerView.scrollStateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (state in channel) action(state) - } - - val scrollListener = listener(this, events::offer) - addOnScrollListener(scrollListener) - events.invokeOnClose { removeOnScrollListener(scrollListener) } + scrollStateChanges(this, capacity, action) } /** diff --git a/corbind-slidingpanelayout/README.md b/corbind-slidingpanelayout/README.md index 03c643af..199a347a 100644 --- a/corbind-slidingpanelayout/README.md +++ b/corbind-slidingpanelayout/README.md @@ -4,7 +4,7 @@ To add androidx slidingpanelayout bindings, import `corbind-slidingpanelayout` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-slidingpanelayout:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-slidingpanelayout:1.1.2' ``` ## List of extensions diff --git a/corbind-slidingpanelayout/src/main/kotlin/ru/ldralighieri/corbind/slidingpanelayout/SlidingPaneLayoutPaneOpens.kt b/corbind-slidingpanelayout/src/main/kotlin/ru/ldralighieri/corbind/slidingpanelayout/SlidingPaneLayoutPaneOpens.kt index 4c94bad7..1e2b8524 100644 --- a/corbind-slidingpanelayout/src/main/kotlin/ru/ldralighieri/corbind/slidingpanelayout/SlidingPaneLayoutPaneOpens.kt +++ b/corbind-slidingpanelayout/src/main/kotlin/ru/ldralighieri/corbind/slidingpanelayout/SlidingPaneLayoutPaneOpens.kt @@ -47,7 +47,6 @@ fun SlidingPaneLayout.panelOpens( capacity: Int = Channel.RENDEZVOUS, action: suspend (Boolean) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -58,7 +57,7 @@ fun SlidingPaneLayout.panelOpens( } /** - * Perform an action on the open state of the pane of [SlidingPaneLayout] inside new + * Perform an action on the open state of the pane of [SlidingPaneLayout], inside new * [CoroutineScope]. * * *Warning:* The created actor uses [SlidingPaneLayout.setPanelSlideListener] to emit dismiss @@ -71,14 +70,7 @@ suspend fun SlidingPaneLayout.panelOpens( capacity: Int = Channel.RENDEZVOUS, action: suspend (Boolean) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - events.offer(isOpen) - setPanelSlideListener(listener(this, events::offer)) - events.invokeOnClose { setPanelSlideListener(null) } + panelOpens(this, capacity, action) } /** diff --git a/corbind-slidingpanelayout/src/main/kotlin/ru/ldralighieri/corbind/slidingpanelayout/SlidingPaneLayoutSlides.kt b/corbind-slidingpanelayout/src/main/kotlin/ru/ldralighieri/corbind/slidingpanelayout/SlidingPaneLayoutSlides.kt index 62fff578..b08267e7 100644 --- a/corbind-slidingpanelayout/src/main/kotlin/ru/ldralighieri/corbind/slidingpanelayout/SlidingPaneLayoutSlides.kt +++ b/corbind-slidingpanelayout/src/main/kotlin/ru/ldralighieri/corbind/slidingpanelayout/SlidingPaneLayoutSlides.kt @@ -37,13 +37,16 @@ import ru.ldralighieri.corbind.offerElement * * *Warning:* The actor channel uses [SlidingPaneLayout.setPanelSlideListener] to emit dismiss * change. Only one actor can be used for a view 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 SlidingPaneLayout.panelSlides( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS, action: suspend (Float) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (slide in channel) action(slide) } @@ -53,22 +56,20 @@ fun SlidingPaneLayout.panelSlides( } /** - * Perform an action on the slide offset of the pane of [SlidingPaneLayout] inside new [CoroutineScope]. + * Perform an action on the slide offset of the pane of [SlidingPaneLayout], inside new + * [CoroutineScope]. * * *Warning:* The actor channel uses [SlidingPaneLayout.setPanelSlideListener] to emit dismiss * change. Only one actor can be used for a view at a time. + * + * @param capacity Capacity of the channel's buffer (no buffer by default) + * @param action An action to perform */ suspend fun SlidingPaneLayout.panelSlides( capacity: Int = Channel.RENDEZVOUS, action: suspend (Float) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (slide in channel) action(slide) - } - - setPanelSlideListener(listener(this, events::offer)) - events.invokeOnClose { setPanelSlideListener(null) } + panelSlides(this, capacity, action) } /** @@ -76,6 +77,9 @@ suspend fun SlidingPaneLayout.panelSlides( * * *Warning:* The created channel uses [SlidingPaneLayout.setPanelSlideListener] to emit dismiss * change. Only one channel can be used for a view at a time. + * + * @param scope Root coroutine scope + * @param capacity Capacity of the channel's buffer (no buffer by default) */ @CheckResult fun SlidingPaneLayout.panelSlides( diff --git a/corbind-swiperefreshlayout/README.md b/corbind-swiperefreshlayout/README.md index c284ea72..5f1b5be4 100644 --- a/corbind-swiperefreshlayout/README.md +++ b/corbind-swiperefreshlayout/README.md @@ -4,7 +4,7 @@ To add androidx swiperefreshlayout bindings, import `corbind-swiperefreshlayout` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.1.2' ``` ## List of extensions diff --git a/corbind-swiperefreshlayout/src/main/kotlin/ru/ldralighieri/corbind/swiperefreshlayout/SwipeRefreshLayoutRefreshes.kt b/corbind-swiperefreshlayout/src/main/kotlin/ru/ldralighieri/corbind/swiperefreshlayout/SwipeRefreshLayoutRefreshes.kt index 95a7d73d..b9b191fb 100644 --- a/corbind-swiperefreshlayout/src/main/kotlin/ru/ldralighieri/corbind/swiperefreshlayout/SwipeRefreshLayoutRefreshes.kt +++ b/corbind-swiperefreshlayout/src/main/kotlin/ru/ldralighieri/corbind/swiperefreshlayout/SwipeRefreshLayoutRefreshes.kt @@ -43,7 +43,6 @@ fun SwipeRefreshLayout.refreshes( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -53,7 +52,7 @@ fun SwipeRefreshLayout.refreshes( } /** - * Perform an action on refresh events on [SwipeRefreshLayout] inside new [CoroutineScope]. + * Perform an action on refresh events on [SwipeRefreshLayout], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -62,13 +61,7 @@ suspend fun SwipeRefreshLayout.refreshes( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - setOnRefreshListener(listener(this, events::offer)) - events.invokeOnClose { setOnRefreshListener(null) } + refreshes(this, capacity, action) } /** diff --git a/corbind-viewpager/README.md b/corbind-viewpager/README.md index b28229da..22f3c966 100644 --- a/corbind-viewpager/README.md +++ b/corbind-viewpager/README.md @@ -4,7 +4,7 @@ To add androidx viewpager bindings, import `corbind-viewpager` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-viewpager:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-viewpager:1.1.2' ``` ## List of extensions diff --git a/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageScrollEvents.kt b/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageScrollEvents.kt index a3ff08c8..09232142 100644 --- a/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageScrollEvents.kt +++ b/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageScrollEvents.kt @@ -50,18 +50,17 @@ fun ViewPager.pageScrollEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewPagerPageScrollEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } - val listener = listener(scope = scope, viewPager = this, emitter = events::offer) + val listener = listener(scope, this, events::offer) addOnPageChangeListener(listener) events.invokeOnClose { removeOnPageChangeListener(listener) } } /** - * Perform an action on [page scroll events][ViewPagerPageScrollEvent] on [ViewPager] inside new + * Perform an action on [page scroll events][ViewPagerPageScrollEvent] on [ViewPager], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -71,15 +70,7 @@ suspend fun ViewPager.pageScrollEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewPagerPageScrollEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - val listener = listener(scope = this, viewPager = this@pageScrollEvents, - emitter = events::offer) - addOnPageChangeListener(listener) - events.invokeOnClose { removeOnPageChangeListener(listener) } + pageScrollEvents(this, capacity, action) } /** diff --git a/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageScrollStateChanges.kt b/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageScrollStateChanges.kt index 9be13471..65cf3b68 100644 --- a/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageScrollStateChanges.kt +++ b/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageScrollStateChanges.kt @@ -43,7 +43,6 @@ fun ViewPager.pageScrollStateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (state in channel) action(state) } @@ -54,7 +53,7 @@ fun ViewPager.pageScrollStateChanges( } /** - * Perform an action on scroll state change events on [ViewPager] inside new [CoroutineScope]. + * Perform an action on scroll state change events on [ViewPager], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,14 +62,7 @@ suspend fun ViewPager.pageScrollStateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (state in channel) action(state) - } - - val listener = listener(this, events::offer) - addOnPageChangeListener(listener) - events.invokeOnClose { removeOnPageChangeListener(listener) } + pageScrollStateChanges(this, capacity, action) } /** diff --git a/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageSelections.kt b/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageSelections.kt index f4a54bbd..2cc45684 100644 --- a/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageSelections.kt +++ b/corbind-viewpager/src/main/kotlin/ru/ldralighieri/corbind/viewpager/ViewPagerPageSelections.kt @@ -43,7 +43,6 @@ fun ViewPager.pageSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (position in channel) action(position) } @@ -55,7 +54,7 @@ fun ViewPager.pageSelections( } /** - * Perform an action on page selected events on [ViewPager] inside new [CoroutineScope]. + * Perform an action on page selected events on [ViewPager], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -64,15 +63,7 @@ suspend fun ViewPager.pageSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (position in channel) action(position) - } - - events.offer(currentItem) - val listener = listener(this, events::offer) - addOnPageChangeListener(listener) - events.invokeOnClose { removeOnPageChangeListener(listener) } + pageSelections(this, capacity, action) } /** diff --git a/corbind-viewpager2/README.md b/corbind-viewpager2/README.md index cf162271..7728494f 100644 --- a/corbind-viewpager2/README.md +++ b/corbind-viewpager2/README.md @@ -4,7 +4,7 @@ To add androidx viewpager2 bindings, import `corbind-viewpager2` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind-viewpager2:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind-viewpager2:1.1.2' ``` ## List of extensions diff --git a/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageScrollEvents.kt b/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageScrollEvents.kt index b41c4e8c..1d272ca6 100644 --- a/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageScrollEvents.kt +++ b/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageScrollEvents.kt @@ -50,18 +50,17 @@ fun ViewPager2.pageScrollEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewPager2PageScrollEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } - val callback = callback(scope = scope, viewPager = this, emitter = events::offer) + val callback = callback(scope, this, events::offer) registerOnPageChangeCallback(callback) events.invokeOnClose { unregisterOnPageChangeCallback(callback) } } /** - * Perform an action on [page scroll events][ViewPager2PageScrollEvent] on [ViewPager2] inside new + * Perform an action on [page scroll events][ViewPager2PageScrollEvent] on [ViewPager2], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -71,15 +70,7 @@ suspend fun ViewPager2.pageScrollEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewPager2PageScrollEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - val callback = callback(scope = this, viewPager = this@pageScrollEvents, - emitter = events::offer) - registerOnPageChangeCallback(callback) - events.invokeOnClose { unregisterOnPageChangeCallback(callback) } + pageScrollEvents(this, capacity, action) } /** diff --git a/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageScrollStateChanges.kt b/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageScrollStateChanges.kt index 6b064075..703f7263 100644 --- a/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageScrollStateChanges.kt +++ b/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageScrollStateChanges.kt @@ -43,7 +43,6 @@ fun ViewPager2.pageScrollStateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (state in channel) action(state) } @@ -54,7 +53,7 @@ fun ViewPager2.pageScrollStateChanges( } /** - * Perform an action on scroll state change events on [ViewPager2] inside new [CoroutineScope]. + * Perform an action on scroll state change events on [ViewPager2], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,14 +62,7 @@ suspend fun ViewPager2.pageScrollStateChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (state in channel) action(state) - } - - val callback = callback(this, events::offer) - registerOnPageChangeCallback(callback) - events.invokeOnClose { unregisterOnPageChangeCallback(callback) } + pageScrollStateChanges(this, capacity, action) } /** diff --git a/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageSelections.kt b/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageSelections.kt index 69bc3c6b..05d15be3 100644 --- a/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageSelections.kt +++ b/corbind-viewpager2/src/main/kotlin/ru/ldralighieri/corbind/viewpager2/ViewPager2PageSelections.kt @@ -43,7 +43,6 @@ fun ViewPager2.pageSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (position in channel) action(position) } @@ -55,7 +54,7 @@ fun ViewPager2.pageSelections( } /** - * Perform an action on page selected events on [ViewPager2] inside new [CoroutineScope]. + * Perform an action on page selected events on [ViewPager2], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -64,15 +63,7 @@ suspend fun ViewPager2.pageSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (position in channel) action(position) - } - - events.offer(currentItem) - val callback = callback(this, events::offer) - registerOnPageChangeCallback(callback) - events.invokeOnClose { unregisterOnPageChangeCallback(callback) } + pageSelections(this, capacity, action) } /** diff --git a/corbind/README.md b/corbind/README.md index 9518010a..3281a548 100644 --- a/corbind/README.md +++ b/corbind/README.md @@ -4,7 +4,7 @@ To add platform bindings, import `corbind` module: ```groovy -implementation 'ru.ldralighieri.corbind:corbind:1.1.0' +implementation 'ru.ldralighieri.corbind:corbind:1.1.2' ``` ## List of extensions diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/MenuItemActionViewEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/MenuItemActionViewEvents.kt index 72da98dc..f8b83dc4 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/MenuItemActionViewEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/MenuItemActionViewEvents.kt @@ -60,9 +60,8 @@ fun MenuItem.actionViewEvents( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS, handled: (MenuItemActionViewEvent) -> Boolean = AlwaysTrue, - action: suspend (MenuItemActionViewEvent) -> Boolean + action: suspend (MenuItemActionViewEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -72,7 +71,7 @@ fun MenuItem.actionViewEvents( } /** - * Perform an action on [action view events][MenuItemActionViewEvent] for [MenuItem] inside new + * Perform an action on [action view events][MenuItemActionViewEvent] for [MenuItem], inside new * [CoroutineScope]. * * *Warning:* The created actor uses [MenuItem.setOnActionExpandListener] to emit action view @@ -88,13 +87,7 @@ suspend fun MenuItem.actionViewEvents( handled: (MenuItemActionViewEvent) -> Boolean = AlwaysTrue, action: suspend (MenuItemActionViewEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - setOnActionExpandListener(listener(this, handled, events::offer)) - events.invokeOnClose { setOnActionExpandListener(null) } + actionViewEvents(this, capacity, handled, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/MenuItemClicks.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/MenuItemClicks.kt index 9688a899..27ec7f4a 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/MenuItemClicks.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/MenuItemClicks.kt @@ -50,7 +50,6 @@ fun MenuItem.clicks( handled: (MenuItem) -> Boolean = AlwaysTrue, action: suspend (MenuItem) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (item in channel) action(item) } @@ -60,7 +59,7 @@ fun MenuItem.clicks( } /** - * Perform an action on [MenuItem] click events inside new [CoroutineScope]. + * Perform an action on [MenuItem] click events, inside new [CoroutineScope]. * * *Warning:* The created actor uses [MenuItem.setOnMenuItemClickListener] to emit clicks. Only * one actor can be used for a menu item at a time. @@ -75,13 +74,7 @@ suspend fun MenuItem.clicks( handled: (MenuItem) -> Boolean = AlwaysTrue, action: suspend (MenuItem) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (item in channel) action(item) - } - - setOnMenuItemClickListener(listener(this, handled, events::offer)) - events.invokeOnClose { setOnMenuItemClickListener(null) } + clicks(this, capacity, handled, action) } /** @@ -128,13 +121,11 @@ private fun listener( handled: (MenuItem) -> Boolean, emitter: (MenuItem) -> Boolean ) = MenuItem.OnMenuItemClickListener { item -> - if (scope.isActive) { if (handled(item)) { emitter(item) return@OnMenuItemClickListener true } } - return@OnMenuItemClickListener false } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewAttachEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewAttachEvents.kt index d7e79816..df204d67 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewAttachEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewAttachEvents.kt @@ -55,7 +55,6 @@ fun View.attachEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewAttachEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -66,7 +65,7 @@ fun View.attachEvents( } /** - * Perform an action on [attach and detach events][ViewAttachEvent] on [View] inside new + * Perform an action on [attach and detach events][ViewAttachEvent] on [View], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -76,14 +75,7 @@ suspend fun View.attachEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewAttachEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - val listener = listener(this, events::offer) - addOnAttachStateChangeListener(listener) - events.invokeOnClose { removeOnAttachStateChangeListener(listener) } + attachEvents(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewAttaches.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewAttaches.kt index a92b475a..3b4d549c 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewAttaches.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewAttaches.kt @@ -43,7 +43,6 @@ fun View.attaches( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -54,7 +53,7 @@ fun View.attaches( } /** - * Perform an action on [View] attach events inside new CoroutineScope. + * Perform an action on [View] attach events, inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,14 +62,7 @@ suspend fun View.attaches( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - val listener = listener(this, true, events::offer) - addOnAttachStateChangeListener(listener) - events.invokeOnClose { removeOnAttachStateChangeListener(listener) } + attaches(this, capacity, action) } /** @@ -84,7 +76,6 @@ fun View.attaches( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { - val listener = listener(scope, true, ::offerElement) addOnAttachStateChangeListener(listener) invokeOnClose { removeOnAttachStateChangeListener(listener) } @@ -112,7 +103,6 @@ fun View.detaches( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -123,7 +113,7 @@ fun View.detaches( } /** - * Perform an action on [View] detach events inside new CoroutineScope. + * Perform an action on [View] detach events, inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -132,14 +122,7 @@ suspend fun View.detaches( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - val listener = listener(this, false, events::offer) - addOnAttachStateChangeListener(listener) - events.invokeOnClose { removeOnAttachStateChangeListener(listener) } + detaches(this, capacity, action) } /** @@ -153,7 +136,6 @@ fun View.detaches( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { - val listener = listener(scope, false, ::offerElement) addOnAttachStateChangeListener(listener) invokeOnClose { removeOnAttachStateChangeListener(listener) } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewClicks.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewClicks.kt index ddc69d1a..ff2713a9 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewClicks.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewClicks.kt @@ -46,7 +46,6 @@ fun View.clicks( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -56,7 +55,7 @@ fun View.clicks( } /** - * Perform an action on [View] click events inside new CoroutineScope. + * Perform an action on [View] click events, inside new [CoroutineScope]. * * *Warning:* The created actor uses [View.setOnClickListener] to emit clicks. Only one actor * can be used for a view at a time. @@ -68,13 +67,7 @@ suspend fun View.clicks( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - setOnClickListener(listener(this, events::offer)) - events.invokeOnClose { setOnClickListener(null) } + clicks(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewDrags.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewDrags.kt index 3441124a..a6d56353 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewDrags.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewDrags.kt @@ -51,7 +51,6 @@ fun View.drags( handled: (DragEvent) -> Boolean = AlwaysTrue, action: suspend (DragEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (drag in channel) action(drag) } @@ -61,7 +60,7 @@ fun View.drags( } /** - * Perform an action on [DragEvent] for [View] inside new CoroutineScope. + * Perform an action on [DragEvent] for [View], inside new [CoroutineScope]. * * *Warning:* The created actor uses [View.setOnDragListener] to emit drags. Only one actor can * be used for a view at a time. @@ -76,13 +75,7 @@ suspend fun View.drags( handled: (DragEvent) -> Boolean = AlwaysTrue, action: suspend (DragEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (drag in channel) action(drag) - } - - setOnDragListener(listener(this, handled, events::offer)) - events.invokeOnClose { setOnDragListener(null) } + drags(this, capacity, handled, action) } /** @@ -129,7 +122,6 @@ private fun listener( handled: (DragEvent) -> Boolean, emitter: (DragEvent) -> Boolean ) = View.OnDragListener { _, dragEvent -> - if (scope.isActive) { if (handled(dragEvent)) { emitter(dragEvent) diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewFocusChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewFocusChanges.kt index 43fabe76..a25384a8 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewFocusChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewFocusChanges.kt @@ -46,7 +46,6 @@ fun View.focusChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Boolean) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (focus in channel) action(focus) } @@ -57,7 +56,7 @@ fun View.focusChanges( } /** - * Perform an action on [View] focus change inside new [CoroutineScope]. + * Perform an action on [View] focus change, inside new [CoroutineScope]. * * *Warning:* The created actor uses [View.setOnFocusChangeListener] to emit focus change. Only * one actor can be used for a view at a time. @@ -69,14 +68,7 @@ suspend fun View.focusChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Boolean) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (focus in channel) action(focus) - } - - events.offer(hasFocus()) - onFocusChangeListener = listener(this, events::offer) - events.invokeOnClose { onFocusChangeListener = null } + focusChanges(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewGroupHierarchyChangeEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewGroupHierarchyChangeEvents.kt index d49799a4..aa4900d3 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewGroupHierarchyChangeEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewGroupHierarchyChangeEvents.kt @@ -59,17 +59,16 @@ fun ViewGroup.changeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewGroupHierarchyChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } - setOnHierarchyChangeListener(listener(scope = scope, viewGroup = this, emitter = events::offer)) + setOnHierarchyChangeListener(listener(scope, this, events::offer)) events.invokeOnClose { setOnHierarchyChangeListener(null) } } /** - * Perform an action on [hierarchy change events][ViewGroupHierarchyChangeEvent] for [ViewGroup] + * Perform an action on [hierarchy change events][ViewGroupHierarchyChangeEvent] for [ViewGroup], * inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -79,14 +78,7 @@ suspend fun ViewGroup.changeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewGroupHierarchyChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - setOnHierarchyChangeListener(listener(scope = this, viewGroup = this@changeEvents, - emitter = events::offer)) - events.invokeOnClose { setOnHierarchyChangeListener(null) } + changeEvents(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewHovers.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewHovers.kt index 8c9d666b..18a074d6 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewHovers.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewHovers.kt @@ -51,7 +51,6 @@ fun View.hovers( handled: (MotionEvent) -> Boolean = AlwaysTrue, action: suspend (MotionEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (motion in channel) action(motion) } @@ -61,7 +60,7 @@ fun View.hovers( } /** - * Perform an action on hover events for [View] inside new [CoroutineScope]. + * Perform an action on hover events for [View], inside new [CoroutineScope]. * * *Warning:* The created actor uses [View.setOnHoverListener] to emit touches. Only one actor * can be used for a view at a time. @@ -76,13 +75,7 @@ suspend fun View.hovers( handled: (MotionEvent) -> Boolean = AlwaysTrue, action: suspend (MotionEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (motion in channel) action(motion) - } - - setOnHoverListener(listener(this, handled, events::offer)) - events.invokeOnClose { setOnHoverListener(null) } + hovers(this, capacity, handled, action) } /** @@ -129,7 +122,6 @@ private fun listener( handled: (MotionEvent) -> Boolean, emitter: (MotionEvent) -> Boolean ) = View.OnHoverListener { _, motionEvent -> - if (scope.isActive) { if (handled(motionEvent)) { emitter(motionEvent) diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewKeys.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewKeys.kt index 3b1fb61d..3da89277 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewKeys.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewKeys.kt @@ -51,7 +51,6 @@ fun View.keys( handled: (KeyEvent) -> Boolean = AlwaysTrue, action: suspend (KeyEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (key in channel) action(key) } @@ -61,7 +60,7 @@ fun View.keys( } /** - * Perform an action on key events for [View] inside new [CoroutineScope]. + * Perform an action on key events for [View], inside new [CoroutineScope]. * * *Warning:* The created actor uses [View.setOnKeyListener] to emit key events. Only one actor * can be used for a view at a time. @@ -76,13 +75,7 @@ suspend fun View.keys( handled: (KeyEvent) -> Boolean = AlwaysTrue, action: suspend (KeyEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (key in channel) action(key) - } - - setOnKeyListener(listener(this, handled, events::offer)) - events.invokeOnClose { setOnKeyListener(null) } + keys(this, capacity, handled, action) } /** @@ -129,7 +122,6 @@ private fun listener( handled: (KeyEvent) -> Boolean, emitter: (KeyEvent) -> Boolean ) = View.OnKeyListener { _, _, keyEvent -> - if (scope.isActive) { if (handled(keyEvent)) { emitter(keyEvent) diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLayoutChangeEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLayoutChangeEvents.kt index 8156a2bc..d81260d7 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLayoutChangeEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLayoutChangeEvents.kt @@ -55,7 +55,6 @@ fun View.layoutChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewLayoutChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -66,7 +65,7 @@ fun View.layoutChangeEvents( } /** - * Perform an action on [layout-change events][ViewLayoutChangeEvent] for [View] inside new + * Perform an action on [layout-change events][ViewLayoutChangeEvent] for [View], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -76,14 +75,7 @@ suspend fun View.layoutChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewLayoutChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - val listener = listener(this, events::offer) - addOnLayoutChangeListener(listener) - events.invokeOnClose { removeOnLayoutChangeListener(listener) } + layoutChangeEvents(this, capacity, action) } /** @@ -117,7 +109,6 @@ private fun listener( scope: CoroutineScope, emitter: (ViewLayoutChangeEvent) -> Boolean ) = View.OnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom -> - if (scope.isActive) { emitter(ViewLayoutChangeEvent(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLayoutChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLayoutChanges.kt index 56049a41..ae740e95 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLayoutChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLayoutChanges.kt @@ -43,7 +43,6 @@ fun View.layoutChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -54,7 +53,7 @@ fun View.layoutChanges( } /** - * Perform an action on [View] layout changes inside new [CoroutineScope]. + * Perform an action on [View] layout changes, inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,14 +62,7 @@ suspend fun View.layoutChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - val listener = listener(this, events::offer) - addOnLayoutChangeListener(listener) - events.invokeOnClose { removeOnLayoutChangeListener(listener) } + layoutChanges(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLongClicks.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLongClicks.kt index 60968be2..21928332 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLongClicks.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewLongClicks.kt @@ -50,7 +50,6 @@ fun View.longClicks( handled: () -> Boolean = AlwaysTrue, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -60,7 +59,7 @@ fun View.longClicks( } /** - * Perform an action on `view` long-click events inside new [CoroutineScope]. + * Perform an action on `view` long-click events, inside new [CoroutineScope]. * * *Warning:* The created actor uses [View.setOnLongClickListener] to emit long clicks. Only one * actor can be used for a view at a time. @@ -75,20 +74,14 @@ suspend fun View.longClicks( handled: () -> Boolean = AlwaysTrue, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - setOnLongClickListener(listener(this, handled, events::offer)) - events.invokeOnClose { setOnLongClickListener(null) } + longClicks(this, capacity, handled, action) } /** * Create a channel which emits on `view` long-click events. * - * *Warning:* The created channel uses [View.setOnLongClickListener] to emit long clicks. Only - * one channel can be used for a view at a time. + * *Warning:* The created channel uses [View.setOnLongClickListener] to emit long clicks. Only one + * channel can be used for a view at a time. * * @param scope Root coroutine scope * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -108,8 +101,8 @@ fun View.longClicks( /** * Create a flow which emits on `view` long-click events. * - * *Warning:* The created flow uses [View.setOnLongClickListener] to emit - * long clicks. Only one flow can be used for a view at a time. + * *Warning:* The created flow uses [View.setOnLongClickListener] to emit long clicks. Only one + * flow can be used for a view at a time. * * @param handled Predicate invoked each occurrence to determine the return value of the underlying * [View.OnLongClickListener] @@ -128,7 +121,6 @@ private fun listener( handled: () -> Boolean, emitter: (Unit) -> Boolean ) = View.OnLongClickListener { - if (scope.isActive) { if (handled()) { emitter(Unit) diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewScrollChangeEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewScrollChangeEvents.kt index 24434686..497eaac6 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewScrollChangeEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewScrollChangeEvents.kt @@ -54,7 +54,6 @@ fun View.scrollChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewScrollChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -64,7 +63,7 @@ fun View.scrollChangeEvents( } /** - * Perform an action on [scroll-change events][ViewScrollChangeEvent] for [View] inside new + * Perform an action on [scroll-change events][ViewScrollChangeEvent] for [View], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -75,13 +74,7 @@ suspend fun View.scrollChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (ViewScrollChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - setOnScrollChangeListener(listener(this, events::offer)) - events.invokeOnClose { setOnScrollChangeListener(null) } + scrollChangeEvents(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewSystemUiVisibilityChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewSystemUiVisibilityChanges.kt index d95017c4..6ee73bc7 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewSystemUiVisibilityChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewSystemUiVisibilityChanges.kt @@ -34,8 +34,8 @@ import ru.ldralighieri.corbind.offerElement /** * Perform an action on a new system UI visibility for [View]. * - * *Warning:* The created actor uses [View.setOnSystemUiVisibilityChangeListener] to emit - * system UI visibility changes. Only one actor can be used for a view at a time. + * *Warning:* The created actor uses [View.setOnSystemUiVisibilityChangeListener] to emit system + * UI visibility changes. Only one actor can be used for a view at a time. * * @param scope Root coroutine scope * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -46,7 +46,6 @@ fun View.systemUiVisibilityChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (visibility in channel) action(visibility) } @@ -56,10 +55,10 @@ fun View.systemUiVisibilityChanges( } /** - * Perform an action on a new system UI visibility for [View] inside new [CoroutineScope]. + * Perform an action on a new system UI visibility for [View], inside new [CoroutineScope]. * - * *Warning:* The created actor uses [View.setOnSystemUiVisibilityChangeListener] to emit - * system UI visibility changes. Only one actor can be used for a view at a time. + * *Warning:* The created actor uses [View.setOnSystemUiVisibilityChangeListener] to emit system + * UI visibility changes. Only one actor can be used for a view at a time. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -68,20 +67,14 @@ suspend fun View.systemUiVisibilityChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (visibility in channel) action(visibility) - } - - setOnSystemUiVisibilityChangeListener(listener(this, events::offer)) - events.invokeOnClose { setOnSystemUiVisibilityChangeListener(null) } + systemUiVisibilityChanges(this, capacity, action) } /** * Create a channel of integers representing a new system UI visibility for [View]. * - * *Warning:* The created channel uses [View.setOnSystemUiVisibilityChangeListener] to emit - * system UI visibility changes. Only one channel can be used for a view at a time. + * *Warning:* The created channel uses [View.setOnSystemUiVisibilityChangeListener] to emit system + * UI visibility changes. Only one channel can be used for a view at a time. * * @param scope Root coroutine scope * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -98,8 +91,8 @@ fun View.systemUiVisibilityChanges( /** * Create a flow of integers representing a new system UI visibility for [View]. * - * *Warning:* The created flow uses [View.setOnSystemUiVisibilityChangeListener] to emit - * system UI visibility changes. Only one flow can be used for a view at a time. + * *Warning:* The created flow uses [View.setOnSystemUiVisibilityChangeListener] to emit system + * UI visibility changes. Only one flow can be used for a view at a time. */ @CheckResult fun View.systemUiVisibilityChanges(): Flow = channelFlow { diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTouchs.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTouchs.kt index d97a4c47..54920316 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTouchs.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTouchs.kt @@ -48,7 +48,6 @@ fun View.touches( handled: (MotionEvent) -> Boolean = AlwaysTrue, action: suspend (MotionEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (motion in channel) action(motion) } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverDraws.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverDraws.kt index a3fa2ff8..78c92801 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverDraws.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverDraws.kt @@ -47,7 +47,6 @@ fun View.draws( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -58,7 +57,7 @@ fun View.draws( } /** - * Perform an action on draws on [View] inside new [CoroutineScope]. + * Perform an action on draws on [View], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -68,14 +67,7 @@ suspend fun View.draws( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - val listener = listener(this, events::offer) - viewTreeObserver.addOnDrawListener(listener) - events.invokeOnClose { viewTreeObserver.removeOnDrawListener(listener) } + draws(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverGlobalLayouts.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverGlobalLayouts.kt index 4d8f8e25..76a1e737 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverGlobalLayouts.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverGlobalLayouts.kt @@ -44,7 +44,6 @@ fun View.globalLayouts( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -58,7 +57,7 @@ fun View.globalLayouts( } /** - * Perform an action on [View] globalLayout events. inside new [CoroutineScope]. + * Perform an action on [View] globalLayout events, inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -67,17 +66,7 @@ suspend fun View.globalLayouts( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - val listener = listener(this, events::offer) - viewTreeObserver.addOnGlobalLayoutListener(listener) - events.invokeOnClose { - @Suppress("DEPRECATION") // Correct when minSdk 16 - viewTreeObserver.removeGlobalOnLayoutListener(listener) - } + globalLayouts(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverPreDraws.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverPreDraws.kt index 7a70eb8a..bf4fc164 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverPreDraws.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/view/ViewTreeObserverPreDraws.kt @@ -56,7 +56,7 @@ fun View.preDraws( } /** - * Perform an action on pre-draws on [View] inside new [CoroutineScope]. + * Perform an action on pre-draws on [View], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param proceedDrawingPass Let drawing process proceed @@ -67,13 +67,7 @@ suspend fun View.preDraws( proceedDrawingPass: () -> Boolean, action: suspend () -> Unit ) = coroutineScope { - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - val listener = listener(this, proceedDrawingPass, events::offer) - viewTreeObserver.addOnPreDrawListener(listener) - events.invokeOnClose { viewTreeObserver.removeOnPreDrawListener(listener) } + preDraws(this, capacity, proceedDrawingPass, action) } /** @@ -114,7 +108,6 @@ private fun listener( proceedDrawingPass: () -> Boolean, emitter: (Unit) -> Boolean ) = ViewTreeObserver.OnPreDrawListener { - if (scope.isActive) { emitter(Unit) return@OnPreDrawListener proceedDrawingPass() diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AbsListViewScrollEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AbsListViewScrollEvents.kt index 74528f44..154784bc 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AbsListViewScrollEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AbsListViewScrollEvents.kt @@ -54,7 +54,6 @@ fun AbsListView.scrollEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (AbsListViewScrollEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -64,7 +63,7 @@ fun AbsListView.scrollEvents( } /** - * Perform an action on [scroll events][AbsListViewScrollEvent] on [AbsListView] inside new + * Perform an action on [scroll events][AbsListViewScrollEvent] on [AbsListView], inside new * [CoroutineScope]. * * *Warning:* The created actor uses [AbsListView.setOnScrollListener] to emit scroll changes. @@ -77,13 +76,7 @@ suspend fun AbsListView.scrollEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (AbsListViewScrollEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - setOnScrollListener(listener(this, events::offer)) - events.invokeOnClose { setOnScrollListener(null) } + scrollEvents(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterDataChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterDataChanges.kt index 79f1b046..3df802a9 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterDataChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterDataChanges.kt @@ -44,19 +44,18 @@ fun T.dataChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (T) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (adapter in channel) action(adapter) } events.offer(this) - val dataSetObserver = observer(scope = scope, adapter = this, emitter = events::offer) + val dataSetObserver = observer(scope, this, events::offer) registerDataSetObserver(dataSetObserver) events.invokeOnClose { unregisterDataSetObserver(dataSetObserver) } } /** - * Perform an action on data change events for [Adapter] inside new [CoroutineScope]. + * Perform an action on data change events for [Adapter], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -65,16 +64,7 @@ suspend fun T.dataChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (T) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (adapter in channel) action(adapter) - } - - events.offer(this@dataChanges) - val dataSetObserver = observer(scope = this, adapter = this@dataChanges, - emitter = events::offer) - registerDataSetObserver(dataSetObserver) - events.invokeOnClose { unregisterDataSetObserver(dataSetObserver) } + dataChanges(this, capacity, action) } /** @@ -88,7 +78,7 @@ fun T.dataChanges( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { - offer(this@dataChanges) + offerElement(this@dataChanges) val dataSetObserver = observer(scope, this@dataChanges, ::offerElement) registerDataSetObserver(dataSetObserver) invokeOnClose { unregisterDataSetObserver(dataSetObserver) } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemClickEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemClickEvents.kt index 21c49f30..645621f5 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemClickEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemClickEvents.kt @@ -52,7 +52,6 @@ fun AdapterView.itemClickEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (AdapterViewItemClickEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -62,7 +61,7 @@ fun AdapterView.itemClickEvents( } /** - * Perform an action on the [item click events][AdapterViewItemClickEvent] for [AdapterView] inside + * Perform an action on the [item click events][AdapterViewItemClickEvent] for [AdapterView], inside * new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -72,13 +71,7 @@ suspend fun AdapterView.itemClickEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (AdapterViewItemClickEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - onItemClickListener = listener(this, events::offer) - events.invokeOnClose { onItemClickListener = null } + itemClickEvents(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemClicks.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemClicks.kt index 042d0f95..a7cbbef6 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemClicks.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemClicks.kt @@ -45,7 +45,6 @@ fun AdapterView.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (position in channel) action(position) } @@ -55,7 +54,7 @@ fun AdapterView.itemClicks( } /** - * Perform an action on the position of item clicks for [AdapterView] inside new CoroutineScope. + * Perform an action on the position of item clicks for [AdapterView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -64,13 +63,7 @@ suspend fun AdapterView.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (position in channel) action(position) - } - - onItemClickListener = listener(this, events::offer) - events.invokeOnClose { onItemClickListener = null } + itemClicks(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemLongClickEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemLongClickEvents.kt index 19394978..e006b838 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemLongClickEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemLongClickEvents.kt @@ -56,7 +56,6 @@ fun AdapterView.itemLongClickEvents( handled: (AdapterViewItemLongClickEvent) -> Boolean = AlwaysTrue, action: suspend (AdapterViewItemLongClickEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -66,7 +65,7 @@ fun AdapterView.itemLongClickEvents( } /** - * Perform an action on [item long-click events][AdapterViewItemLongClickEvent] for [AdapterView] + * Perform an action on [item long-click events][AdapterViewItemLongClickEvent] for [AdapterView], * inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -79,13 +78,7 @@ suspend fun AdapterView.itemLongClickEvents( handled: (AdapterViewItemLongClickEvent) -> Boolean = AlwaysTrue, action: suspend (AdapterViewItemLongClickEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - onItemLongClickListener = listener(this, handled, events::offer) - events.invokeOnClose { onItemLongClickListener = null } + itemLongClickEvents(this, capacity, handled, action) } /** @@ -127,7 +120,6 @@ private fun listener( handled: (AdapterViewItemLongClickEvent) -> Boolean, emitter: (AdapterViewItemLongClickEvent) -> Boolean ) = AdapterView.OnItemLongClickListener { parent, view: View?, position, id -> - if (scope.isActive) { val event = AdapterViewItemLongClickEvent(parent, view, position, id) if (handled(event)) { diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemLongClicks.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemLongClicks.kt index ed496a06..5c4a59d7 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemLongClicks.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemLongClicks.kt @@ -49,7 +49,6 @@ fun AdapterView.itemLongClicks( handled: () -> Boolean = AlwaysTrue, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (position in channel) action(position) } @@ -59,7 +58,7 @@ fun AdapterView.itemLongClicks( } /** - * Perform an action on position of item long-clicks for [AdapterView] inside new CoroutineScope. + * Perform an action on position of item long-clicks for [AdapterView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param handled Function invoked each occurrence to determine the return value of the underlying @@ -71,13 +70,7 @@ suspend fun AdapterView.itemLongClicks( handled: () -> Boolean = AlwaysTrue, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (position in channel) action(position) - } - - onItemLongClickListener = listener(this, handled, events::offer) - events.invokeOnClose { onItemLongClickListener = null } + itemLongClicks(this, capacity, handled, action) } /** @@ -118,7 +111,6 @@ private fun listener( handled: () -> Boolean, emitter: (Int) -> Boolean ) = AdapterView.OnItemLongClickListener { _, _: View?, position, _ -> - if (scope.isActive) { if (handled()) { emitter(position) diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemSelections.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemSelections.kt index 0f955c6c..2466d09f 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemSelections.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewItemSelections.kt @@ -45,7 +45,6 @@ fun AdapterView.itemSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (position in channel) action(position) } @@ -56,7 +55,7 @@ fun AdapterView.itemSelections( } /** - * Perform an action on the selected position of [AdapterView] inside new [CoroutineScope]. + * Perform an action on the selected position of [AdapterView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -65,14 +64,7 @@ suspend fun AdapterView.itemSelections( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (position in channel) action(position) - } - - events.offer(selectedItemPosition) - onItemSelectedListener = listener(this, events::offer) - events.invokeOnClose { onItemSelectedListener = null } + itemSelections(this, capacity, action) } /** @@ -87,7 +79,7 @@ fun AdapterView.itemSelections( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { - offer(selectedItemPosition) + offerElement(selectedItemPosition) onItemSelectedListener = listener(scope, ::offerElement) invokeOnClose { onItemSelectedListener = null } } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewSelections.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewSelections.kt index f176b4b2..e7acab53 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewSelections.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AdapterViewSelections.kt @@ -60,7 +60,6 @@ fun AdapterView.selectionEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (AdapterViewSelectionEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -71,7 +70,7 @@ fun AdapterView.selectionEvents( } /** - * Perform an action on selection events for [AdapterView] inside new CoroutineScope. + * Perform an action on selection events for [AdapterView], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -80,14 +79,7 @@ suspend fun AdapterView.selectionEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (AdapterViewSelectionEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - events.offer(initialValue(this@selectionEvents)) - onItemSelectedListener = listener(this, events::offer) - events.invokeOnClose { onItemSelectedListener = null } + selectionEvents(this, capacity, action) } /** @@ -101,7 +93,7 @@ fun AdapterView.selectionEvents( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { - offer(initialValue(this@selectionEvents)) + offerElement(initialValue(this@selectionEvents)) onItemSelectedListener = listener(scope, ::offerElement) invokeOnClose { onItemSelectedListener = null } } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AutoCompleteTextViewItemClickEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AutoCompleteTextViewItemClickEvents.kt index 0ef08fc6..cd4c13fd 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AutoCompleteTextViewItemClickEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/AutoCompleteTextViewItemClickEvents.kt @@ -45,7 +45,6 @@ fun AutoCompleteTextView.itemClickEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (AdapterViewItemClickEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -55,7 +54,7 @@ fun AutoCompleteTextView.itemClickEvents( } /** - * Perform an action on [item click events][AdapterViewItemClickEvent] on [AutoCompleteTextView] + * Perform an action on [item click events][AdapterViewItemClickEvent] on [AutoCompleteTextView], * inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -65,13 +64,7 @@ suspend fun AutoCompleteTextView.itemClickEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (AdapterViewItemClickEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - onItemClickListener = listener(this, events::offer) - events.invokeOnClose { onItemClickListener = null } + itemClickEvents(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/CompoundButtonCheckedChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/CompoundButtonCheckedChanges.kt index 9eec8163..657c7491 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/CompoundButtonCheckedChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/CompoundButtonCheckedChanges.kt @@ -46,7 +46,6 @@ fun CompoundButton.checkedChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Boolean) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (checked in channel) action(checked) } @@ -57,7 +56,7 @@ fun CompoundButton.checkedChanges( } /** - * Perform an action on checked state of [CompoundButton] inside new [CoroutineScope]. + * Perform an action on checked state of [CompoundButton], inside new [CoroutineScope]. * * *Warning:* The created actor uses [CompoundButton.setOnCheckedChangeListener] to emit checked * changes. Only one actor can be used for a view at a time. @@ -69,14 +68,7 @@ suspend fun CompoundButton.checkedChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Boolean) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (checked in channel) action(checked) - } - - events.offer(isChecked) - setOnCheckedChangeListener(listener(this, events::offer)) - events.invokeOnClose { setOnCheckedChangeListener(null) } + checkedChanges(this, capacity, action) } /** @@ -93,7 +85,7 @@ fun CompoundButton.checkedChanges( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { - offer(isChecked) + offerElement(isChecked) setOnCheckedChangeListener(listener(scope, ::offerElement)) invokeOnClose { setOnCheckedChangeListener(null) } } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/PopupMenuDismisses.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/PopupMenuDismisses.kt index 4873f804..7cc41f92 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/PopupMenuDismisses.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/PopupMenuDismisses.kt @@ -46,7 +46,6 @@ fun PopupMenu.dismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -56,7 +55,7 @@ fun PopupMenu.dismisses( } /** - * Perform an action on [PopupMenu] dismiss events inside new CoroutineScope. + * Perform an action on [PopupMenu] dismiss events, inside new [CoroutineScope]. * * *Warning:* The created actor uses [PopupMenu.setOnDismissListener] to emit dismiss change. * Only one actor can be used for a view at a time. @@ -68,13 +67,7 @@ suspend fun PopupMenu.dismisses( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - setOnDismissListener(listener(this, events::offer)) - events.invokeOnClose { setOnDismissListener(null) } + dismisses(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/PopupMenuItemClicks.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/PopupMenuItemClicks.kt index 9c32350a..357709f3 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/PopupMenuItemClicks.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/PopupMenuItemClicks.kt @@ -47,7 +47,6 @@ fun PopupMenu.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (item in channel) action(item) } @@ -57,7 +56,7 @@ fun PopupMenu.itemClicks( } /** - * Perform an action on clicked item in [PopupMenu] inside new [CoroutineScope]. + * Perform an action on clicked item in [PopupMenu], inside new [CoroutineScope]. * * *Warning:* The created actor uses [PopupMenu.setOnMenuItemClickListener] to emit dismiss * change. Only one actor can be used for a view at a time. @@ -69,13 +68,7 @@ suspend fun PopupMenu.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (item in channel) action(item) - } - - setOnMenuItemClickListener(listener(this, events::offer)) - events.invokeOnClose { setOnMenuItemClickListener(null) } + itemClicks(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RadioGroupCheckedChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RadioGroupCheckedChanges.kt index f9f4781f..1211d4fa 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RadioGroupCheckedChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RadioGroupCheckedChanges.kt @@ -46,7 +46,6 @@ fun RadioGroup.checkedChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (checkedId in channel) action(checkedId) } @@ -57,7 +56,7 @@ fun RadioGroup.checkedChanges( } /** - * Perform an action on checked view ID changes in [RadioGroup] inside new CoroutineScope. + * Perform an action on checked view ID changes in [RadioGroup], inside new [CoroutineScope]. * * *Note:* When the selection is cleared, checkedId is [View.NO_ID] * @@ -68,14 +67,7 @@ suspend fun RadioGroup.checkedChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (checkedId in channel) action(checkedId) - } - - events.offer(checkedRadioButtonId) - setOnCheckedChangeListener(listener(this, events::offer)) - events.invokeOnClose { setOnCheckedChangeListener(null) } + checkedChanges(this, capacity, action) } /** @@ -91,7 +83,7 @@ fun RadioGroup.checkedChanges( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { - offer(checkedRadioButtonId) + offerElement(checkedRadioButtonId) setOnCheckedChangeListener(listener(scope, ::offerElement)) invokeOnClose { setOnCheckedChangeListener(null) } } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RatingBarRatingChangeEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RatingBarRatingChangeEvents.kt index d63901ff..d0162dfc 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RatingBarRatingChangeEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RatingBarRatingChangeEvents.kt @@ -49,7 +49,6 @@ fun RatingBar.ratingChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (RatingBarChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -60,7 +59,7 @@ fun RatingBar.ratingChangeEvents( } /** - * Perform an action on [rating change events][RatingBarChangeEvent] on [RatingBar] inside new + * Perform an action on [rating change events][RatingBarChangeEvent] on [RatingBar], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -70,14 +69,7 @@ suspend fun RatingBar.ratingChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (RatingBarChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - events.offer(initialValue(this@ratingChangeEvents)) - onRatingBarChangeListener = listener(this, events::offer) - events.invokeOnClose { onRatingBarChangeListener = null } + ratingChangeEvents(this, capacity, action) } /** @@ -88,11 +80,11 @@ suspend fun RatingBar.ratingChangeEvents( */ @CheckResult fun RatingBar.ratingChangeEvents( - capacity: Int = Channel.RENDEZVOUS, - scope: CoroutineScope + scope: CoroutineScope, + capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { offerElement(initialValue(this@ratingChangeEvents)) - onRatingBarChangeListener = listener(scope, ::offer) + onRatingBarChangeListener = listener(scope, ::offerElement) invokeOnClose { onRatingBarChangeListener = null } } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RatingBarRatingChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RatingBarRatingChanges.kt index d36c5099..293b7742 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RatingBarRatingChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/RatingBarRatingChanges.kt @@ -43,7 +43,6 @@ fun RatingBar.ratingChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Float) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (rating in channel) action(rating) } @@ -54,7 +53,7 @@ fun RatingBar.ratingChanges( } /** - * Perform an action on rating changes on [RatingBar] inside new CoroutineScope. + * Perform an action on rating changes on [RatingBar], inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -63,14 +62,7 @@ suspend fun RatingBar.ratingChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (Float) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (rating in channel) action(rating) - } - - events.offer(rating) - onRatingBarChangeListener = listener(this, events::offer) - events.invokeOnClose { onRatingBarChangeListener = null } + ratingChanges(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SearchViewQueryTextChangeEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SearchViewQueryTextChangeEvents.kt index e9c55a73..5166a152 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SearchViewQueryTextChangeEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SearchViewQueryTextChangeEvents.kt @@ -49,18 +49,17 @@ fun SearchView.queryTextChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (SearchViewQueryTextEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } events.offer(initialValue(this)) - setOnQueryTextListener(listener(scope = scope, searchView = this, emitter = events::offer)) + setOnQueryTextListener(listener(scope, this, events::offer)) events.invokeOnClose { setOnQueryTextListener(null) } } /** - * Perform an action on [query text events][SearchViewQueryTextEvent] on [SearchView] inside new + * Perform an action on [query text events][SearchViewQueryTextEvent] on [SearchView], inside new * [CoroutineScope] * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -70,15 +69,7 @@ suspend fun SearchView.queryTextChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (SearchViewQueryTextEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - events.offer(initialValue(this@queryTextChangeEvents)) - setOnQueryTextListener(listener(scope = this, searchView = this@queryTextChangeEvents, - emitter = events::offer)) - events.invokeOnClose { setOnQueryTextListener(null) } + queryTextChangeEvents(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SearchViewQueryTextChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SearchViewQueryTextChanges.kt index 272fb7b1..66a503be 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SearchViewQueryTextChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SearchViewQueryTextChanges.kt @@ -43,7 +43,6 @@ fun SearchView.queryTextChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (CharSequence) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (chars in channel) action(chars) } @@ -54,7 +53,7 @@ fun SearchView.queryTextChanges( } /** - * Perform an action on character sequences for query text changes on [SearchView] inside new + * Perform an action on character sequences for query text changes on [SearchView], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -64,14 +63,7 @@ suspend fun SearchView.queryTextChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (CharSequence) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (chars in channel) action(chars) - } - - events.offer(query) - setOnQueryTextListener(listener(this, events::offer)) - events.invokeOnClose { setOnQueryTextListener(null) } + queryTextChanges(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SeekBarChangeEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SeekBarChangeEvents.kt index bf137b45..86d49f70 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SeekBarChangeEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SeekBarChangeEvents.kt @@ -61,7 +61,6 @@ fun SeekBar.changeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (SeekBarChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -72,7 +71,7 @@ fun SeekBar.changeEvents( } /** - * Perform an action on [change events][SeekBarChangeEvent] for [SeekBar] inside new + * Perform an action on [change events][SeekBarChangeEvent] for [SeekBar], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -82,14 +81,7 @@ suspend fun SeekBar.changeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (SeekBarChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - events.offer(initialValue(this@changeEvents)) - setOnSeekBarChangeListener(listener(this, events::offer)) - events.invokeOnClose { setOnSeekBarChangeListener(null) } + changeEvents(this, capacity, action) } /** @@ -103,7 +95,7 @@ fun SeekBar.changeEvents( scope: CoroutineScope, capacity: Int = Channel.RENDEZVOUS ): ReceiveChannel = corbindReceiveChannel(capacity) { - offer(initialValue(this@changeEvents)) + offerElement(initialValue(this@changeEvents)) setOnSeekBarChangeListener(listener(scope, ::offerElement)) invokeOnClose { setOnSeekBarChangeListener(null) } } diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SeekBarChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SeekBarChanges.kt index dc03c4a0..3a966e3a 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SeekBarChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/SeekBarChanges.kt @@ -37,7 +37,6 @@ private fun SeekBar.changes( shouldBeFromUser: Boolean?, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (progress in channel) action(progress) } @@ -52,14 +51,7 @@ private suspend fun SeekBar.changes( shouldBeFromUser: Boolean?, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (progress in channel) action(progress) - } - - events.offer(progress) - setOnSeekBarChangeListener(listener(this, shouldBeFromUser, events::offer)) - events.invokeOnClose { setOnSeekBarChangeListener(null) } + changes(this, capacity, shouldBeFromUser, action) } @CheckResult diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewAfterTextChangeEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewAfterTextChangeEvents.kt index b0123049..085b4d24 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewAfterTextChangeEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewAfterTextChangeEvents.kt @@ -50,19 +50,18 @@ fun TextView.afterTextChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (TextViewAfterTextChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } events.offer(initialValue(this)) - val listener = listener(scope = scope, textView = this, emitter = events::offer) + val listener = listener(scope, this, events::offer) addTextChangedListener(listener) events.invokeOnClose { removeTextChangedListener(listener) } } /** - * Perform an action [after text change events][TextViewAfterTextChangeEvent] for [TextView] inside + * Perform an action [after text change events][TextViewAfterTextChangeEvent] for [TextView], inside * new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -72,16 +71,7 @@ suspend fun TextView.afterTextChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (TextViewAfterTextChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - events.offer(initialValue(this@afterTextChangeEvents)) - val listener = listener(scope = this, textView = this@afterTextChangeEvents, - emitter = events::offer) - addTextChangedListener(listener) - events.invokeOnClose { removeTextChangedListener(listener) } + afterTextChangeEvents(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewBeforeTextChangeEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewBeforeTextChangeEvents.kt index c4f80cd9..e9ffaf80 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewBeforeTextChangeEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewBeforeTextChangeEvents.kt @@ -53,19 +53,18 @@ fun TextView.beforeTextChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (TextViewBeforeTextChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } events.offer(initialValue(this)) - val listener = listener(scope = scope, textView = this, emitter = events::offer) + val listener = listener(scope, this, events::offer) addTextChangedListener(listener) events.invokeOnClose { removeTextChangedListener(listener) } } /** - * Perform an action [before text change events][TextViewBeforeTextChangeEvent] for [TextView] + * Perform an action [before text change events][TextViewBeforeTextChangeEvent] for [TextView], * inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -75,16 +74,7 @@ suspend fun TextView.beforeTextChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (TextViewBeforeTextChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - events.offer(initialValue(this@beforeTextChangeEvents)) - val listener = listener(scope = this, textView = this@beforeTextChangeEvents, - emitter = events::offer) - addTextChangedListener(listener) - events.invokeOnClose { removeTextChangedListener(listener) } + beforeTextChangeEvents(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewEditorActionEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewEditorActionEvents.kt index 20bca4be..f6f781ef 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewEditorActionEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewEditorActionEvents.kt @@ -54,7 +54,6 @@ fun TextView.editorActionEvents( handled: (TextViewEditorActionEvent) -> Boolean = AlwaysTrue, action: suspend (TextViewEditorActionEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } @@ -64,7 +63,7 @@ fun TextView.editorActionEvents( } /** - * Perform an action on [editor action events][TextViewEditorActionEvent] on [TextView] inside new + * Perform an action on [editor action events][TextViewEditorActionEvent] on [TextView], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -77,13 +76,7 @@ suspend fun TextView.editorActionEvents( handled: (TextViewEditorActionEvent) -> Boolean = AlwaysTrue, action: suspend (TextViewEditorActionEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - setOnEditorActionListener(listener(this, handled, events::offer)) - events.invokeOnClose { setOnEditorActionListener(null) } + editorActionEvents(this, capacity, handled, action) } /** @@ -124,7 +117,6 @@ private fun listener( handled: (TextViewEditorActionEvent) -> Boolean, emitter: (TextViewEditorActionEvent) -> Boolean ) = TextView.OnEditorActionListener { v, actionId, keyEvent -> - if (scope.isActive) { val event = TextViewEditorActionEvent(v, actionId, keyEvent) if (handled(event)) { diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewEditorActions.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewEditorActions.kt index a99bc475..257380cb 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewEditorActions.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewEditorActions.kt @@ -50,7 +50,6 @@ fun TextView.editorActions( handled: (Int) -> Boolean = AlwaysTrue, action: suspend (Int) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (actionId in channel) action(actionId) } @@ -60,7 +59,7 @@ fun TextView.editorActions( } /** - * Perform an action on editor actions on [TextView] inside new [CoroutineScope]. + * Perform an action on editor actions on [TextView], inside new [CoroutineScope]. * * *Warning:* The created actor uses [TextView.OnEditorActionListener] to emit actions. Only one * actor can be used for a view at a time. @@ -75,13 +74,7 @@ suspend fun TextView.editorActions( handled: (Int) -> Boolean = AlwaysTrue, action: suspend (Int) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (actionId in channel) action(actionId) - } - - setOnEditorActionListener(listener(this, handled, events::offer)) - events.invokeOnClose { setOnEditorActionListener(null) } + editorActions(this, capacity, handled, action) } /** @@ -128,7 +121,6 @@ private fun listener( handled: (Int) -> Boolean, emitter: (Int) -> Boolean ) = TextView.OnEditorActionListener { _, actionId, _ -> - if (scope.isActive && handled(actionId)) { emitter(actionId) return@OnEditorActionListener true diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewTextChangeEvents.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewTextChangeEvents.kt index 0803ef48..52a7cad0 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewTextChangeEvents.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewTextChangeEvents.kt @@ -53,19 +53,18 @@ fun TextView.textChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (TextViewTextChangeEvent) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (event in channel) action(event) } events.offer(initialValue(this)) - val listener = listener(scope = scope, textView = this, emitter = events::offer) + val listener = listener(scope, this, events::offer) addTextChangedListener(listener) events.invokeOnClose { removeTextChangedListener(listener) } } /** - * Perform an action on [text change events][TextViewTextChangeEvent] for [TextView] inside new + * Perform an action on [text change events][TextViewTextChangeEvent] for [TextView], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -75,15 +74,7 @@ suspend fun TextView.textChangeEvents( capacity: Int = Channel.RENDEZVOUS, action: suspend (TextViewTextChangeEvent) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (event in channel) action(event) - } - - events.offer(initialValue(this@textChangeEvents)) - val listener = listener(scope = this, textView = this@textChangeEvents, emitter = events::offer) - addTextChangedListener(listener) - events.invokeOnClose { removeTextChangedListener(listener) } + textChangeEvents(this, capacity, action) } /** @@ -135,4 +126,5 @@ private fun listener( } } - override fun afterTextChanged(s: Editable) { } } + override fun afterTextChanged(s: Editable) { } +} diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewTextChanges.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewTextChanges.kt index b55f5efa..935ecf84 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewTextChanges.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/TextViewTextChanges.kt @@ -45,7 +45,6 @@ fun TextView.textChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (CharSequence) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (chars in channel) action(chars) } @@ -57,7 +56,7 @@ fun TextView.textChanges( } /** - * Perform an action on character sequences for text changes on [TextView] inside new + * Perform an action on character sequences for text changes on [TextView], inside new * [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) @@ -67,15 +66,7 @@ suspend fun TextView.textChanges( capacity: Int = Channel.RENDEZVOUS, action: suspend (CharSequence) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (chars in channel) action(chars) - } - - events.offer(text) - val listener = listener(this, events::offer) - addTextChangedListener(listener) - events.invokeOnClose { removeTextChangedListener(listener) } + textChanges(this, capacity, action) } /** diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/ToolbarItemClicks.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/ToolbarItemClicks.kt index 5b95f495..171942ef 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/ToolbarItemClicks.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/ToolbarItemClicks.kt @@ -47,7 +47,6 @@ fun Toolbar.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (item in channel) action(item) } @@ -57,7 +56,7 @@ fun Toolbar.itemClicks( } /** - * Perform an action on the clicked item in [Toolbar] menu inside new [CoroutineScope]. + * Perform an action on the clicked item in [Toolbar] menu, inside new [CoroutineScope]. * * @param capacity Capacity of the channel's buffer (no buffer by default) * @param action An action to perform @@ -67,13 +66,7 @@ suspend fun Toolbar.itemClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend (MenuItem) -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (item in channel) action(item) - } - - setOnMenuItemClickListener(listener(this, events::offer)) - events.invokeOnClose { setOnMenuItemClickListener(null) } + itemClicks(this, capacity, action) } /** @@ -107,7 +100,6 @@ private fun listener( scope: CoroutineScope, emitter: (MenuItem) -> Boolean ) = Toolbar.OnMenuItemClickListener { - if (scope.isActive) { emitter(it) return@OnMenuItemClickListener true diff --git a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/ToolbarNavigationClicks.kt b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/ToolbarNavigationClicks.kt index 3986f819..dc1d4ac4 100644 --- a/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/ToolbarNavigationClicks.kt +++ b/corbind/src/main/kotlin/ru/ldralighieri/corbind/widget/ToolbarNavigationClicks.kt @@ -50,7 +50,6 @@ fun Toolbar.navigationClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) { - val events = scope.actor(Dispatchers.Main, capacity) { for (unit in channel) action() } @@ -60,7 +59,7 @@ fun Toolbar.navigationClicks( } /** - * Perform an action on [Toolbar] navigation click events inside new [CoroutineScope]. + * Perform an action on [Toolbar] navigation click events, inside new [CoroutineScope]. * * *Warning:* The created actor uses [Toolbar.setNavigationOnClickListener] to emit clicks. * Only one actor can be used for a view at a time. @@ -73,13 +72,7 @@ suspend fun Toolbar.navigationClicks( capacity: Int = Channel.RENDEZVOUS, action: suspend () -> Unit ) = coroutineScope { - - val events = actor(Dispatchers.Main, capacity) { - for (unit in channel) action() - } - - setNavigationOnClickListener(listener(this, events::offer)) - events.invokeOnClose { setNavigationOnClickListener(null) } + navigationClicks(this, capacity, action) } /** diff --git a/gradle.properties b/gradle.properties index 313461e7..cd8e482c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ android.useAndroidX=true # Maven GROUP=ru.ldralighieri.corbind -VERSION_NAME=1.1.1-SNAPSHOT +VERSION_NAME=1.1.2 POM_DESCRIPTION=Kotlin Coroutines binding APIs for Android UI widgets from the platform and support libraries. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ad8f27a0..c4b9c2b6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -18,4 +18,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 22d025f1..79b9b721 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,3 +1,19 @@ +/* + * Copyright 2019 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. + */ + apply plugin: 'com.android.application' apply plugin: 'kotlin-android' @@ -67,8 +83,8 @@ dependencies { implementation project(":corbind") implementation project(":corbind-swiperefreshlayout") - implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' - implementation 'com.google.android.material:material:1.1.0-alpha09' + implementation 'com.google.android.material:material:1.1.0-alpha10' } diff --git a/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/LoginActivity.kt b/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/LoginActivity.kt index da98cd3a..610f82e3 100644 --- a/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/LoginActivity.kt +++ b/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/LoginActivity.kt @@ -18,7 +18,6 @@ package ru.ldralighieri.corbind.sample import android.os.Bundle import android.util.Patterns -import android.view.WindowManager import android.view.inputmethod.EditorInfo import android.widget.Toast import kotlinx.android.synthetic.main.activity_login.* @@ -41,18 +40,9 @@ class LoginActivity : CorbindActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login) - - setFullscreenFlags() bindViews() } - private fun setFullscreenFlags() { - window.setFlags( - WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN - ) - } - private fun bindViews() { combine( diff --git a/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/CorbindActivity.kt b/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/CorbindActivity.kt index b653a163..20827ee3 100644 --- a/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/CorbindActivity.kt +++ b/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/CorbindActivity.kt @@ -16,7 +16,9 @@ package ru.ldralighieri.corbind.sample.core +import android.os.Build import android.os.Bundle +import android.view.View import androidx.appcompat.app.AppCompatActivity import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -33,10 +35,17 @@ abstract class CorbindActivity : AppCompatActivity(), CoroutineScope { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) job = Job() + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + val view = window.decorView + view.systemUiVisibility = view.systemUiVisibility or + View.SYSTEM_UI_FLAG_LAYOUT_STABLE or + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + } } override fun onDestroy() { job.cancel() super.onDestroy() } -} \ No newline at end of file +} diff --git a/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/extensions/Activity+Extensions.kt b/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/extensions/Activity+Extensions.kt index 175da9f0..965829a2 100644 --- a/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/extensions/Activity+Extensions.kt +++ b/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/extensions/Activity+Extensions.kt @@ -25,4 +25,4 @@ fun Activity.hideSoftInput() { if (currentFocus != null && imm != null) { imm.hideSoftInputFromWindow(currentFocus.windowToken, 0) } -} \ No newline at end of file +} diff --git a/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/extensions/Context+Extensions.kt b/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/extensions/Context+Extensions.kt index 746aa6d7..f88dbd0d 100644 --- a/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/extensions/Context+Extensions.kt +++ b/sample/src/main/kotlin/ru/ldralighieri/corbind/sample/core/extensions/Context+Extensions.kt @@ -20,4 +20,4 @@ import android.content.Context import android.view.inputmethod.InputMethodManager val Context.inputMethodManager: InputMethodManager - get() = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager \ No newline at end of file + get() = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager diff --git a/sample/src/main/res/drawable/ic_email_grey_500.xml b/sample/src/main/res/drawable/ic_email_grey_500.xml index 66103bda..67a46503 100644 --- a/sample/src/main/res/drawable/ic_email_grey_500.xml +++ b/sample/src/main/res/drawable/ic_email_grey_500.xml @@ -20,6 +20,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/sample/src/main/res/drawable/ic_lock_grey_500.xml b/sample/src/main/res/drawable/ic_lock_grey_500.xml index b378a983..15ddfd5a 100644 --- a/sample/src/main/res/drawable/ic_lock_grey_500.xml +++ b/sample/src/main/res/drawable/ic_lock_grey_500.xml @@ -20,6 +20,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/sample/src/main/res/drawable/ic_person_grey_500.xml b/sample/src/main/res/drawable/ic_person_grey_500.xml index 02485874..61531e2c 100644 --- a/sample/src/main/res/drawable/ic_person_grey_500.xml +++ b/sample/src/main/res/drawable/ic_person_grey_500.xml @@ -20,6 +20,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/sample/src/main/res/layout/activity_login.xml b/sample/src/main/res/layout/activity_login.xml index 4edd8950..107765d6 100644 --- a/sample/src/main/res/layout/activity_login.xml +++ b/sample/src/main/res/layout/activity_login.xml @@ -53,7 +53,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" - app:layout_constraintGuide_end="80dp" /> + app:layout_constraintGuide_end="100dp" /> + + + + + + #EF5350 + #C2185B + #C2185B + #000000 + + #C86470 + #C86470 + #FFFFFF + + #000 + #FFF + + #121212 + #FFFFFF + + #CF6679 + #000000 + + + #2EFFFFFF + #B3000000 + + @android:color/transparent + + diff --git a/sample/src/main/res/values-night/config.xml b/sample/src/main/res/values-night/config.xml new file mode 100644 index 00000000..3f99ea7b --- /dev/null +++ b/sample/src/main/res/values-night/config.xml @@ -0,0 +1,20 @@ + + + + + false + \ No newline at end of file diff --git a/sample/src/main/res/values-notnight-v23/colors.xml b/sample/src/main/res/values-notnight-v23/colors.xml new file mode 100644 index 00000000..edf52f9b --- /dev/null +++ b/sample/src/main/res/values-notnight-v23/colors.xml @@ -0,0 +1,20 @@ + + + + + @color/system_ui_scrim_light + diff --git a/sample/src/main/res/values-notnight-v27/colors.xml b/sample/src/main/res/values-notnight-v27/colors.xml new file mode 100644 index 00000000..5e22b457 --- /dev/null +++ b/sample/src/main/res/values-notnight-v27/colors.xml @@ -0,0 +1,20 @@ + + + + + @color/system_ui_scrim_light + diff --git a/sample/src/main/res/values-notnight-v27/config.xml b/sample/src/main/res/values-notnight-v27/config.xml new file mode 100644 index 00000000..f2ad1022 --- /dev/null +++ b/sample/src/main/res/values-notnight-v27/config.xml @@ -0,0 +1,20 @@ + + + + + true + \ No newline at end of file diff --git a/sample/src/main/res/values-v29/themes.xml b/sample/src/main/res/values-v29/themes.xml new file mode 100644 index 00000000..808d87fb --- /dev/null +++ b/sample/src/main/res/values-v29/themes.xml @@ -0,0 +1,25 @@ + + + + + + + - - + +