From 4419ef08371ad6edc7de3ccec254ddfed46cf8fe Mon Sep 17 00:00:00 2001 From: Rifat Azad Date: Thu, 2 Jan 2025 17:27:02 +0600 Subject: [PATCH] manager: added animation for nav bar hiding and improved flash screen and action screen --- .../com/rifsxd/ksunext/ui/MainActivity.kt | 9 ++- .../ksunext/ui/screen/ExecuteModuleAction.kt | 18 +++-- .../com/rifsxd/ksunext/ui/screen/Flash.kt | 69 ++++++++----------- 3 files changed, 50 insertions(+), 46 deletions(-) diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt index dd681713..ac82699a 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt @@ -5,6 +5,9 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically import androidx.compose.animation.AnimatedContentTransitionScope import androidx.compose.animation.EnterTransition import androidx.compose.animation.ExitTransition @@ -91,7 +94,11 @@ class MainActivity : ComponentActivity() { Scaffold( bottomBar = { - if (showBottomBar) { + AnimatedVisibility( + visible = showBottomBar, + enter = slideInVertically(initialOffsetY = { it }) + fadeIn(), + exit = slideOutVertically(targetOffsetY = { it }) + fadeOut() + ) { BottomBar(navController) } }, diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/ExecuteModuleAction.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/ExecuteModuleAction.kt index 2b3b4ef0..d6214f0f 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/ExecuteModuleAction.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/ExecuteModuleAction.kt @@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.defaultMinSize import androidx.compose.foundation.layout.safeDrawing import androidx.compose.foundation.layout.only import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Save import androidx.compose.material3.ExperimentalMaterial3Api @@ -99,6 +100,9 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String topBar = { TopBar( isActionRunning = isActionRunning, + onBack = { + navigator.popBackStack() + }, onSave = { if (!isActionRunning) { scope.launch { @@ -122,13 +126,11 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String icon = { Icon(Icons.Filled.Close, contentDescription = null) }, onClick = { navigator.popBackStack() - }, - modifier = Modifier - .navigationBarsPadding() + } ) } }, - contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal), + contentWindowInsets = WindowInsets.safeDrawing, snackbarHost = { SnackbarHost(snackBarHost) } ) { innerPadding -> KeyEventBlocker { @@ -156,9 +158,15 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String @OptIn(ExperimentalMaterial3Api::class) @Composable -private fun TopBar(isActionRunning: Boolean, onSave: () -> Unit = {}) { +private fun TopBar(isActionRunning: Boolean, onBack: () -> Unit = {}, onSave: () -> Unit = {}) { TopAppBar( title = { Text(stringResource(R.string.action)) }, + navigationIcon = { + IconButton( + onClick = onBack, + enabled = !isActionRunning + ) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null) } + }, actions = { IconButton( onClick = onSave, diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Flash.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Flash.kt index 5b935836..7eaef732 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Flash.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Flash.kt @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.safeDrawing import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.Refresh import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Save @@ -133,6 +134,9 @@ fun FlashScreen(navigator: DestinationsNavigator, flashIt: FlashIt) { topBar = { TopBar( flashing, + onBack = { + navigator.popBackStack() + }, onSave = { scope.launch { val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault()) @@ -148,8 +152,24 @@ fun FlashScreen(navigator: DestinationsNavigator, flashIt: FlashIt) { scrollBehavior = scrollBehavior ) }, - snackbarHost = { SnackbarHost(hostState = snackBarHost) }, - contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal) + floatingActionButton = { + if (showFloatAction) { + // Reboot button (bottom left) + ExtendedFloatingActionButton( + onClick = { + scope.launch { + withContext(Dispatchers.IO) { + reboot() + } + } + }, + icon = { Icon(Icons.Filled.Refresh, contentDescription = stringResource(R.string.reboot)) }, + text = { Text(text = stringResource(R.string.reboot)) } + ) + } + }, + contentWindowInsets = WindowInsets.safeDrawing, + snackbarHost = { SnackbarHost(hostState = snackBarHost) } ) { innerPadding -> KeyEventBlocker { it.key == Key.VolumeDown || it.key == Key.VolumeUp @@ -172,44 +192,6 @@ fun FlashScreen(navigator: DestinationsNavigator, flashIt: FlashIt) { lineHeight = MaterialTheme.typography.bodySmall.lineHeight, ) } - - // Floating Action Buttons - Box(modifier = Modifier.fillMaxSize()) { - // Reboot button (bottom left) - if (showFloatAction) { - val reboot = stringResource(id = R.string.reboot) - ExtendedFloatingActionButton( - onClick = { - scope.launch { - withContext(Dispatchers.IO) { - reboot() - } - } - }, - icon = { Icon(Icons.Filled.Refresh, reboot) }, - text = { Text(text = reboot) }, - modifier = Modifier - .align(Alignment.BottomStart) - .padding(16.dp) - .navigationBarsPadding() - ) - } - - if (showFloatAction) { - // Back button (bottom right) - ExtendedFloatingActionButton( - onClick = { - navigator.popBackStack() - }, - text = { Text(text = stringResource(R.string.close)) }, - icon = { Icon(Icons.Filled.Close, contentDescription = null) }, - modifier = Modifier - .align(Alignment.BottomEnd) - .padding(16.dp) - .navigationBarsPadding() - ) - } - } } } @@ -252,6 +234,7 @@ fun flashIt( @Composable private fun TopBar( status: FlashingStatus, + onBack: () -> Unit = {}, onSave: () -> Unit = {}, scrollBehavior: TopAppBarScrollBehavior? = null ) { @@ -267,6 +250,12 @@ private fun TopBar( ) ) }, + navigationIcon = { + IconButton( + onClick = { if (status != FlashingStatus.FLASHING) onBack() }, + enabled = status != FlashingStatus.FLASHING + ) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null) } + }, actions = { IconButton( onClick = { if (status != FlashingStatus.FLASHING) onSave() },