mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-09 04:18:11 +02:00
Fixes edge to edge issues when the keyboard is shown.
This commit is contained in:
parent
f38383d4e4
commit
d0961d08da
@ -24,8 +24,10 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.consumeWindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
@ -56,6 +58,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.ui.actions.relays.SettingsCategory
|
||||
import com.vitorpamplona.amethyst.ui.actions.relays.SettingsCategoryWithButton
|
||||
import com.vitorpamplona.amethyst.ui.components.SetDialogToEdgeToEdge
|
||||
import com.vitorpamplona.amethyst.ui.navigation.INav
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.CloseButton
|
||||
@ -67,7 +70,6 @@ import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.grayText
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun MediaServersListView(
|
||||
onClose: () -> Unit,
|
||||
@ -75,10 +77,7 @@ fun MediaServersListView(
|
||||
nav: INav,
|
||||
) {
|
||||
val nip96ServersViewModel: NIP96ServersViewModel = viewModel()
|
||||
val nip96ServersState by nip96ServersViewModel.fileServers.collectAsStateWithLifecycle()
|
||||
|
||||
val blossomServersViewModel: BlossomServersViewModel = viewModel()
|
||||
val blossomServersState by blossomServersViewModel.fileServers.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(key1 = Unit) {
|
||||
nip96ServersViewModel.load(accountViewModel.account)
|
||||
@ -87,162 +86,185 @@ fun MediaServersListView(
|
||||
|
||||
Dialog(
|
||||
onDismissRequest = onClose,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false),
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceAround,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = stringRes(id = R.string.media_servers),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
)
|
||||
}
|
||||
},
|
||||
navigationIcon = {
|
||||
CloseButton(
|
||||
onPress = {
|
||||
nip96ServersViewModel.refresh()
|
||||
blossomServersViewModel.refresh()
|
||||
onClose()
|
||||
},
|
||||
SetDialogToEdgeToEdge()
|
||||
DialogContent(nip96ServersViewModel, blossomServersViewModel, onClose)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DialogContent(
|
||||
nip96ServersViewModel: NIP96ServersViewModel,
|
||||
blossomServersViewModel: BlossomServersViewModel,
|
||||
onClose: () -> Unit,
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceAround,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = stringRes(id = R.string.media_servers),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
SaveButton(
|
||||
onPost = {
|
||||
nip96ServersViewModel.saveFileServers()
|
||||
blossomServersViewModel.saveFileServers()
|
||||
onClose()
|
||||
},
|
||||
isActive = true,
|
||||
)
|
||||
},
|
||||
colors =
|
||||
TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
),
|
||||
)
|
||||
}
|
||||
},
|
||||
navigationIcon = {
|
||||
CloseButton(
|
||||
onPress = {
|
||||
nip96ServersViewModel.refresh()
|
||||
blossomServersViewModel.refresh()
|
||||
onClose()
|
||||
},
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
SaveButton(
|
||||
onPost = {
|
||||
nip96ServersViewModel.saveFileServers()
|
||||
blossomServersViewModel.saveFileServers()
|
||||
onClose()
|
||||
},
|
||||
isActive = true,
|
||||
)
|
||||
},
|
||||
colors =
|
||||
TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
),
|
||||
)
|
||||
},
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier =
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.padding(
|
||||
start = 16.dp,
|
||||
top = padding.calculateTopPadding(),
|
||||
end = 16.dp,
|
||||
bottom = padding.calculateBottomPadding(),
|
||||
).consumeWindowInsets(padding)
|
||||
.imePadding(),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp, alignment = Alignment.Top),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(
|
||||
stringRes(id = R.string.set_preferred_media_servers),
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.grayText,
|
||||
)
|
||||
|
||||
AllMediaBody(nip96ServersViewModel, blossomServersViewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AllMediaBody(
|
||||
nip96ServersViewModel: NIP96ServersViewModel,
|
||||
blossomServersViewModel: BlossomServersViewModel,
|
||||
) {
|
||||
val nip96ServersState by nip96ServersViewModel.fileServers.collectAsStateWithLifecycle()
|
||||
val blossomServersState by blossomServersViewModel.fileServers.collectAsStateWithLifecycle()
|
||||
|
||||
LazyColumn(
|
||||
verticalArrangement = Arrangement.SpaceAround,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
contentPadding = FeedPadding,
|
||||
) {
|
||||
item {
|
||||
SettingsCategory(
|
||||
stringRes(R.string.media_servers_nip96_section),
|
||||
stringRes(R.string.media_servers_nip96_explainer),
|
||||
Modifier.padding(bottom = 8.dp),
|
||||
)
|
||||
}
|
||||
|
||||
renderMediaServerList(
|
||||
mediaServersState = nip96ServersState,
|
||||
keyType = "nip96",
|
||||
editLabel = R.string.add_a_nip96_server,
|
||||
emptyLabel = R.string.no_nip96_server_message,
|
||||
onAddServer = { server ->
|
||||
nip96ServersViewModel.addServer(server)
|
||||
},
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier =
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.padding(
|
||||
start = 16.dp,
|
||||
top = padding.calculateTopPadding(),
|
||||
end = 16.dp,
|
||||
bottom = padding.calculateBottomPadding(),
|
||||
),
|
||||
verticalArrangement = Arrangement.spacedBy(5.dp, alignment = Alignment.Top),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(
|
||||
stringRes(id = R.string.set_preferred_media_servers),
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.grayText,
|
||||
)
|
||||
onDeleteServer = {
|
||||
nip96ServersViewModel.removeServer(serverUrl = it)
|
||||
},
|
||||
)
|
||||
|
||||
LazyColumn(
|
||||
verticalArrangement = Arrangement.SpaceAround,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
contentPadding = FeedPadding,
|
||||
) {
|
||||
item {
|
||||
SettingsCategory(
|
||||
stringRes(R.string.media_servers_nip96_section),
|
||||
stringRes(R.string.media_servers_nip96_explainer),
|
||||
Modifier.padding(bottom = 8.dp),
|
||||
)
|
||||
}
|
||||
item {
|
||||
SettingsCategory(
|
||||
stringRes(R.string.media_servers_blossom_section),
|
||||
stringRes(R.string.media_servers_blossom_explainer),
|
||||
)
|
||||
}
|
||||
|
||||
renderMediaServerList(
|
||||
mediaServersState = nip96ServersState,
|
||||
keyType = "nip96",
|
||||
editLabel = R.string.add_a_nip96_server,
|
||||
emptyLabel = R.string.no_nip96_server_message,
|
||||
onAddServer = { server ->
|
||||
nip96ServersViewModel.addServer(server)
|
||||
},
|
||||
onDeleteServer = {
|
||||
nip96ServersViewModel.removeServer(serverUrl = it)
|
||||
},
|
||||
)
|
||||
renderMediaServerList(
|
||||
mediaServersState = blossomServersState,
|
||||
keyType = "blossom",
|
||||
editLabel = R.string.add_a_blossom_server,
|
||||
emptyLabel = R.string.no_blossom_server_message,
|
||||
onAddServer = { server ->
|
||||
blossomServersViewModel.addServer(server)
|
||||
},
|
||||
onDeleteServer = {
|
||||
blossomServersViewModel.removeServer(serverUrl = it)
|
||||
},
|
||||
)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
stringRes(R.string.media_servers_blossom_section),
|
||||
stringRes(R.string.media_servers_blossom_explainer),
|
||||
)
|
||||
}
|
||||
DEFAULT_MEDIA_SERVERS.let {
|
||||
item {
|
||||
SettingsCategoryWithButton(
|
||||
title = stringRes(id = R.string.built_in_media_servers_title),
|
||||
description = stringRes(id = R.string.built_in_servers_description),
|
||||
action = {
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
nip96ServersViewModel.addServerList(
|
||||
it.mapNotNull { s -> if (s.type == ServerType.NIP96) s.baseUrl else null },
|
||||
)
|
||||
|
||||
renderMediaServerList(
|
||||
mediaServersState = blossomServersState,
|
||||
keyType = "blossom",
|
||||
editLabel = R.string.add_a_blossom_server,
|
||||
emptyLabel = R.string.no_blossom_server_message,
|
||||
onAddServer = { server ->
|
||||
blossomServersViewModel.addServer(server)
|
||||
},
|
||||
onDeleteServer = {
|
||||
blossomServersViewModel.removeServer(serverUrl = it)
|
||||
},
|
||||
)
|
||||
|
||||
DEFAULT_MEDIA_SERVERS.let {
|
||||
item {
|
||||
SettingsCategoryWithButton(
|
||||
title = stringRes(id = R.string.built_in_media_servers_title),
|
||||
description = stringRes(id = R.string.built_in_servers_description),
|
||||
action = {
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
nip96ServersViewModel.addServerList(
|
||||
it.mapNotNull { s -> if (s.type == ServerType.NIP96) s.baseUrl else null },
|
||||
)
|
||||
|
||||
blossomServersViewModel.addServerList(
|
||||
it.mapNotNull { s -> if (s.type == ServerType.Blossom) s.baseUrl else null },
|
||||
)
|
||||
},
|
||||
) {
|
||||
Text(text = stringRes(id = R.string.use_default_servers))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
itemsIndexed(
|
||||
it,
|
||||
key = { index: Int, server: ServerName ->
|
||||
"Proposed" + server.baseUrl
|
||||
blossomServersViewModel.addServerList(
|
||||
it.mapNotNull { s -> if (s.type == ServerType.Blossom) s.baseUrl else null },
|
||||
)
|
||||
},
|
||||
) { index, server ->
|
||||
MediaServerEntry(
|
||||
serverEntry = server,
|
||||
isAmethystDefault = true,
|
||||
onAddOrDelete = { serverUrl ->
|
||||
if (server.type == ServerType.NIP96) {
|
||||
nip96ServersViewModel.addServer(serverUrl)
|
||||
} else if (server.type == ServerType.Blossom) {
|
||||
blossomServersViewModel.addServer(serverUrl)
|
||||
}
|
||||
},
|
||||
)
|
||||
) {
|
||||
Text(text = stringRes(id = R.string.use_default_servers))
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
Spacer(DoubleHorzSpacer)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
itemsIndexed(
|
||||
it,
|
||||
key = { index: Int, server: ServerName ->
|
||||
"Proposed" + server.baseUrl
|
||||
},
|
||||
) { index, server ->
|
||||
MediaServerEntry(
|
||||
serverEntry = server,
|
||||
isAmethystDefault = true,
|
||||
onAddOrDelete = { serverUrl ->
|
||||
if (server.type == ServerType.NIP96) {
|
||||
nip96ServersViewModel.addServer(serverUrl)
|
||||
} else if (server.type == ServerType.Blossom) {
|
||||
blossomServersViewModel.addServer(serverUrl)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
Spacer(DoubleHorzSpacer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user