Skip to content

Commit c78331a

Browse files
author
DenisPopkov
committed
Merge branch 'develop'
2 parents a557376 + cf36a3c commit c78331a

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ android {
3333

3434
dependencies {
3535

36-
implementation 'androidx.core:core-ktx:1.7.0'
36+
implementation 'androidx.core:core-ktx:1.8.0'
3737
implementation 'androidx.appcompat:appcompat:1.5.0'
3838
implementation 'com.google.android.material:material:1.6.1'
3939
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

extensionpack/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ afterEvaluate {
4646

4747
dependencies {
4848

49-
implementation 'androidx.core:core-ktx:1.7.0'
49+
implementation 'androidx.core:core-ktx:1.8.0'
5050
implementation 'androidx.appcompat:appcompat:1.5.0'
5151
implementation 'com.google.android.material:material:1.6.1'
5252
testImplementation 'junit:junit:4.13.2'
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
package ru.livetyping.extensionpack
22

3-
import android.content.Context
4-
import android.widget.Toast
3+
import kotlinx.coroutines.*
54

6-
object AndroidExtensionPack {
5+
fun CoroutineScope.launchUI(callback: suspend () -> Unit) = launch(Dispatchers.Main) { callback() }
76

8-
fun makeToast(context: Context) {
9-
Toast.makeText(context, "Greeting", Toast.LENGTH_SHORT).show()
10-
}
11-
}
7+
fun CoroutineScope.launchUI(handler: CoroutineExceptionHandler, callback: suspend () -> Unit) =
8+
launch(Dispatchers.Main + handler) { callback() }
9+
10+
fun CoroutineScope.launchIO(callback: suspend () -> Unit) = launch(Dispatchers.IO) { callback() }
11+
12+
fun CoroutineScope.launchIO(handler: CoroutineExceptionHandler, callback: suspend () -> Unit) =
13+
launch(Dispatchers.IO + handler) { callback() }
14+
15+
suspend fun <T> withIO(callback: suspend () -> T) = withContext(Dispatchers.IO) { callback() }
16+
17+
suspend fun <T> withUI(callback: suspend () -> T) = withContext(Dispatchers.Main) { callback() }
18+
19+
fun <T> CoroutineScope.asyncIO(callback: suspend () -> T) = async(Dispatchers.IO) { callback() }

0 commit comments

Comments
 (0)