Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
machiav3lli committed Oct 25, 2024
1 parent eef3ea2 commit 0ec94d5
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 272 deletions.
35 changes: 0 additions & 35 deletions src/main/java/com/machiav3lli/backup/sheets/Sheet.kt

This file was deleted.

60 changes: 0 additions & 60 deletions src/main/java/com/machiav3lli/backup/ui/navigation/BottomNavBar.kt

This file was deleted.

177 changes: 0 additions & 177 deletions src/main/java/com/machiav3lli/backup/ui/navigation/Pager.kt
Original file line number Diff line number Diff line change
@@ -1,41 +1,10 @@
package com.machiav3lli.backup.ui.navigation

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.expandHorizontally
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.machiav3lli.backup.preferences.pref_altNavBarItem
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.launch

@Composable
fun SlidePager(
Expand All @@ -59,150 +28,4 @@ fun SlidePager(
HorizontalPager(modifier = modifier, state = pagerState, beyondViewportPageCount = 3) { page ->
pageItems[page].content()
}
}

@Composable
fun PagerNavBar(pageItems: List<NavItem>, pagerState: PagerState) {
val scope = rememberCoroutineScope()

NavigationBar(
modifier = Modifier.padding(horizontal = 8.dp),
containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onSurface,
) {
pageItems.forEachIndexed { index, item ->
val selected by derivedStateOf { pagerState.currentPage == index }

if (pref_altNavBarItem.value)
AltNavBarItem(
modifier = Modifier.weight(1f),
icon = item.icon,
labelId = item.title,
selected = selected,
onClick = {
scope.launch { pagerState.animateScrollToPage(index) }
},
)
else NavBarItem(
modifier = Modifier.weight(if (selected) 2f else 1f),
icon = item.icon,
labelId = item.title,
selected = selected,
onClick = {
scope.launch { pagerState.animateScrollToPage(index) }
},
)
}
}
}

@Composable
fun RowScope.AltNavBarItem(
modifier: Modifier = Modifier,
icon: ImageVector,
labelId: Int,
selected: Boolean,
onClick: () -> Unit = {},
) {
val backgroundColor by animateColorAsState(
targetValue = if (selected) MaterialTheme.colorScheme.surfaceContainer
else Color.Transparent,
label = "backgroundColor",
)
val iconSize by animateDpAsState(
targetValue = if (selected) 32.dp else 24.dp,
label = "iconSize",
)
val iconColor by animateColorAsState(
targetValue = if (selected) MaterialTheme.colorScheme.primary
else MaterialTheme.colorScheme.onBackground,
label = "iconColor",
)

Row(
modifier = Modifier
.clickable { onClick() }
.weight(1f),
horizontalArrangement = Arrangement.Center,
) {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Icon(
imageVector = icon,
contentDescription = stringResource(id = labelId),
modifier = Modifier
.background(backgroundColor, CircleShape)
.padding(8.dp)
.size(iconSize),
tint = iconColor,
)
AnimatedVisibility(
visible = !selected,
enter = fadeIn() + expandVertically(expandFrom = Alignment.Top),
) {
Text(
text = stringResource(id = labelId),
style = MaterialTheme.typography.bodyMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
color = iconColor,
)
}
}
}
}

@Composable
fun RowScope.NavBarItem(
modifier: Modifier = Modifier,
icon: ImageVector,
labelId: Int,
selected: Boolean,
onClick: () -> Unit = {},
) {
val background by animateColorAsState(
targetValue = if (selected) MaterialTheme.colorScheme.surfaceContainer
else Color.Transparent, label = "backgroundColor"
)
val iconColor by animateColorAsState(
targetValue = if (selected) MaterialTheme.colorScheme.primary
else MaterialTheme.colorScheme.onBackground,
label = "iconColor",
)

Row(
modifier = modifier
.padding(vertical = 8.dp)
.clip(MaterialTheme.shapes.extraLarge)
.clickable { onClick() }
.background(
background,
MaterialTheme.shapes.extraLarge
)
.padding(8.dp)
.weight(1f),
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = icon,
contentDescription = stringResource(id = labelId),
modifier = Modifier.size(24.dp),
tint = iconColor,
)
AnimatedVisibility(
visible = selected,
enter = fadeIn() + expandHorizontally(expandFrom = Alignment.Start),
) {
Text(
text = stringResource(id = labelId),
style = MaterialTheme.typography.bodyMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
color = iconColor,
)
}
}
}

0 comments on commit 0ec94d5

Please sign in to comment.