compose: Extract force restart dialog logic into separate file
We also require users to force restart on applying proxy. This logic can be reused there when migrated to compose. Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2026 Aurora OSS
|
||||||
|
* SPDX-FileCopyrightText: 2026 The Calyx Institute
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.aurora.store.compose.ui.commons
|
||||||
|
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.tooling.preview.PreviewWrapper
|
||||||
|
import com.aurora.store.R
|
||||||
|
import com.aurora.store.compose.preview.ThemePreviewProvider
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dialog for prompting users to restart Aurora Store
|
||||||
|
* @param onConfirm Callback on confirmation
|
||||||
|
* @param onDismiss Callback on dismissal
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun ForceRestartDialog(onConfirm: () -> Unit = {}, onDismiss: () -> Unit = {}) {
|
||||||
|
AlertDialog(
|
||||||
|
title = { Text(text = stringResource(R.string.force_restart_title)) },
|
||||||
|
text = { Text(text = stringResource(R.string.force_restart_summary)) },
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onConfirm) {
|
||||||
|
Text(text = stringResource(R.string.action_restart))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreviewWrapper(ThemePreviewProvider::class)
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
private fun ForceRestartDialogPreview() {
|
||||||
|
ForceRestartDialog()
|
||||||
|
}
|
||||||
@@ -20,11 +20,8 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.AlertDialog
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.TextButton
|
|
||||||
import androidx.compose.material3.adaptive.WindowAdaptiveInfo
|
import androidx.compose.material3.adaptive.WindowAdaptiveInfo
|
||||||
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
|
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
|
||||||
import androidx.compose.material3.adaptive.layout.AdaptStrategy
|
import androidx.compose.material3.adaptive.layout.AdaptStrategy
|
||||||
@@ -73,6 +70,7 @@ import com.aurora.store.compose.composable.app.LargeAppListItem
|
|||||||
import com.aurora.store.compose.navigation.Screen
|
import com.aurora.store.compose.navigation.Screen
|
||||||
import com.aurora.store.compose.preview.AppPreviewProvider
|
import com.aurora.store.compose.preview.AppPreviewProvider
|
||||||
import com.aurora.store.compose.preview.ThemePreviewProvider
|
import com.aurora.store.compose.preview.ThemePreviewProvider
|
||||||
|
import com.aurora.store.compose.ui.commons.ForceRestartDialog
|
||||||
import com.aurora.store.compose.ui.commons.PermissionRationaleScreen
|
import com.aurora.store.compose.ui.commons.PermissionRationaleScreen
|
||||||
import com.aurora.store.compose.ui.details.composable.Actions
|
import com.aurora.store.compose.ui.details.composable.Actions
|
||||||
import com.aurora.store.compose.ui.details.composable.Changelog
|
import com.aurora.store.compose.ui.details.composable.Changelog
|
||||||
@@ -171,7 +169,12 @@ fun AppDetailsScreen(
|
|||||||
onTestingSubscriptionChange = { subscribe ->
|
onTestingSubscriptionChange = { subscribe ->
|
||||||
viewModel.updateTestingProgramStatus(packageName, subscribe)
|
viewModel.updateTestingProgramStatus(packageName, subscribe)
|
||||||
},
|
},
|
||||||
forceSinglePane = forceSinglePane
|
forceSinglePane = forceSinglePane,
|
||||||
|
onForceRestart = {
|
||||||
|
val intent = Intent(context, ComposeActivity::class.java)
|
||||||
|
.putExtra("packageName", packageName)
|
||||||
|
ProcessPhoenix.triggerRebirth(context, intent)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,7 +238,8 @@ private fun ScreenContentApp(
|
|||||||
onOpen: () -> Unit = {},
|
onOpen: () -> Unit = {},
|
||||||
onTestingSubscriptionChange: (subscribe: Boolean) -> Unit = {},
|
onTestingSubscriptionChange: (subscribe: Boolean) -> Unit = {},
|
||||||
windowAdaptiveInfo: WindowAdaptiveInfo = currentWindowAdaptiveInfo(),
|
windowAdaptiveInfo: WindowAdaptiveInfo = currentWindowAdaptiveInfo(),
|
||||||
forceSinglePane: Boolean = false
|
forceSinglePane: Boolean = false,
|
||||||
|
onForceRestart: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
var scaffoldDirective = calculatePaneScaffoldDirective(windowAdaptiveInfo)
|
var scaffoldDirective = calculatePaneScaffoldDirective(windowAdaptiveInfo)
|
||||||
@@ -255,6 +259,10 @@ private fun ScreenContentApp(
|
|||||||
.scaffoldValue[SupportingPaneScaffoldRole.Supporting] == PaneAdaptedValue.Hidden
|
.scaffoldValue[SupportingPaneScaffoldRole.Supporting] == PaneAdaptedValue.Hidden
|
||||||
var showRestartDialog by remember { mutableStateOf(false) }
|
var showRestartDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (showRestartDialog) {
|
||||||
|
ForceRestartDialog(onConfirm = onForceRestart)
|
||||||
|
}
|
||||||
|
|
||||||
fun onNavigateBack() {
|
fun onNavigateBack() {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
scaffoldNavigator.navigateBack()
|
scaffoldNavigator.navigateBack()
|
||||||
@@ -583,25 +591,6 @@ private fun ScreenContentApp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (showRestartDialog) {
|
|
||||||
AlertDialog(
|
|
||||||
onDismissRequest = {},
|
|
||||||
title = { Text(text = stringResource(R.string.force_restart_title)) },
|
|
||||||
text = { Text(text = stringResource(R.string.force_restart_summary)) },
|
|
||||||
confirmButton = {
|
|
||||||
TextButton(
|
|
||||||
onClick = {
|
|
||||||
val intent = Intent(context, ComposeActivity::class.java)
|
|
||||||
.putExtra("packageName", app.packageName)
|
|
||||||
ProcessPhoenix.triggerRebirth(context, intent)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(R.string.action_restart))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreviewWrapper(ThemePreviewProvider::class)
|
@PreviewWrapper(ThemePreviewProvider::class)
|
||||||
|
|||||||
Reference in New Issue
Block a user