File tree Expand file tree Collapse file tree
src/main/java/ru/livetyping/extensionpack Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ android {
3333
3434dependencies {
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'
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ afterEvaluate {
4646
4747dependencies {
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'
Original file line number Diff line number Diff line change 11package 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() }
You can’t perform that action at this time.
0 commit comments