android/ui: add back fast user switching status and clean up avatar scaling

Updates #cleanup

Signed-off-by: Percy Wegmann <percy@tailscale.com>
pull/255/head
Percy Wegmann 8 months ago committed by Percy Wegmann
parent e59112a8fb
commit 5599f2ddeb

@ -44,7 +44,7 @@ inline fun <T> LazyListScope.itemsWithDividers(
key = if (key != null) { index: Int -> key(items[index]) } else null, key = if (key != null) { index: Int -> key(items[index]) } else null,
contentType = { index -> contentType(items[index]) }) { contentType = { index -> contentType(items[index]) }) {
if (forceLeading && it == 0 || if (forceLeading && it == 0 ||
forceTrailing && it == items.size - 1 || forceTrailing && it == items.size ||
it > 0 && it < items.size) { it > 0 && it < items.size) {
Lists.ItemDivider() Lists.ItemDivider()
} }

@ -36,7 +36,8 @@ fun Avatar(profile: IpnLocal.LoginProfile?, size: Int = 50) {
modifier = Modifier.size((size * .8f).dp)) modifier = Modifier.size((size * .8f).dp))
profile?.UserProfile?.ProfilePicURL?.let { url -> profile?.UserProfile?.ProfilePicURL?.let { url ->
AsyncImage(model = url, contentDescription = null) AsyncImage(
model = url, modifier = Modifier.size((size * 1.2f).dp), contentDescription = null)
} }
} }
} }

@ -5,10 +5,9 @@ package com.tailscale.ipn.ui.view
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -19,8 +18,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.tailscale.ipn.R import com.tailscale.ipn.R
import com.tailscale.ipn.ui.util.Lists
import com.tailscale.ipn.ui.util.itemsWithDividers
import com.tailscale.ipn.ui.util.set import com.tailscale.ipn.ui.util.set
import com.tailscale.ipn.ui.util.settingsRowModifier
import com.tailscale.ipn.ui.viewModel.UserSwitcherViewModel import com.tailscale.ipn.ui.viewModel.UserSwitcherViewModel
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@ -39,17 +39,16 @@ fun UserSwitcherView(nav: BackNavigation, viewModel: UserSwitcherViewModel = vie
// Show the error overlay if need be // Show the error overlay if need be
showDialog?.let { ErrorDialog(type = it, action = { viewModel.showDialog.set(null) }) } showDialog?.let { ErrorDialog(type = it, action = { viewModel.showDialog.set(null) }) }
Column(modifier = settingsRowModifier()) { // When switch is invoked, this stores the ID of the user we're trying to switch to
// so we can decorate it with a spinner. The actual logged in user will not change
// until
// we get our first netmap update back with the new userId for SelfNode.
// (jonathan) TODO: This user switch is not immediate. We may need to represent the
// "switching users" state globally (if ipnState is insufficient)
val nextUserId = remember { mutableStateOf<String?>(null) }
// When switch is invoked, this stores the ID of the user we're trying to switch to LazyColumn {
// so we can decorate it with a spinner. The actual logged in user will not change itemsWithDividers(users ?: emptyList()) { user ->
// until
// we get our first netmap update back with the new userId for SelfNode.
// (jonathan) TODO: This user switch is not immediate. We may need to represent the
// "switching users" state globally (if ipnState is insufficient)
val nextUserId = remember { mutableStateOf<String?>(null) }
users?.forEach { user ->
if (user.ID == currentUser?.ID) { if (user.ID == currentUser?.ID) {
UserView(profile = user, actionState = UserActionState.CURRENT) UserView(profile = user, actionState = UserActionState.CURRENT)
} else { } else {
@ -70,14 +69,15 @@ fun UserSwitcherView(nav: BackNavigation, viewModel: UserSwitcherViewModel = vie
}) })
} }
} }
SettingRow(viewModel.addProfileSetting)
}
Spacer(modifier = Modifier.height(8.dp)) item {
Lists.SectionDivider()
Column(modifier = settingsRowModifier()) { SettingRow(viewModel.addProfileSetting)
SettingRow(viewModel.loginSetting) Lists.ItemDivider()
SettingRow(viewModel.logoutSetting) SettingRow(viewModel.loginSetting)
Lists.ItemDivider()
SettingRow(viewModel.logoutSetting)
}
} }
} }
} }

@ -6,16 +6,11 @@ package com.tailscale.ipn.ui.view
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.material3.ListItem import androidx.compose.material3.ListItem
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.tailscale.ipn.R import com.tailscale.ipn.R
import com.tailscale.ipn.ui.model.IpnLocal import com.tailscale.ipn.ui.model.IpnLocal
@ -50,7 +45,14 @@ fun UserView(
supportingContent = { supportingContent = {
Text(text = profile.Name, style = MaterialTheme.typography.bodyMedium) Text(text = profile.Name, style = MaterialTheme.typography.bodyMedium)
}, },
) trailingContent = {
when (actionState) {
UserActionState.CURRENT -> CheckedIndicator()
UserActionState.SWITCHING -> SimpleActivityIndicator(size = 26)
UserActionState.NAV -> Unit
UserActionState.NONE -> Unit
}
})
} }
?: run { ?: run {
ListItem( ListItem(

Loading…
Cancel
Save