File tree Expand file tree Collapse file tree
codebase/src/main/java/com/singularity_code/codebase/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,8 +45,8 @@ allprojects {
4545}
4646
4747dependencies {
48- releaseImplementation 'com.github.SingularityIndonesia:AndroidCodebase:2.0.0-alpha1-20230906 '
49- debugImplementation 'com.github.SingularityIndonesia:AndroidCodebase:2.0.0-alpha1-20230906 -debug'
48+ releaseImplementation 'com.github.SingularityIndonesia:AndroidCodebase:2.0.0-alpha1-20230908 '
49+ debugImplementation 'com.github.SingularityIndonesia:AndroidCodebase:2.0.0-alpha1-20230908 -debug'
5050}
5151```
5252
Original file line number Diff line number Diff line change 11package com.singularity_code.codebase.util.debug.pluto
22
3+ import android.app.Activity
34import android.app.Application
5+ import android.content.Intent
6+ import android.net.Uri
7+ import android.provider.Settings
8+ import android.widget.Toast
49import com.pluto.Pluto
510import com.pluto.plugins.datastore.pref.PlutoDatastorePreferencesPlugin
611import com.pluto.plugins.exceptions.PlutoExceptions
@@ -13,6 +18,24 @@ import com.pluto.plugins.preferences.PlutoSharePreferencesPlugin
1318import timber.log.Timber
1419import java.lang.Thread.UncaughtExceptionHandler
1520
21+ context(Activity )
22+ fun preparePluto () {
23+ if (! Settings .canDrawOverlays(this @Activity)) {
24+ val intent = Intent (
25+ Settings .ACTION_MANAGE_OVERLAY_PERMISSION ,
26+ Uri .parse(" package:$packageName " )
27+ )
28+
29+ startActivityForResult(intent, 0 )
30+
31+ Toast .makeText(
32+ this @Activity,
33+ " Allow Pluto to display over window." ,
34+ Toast .LENGTH_SHORT
35+ ).show()
36+ }
37+ }
38+
1639fun preparePluto (
1740 application : Application ,
1841 anrHandler : UncaughtANRHandler ? = null,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package com.singularity_code.codebase.util.flow
22
33import androidx.lifecycle.ViewModel
44import androidx.lifecycle.viewModelScope
5+ import kotlinx.coroutines.CoroutineScope
56import kotlinx.coroutines.launch
67
78fun <R > ViewModel.auto (block : () -> R ): Lazy <R > = lazy { block.invoke() }
@@ -12,3 +13,10 @@ fun <T> T.automate(block: suspend T.() -> Unit): T = this.also {
1213 block.invoke(it)
1314 }
1415}
16+
17+ context (CoroutineScope )
18+ fun <T > T.automate (block : suspend T .() -> Unit ): T = this .also {
19+ launch {
20+ block.invoke(it)
21+ }
22+ }
Original file line number Diff line number Diff line change @@ -3,11 +3,26 @@ package com.singularity_code.codebase.util.flow
33import androidx.lifecycle.ViewModel
44import androidx.lifecycle.viewModelScope
55import com.singularity_code.codebase.pattern.Register
6+ import kotlinx.coroutines.CoroutineScope
67import kotlinx.coroutines.flow.Flow
78import kotlinx.coroutines.flow.MutableSharedFlow
89import kotlinx.coroutines.flow.MutableStateFlow
910import kotlinx.coroutines.launch
1011
12+ context (CoroutineScope )
13+ fun <T > createRegister (default : T ) = object : Register <T > {
14+ private val _data = MutableStateFlow <T >(default)
15+ override val data: Flow <T >
16+ get() = _data
17+
18+ override fun set (
19+ data : T
20+ ) {
21+ launch {
22+ _data .emit(data)
23+ }
24+ }
25+ }
1126
1227fun <T > ViewModel.register (
1328 default : T
You can’t perform that action at this time.
0 commit comments