Skip to content

Commit d8a502e

Browse files
committed
Added Coroutines Extensions
1 parent 353da7f commit d8a502e

File tree

11 files changed

+142
-21
lines changed

11 files changed

+142
-21
lines changed

.idea/codeStyles/Project.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Add it in your root build.gradle at the end of repositories:
1616
Step 2. Add the dependency
1717

1818
dependencies {
19-
implementation 'com.github.Omega-R:OmegaExtensions:1.0.1'
19+
implementation 'com.github.Omega-R:OmegaExtensions:1.0.4'
2020
}

app/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44

55
android {
6-
compileSdkVersion 28
6+
compileSdkVersion 30
77
defaultConfig {
88
applicationId "omega_r.com.extensions.simple"
99
minSdkVersion 14
10-
targetSdkVersion 28
10+
targetSdkVersion 30
1111
versionCode 1
1212
versionName "1.0"
1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -22,12 +22,12 @@ android {
2222

2323
dependencies {
2424
implementation fileTree(dir: 'libs', include: ['*.jar'])
25+
implementation project(':extensionslib')
2526
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
2627
implementation "androidx.appcompat:appcompat:$appcompat"
27-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
28-
implementation project(':extensionslib')
28+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
2929

30-
testImplementation 'junit:junit:4.12'
31-
androidTestImplementation 'androidx.test:runner:1.2.0-alpha03'
32-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha03'
30+
testImplementation 'junit:junit:4.13.1'
31+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
32+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
3333
}

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.30'
5-
ext.appcompat = '1.1.0-alpha04'
4+
ext.kotlin_version = '1.4.10'
5+
ext.appcompat = '1.2.0'
66

77
repositories {
88
google()
99
jcenter()
1010

1111
}
1212
dependencies {
13-
classpath 'com.android.tools.build:gradle:3.3.2'
13+
classpath 'com.android.tools.build:gradle:4.1.1'
1414
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1515
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1616
// NOTE: Do not place your application dependencies here; they belong

extensionslib/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'com.github.dcendents.android-maven'
44

55
android {
6-
compileSdkVersion 28
6+
compileSdkVersion 30
77

88
defaultConfig {
99
minSdkVersion 14
10-
targetSdkVersion 28
10+
targetSdkVersion 30
1111
versionCode 1
1212
versionName "1.0"
1313

1414
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1515

16+
kotlinOptions.freeCompilerArgs += [
17+
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
18+
"-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi",
19+
"-Xuse-experimental=kotlin.time.ExperimentalTime"]
1620
}
1721

1822
buildTypes {
@@ -28,9 +32,10 @@ dependencies {
2832
implementation fileTree(dir: 'libs', include: ['*.jar'])
2933
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3034
implementation "androidx.appcompat:appcompat:$appcompat"
31-
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04'
35+
implementation 'androidx.recyclerview:recyclerview:1.2.0'
36+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
3237

33-
testImplementation 'junit:junit:4.12'
38+
testImplementation 'junit:junit:4.13.1'
3439
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3540
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
3641
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.omega_r.libs.extensions.coroutines
2+
3+
import kotlinx.coroutines.CoroutineScope
4+
import kotlinx.coroutines.channels.ReceiveChannel
5+
import kotlinx.coroutines.channels.ticker
6+
import kotlinx.coroutines.delay
7+
import kotlinx.coroutines.launch
8+
import kotlin.time.Duration
9+
import kotlin.time.DurationUnit
10+
import kotlin.time.toDuration
11+
12+
fun CoroutineScope.launchWithTicker(
13+
ticksCount: Int,
14+
durationUnit: DurationUnit,
15+
onTick: suspend (Int) -> Unit,
16+
onEnd: (suspend () -> Unit)? = null,
17+
initialDelayMillis: Long = 0,
18+
): ReceiveChannel<Unit> {
19+
val tickerChannel = ticker(
20+
ticksCount.toDuration(durationUnit).toLongMilliseconds(),
21+
initialDelayMillis
22+
)
23+
launch {
24+
var currentTick = 0
25+
for (event in tickerChannel) {
26+
if (currentTick >= ticksCount) {
27+
onEnd?.invoke()
28+
tickerChannel.cancel()
29+
break
30+
}
31+
onTick(currentTick)
32+
currentTick++
33+
}
34+
}
35+
return tickerChannel
36+
}
37+
38+
fun CoroutineScope.launchDelayed(delayMillis: Long, action: suspend () -> Unit) {
39+
launch {
40+
delay(delayMillis)
41+
action()
42+
}
43+
}
44+
45+
fun CoroutineScope.launchDelayed(delayDuration: Duration, action: suspend () -> Unit) {
46+
launch {
47+
delay(delayDuration)
48+
action()
49+
}
50+
}

0 commit comments

Comments
 (0)