Skip to content

Commit b5c2b7a

Browse files
author
Singularity Indonesia
authored
Merge pull request #29 from SingularityIndonesia/main
Release Debug
2 parents d08bc54 + f656117 commit b5c2b7a

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ allprojects {
4545
}
4646
4747
dependencies {
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

codebase/src/main/java/com/singularity_code/codebase/util/debug/pluto/Pluto.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package com.singularity_code.codebase.util.debug.pluto
22

3+
import android.app.Activity
34
import android.app.Application
5+
import android.content.Intent
6+
import android.net.Uri
7+
import android.provider.Settings
8+
import android.widget.Toast
49
import com.pluto.Pluto
510
import com.pluto.plugins.datastore.pref.PlutoDatastorePreferencesPlugin
611
import com.pluto.plugins.exceptions.PlutoExceptions
@@ -13,6 +18,24 @@ import com.pluto.plugins.preferences.PlutoSharePreferencesPlugin
1318
import timber.log.Timber
1419
import 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+
1639
fun preparePluto(
1740
application: Application,
1841
anrHandler: UncaughtANRHandler? = null,

codebase/src/main/java/com/singularity_code/codebase/util/flow/Auto.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.singularity_code.codebase.util.flow
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5+
import kotlinx.coroutines.CoroutineScope
56
import kotlinx.coroutines.launch
67

78
fun <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+
}

codebase/src/main/java/com/singularity_code/codebase/util/flow/Register.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,26 @@ package com.singularity_code.codebase.util.flow
33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
55
import com.singularity_code.codebase.pattern.Register
6+
import kotlinx.coroutines.CoroutineScope
67
import kotlinx.coroutines.flow.Flow
78
import kotlinx.coroutines.flow.MutableSharedFlow
89
import kotlinx.coroutines.flow.MutableStateFlow
910
import 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

1227
fun <T> ViewModel.register(
1328
default: T

0 commit comments

Comments
 (0)