From b8c58c06953b8c40c64ed2c37a1c82fe44968946 Mon Sep 17 00:00:00 2001 From: CnC-Robert Date: Sat, 3 Jun 2023 20:12:03 +0200 Subject: [PATCH] feat: hide tabs when 1 bundle is used --- .../revanced/manager/compose/MainActivity.kt | 2 +- .../ui/screen/PatchesSelectorScreen.kt | 37 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/compose/MainActivity.kt b/app/src/main/java/app/revanced/manager/compose/MainActivity.kt index 570dfee..996e5eb 100644 --- a/app/src/main/java/app/revanced/manager/compose/MainActivity.kt +++ b/app/src/main/java/app/revanced/manager/compose/MainActivity.kt @@ -82,7 +82,7 @@ class MainActivity : ComponentActivity() { is Destination.PatchesSelector -> PatchesSelectorScreen( onBackClick = { navController.pop() }, - startPatching = { + onPatchClick = { navController.navigate( Destination.Installer( destination.input, diff --git a/app/src/main/java/app/revanced/manager/compose/ui/screen/PatchesSelectorScreen.kt b/app/src/main/java/app/revanced/manager/compose/ui/screen/PatchesSelectorScreen.kt index 613bc0f..a7c2659 100644 --- a/app/src/main/java/app/revanced/manager/compose/ui/screen/PatchesSelectorScreen.kt +++ b/app/src/main/java/app/revanced/manager/compose/ui/screen/PatchesSelectorScreen.kt @@ -34,7 +34,9 @@ const val allowUnsupported = false @OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class) @Composable fun PatchesSelectorScreen( - startPatching: (PatchesSelection) -> Unit, onBackClick: () -> Unit, vm: PatchesSelectorViewModel + onPatchClick: (PatchesSelection) -> Unit, + onBackClick: () -> Unit, + vm: PatchesSelectorViewModel ) { val pagerState = rememberPagerState() val coroutineScope = rememberCoroutineScope() @@ -57,21 +59,23 @@ fun PatchesSelectorScreen( }, floatingActionButton = { ExtendedFloatingActionButton(text = { Text(stringResource(R.string.patch)) }, icon = { Icon(Icons.Default.Build, null) }, - onClick = { startPatching(vm.generateSelection()) }) + onClick = { onPatchClick(vm.generateSelection()) }) }) { paddingValues -> Column(Modifier.fillMaxSize().padding(paddingValues)) { - TabRow( - selectedTabIndex = pagerState.currentPage, - containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(3.0.dp) - ) { - bundles.forEachIndexed { index, bundle -> - Tab( - selected = pagerState.currentPage == index, - onClick = { coroutineScope.launch { pagerState.animateScrollToPage(index) } }, - text = { Text(bundle.name) }, - selectedContentColor = MaterialTheme.colorScheme.primary, - unselectedContentColor = MaterialTheme.colorScheme.onSurfaceVariant - ) + if (bundles.size > 1) { + TabRow( + selectedTabIndex = pagerState.currentPage, + containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(3.0.dp) + ) { + bundles.forEachIndexed { index, bundle -> + Tab( + selected = pagerState.currentPage == index, + onClick = { coroutineScope.launch { pagerState.animateScrollToPage(index) } }, + text = { Text(bundle.name) }, + selectedContentColor = MaterialTheme.colorScheme.primary, + unselectedContentColor = MaterialTheme.colorScheme.onSurfaceVariant + ) + } } } @@ -131,9 +135,8 @@ fun PatchesSelectorScreen( ) } } - - - }) + } + ) } } }