Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] Dialog Preview 반복 되는 코드 제거 및 코드 개선 #133

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nexters.ilab.core.ui.component

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -33,13 +35,13 @@ import com.nexters.ilab.core.ui.ComponentPreview
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ILabDialog(
titleResId: Int,
iconResId: Int?,
@StringRes titleResId: Int,
@DrawableRes iconResId: Int?,
iconDescription: String?,
firstDescriptionResId: Int,
secondDescriptionResId: Int?,
cancelTextResId: Int?,
confirmTextResId: Int,
@StringRes firstDescriptionResId: Int,
@StringRes secondDescriptionResId: Int?,
@StringRes cancelTextResId: Int?,
@StringRes confirmTextResId: Int,
onCancelClick: () -> Unit,
onConfirmClick: () -> Unit,
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -113,7 +115,13 @@ fun ILabDialog(
modifier = Modifier
.weight(1f)
.height(48.dp)
.padding(start = 4.dp),
.then(
if (cancelTextResId != null) {
Modifier.padding(start = 4.dp)
} else {
Modifier
},
),
text = {
Text(
text = stringResource(id = confirmTextResId),
Expand Down Expand Up @@ -161,9 +169,11 @@ fun NetworkErrorDialog(
)
}

@ComponentPreview
@Composable
fun CreateImageStopDialogPreview() {
fun CreateImageStopDialog(
onCancelClick: () -> Unit,
onConfirmClick: () -> Unit,
) {
ILabDialog(
titleResId = R.string.creating_image_stop_confirmation,
iconResId = null,
Expand All @@ -172,41 +182,50 @@ fun CreateImageStopDialogPreview() {
secondDescriptionResId = R.string.creating_image_stop_warning_description2,
cancelTextResId = R.string.creating_image_stop_confirm,
confirmTextResId = R.string.creating_image_continue,
onCancelClick = {},
onConfirmClick = {},
onCancelClick = onCancelClick,
onConfirmClick = onConfirmClick,
)
}

@Composable
fun DeleteAccountDialog(
onCancelClick: () -> Unit,
onConfirmClick: () -> Unit,
) {
ILabDialog(
titleResId = R.string.setting_delete_account,
iconResId = R.drawable.ic_warning,
iconDescription = "Warning Icon",
firstDescriptionResId = R.string.setting_delete_account_description,
secondDescriptionResId = null,
cancelTextResId = R.string.setting_delete_account_cancel,
confirmTextResId = R.string.setting_delete_account_confirm,
onCancelClick = onCancelClick,
onConfirmClick = onConfirmClick,
)
}

@ComponentPreview
@Composable
fun DeleteAccountDialogPreview() {
fun ServerErrorDialogPreview() {
ILabTheme {
ILabDialog(
titleResId = R.string.setting_delete_account,
iconResId = R.drawable.ic_warning,
iconDescription = "Warning Icon",
firstDescriptionResId = R.string.setting_delete_account_description,
secondDescriptionResId = null,
cancelTextResId = R.string.setting_delete_account_cancel,
confirmTextResId = R.string.setting_delete_account_confirm,
onCancelClick = {},
onConfirmClick = {},
)
ServerErrorDialog(onRetryClick = {})
}
}

@ComponentPreview
@Composable
fun ServerErrorDialogPreview() {
fun NetworkErrorDialogPreview() {
ILabTheme {
ILabDialog(
titleResId = R.string.server_error_title,
iconResId = R.drawable.ic_server_error,
iconDescription = "Network Error Icon",
firstDescriptionResId = R.string.server_error_description1,
secondDescriptionResId = R.string.server_error_description2,
confirmTextResId = R.string.retry,
cancelTextResId = null,
NetworkErrorDialog(onRetryClick = {})
}
}

@ComponentPreview
@Composable
fun CreateImageStopDialogPreview() {
ILabTheme {
CreateImageStopDialog(
onCancelClick = {},
onConfirmClick = {},
)
Expand All @@ -215,16 +234,9 @@ fun ServerErrorDialogPreview() {

@ComponentPreview
@Composable
fun NetworkErrorDialogPreview() {
fun DeleteAccountDialogPreview() {
ILabTheme {
ILabDialog(
titleResId = R.string.network_error_title,
iconResId = R.drawable.ic_network_error,
iconDescription = "Network Error Icon",
firstDescriptionResId = R.string.network_error_description1,
secondDescriptionResId = R.string.network_error_description2,
confirmTextResId = R.string.retry,
cancelTextResId = null,
DeleteAccountDialog(
onCancelClick = {},
onConfirmClick = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.nexters.ilab.android.core.designsystem.theme.ILabTheme
import com.nexters.ilab.android.core.designsystem.theme.Subtitle2
import com.nexters.ilab.android.core.designsystem.theme.Title1
import com.nexters.ilab.core.ui.DevicePreview
import com.nexters.ilab.core.ui.component.ILabDialog
import com.nexters.ilab.core.ui.component.CreateImageStopDialog
import com.nexters.ilab.core.ui.component.ILabTopAppBar
import com.nexters.ilab.core.ui.component.LoadingImage
import com.nexters.ilab.core.ui.component.NetworkErrorDialog
Expand Down Expand Up @@ -208,24 +208,6 @@ private fun CreateImageContent(creatingImageWaitText: String) {
}
}

@Composable
private fun CreateImageStopDialog(
onCancelClick: () -> Unit,
onConfirmClick: () -> Unit,
) {
ILabDialog(
titleResId = R.string.creating_image_stop_confirmation,
iconResId = null,
iconDescription = null,
firstDescriptionResId = R.string.creating_image_stop_warning_description1,
secondDescriptionResId = R.string.creating_image_stop_warning_description2,
cancelTextResId = R.string.creating_image_stop_confirm,
confirmTextResId = R.string.creating_image_continue,
onCancelClick = onCancelClick,
onConfirmClick = onConfirmClick,
)
}

@DevicePreview
@Composable
fun CreateImageScreenPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.nexters.ilab.android.feature.setting.viewmodel.SettingSideEffect
import com.nexters.ilab.android.feature.setting.viewmodel.SettingState
import com.nexters.ilab.android.feature.setting.viewmodel.SettingViewModel
import com.nexters.ilab.core.ui.DevicePreview
import com.nexters.ilab.core.ui.component.ILabDialog
import com.nexters.ilab.core.ui.component.DeleteAccountDialog
import com.nexters.ilab.core.ui.component.ILabTopAppBar
import com.nexters.ilab.core.ui.component.TopAppBarNavigationType

Expand Down Expand Up @@ -224,24 +224,6 @@ internal fun SettingTopAppBar(onBackClick: () -> Unit) {
)
}

@Composable
internal fun DeleteAccountDialog(
onCancelClick: () -> Unit,
onConfirmClick: () -> Unit,
) {
ILabDialog(
titleResId = R.string.setting_delete_account,
iconResId = R.drawable.ic_warning,
iconDescription = "Warning Icon",
firstDescriptionResId = R.string.setting_delete_account_description,
secondDescriptionResId = null,
cancelTextResId = R.string.setting_delete_account_cancel,
confirmTextResId = R.string.setting_delete_account_confirm,
onCancelClick = onCancelClick,
onConfirmClick = onConfirmClick,
)
}

@DevicePreview
@Composable
fun SettingScreenPreview() {
Expand Down
Loading