Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
Expand All @@ -23,8 +21,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -36,6 +32,7 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -63,7 +60,9 @@ private enum class IdentityConfirmation(val title: String, val message: String,
}

@Composable
internal fun IdentityPage(
internal fun IdentitySettingsContent(
modifier: Modifier,
horizontalPadding: Dp,
previewMode: Boolean,
nodeState: ReticulumNodeState,
rrcState: ReticulumConnectionState,
Expand All @@ -85,11 +84,6 @@ internal fun IdentityPage(
networks: List<ChatNetwork>,
onGlobalNicknameChange: (String) -> Unit,
onNetworkNicknameChange: (String, String?) -> Unit,
compact: Boolean = false,
showBackButton: Boolean = false,
onBack: () -> Unit = {},
showNavigationButton: Boolean = false,
onOpenNavigation: () -> Unit = {},
onDismissKeyboard: () -> Unit = {},
onManageNetwork: () -> Unit,
) {
Expand All @@ -102,26 +96,9 @@ internal fun IdentityPage(
val identityMutable = identitySupported && !identityBusy && nodeState == ReticulumNodeState.Stopped
val identityActionHeight = 56.dp

Column(Modifier.fillMaxSize().background(Canvas)) {
Row(
modifier = Modifier.fillMaxWidth().height(68.dp).background(Paper)
.padding(horizontal = if (compact) 8.dp else 20.dp),
verticalAlignment = Alignment.CenterVertically,
) {
if (showBackButton) {
IconButton(onClick = { onDismissKeyboard(); onBack() }) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back to settings", tint = Accent)
}
Spacer(Modifier.width(6.dp))
} else if (compact || showNavigationButton) {
NavigationToggle(onClick = { onDismissKeyboard(); onOpenNavigation() })
Spacer(Modifier.width(6.dp))
}
Text("Identity", color = Ink, fontSize = 17.sp, fontWeight = FontWeight.SemiBold)
}
Column(
modifier = Modifier.fillMaxWidth().weight(1f).verticalScroll(rememberScrollState())
.preferredFrameRate(120f).padding(horizontal = 24.dp, vertical = 26.dp),
Column(
modifier = modifier.fillMaxWidth().verticalScroll(rememberScrollState())
.preferredFrameRate(120f).padding(horizontal = horizontalPadding, vertical = 26.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
Text("DEVICE IDENTITY", color = Muted, fontSize = 10.sp, letterSpacing = 1.3.sp, fontWeight = FontWeight.Bold)
Expand Down Expand Up @@ -347,7 +324,6 @@ internal fun IdentityPage(
Button(onClick = { onDismissKeyboard(); onManageNetwork() }, colors = ButtonDefaults.buttonColors(containerColor = Accent)) {
Text("Network settings")
}
}
}
identityConfirmation?.let { action ->
AlertDialog(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package com.sidpatchy.Starling

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.Chat
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.DrawerState
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.NavigationRail
import androidx.compose.material3.NavigationRailItem
import androidx.compose.material3.NavigationRailItemDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

internal enum class MainTab(val label: String, val icon: ImageVector) {
CHAT("Chat", Icons.AutoMirrored.Filled.Chat),
SETTINGS("Settings", Icons.Filled.Settings);

fun showsBottomNavigation(chatDrawerOpen: Boolean): Boolean = when (this) {
CHAT -> chatDrawerOpen
SETTINGS -> true
}
}

internal enum class MainPage(val parent: MainPage? = null, val tab: MainTab = parent?.tab ?: MainTab.CHAT) {
CHAT,
NEARBY(CHAT),
CONTACT_REQUESTS(CHAT),
SETTINGS(CHAT, MainTab.SETTINGS),
}

@Composable
internal fun WideNavigationLayout(
selectedTab: MainTab,
onTabSelected: (MainTab) -> Unit,
showRail: Boolean,
content: @Composable RowScope.() -> Unit,
) {
Row(Modifier.fillMaxSize()) {
if (showRail) {
NavigationRail(
modifier = Modifier.width(80.dp).fillMaxHeight(),
containerColor = Paper,
windowInsets = WindowInsets(0, 0, 0, 0),
) {
MainTab.entries.forEach { tab ->
val selected = tab == selectedTab
NavigationRailItem(
selected = selected,
onClick = { onTabSelected(tab) },
icon = { Icon(tab.icon, contentDescription = null) },
label = { MainTabLabel(tab, selected) },
alwaysShowLabel = true,
colors = NavigationRailItemDefaults.colors(
selectedIconColor = Accent,
selectedTextColor = Ink,
indicatorColor = PaleAccent,
unselectedIconColor = Muted,
unselectedTextColor = Ink,
),
)
}
}
VerticalDivider(color = Line)
}
Row(Modifier.weight(1f).fillMaxHeight(), content = content)
}
}

@Composable
internal fun CompactNavigationLayout(
selectedTab: MainTab,
onTabSelected: (MainTab) -> Unit,
showBottomBar: Boolean,
content: @Composable () -> Unit,
) {
val reducedMotion = LocalReducedMotion.current
Column(Modifier.fillMaxSize()) {
Box(Modifier.weight(1f).fillMaxWidth()) { content() }
AnimatedVisibility(
visible = showBottomBar,
enter = if (reducedMotion) EnterTransition.None else expandVertically(expandFrom = Alignment.Bottom) + fadeIn(),
exit = if (reducedMotion) ExitTransition.None else shrinkVertically(shrinkTowards = Alignment.Bottom) + fadeOut(),
) {
BottomNavigationBar(selectedTab, onTabSelected)
}
}
}

@Composable
internal fun CompactChatNavigationLayout(
drawerState: DrawerState,
gesturesEnabled: Boolean,
onTabSelected: (MainTab) -> Unit,
drawerContent: @Composable () -> Unit,
content: @Composable () -> Unit,
) {
CompactNavigationLayout(
selectedTab = MainTab.CHAT,
onTabSelected = onTabSelected,
showBottomBar = MainTab.CHAT.showsBottomNavigation(drawerState.targetValue == DrawerValue.Open),
) {
// The chat drawer and its scrim cover the content, not the app's navigation.
ModalNavigationDrawer(
modifier = Modifier.fillMaxSize(),
drawerState = drawerState,
gesturesEnabled = gesturesEnabled,
drawerContent = drawerContent,
content = content,
)
}
}

@Composable
private fun BottomNavigationBar(selectedTab: MainTab, onTabSelected: (MainTab) -> Unit) {
Column {
HorizontalDivider(color = Line)
NavigationBar(containerColor = Paper, tonalElevation = 0.dp, windowInsets = WindowInsets(0, 0, 0, 0)) {
MainTab.entries.forEach { tab ->
val selected = tab == selectedTab
NavigationBarItem(
selected = selected,
onClick = { onTabSelected(tab) },
icon = { Icon(tab.icon, contentDescription = null) },
label = { MainTabLabel(tab, selected) },
alwaysShowLabel = true,
colors = NavigationBarItemDefaults.colors(
selectedIconColor = Accent,
selectedTextColor = Ink,
indicatorColor = PaleAccent,
unselectedIconColor = Muted,
unselectedTextColor = Ink,
),
)
}
}
}
}

@Composable
private fun MainTabLabel(tab: MainTab, selected: Boolean) {
Text(tab.label, fontWeight = if (selected) FontWeight.SemiBold else FontWeight.Medium)
}
Loading
Loading