mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-06-10 23:40:50 +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.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.consumeWindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.imePadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyListScope
|
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.R
|
||||||
import com.vitorpamplona.amethyst.ui.actions.relays.SettingsCategory
|
import com.vitorpamplona.amethyst.ui.actions.relays.SettingsCategory
|
||||||
import com.vitorpamplona.amethyst.ui.actions.relays.SettingsCategoryWithButton
|
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.navigation.INav
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.CloseButton
|
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.StdVertSpacer
|
||||||
import com.vitorpamplona.amethyst.ui.theme.grayText
|
import com.vitorpamplona.amethyst.ui.theme.grayText
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MediaServersListView(
|
fun MediaServersListView(
|
||||||
onClose: () -> Unit,
|
onClose: () -> Unit,
|
||||||
@ -75,10 +77,7 @@ fun MediaServersListView(
|
|||||||
nav: INav,
|
nav: INav,
|
||||||
) {
|
) {
|
||||||
val nip96ServersViewModel: NIP96ServersViewModel = viewModel()
|
val nip96ServersViewModel: NIP96ServersViewModel = viewModel()
|
||||||
val nip96ServersState by nip96ServersViewModel.fileServers.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
val blossomServersViewModel: BlossomServersViewModel = viewModel()
|
val blossomServersViewModel: BlossomServersViewModel = viewModel()
|
||||||
val blossomServersState by blossomServersViewModel.fileServers.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
LaunchedEffect(key1 = Unit) {
|
LaunchedEffect(key1 = Unit) {
|
||||||
nip96ServersViewModel.load(accountViewModel.account)
|
nip96ServersViewModel.load(accountViewModel.account)
|
||||||
@ -87,162 +86,185 @@ fun MediaServersListView(
|
|||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = onClose,
|
onDismissRequest = onClose,
|
||||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false),
|
||||||
) {
|
) {
|
||||||
Scaffold(
|
SetDialogToEdgeToEdge()
|
||||||
topBar = {
|
DialogContent(nip96ServersViewModel, blossomServersViewModel, onClose)
|
||||||
TopAppBar(
|
}
|
||||||
title = {
|
}
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
horizontalArrangement = Arrangement.SpaceAround,
|
@Composable
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
fun DialogContent(
|
||||||
) {
|
nip96ServersViewModel: NIP96ServersViewModel,
|
||||||
Text(
|
blossomServersViewModel: BlossomServersViewModel,
|
||||||
text = stringRes(id = R.string.media_servers),
|
onClose: () -> Unit,
|
||||||
style = MaterialTheme.typography.titleLarge,
|
) {
|
||||||
)
|
Scaffold(
|
||||||
}
|
topBar = {
|
||||||
},
|
TopAppBar(
|
||||||
navigationIcon = {
|
title = {
|
||||||
CloseButton(
|
Row(
|
||||||
onPress = {
|
modifier = Modifier.fillMaxWidth(),
|
||||||
nip96ServersViewModel.refresh()
|
horizontalArrangement = Arrangement.SpaceAround,
|
||||||
blossomServersViewModel.refresh()
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
onClose()
|
) {
|
||||||
},
|
Text(
|
||||||
|
text = stringRes(id = R.string.media_servers),
|
||||||
|
style = MaterialTheme.typography.titleLarge,
|
||||||
)
|
)
|
||||||
},
|
}
|
||||||
actions = {
|
},
|
||||||
SaveButton(
|
navigationIcon = {
|
||||||
onPost = {
|
CloseButton(
|
||||||
nip96ServersViewModel.saveFileServers()
|
onPress = {
|
||||||
blossomServersViewModel.saveFileServers()
|
nip96ServersViewModel.refresh()
|
||||||
onClose()
|
blossomServersViewModel.refresh()
|
||||||
},
|
onClose()
|
||||||
isActive = true,
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
colors =
|
actions = {
|
||||||
TopAppBarDefaults.topAppBarColors(
|
SaveButton(
|
||||||
containerColor = MaterialTheme.colorScheme.surface,
|
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 ->
|
onDeleteServer = {
|
||||||
Column(
|
nip96ServersViewModel.removeServer(serverUrl = it)
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
LazyColumn(
|
item {
|
||||||
verticalArrangement = Arrangement.SpaceAround,
|
SettingsCategory(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
stringRes(R.string.media_servers_blossom_section),
|
||||||
contentPadding = FeedPadding,
|
stringRes(R.string.media_servers_blossom_explainer),
|
||||||
) {
|
)
|
||||||
item {
|
}
|
||||||
SettingsCategory(
|
|
||||||
stringRes(R.string.media_servers_nip96_section),
|
|
||||||
stringRes(R.string.media_servers_nip96_explainer),
|
|
||||||
Modifier.padding(bottom = 8.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
renderMediaServerList(
|
renderMediaServerList(
|
||||||
mediaServersState = nip96ServersState,
|
mediaServersState = blossomServersState,
|
||||||
keyType = "nip96",
|
keyType = "blossom",
|
||||||
editLabel = R.string.add_a_nip96_server,
|
editLabel = R.string.add_a_blossom_server,
|
||||||
emptyLabel = R.string.no_nip96_server_message,
|
emptyLabel = R.string.no_blossom_server_message,
|
||||||
onAddServer = { server ->
|
onAddServer = { server ->
|
||||||
nip96ServersViewModel.addServer(server)
|
blossomServersViewModel.addServer(server)
|
||||||
},
|
},
|
||||||
onDeleteServer = {
|
onDeleteServer = {
|
||||||
nip96ServersViewModel.removeServer(serverUrl = it)
|
blossomServersViewModel.removeServer(serverUrl = it)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
item {
|
DEFAULT_MEDIA_SERVERS.let {
|
||||||
SettingsCategory(
|
item {
|
||||||
stringRes(R.string.media_servers_blossom_section),
|
SettingsCategoryWithButton(
|
||||||
stringRes(R.string.media_servers_blossom_explainer),
|
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(
|
blossomServersViewModel.addServerList(
|
||||||
mediaServersState = blossomServersState,
|
it.mapNotNull { s -> if (s.type == ServerType.Blossom) s.baseUrl else null },
|
||||||
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
|
|
||||||
},
|
},
|
||||||
) { index, server ->
|
) {
|
||||||
MediaServerEntry(
|
Text(text = stringRes(id = R.string.use_default_servers))
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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