-
-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Select bundle type before adding bundle (#1490)
- Loading branch information
Showing
6 changed files
with
305 additions
and
20 deletions.
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
app/src/main/java/app/revanced/manager/ui/component/AlertDialogExtended.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package app.revanced.manager.ui.component | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.ExperimentalLayoutApi | ||
import androidx.compose.foundation.layout.FlowRow | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.AlertDialogDefaults | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.material3.LocalTextStyle | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.ProvideTextStyle | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.Shape | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
|
||
@OptIn(ExperimentalLayoutApi::class, ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun AlertDialogExtended( | ||
modifier: Modifier = Modifier, | ||
onDismissRequest: () -> Unit, | ||
confirmButton: @Composable () -> Unit, | ||
dismissButton: @Composable (() -> Unit)? = null, | ||
tertiaryButton: @Composable (() -> Unit)? = null, | ||
icon: @Composable (() -> Unit)? = null, | ||
title: @Composable (() -> Unit)? = null, | ||
text: @Composable (() -> Unit)? = null, | ||
shape: Shape = AlertDialogDefaults.shape, | ||
containerColor: Color = AlertDialogDefaults.containerColor, | ||
iconContentColor: Color = AlertDialogDefaults.iconContentColor, | ||
titleContentColor: Color = AlertDialogDefaults.titleContentColor, | ||
textContentColor: Color = AlertDialogDefaults.textContentColor, | ||
tonalElevation: Dp = AlertDialogDefaults.TonalElevation, | ||
textHorizontalPadding: PaddingValues = PaddingValues(horizontal = 24.dp) | ||
) { | ||
AlertDialog(onDismissRequest = onDismissRequest) { | ||
Surface( | ||
modifier = modifier, | ||
shape = shape, | ||
color = containerColor, | ||
tonalElevation = tonalElevation, | ||
) { | ||
Column(modifier = Modifier.padding(vertical = 24.dp)) { | ||
Column( | ||
modifier = Modifier.padding(horizontal = 24.dp) | ||
) { | ||
icon?.let { | ||
ContentStyle(color = iconContentColor) { | ||
Box( | ||
Modifier | ||
.padding(bottom = 16.dp) | ||
.align(Alignment.CenterHorizontally) | ||
) { | ||
icon() | ||
} | ||
} | ||
} | ||
title?.let { | ||
ContentStyle( | ||
color = titleContentColor, | ||
textStyle = MaterialTheme.typography.headlineSmall | ||
) { | ||
Box( | ||
// Align the title to the center when an icon is present. | ||
Modifier | ||
.padding(bottom = 16.dp) | ||
.align( | ||
if (icon == null) { | ||
Alignment.Start | ||
} else { | ||
Alignment.CenterHorizontally | ||
} | ||
) | ||
) { | ||
title() | ||
} | ||
} | ||
} | ||
} | ||
text?.let { | ||
ContentStyle( | ||
color = textContentColor, | ||
textStyle = MaterialTheme.typography.bodyMedium | ||
) { | ||
Box( | ||
Modifier | ||
.weight(weight = 1f, fill = false) | ||
.padding(bottom = 24.dp) | ||
.padding(textHorizontalPadding) | ||
.align(Alignment.Start) | ||
) { | ||
text() | ||
} | ||
} | ||
} | ||
Box( | ||
modifier = Modifier | ||
.padding(horizontal = 24.dp) | ||
) { | ||
ContentStyle( | ||
color = MaterialTheme.colorScheme.primary, | ||
textStyle = MaterialTheme.typography.labelLarge | ||
) { | ||
FlowRow( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.spacedBy( | ||
12.dp, | ||
if (tertiaryButton != null) Alignment.Start else Alignment.End | ||
), | ||
verticalArrangement = Arrangement.spacedBy(8.dp) | ||
) { | ||
tertiaryButton?.let { | ||
it() | ||
Spacer(modifier = Modifier.weight(1f)) | ||
} | ||
dismissButton?.invoke() | ||
confirmButton() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ContentStyle( | ||
color: Color = LocalContentColor.current, | ||
textStyle: TextStyle = LocalTextStyle.current, | ||
content: @Composable () -> Unit | ||
) { | ||
CompositionLocalProvider(LocalContentColor provides color) { | ||
ProvideTextStyle(textStyle) { | ||
content() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
app/src/main/java/app/revanced/manager/ui/component/bundle/ImportBundleTypeSelectorDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package app.revanced.manager.ui.component.bundle | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Divider | ||
import androidx.compose.material3.ListItem | ||
import androidx.compose.material3.RadioButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.semantics.Role | ||
import androidx.compose.ui.unit.dp | ||
import app.revanced.manager.R | ||
import app.revanced.manager.ui.component.AlertDialogExtended | ||
import app.revanced.manager.ui.model.BundleType | ||
|
||
@Composable | ||
fun ImportBundleTypeSelectorDialog( | ||
onDismiss: () -> Unit, | ||
onConfirm: (BundleType) -> Unit, | ||
) { | ||
var bundleType: BundleType by rememberSaveable { mutableStateOf(BundleType.Remote) } | ||
|
||
AlertDialogExtended( | ||
onDismissRequest = onDismiss, | ||
confirmButton = { | ||
TextButton( | ||
onClick = { onConfirm(bundleType) } | ||
) { | ||
Text(stringResource(R.string.select)) | ||
} | ||
}, | ||
dismissButton = { | ||
TextButton(onClick = onDismiss) { | ||
Text(stringResource(R.string.cancel)) | ||
} | ||
}, | ||
title = { | ||
Text(stringResource(R.string.select_bundle_type_dialog_title)) | ||
}, | ||
text = { | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(24.dp) | ||
) { | ||
Text( | ||
modifier = Modifier.padding(horizontal = 24.dp), | ||
text = stringResource(R.string.select_bundle_type_dialog_description) | ||
) | ||
Column { | ||
ListItem( | ||
modifier = Modifier.clickable( | ||
role = Role.RadioButton, | ||
onClick = { bundleType = BundleType.Remote } | ||
), | ||
headlineContent = { Text(stringResource(R.string.remote)) }, | ||
overlineContent = { Text(stringResource(R.string.recommended)) }, | ||
supportingContent = { Text(stringResource(R.string.remote_bundle_description)) }, | ||
leadingContent = { | ||
RadioButton( | ||
selected = bundleType == BundleType.Remote, | ||
onClick = null | ||
) | ||
} | ||
) | ||
Divider(modifier = Modifier.padding(horizontal = 16.dp)) | ||
ListItem( | ||
modifier = Modifier.clickable( | ||
role = Role.RadioButton, | ||
onClick = { bundleType = BundleType.Local } | ||
), | ||
headlineContent = { Text(stringResource(R.string.local)) }, | ||
supportingContent = { Text(stringResource(R.string.local_bundle_description)) }, | ||
overlineContent = { }, // we're using this parameter to force the 3-line ListItem state | ||
leadingContent = { | ||
RadioButton( | ||
selected = bundleType == BundleType.Local, | ||
onClick = null | ||
) | ||
} | ||
) | ||
} | ||
} | ||
}, | ||
textHorizontalPadding = PaddingValues(0.dp) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,4 +79,9 @@ data class BundleInfo( | |
} | ||
} | ||
} | ||
} | ||
|
||
enum class BundleType { | ||
Local, | ||
Remote | ||
} |
Oops, something went wrong.