-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add broadcast receiver flow * Make android's plugin match format of other plugins * Add Android-only temporal module * Add JVM and JS modules with simple ticker flow * Write tests for ticker and date time flows * Readme fix * Readme cleanups & reduce API surface * Revert accidentally commented line * Remove unused imports * Google above JCenter in repo order
- Loading branch information
1 parent
2a13bee
commit bca8844
Showing
30 changed files
with
701 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
![badge-android] | ||
![badge-js] | ||
![badge-jvm] | ||
![badge-mac] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.juul.tuulbox.coroutines"> | ||
|
||
<application> | ||
<provider | ||
android:name="androidx.startup.InitializationProvider" | ||
android:authorities="${applicationId}.androidx-startup" | ||
android:exported="false" | ||
tools:node="merge" | ||
> | ||
|
||
<meta-data | ||
android:name="com.juul.tuulbox.coroutines.TuulboxCoroutinesInitializer" | ||
android:value="androidx.startup" | ||
/> | ||
</provider> | ||
</application> | ||
|
||
</manifest> |
18 changes: 18 additions & 0 deletions
18
coroutines/src/androidMain/kotlin/TuulboxCoroutinesInitializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.juul.tuulbox.coroutines | ||
|
||
import android.content.Context | ||
import androidx.startup.Initializer | ||
|
||
internal lateinit var applicationContext: Context | ||
private set | ||
|
||
public object TuulboxCoroutines | ||
|
||
public class TuulboxCoroutinesInitializer : Initializer<TuulboxCoroutines> { | ||
override fun create(context: Context): TuulboxCoroutines { | ||
applicationContext = context | ||
return TuulboxCoroutines | ||
} | ||
|
||
override fun dependencies(): List<Class<out Initializer<*>>> = emptyList() | ||
} |
25 changes: 25 additions & 0 deletions
25
coroutines/src/androidMain/kotlin/flow/BroadcastReceiverFlow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.juul.tuulbox.coroutines.flow | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.IntentFilter | ||
import com.juul.tuulbox.coroutines.applicationContext | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.callbackFlow | ||
|
||
@Suppress("EXPERIMENTAL_API_USAGE") | ||
public fun broadcastReceiverFlow( | ||
intentFilter: IntentFilter | ||
): Flow<Intent> = callbackFlow { | ||
val broadcastReceiver = object : BroadcastReceiver() { | ||
override fun onReceive(context: Context?, intent: Intent?) { | ||
if (intent != null) { | ||
offer(intent) | ||
} | ||
} | ||
} | ||
applicationContext.registerReceiver(broadcastReceiver, intentFilter) | ||
awaitClose { applicationContext.unregisterReceiver(broadcastReceiver) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
![badge-android] | ||
![badge-js] | ||
![badge-jvm] | ||
|
||
# Coroutines | ||
|
||
Toolbox of utilities for dates and times, building on [KotlinX DateTime]. | ||
|
||
## Setup | ||
|
||
### Gradle | ||
|
||
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.juul.tuulbox/temporal/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.juul.tuulbox/temporal) | ||
|
||
Coroutines toolbox can be configured via Gradle Kotlin DSL as follows: | ||
|
||
#### Multiplatform | ||
|
||
```kotlin | ||
plugins { | ||
id("com.android.application") // or id("com.android.library") | ||
kotlin("multiplatform") | ||
} | ||
|
||
repositories { | ||
jcenter() // or mavenCentral() | ||
} | ||
|
||
kotlin { | ||
js().browser() // and/or js().node() | ||
jvm() // or android() | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation("com.juul.tuulbox:temporal:$version") | ||
} | ||
} | ||
} | ||
} | ||
|
||
android { | ||
// If this is an application module and your minimum API version is below 26, enable core library | ||
// desugaring. See https://developer.android.com/studio/write/java8-support#library-desugaring | ||
} | ||
``` | ||
|
||
#### Platform-specific | ||
|
||
```kotlin | ||
repositories { | ||
jcenter() // or mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("com.juul.tuulbox:temporal-$platform:$version") | ||
} | ||
``` | ||
|
||
_Where `$platform` represents (should be replaced with) the desired platform dependency (e.g. `jvm`)._ | ||
|
||
#### Android Notes | ||
|
||
Because this is built on top of KotlinX DateTime, [core library desugaring] must be enabled for your project | ||
|
||
[core library desugaring]: https://developer.android.com/studio/write/java8-support#library-desugaring | ||
[KotlinX DateTime]: https://github.com/Kotlin/kotlinx-datetime | ||
|
||
[badge-android]: http://img.shields.io/badge/platform-android-6EDB8D.svg?style=flat | ||
[badge-ios]: http://img.shields.io/badge/platform-ios-CDCDCD.svg?style=flat | ||
[badge-js]: http://img.shields.io/badge/platform-js-F8DB5D.svg?style=flat | ||
[badge-jvm]: http://img.shields.io/badge/platform-jvm-DB413D.svg?style=flat | ||
[badge-linux]: http://img.shields.io/badge/platform-linux-2D3F6C.svg?style=flat | ||
[badge-windows]: http://img.shields.io/badge/platform-windows-4D76CD.svg?style=flat | ||
[badge-mac]: http://img.shields.io/badge/platform-macos-111111.svg?style=flat | ||
[badge-watchos]: http://img.shields.io/badge/platform-watchos-C0C0C0.svg?style=flat | ||
[badge-tvos]: http://img.shields.io/badge/platform-tvos-808080.svg?style=flat | ||
[badge-wasm]: https://img.shields.io/badge/platform-wasm-624FE8.svg?style=flat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public final class com/juul/tuulbox/temporal/DateTimeFlowKt { | ||
public static final fun instantFlow ()Lkotlinx/coroutines/flow/Flow; | ||
public static final fun localDateFlow ()Lkotlinx/coroutines/flow/Flow; | ||
public static final fun localDateTimeFlow ()Lkotlinx/coroutines/flow/Flow; | ||
} | ||
|
||
public final class com/juul/tuulbox/temporal/TickerTemporalFlowKt { | ||
public static final fun temporalFlow (Lkotlin/jvm/functions/Function0;)Lkotlinx/coroutines/flow/Flow; | ||
} | ||
|
Oops, something went wrong.