From 2f8c5f3ae6069e6fe4cdad5ea9d5687ac7e82474 Mon Sep 17 00:00:00 2001 From: Vadik Sirekanyan Date: Fri, 29 Dec 2023 19:11:41 +0400 Subject: [PATCH] Added about dialog --- .../org/sirekanyan/outline/MainActivity.kt | 6 ++ .../java/org/sirekanyan/outline/MainState.kt | 2 + .../org/sirekanyan/outline/ui/AboutDialog.kt | 61 +++++++++++++++++++ .../sirekanyan/outline/ui/DrawerContent.kt | 15 ++--- 4 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/org/sirekanyan/outline/ui/AboutDialog.kt diff --git a/app/src/main/java/org/sirekanyan/outline/MainActivity.kt b/app/src/main/java/org/sirekanyan/outline/MainActivity.kt index e6c65f5..bf1f911 100644 --- a/app/src/main/java/org/sirekanyan/outline/MainActivity.kt +++ b/app/src/main/java/org/sirekanyan/outline/MainActivity.kt @@ -9,6 +9,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.ui.Modifier import androidx.core.view.WindowCompat +import org.sirekanyan.outline.ui.AboutDialogContent import org.sirekanyan.outline.ui.AddServerContent import org.sirekanyan.outline.ui.DeleteKeyContent import org.sirekanyan.outline.ui.DeleteServerContent @@ -53,6 +54,11 @@ class MainActivity : ComponentActivity() { onConfirm = { state.onDeleteServerConfirmed(server) } ) } + is AboutDialog -> { + AboutDialogContent( + onDismiss = { state.dialog = null }, + ) + } } } } diff --git a/app/src/main/java/org/sirekanyan/outline/MainState.kt b/app/src/main/java/org/sirekanyan/outline/MainState.kt index bba61cf..5f62c2e 100644 --- a/app/src/main/java/org/sirekanyan/outline/MainState.kt +++ b/app/src/main/java/org/sirekanyan/outline/MainState.kt @@ -154,3 +154,5 @@ data class RenameKeyDialog(val key: Key) : Dialog() data class DeleteKeyDialog(val key: Key) : Dialog() data class DeleteServerDialog(val server: Server) : Dialog() + +data object AboutDialog : Dialog() diff --git a/app/src/main/java/org/sirekanyan/outline/ui/AboutDialog.kt b/app/src/main/java/org/sirekanyan/outline/ui/AboutDialog.kt new file mode 100644 index 0000000..cba651b --- /dev/null +++ b/app/src/main/java/org/sirekanyan/outline/ui/AboutDialog.kt @@ -0,0 +1,61 @@ +package org.sirekanyan.outline.ui + +import android.content.Intent +import android.net.Uri +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Info +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import org.sirekanyan.outline.BuildConfig +import org.sirekanyan.outline.R +import org.sirekanyan.outline.ui.icons.IconOpenInNew +import org.sirekanyan.outline.ui.icons.IconPlayStore + +@Composable +fun AboutDialogContent(onDismiss: () -> Unit) { + AlertDialog( + icon = { Icon(Icons.Default.Info, null) }, + title = { Text(stringResource(R.string.outln_app_name) + " " + BuildConfig.VERSION_NAME) }, + text = { + Text( + "An application for managing Outline VPN servers. You can find more information " + + "on https://getoutline.org.", + ) + }, + onDismissRequest = onDismiss, + confirmButton = { + val context = LocalContext.current + val playUri = "https://play.google.com/store/apps/details?id=${context.packageName}" + TextButton( + onClick = { + context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(playUri))) + onDismiss() + }, + modifier = Modifier.fillMaxWidth().heightIn(min = 56.dp), + border = BorderStroke(1.dp, MaterialTheme.colorScheme.primary), + ) { + Icon(IconPlayStore, null, Modifier.padding(horizontal = 4.dp)) + Text( + text = "Rate on Play Store", + modifier = Modifier.weight(1f).padding(horizontal = 8.dp), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + Icon(IconOpenInNew, null, Modifier.padding(horizontal = 8.dp)) + } + }, + ) +} diff --git a/app/src/main/java/org/sirekanyan/outline/ui/DrawerContent.kt b/app/src/main/java/org/sirekanyan/outline/ui/DrawerContent.kt index e6aa68b..4f08c37 100644 --- a/app/src/main/java/org/sirekanyan/outline/ui/DrawerContent.kt +++ b/app/src/main/java/org/sirekanyan/outline/ui/DrawerContent.kt @@ -1,8 +1,5 @@ package org.sirekanyan.outline.ui -import android.content.Intent -import android.content.Intent.ACTION_VIEW -import android.net.Uri import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Spacer @@ -16,6 +13,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Done +import androidx.compose.material.icons.filled.Info import androidx.compose.material.icons.filled.Search import androidx.compose.material.icons.filled.Warning import androidx.compose.material3.Divider @@ -37,6 +35,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch +import org.sirekanyan.outline.AboutDialog import org.sirekanyan.outline.AddServerDialog import org.sirekanyan.outline.HelloPage import org.sirekanyan.outline.MainState @@ -47,8 +46,6 @@ import org.sirekanyan.outline.ext.rememberFlowAsState import org.sirekanyan.outline.isDebugBuild import org.sirekanyan.outline.isPlayFlavor import org.sirekanyan.outline.text.formatTraffic -import org.sirekanyan.outline.ui.icons.IconOpenInNew -import org.sirekanyan.outline.ui.icons.IconPlayStore @Composable fun DrawerContent(state: MainState) { @@ -133,12 +130,10 @@ private fun DrawerSheetContent(state: MainState, insets: PaddingValues) { }, ) } - val playUri = "https://play.google.com/store/apps/details?id=${context.packageName}" DrawerItem( - icon = IconPlayStore, - label = "Rate on Play Store", - badge = { Icon(IconOpenInNew, null) }, - onClick = { context.startActivity(Intent(ACTION_VIEW, Uri.parse(playUri))) }, + icon = Icons.Default.Info, + label = "About", + onClick = { state.dialog = AboutDialog }, ) } }