Skip to content

Commit fd6921d

Browse files
committed
Refactor permission handling and clean up unused code in ActionHandler, fix async issue
1 parent 7596c81 commit fd6921d

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

app/src/main/java/com/rosan/installer/data/installer/model/impl/installer/ActionHandler.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ class ActionHandler(scope: CoroutineScope, installer: InstallerRepo) :
113113

114114
private suspend fun requestNotificationPermission(activity: Activity) {
115115
callbackFlow<Any?> {
116-
val permissions = listOf(Manifest.permission.POST_NOTIFICATIONS)
116+
val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
117+
listOf(Manifest.permission.POST_NOTIFICATIONS)
118+
} else emptyList()
117119
if (XXPermissions.isGranted(activity, permissions)) {
118120
send(null)
119121
} else {
@@ -162,9 +164,11 @@ class ActionHandler(scope: CoroutineScope, installer: InstallerRepo) :
162164
val uris = when (intentAction) {
163165
Intent.ACTION_SEND -> {
164166
val uri =
165-
intent.getParcelableExtra(
166-
Intent.EXTRA_STREAM, Uri::class.java
167-
)
167+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
168+
intent.getParcelableExtra(
169+
Intent.EXTRA_STREAM, Uri::class.java
170+
)
171+
else intent.getParcelableExtra(Intent.EXTRA_STREAM)
168172
if (uri == null) emptyList() else listOf(uri)
169173
}
170174

app/src/main/java/com/rosan/installer/data/settings/util/ConfigUtil.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ class ConfigUtil {
3737
// DataStore
3838
private val appDataStore by inject<AppDataStore>()
3939

40-
/*
41-
val globalAuthorizer: ConfigEntity.Authorizer
40+
/* val globalAuthorizer: ConfigEntity.Authorizer
4241
get() = AuthorizerConverter.revert(sharedPreferences.getString("authorizer", null))
4342
4443
val globalCustomizeAuthorizer: String
4544
get() = sharedPreferences.getString("customize_authorizer", null) ?: ""
4645
4746
val globalInstallMode: ConfigEntity.InstallMode
48-
get() = InstallModeConverter.revert(sharedPreferences.getString("install_mode", null))
49-
*/
47+
get() = InstallModeConverter.revert(sharedPreferences.getString("install_mode", null))*/
5048

5149
suspend fun getGlobalAuthorizer(): ConfigEntity.Authorizer {
5250
val str = appDataStore.getString("authorizer", "").first()

app/src/main/java/com/rosan/installer/ui/activity/InstallerActivity.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.rosan.installer.ui.activity
22

3+
import android.content.Intent
34
import android.os.Bundle
45
import androidx.activity.ComponentActivity
56
import androidx.activity.compose.setContent
@@ -42,11 +43,11 @@ class InstallerActivity : ComponentActivity(), KoinComponent {
4243
super.onSaveInstanceState(outState)
4344
}
4445

45-
/* override fun onNewIntent(intent: Intent?) {
46-
this.intent = intent
47-
super.onNewIntent(intent!!)
48-
restoreInstaller()
49-
}*/
46+
override fun onNewIntent(intent: Intent) {
47+
this.intent = intent
48+
super.onNewIntent(intent)
49+
restoreInstaller()
50+
}
5051

5152
private var job: Job? = null
5253

app/src/main/java/com/rosan/installer/ui/page/installer/dialog/DialogPage.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.koin.core.parameter.parametersOf
1111

1212
@Composable
1313
fun DialogPage(
14-
installer: InstallerRepo, viewModel: DialogViewModel = koinViewModel() {
14+
installer: InstallerRepo, viewModel: DialogViewModel = koinViewModel {
1515
parametersOf(installer)
1616
}
1717
) {

app/src/main/java/com/rosan/installer/ui/page/settings/config/edit/EditPage.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ fun DataDeclareInstallerWidget(viewModel: EditViewModel) {
303303
val globalAuthorizer by produceState<ConfigEntity.Authorizer?>(null) {
304304
value = ConfigUtil.getGlobalAuthorizer()
305305
}
306+
if (globalAuthorizer == null) return // 等待异步结果
306307
authorizer = globalAuthorizer!!
307308
}
308309
val declareInstaller = viewModel.state.data.declareInstaller

app/src/main/java/com/rosan/installer/ui/page/settings/preferred/PreferredViewModel.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.rosan.installer.ui.page.settings.preferred
22

3-
import android.content.Context
43
import androidx.compose.runtime.getValue
54
import androidx.compose.runtime.mutableStateOf
65
import androidx.compose.runtime.setValue
@@ -13,15 +12,12 @@ import com.rosan.installer.data.settings.model.room.entity.converter.InstallMode
1312
import kotlinx.coroutines.flow.collectLatest
1413
import kotlinx.coroutines.launch
1514
import org.koin.core.component.KoinComponent
16-
import org.koin.core.component.inject
1715

1816
class PreferredViewModel(
1917
private val appDataStore: AppDataStore
2018
) : ViewModel(), KoinComponent {
21-
// TODO manage context injection properly, avoid using context directly in ViewModel
22-
private val context by inject<Context>()
23-
2419
// TODO migrate to DataStore instead of SharedPreferences
20+
//private val context by inject<Context>()
2521
// private val appSharedPreferences = context.getSharedPreferences("app", Context.MODE_PRIVATE)
2622

2723
var state by mutableStateOf(PreferredViewState())

0 commit comments

Comments
 (0)