Improve the use of BaseDialog
This commit is contained in:
parent
7b537123c8
commit
5a0affdf3b
@ -1,26 +1,13 @@
|
|||||||
package com.readrops.app.compose.account.selection
|
package com.readrops.app.compose.account.selection
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Card
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import com.readrops.app.compose.R
|
import com.readrops.app.compose.R
|
||||||
|
import com.readrops.app.compose.util.components.BaseDialog
|
||||||
import com.readrops.app.compose.util.components.SelectableImageText
|
import com.readrops.app.compose.util.components.SelectableImageText
|
||||||
import com.readrops.app.compose.util.theme.MediumSpacer
|
|
||||||
import com.readrops.app.compose.util.theme.spacing
|
import com.readrops.app.compose.util.theme.spacing
|
||||||
import com.readrops.db.entities.account.AccountType
|
import com.readrops.db.entities.account.AccountType
|
||||||
|
|
||||||
@ -29,35 +16,11 @@ fun AccountSelectionDialog(
|
|||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onValidate: (AccountType) -> Unit,
|
onValidate: (AccountType) -> Unit,
|
||||||
) {
|
) {
|
||||||
Dialog(
|
BaseDialog(
|
||||||
onDismissRequest = onDismiss
|
title = stringResource(R.string.new_account),
|
||||||
|
icon = painterResource(id = R.drawable.ic_add_account),
|
||||||
|
onDismiss = onDismiss
|
||||||
) {
|
) {
|
||||||
Card(
|
|
||||||
shape = RoundedCornerShape(24.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(MaterialTheme.colorScheme.background)
|
|
||||||
.padding(MaterialTheme.spacing.largeSpacing)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.drawable.ic_add_account),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(MaterialTheme.spacing.largeSpacing)
|
|
||||||
)
|
|
||||||
|
|
||||||
MediumSpacer()
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.new_account),
|
|
||||||
style = MaterialTheme.typography.headlineSmall
|
|
||||||
)
|
|
||||||
|
|
||||||
MediumSpacer()
|
|
||||||
|
|
||||||
AccountType.values().forEach { type ->
|
AccountType.values().forEach { type ->
|
||||||
SelectableImageText(
|
SelectableImageText(
|
||||||
image = painterResource(
|
image = painterResource(
|
||||||
@ -76,5 +39,3 @@ fun AccountSelectionDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
@ -56,6 +56,8 @@ data class UpdateFeedDialogState(
|
|||||||
|
|
||||||
val isFeedUrlReadOnly: Boolean
|
val isFeedUrlReadOnly: Boolean
|
||||||
get() = accountType != null && !accountType.accountConfig!!.isFeedUrlEditable
|
get() = accountType != null && !accountType.accountConfig!!.isFeedUrlEditable
|
||||||
|
|
||||||
|
val hasFolders = folders.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
data class FolderState(
|
data class FolderState(
|
||||||
|
@ -1,22 +1,13 @@
|
|||||||
package com.readrops.app.compose.feeds.dialogs
|
package com.readrops.app.compose.feeds.dialogs
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Clear
|
import androidx.compose.material.icons.filled.Clear
|
||||||
import androidx.compose.material3.Card
|
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
@ -25,19 +16,15 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.readrops.app.compose.R
|
import com.readrops.app.compose.R
|
||||||
import com.readrops.app.compose.feeds.FeedViewModel
|
import com.readrops.app.compose.feeds.FeedViewModel
|
||||||
|
import com.readrops.app.compose.util.components.BaseDialog
|
||||||
import com.readrops.app.compose.util.theme.LargeSpacer
|
import com.readrops.app.compose.util.theme.LargeSpacer
|
||||||
import com.readrops.app.compose.util.theme.MediumSpacer
|
|
||||||
import com.readrops.app.compose.util.theme.ShortSpacer
|
import com.readrops.app.compose.util.theme.ShortSpacer
|
||||||
import com.readrops.app.compose.util.theme.spacing
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@ -49,35 +36,11 @@ fun AddFeedDialog(
|
|||||||
|
|
||||||
var isExpanded by remember { mutableStateOf(false) }
|
var isExpanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
Dialog(
|
BaseDialog(
|
||||||
onDismissRequest = onDismiss
|
title = stringResource(R.string.add_feed_item),
|
||||||
|
icon = painterResource(id = R.drawable.ic_rss_feed_grey),
|
||||||
|
onDismiss = onDismiss
|
||||||
) {
|
) {
|
||||||
Card(
|
|
||||||
shape = RoundedCornerShape(24.dp),
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(MaterialTheme.colorScheme.background)
|
|
||||||
.padding(MaterialTheme.spacing.largeSpacing)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.drawable.ic_rss_feed_grey),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(MaterialTheme.spacing.largeSpacing)
|
|
||||||
)
|
|
||||||
|
|
||||||
MediumSpacer()
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.add_feed_item),
|
|
||||||
style = MaterialTheme.typography.headlineSmall
|
|
||||||
)
|
|
||||||
|
|
||||||
MediumSpacer()
|
|
||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = state.url,
|
value = state.url,
|
||||||
label = {
|
label = {
|
||||||
@ -164,5 +127,3 @@ fun AddFeedDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -6,6 +6,7 @@ import androidx.compose.material3.Icon
|
|||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
@ -14,6 +15,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|||||||
import com.readrops.app.compose.R
|
import com.readrops.app.compose.R
|
||||||
import com.readrops.app.compose.feeds.FeedViewModel
|
import com.readrops.app.compose.feeds.FeedViewModel
|
||||||
import com.readrops.app.compose.util.components.BaseDialog
|
import com.readrops.app.compose.util.components.BaseDialog
|
||||||
|
import com.readrops.app.compose.util.theme.LargeSpacer
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FolderDialog(
|
fun FolderDialog(
|
||||||
@ -27,8 +29,7 @@ fun FolderDialog(
|
|||||||
BaseDialog(
|
BaseDialog(
|
||||||
title = stringResource(id = if (updateFolder) R.string.edit_folder else R.string.add_folder),
|
title = stringResource(id = if (updateFolder) R.string.edit_folder else R.string.add_folder),
|
||||||
icon = painterResource(id = if (updateFolder) R.drawable.ic_folder_grey else R.drawable.ic_new_folder),
|
icon = painterResource(id = if (updateFolder) R.drawable.ic_folder_grey else R.drawable.ic_new_folder),
|
||||||
onDismiss = onDismiss,
|
onDismiss = onDismiss
|
||||||
onValidate = onValidate
|
|
||||||
) {
|
) {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = state.name.orEmpty(),
|
value = state.name.orEmpty(),
|
||||||
@ -52,5 +53,13 @@ fun FolderDialog(
|
|||||||
isError = state.isError,
|
isError = state.isError,
|
||||||
supportingText = { Text(text = state.nameError?.errorText().orEmpty()) }
|
supportingText = { Text(text = state.nameError?.errorText().orEmpty()) }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
LargeSpacer()
|
||||||
|
|
||||||
|
TextButton(
|
||||||
|
onClick = { onValidate() },
|
||||||
|
) {
|
||||||
|
Text(text = stringResource(R.string.validate))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,36 +1,24 @@
|
|||||||
package com.readrops.app.compose.feeds.dialogs
|
package com.readrops.app.compose.feeds.dialogs
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Card
|
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.readrops.app.compose.R
|
import com.readrops.app.compose.R
|
||||||
import com.readrops.app.compose.feeds.FeedViewModel
|
import com.readrops.app.compose.feeds.FeedViewModel
|
||||||
|
import com.readrops.app.compose.util.components.BaseDialog
|
||||||
import com.readrops.app.compose.util.theme.LargeSpacer
|
import com.readrops.app.compose.util.theme.LargeSpacer
|
||||||
import com.readrops.app.compose.util.theme.MediumSpacer
|
import com.readrops.app.compose.util.theme.MediumSpacer
|
||||||
import com.readrops.app.compose.util.theme.spacing
|
|
||||||
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@ -41,35 +29,11 @@ fun UpdateFeedDialog(
|
|||||||
) {
|
) {
|
||||||
val state by viewModel.updateFeedDialogState.collectAsStateWithLifecycle()
|
val state by viewModel.updateFeedDialogState.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
Dialog(
|
BaseDialog(
|
||||||
onDismissRequest = onDismissRequest
|
title = stringResource(R.string.edit_feed),
|
||||||
|
icon = painterResource(id = R.drawable.ic_rss_feed_grey),
|
||||||
|
onDismiss = onDismissRequest
|
||||||
) {
|
) {
|
||||||
Card(
|
|
||||||
shape = RoundedCornerShape(24.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(MaterialTheme.colorScheme.background)
|
|
||||||
.padding(MaterialTheme.spacing.largeSpacing)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.drawable.ic_rss_feed_grey),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(MaterialTheme.spacing.largeSpacing)
|
|
||||||
)
|
|
||||||
|
|
||||||
MediumSpacer()
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.edit_feed),
|
|
||||||
style = MaterialTheme.typography.headlineSmall
|
|
||||||
)
|
|
||||||
|
|
||||||
MediumSpacer()
|
|
||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = state.feedName,
|
value = state.feedName,
|
||||||
onValueChange = { viewModel.setUpdateFeedDialogStateFeedName(it) },
|
onValueChange = { viewModel.setUpdateFeedDialogStateFeedName(it) },
|
||||||
@ -106,11 +70,11 @@ fun UpdateFeedDialog(
|
|||||||
MediumSpacer()
|
MediumSpacer()
|
||||||
|
|
||||||
ExposedDropdownMenuBox(
|
ExposedDropdownMenuBox(
|
||||||
expanded = state.isAccountDropDownExpanded,
|
expanded = state.isAccountDropDownExpanded && state.hasFolders,
|
||||||
onExpandedChange = { viewModel.setAccountDropDownState(state.isAccountDropDownExpanded.not()) }
|
onExpandedChange = { viewModel.setAccountDropDownState(state.isAccountDropDownExpanded.not()) }
|
||||||
) {
|
) {
|
||||||
ExposedDropdownMenu(
|
ExposedDropdownMenu(
|
||||||
expanded = state.isAccountDropDownExpanded,
|
expanded = state.isAccountDropDownExpanded && state.hasFolders,
|
||||||
onDismissRequest = { viewModel.setAccountDropDownState(false) }
|
onDismissRequest = { viewModel.setAccountDropDownState(false) }
|
||||||
) {
|
) {
|
||||||
for (folder in state.folders) {
|
for (folder in state.folders) {
|
||||||
@ -133,6 +97,7 @@ fun UpdateFeedDialog(
|
|||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = state.selectedFolder?.name.orEmpty(),
|
value = state.selectedFolder?.name.orEmpty(),
|
||||||
readOnly = true,
|
readOnly = true,
|
||||||
|
enabled = state.hasFolders,
|
||||||
onValueChange = {},
|
onValueChange = {},
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
ExposedDropdownMenuDefaults.TrailingIcon(expanded = state.isAccountDropDownExpanded)
|
ExposedDropdownMenuDefaults.TrailingIcon(expanded = state.isAccountDropDownExpanded)
|
||||||
@ -158,5 +123,3 @@ fun UpdateFeedDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -11,14 +11,12 @@ import androidx.compose.material3.Card
|
|||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import com.readrops.app.compose.util.theme.LargeSpacer
|
|
||||||
import com.readrops.app.compose.util.theme.MediumSpacer
|
import com.readrops.app.compose.util.theme.MediumSpacer
|
||||||
import com.readrops.app.compose.util.theme.spacing
|
import com.readrops.app.compose.util.theme.spacing
|
||||||
|
|
||||||
@ -27,7 +25,6 @@ fun BaseDialog(
|
|||||||
title: String,
|
title: String,
|
||||||
icon: Painter,
|
icon: Painter,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onValidate: () -> Unit,
|
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
Dialog(
|
Dialog(
|
||||||
@ -60,14 +57,6 @@ fun BaseDialog(
|
|||||||
MediumSpacer()
|
MediumSpacer()
|
||||||
|
|
||||||
content()
|
content()
|
||||||
|
|
||||||
LargeSpacer()
|
|
||||||
|
|
||||||
TextButton(
|
|
||||||
onClick = { onValidate() },
|
|
||||||
) {
|
|
||||||
Text(text = "Validate")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user