mirror of
https://github.com/owenlejeune/TVTime.git
synced 2025-11-18 01:30:54 -05:00
update account menu
This commit is contained in:
@@ -5,10 +5,8 @@ import androidx.compose.foundation.layout.*
|
|||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.AccountCircle
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -91,6 +89,11 @@ fun AccountTab(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
when(session.isAuthorized) {
|
||||||
|
true -> { AuthorizedSessionIcon() }
|
||||||
|
false -> { GuestSessionIcon() }
|
||||||
|
}
|
||||||
|
|
||||||
val pagerState = rememberPagerState()
|
val pagerState = rememberPagerState()
|
||||||
ScrollableTabs(tabs = tabs, pagerState = pagerState)
|
ScrollableTabs(tabs = tabs, pagerState = pagerState)
|
||||||
AccountTabs(
|
AccountTabs(
|
||||||
@@ -251,15 +254,18 @@ private fun AccountDropdownMenu(
|
|||||||
session: SessionManager.Session?,
|
session: SessionManager.Session?,
|
||||||
lastSelectedOption: MutableState<String>
|
lastSelectedOption: MutableState<String>
|
||||||
) {
|
) {
|
||||||
CustomTopAppBarDropdownMenu(
|
val expanded = remember { mutableStateOf(false) }
|
||||||
icon = {
|
|
||||||
when(session?.isAuthorized) {
|
IconButton(
|
||||||
true -> { AuthorizedSessionIcon() }
|
onClick = { expanded.value = true }
|
||||||
false -> { GuestSessionIcon() }
|
) {
|
||||||
null -> { NoSessionAccountIcon() }
|
Icon(imageVector = Icons.Filled.MoreVert, contentDescription = null)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
) { expanded ->
|
DropdownMenu(
|
||||||
|
expanded = expanded.value,
|
||||||
|
onDismissRequest = { expanded.value = false }
|
||||||
|
) {
|
||||||
when(session?.isAuthorized) {
|
when(session?.isAuthorized) {
|
||||||
true -> { AuthorizedSessionMenuItems(expanded = expanded, lastSelectedOption = lastSelectedOption) }
|
true -> { AuthorizedSessionMenuItems(expanded = expanded, lastSelectedOption = lastSelectedOption) }
|
||||||
false -> { GuestSessionMenuItems(expanded = expanded, lastSelectedOption = lastSelectedOption) }
|
false -> { GuestSessionMenuItems(expanded = expanded, lastSelectedOption = lastSelectedOption) }
|
||||||
@@ -269,45 +275,16 @@ private fun AccountDropdownMenu(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun NoSessionMenuItems(
|
private fun AuthorizedSessionMenuItems(
|
||||||
expanded: MutableState<Boolean>,
|
expanded: MutableState<Boolean>,
|
||||||
lastSelectedOption: MutableState<String>
|
lastSelectedOption: MutableState<String>
|
||||||
) {
|
) {
|
||||||
val showSignInDialog = remember { mutableStateOf(false) }
|
DropdownMenuItem(
|
||||||
CustomMenuItem(
|
text = { Text(text = stringResource(id = R.string.action_sign_out)) },
|
||||||
text = stringResource(id = R.string.action_sign_in),
|
|
||||||
onClick = {
|
onClick = {
|
||||||
showSignInDialog.value = true
|
signOut(lastSelectedOption)
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
CustomMenuDivider()
|
|
||||||
|
|
||||||
if (showSignInDialog.value) {
|
|
||||||
SignInDialog(showDialog = showSignInDialog) { success ->
|
|
||||||
if (success) {
|
|
||||||
lastSelectedOption.value = NO_SESSION_SIGN_IN
|
|
||||||
expanded.value = false
|
expanded.value = false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomMenuItem(
|
|
||||||
text = stringResource(R.string.action_sign_in_as_guest),
|
|
||||||
onClick = {
|
|
||||||
createGuestSession(lastSelectedOption)
|
|
||||||
expanded.value = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun NoSessionAccountIcon() {
|
|
||||||
Icon(
|
|
||||||
modifier = Modifier.size(45.dp),
|
|
||||||
imageVector = Icons.Filled.AccountCircle,
|
|
||||||
contentDescription = stringResource(R.string.account_menu_content_description),
|
|
||||||
tint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,10 +294,6 @@ private fun GuestSessionMenuItems(
|
|||||||
lastSelectedOption: MutableState<String>
|
lastSelectedOption: MutableState<String>
|
||||||
) {
|
) {
|
||||||
val showSignInDialog = remember { mutableStateOf(false) }
|
val showSignInDialog = remember { mutableStateOf(false) }
|
||||||
CustomMenuItem(
|
|
||||||
text = stringResource(id = R.string.action_sign_in),
|
|
||||||
onClick = { showSignInDialog.value = true }
|
|
||||||
)
|
|
||||||
|
|
||||||
if (showSignInDialog.value) {
|
if (showSignInDialog.value) {
|
||||||
SignInDialog(showDialog = showSignInDialog) { success ->
|
SignInDialog(showDialog = showSignInDialog) { success ->
|
||||||
@@ -331,10 +304,13 @@ private fun GuestSessionMenuItems(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomMenuDivider()
|
DropdownMenuItem(
|
||||||
|
text = { Text(text = stringResource(id = R.string.action_sign_in)) },
|
||||||
|
onClick = { showSignInDialog.value = true }
|
||||||
|
)
|
||||||
|
|
||||||
CustomMenuItem(
|
DropdownMenuItem(
|
||||||
text = stringResource(id = R.string.action_sign_out),
|
text = { Text(text = stringResource(id = R.string.action_sign_out)) },
|
||||||
onClick = {
|
onClick = {
|
||||||
signOut(lastSelectedOption)
|
signOut(lastSelectedOption)
|
||||||
expanded.value = false
|
expanded.value = false
|
||||||
@@ -342,24 +318,40 @@ private fun GuestSessionMenuItems(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun NoSessionMenuItems(
|
||||||
|
expanded: MutableState<Boolean>,
|
||||||
|
lastSelectedOption: MutableState<String>
|
||||||
|
) {
|
||||||
|
val showSignInDialog = remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (showSignInDialog.value) {
|
||||||
|
SignInDialog(showDialog = showSignInDialog) { success ->
|
||||||
|
if (success) {
|
||||||
|
lastSelectedOption.value = NO_SESSION_SIGN_IN
|
||||||
|
expanded.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(text = stringResource(id = R.string.action_sign_in)) },
|
||||||
|
onClick = { showSignInDialog.value = true }
|
||||||
|
)
|
||||||
|
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(text = stringResource(id = R.string.action_sign_in_as_guest)) },
|
||||||
|
onClick = {
|
||||||
|
createGuestSession(lastSelectedOption)
|
||||||
|
expanded.value = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun GuestSessionIcon() {
|
private fun GuestSessionIcon() {
|
||||||
val guestName = stringResource(id = R.string.account_name_guest)
|
val guestName = stringResource(id = R.string.account_name_guest)
|
||||||
RoundedLetterImage(size = 40.dp, character = guestName[0], topPadding = 40.dp / 8)
|
RoundedLetterImage(size = 60.dp, character = guestName[0], topPadding = 60.dp / 4)
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun AuthorizedSessionMenuItems(
|
|
||||||
expanded: MutableState<Boolean>,
|
|
||||||
lastSelectedOption: MutableState<String>
|
|
||||||
) {
|
|
||||||
CustomMenuItem(
|
|
||||||
text = stringResource(id = R.string.action_sign_out),
|
|
||||||
onClick = {
|
|
||||||
signOut(lastSelectedOption)
|
|
||||||
expanded.value = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -376,22 +368,25 @@ private fun AuthorizedSessionIcon() {
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Box(modifier = Modifier.padding(start = 12.dp)) {
|
||||||
if (accountDetails == null || avatarUrl == null) {
|
if (accountDetails == null || avatarUrl == null) {
|
||||||
val accLetter = (accountDetails?.name?.ifEmpty { accountDetails.username } ?: " ")[0]
|
val accLetter = (accountDetails?.name?.ifEmpty { accountDetails.username } ?: " ")[0]
|
||||||
RoundedLetterImage(size = 40.dp, character = accLetter, topPadding = 40.dp / 8)
|
RoundedLetterImage(size = 60.dp, character = accLetter, topPadding = 60.dp / 4)
|
||||||
} else {
|
} else {
|
||||||
Box(modifier = Modifier.size(50.dp)) {
|
Box(modifier = Modifier.size(60.dp)) {
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = avatarUrl,
|
model = avatarUrl,
|
||||||
contentDescription = "",
|
contentDescription = "",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(40.dp)
|
.size(60.dp)
|
||||||
.clip(CircleShape),
|
.clip(CircleShape),
|
||||||
contentScale = ContentScale.Fit
|
contentScale = ContentScale.Fit
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createGuestSession(lastSelectedOption: MutableState<String>) {
|
private fun createGuestSession(lastSelectedOption: MutableState<String>) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
|||||||
Reference in New Issue
Block a user