Skip to content

Commit

Permalink
Add title and buttons to DefaultAlertDialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
msimonides committed Nov 8, 2024
1 parent f2f5517 commit c7c3734
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import androidx.compose.ui.unit.dp
import com.studio4plus.homerplayer2.FeatureFlags
import com.studio4plus.homerplayer2.R
import com.studio4plus.homerplayer2.audiobookfoldersui.AudiobookFolderViewState
import com.studio4plus.homerplayer2.base.ui.DefaultAlertDialog
import com.studio4plus.homerplayer2.base.ui.SectionTitle
import com.studio4plus.homerplayer2.base.ui.theme.HomerPlayer2Theme
import com.studio4plus.homerplayer2.podcastsui.PodcastItemViewState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ fun HideSettingsButtonConfirmationDialog(
onDismissRequest = onDismissRequest,
modifier = modifier,
usePlatformDefaultWidth = false
) {
) { horizontalPadding ->
HideSettingsButtonConfirmation(
onConfirm = onConfirm,
modifier = Modifier.padding(24.dp)
modifier = Modifier.padding(horizontal = horizontalPadding)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,16 @@
package com.studio4plus.homerplayer2.settingsui.composables

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.studio4plus.homerplayer2.base.ui.DefaultAlertDialog

@Composable
fun SettingsDialog(
title: String,
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
buttons: (@Composable RowScope.() -> Unit)? = null,
content: @Composable ColumnScope.(Dp) -> Unit,
) {
DefaultAlertDialog(
onDismissRequest = onDismissRequest,
modifier = modifier
) {
Column(
modifier = Modifier
.padding(vertical = 24.dp)
) {
Text(
title,
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(bottom = 16.dp, start = 24.dp, end = 24.dp)
)
Column(
modifier = Modifier.verticalScroll(rememberScrollState())
) {
content(24.dp)
}
if (buttons != null) {
Row(
horizontalArrangement = Arrangement.End,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp),
content = buttons
)
}
}
}
}

@Composable
fun <T> SelectFromRadioListDialog(
selectedValue: T,
Expand All @@ -93,7 +46,7 @@ fun <T> SelectFromRadioListDialog(
modifier: Modifier = Modifier,
buttons: (@Composable RowScope.() -> Unit)? = null,
) {
SettingsDialog(
DefaultAlertDialog(
title = title,
onDismissRequest = onDismissRequest,
modifier = modifier,
Expand Down Expand Up @@ -124,7 +77,7 @@ fun <T> SelectFromListDialog(
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
) {
SettingsDialog(
DefaultAlertDialog(
title = title,
onDismissRequest = onDismissRequest,
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,32 @@

package com.studio4plus.homerplayer2.base.ui

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.BasicAlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DefaultAlertDialog(
private fun BasicDefaultAlertDialog(
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
usePlatformDefaultWidth: Boolean = true,
Expand All @@ -54,4 +66,65 @@ fun DefaultAlertDialog(
content = content
)
}
}
}

@Composable
fun DefaultAlertDialog(
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
title: String? = null,
buttons: (@Composable RowScope.() -> Unit)? = null,
usePlatformDefaultWidth: Boolean = true,
content: @Composable ColumnScope.(Dp) -> Unit,
) {
BasicDefaultAlertDialog(
onDismissRequest = onDismissRequest,
usePlatformDefaultWidth = usePlatformDefaultWidth,
modifier = modifier,
) {
Column(
modifier = Modifier
.padding(vertical = 24.dp)
) {
if (title != null) {
Text(
title,
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(start = 24.dp, end = 24.dp)
)
}
Column(
modifier = Modifier
.padding(top = 16.dp)
.verticalScroll(rememberScrollState())
) {
content(24.dp)
}
if (buttons != null) {
Row(
horizontalArrangement = Arrangement.End,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp),
content = buttons
)
}
}
}
}

@Preview
@Composable
private fun PreviewDialogWithTitleAndButtons() {
DefaultAlertDialog(
title = null,
buttons = {
TextButton(onClick = {}) { Text("Cancel") }
TextButton(onClick = {}) { Text("Ok") }
},
content = { horizontalPadding ->
Text( "Some message", modifier = Modifier.padding(horizontal = horizontalPadding))
},
onDismissRequest = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
package com.studio4plus.homerplayer2.kiosk.ui

import androidx.compose.foundation.Image
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.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -171,29 +169,20 @@ private fun ConfirmDropPrivilegeDialog(
) {
DefaultAlertDialog(
onDismissRequest = onDismissRequest,
) {
Column(
modifier = modifier
.padding(24.dp),
) {
Text(
text = stringResource(R.string.drop_privilege_confirm_message),
modifier = Modifier.padding(top = 8.dp)
)
Row(
modifier = Modifier
.padding(top = 24.dp)
.fillMaxWidth(),
horizontalArrangement = Arrangement.End
) {
TextButton(onClick = onDismissRequest) {
Text(stringResource(R.string.drop_privilege_confirm_cancel_button))
}
TextButton(onClick = onConfirm) {
Text(stringResource(R.string.drop_privilege_confirm_confirm_button))
}
modifier = modifier,
buttons = {
TextButton(onClick = onDismissRequest) {
Text(stringResource(R.string.drop_privilege_confirm_cancel_button))
}
TextButton(onClick = onConfirm) {
Text(stringResource(R.string.drop_privilege_confirm_confirm_button))
}
}
) { horizontalPadding ->
Text(
text = stringResource(R.string.drop_privilege_confirm_message),
modifier = Modifier.padding(horizontal = horizontalPadding)
)
}
}

Expand Down

0 comments on commit c7c3734

Please sign in to comment.