Skip to content

Commit

Permalink
move dialog to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Metaroll committed Dec 11, 2024
1 parent 510d714 commit 8438aae
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 42 deletions.
52 changes: 52 additions & 0 deletions app/src/main/java/com/mensinator/app/NotificationDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.mensinator.app

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.res.stringResource

@Composable
fun NotificationDialog(
title: String,
messageText: String,
onDismissRequest: () -> Unit,
onSave: (String) -> Unit
) {
var newMessageText by remember { mutableStateOf(messageText) }

AlertDialog(
title = { Text(title) },
text = {
TextField(
value = newMessageText,
onValueChange = { newMessageText = it },
singleLine = false
)
},
confirmButton = {
Button(onClick = {
onSave(newMessageText)
onDismissRequest()
}) {
Text(text = stringResource(id = R.string.save_button))
}
},
onDismissRequest = onDismissRequest,
dismissButton = {
Button(
onClick = {
onDismissRequest()
}
) {
Text(text = stringResource(id = R.string.cancel_button))
}
}
)
}

43 changes: 1 addition & 42 deletions app/src/main/java/com/mensinator/app/settings/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -31,14 +30,13 @@ import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.mensinator.app.ExportDialog
import com.mensinator.app.FaqDialog
import com.mensinator.app.IPeriodDatabaseHelper
import com.mensinator.app.ImportDialog
import com.mensinator.app.NotificationDialog
import com.mensinator.app.R
import com.mensinator.app.data.ColorSource
import com.mensinator.app.ui.theme.MensinatorTheme
import com.mensinator.app.ui.theme.isDarkMode
import org.koin.androidx.compose.koinViewModel
import org.koin.compose.koinInject

private val colorCircleSize = 24.dp

Expand Down Expand Up @@ -225,45 +223,6 @@ fun SettingsScreen(
}
}

@Composable
fun NotificationDialog(
title: String,
messageText: String,
onDismissRequest: () -> Unit,
onSave: (String) -> Unit
) {
var newMessageText by remember { mutableStateOf(messageText) }

AlertDialog(
title = { Text(title) },
text = {
TextField(
value = newMessageText,
onValueChange = { newMessageText = it },
singleLine = false
)
},
confirmButton = {
Button(onClick = {
onSave(newMessageText)
onDismissRequest()
}) {
Text(text = stringResource(id = R.string.save_button))
}
},
onDismissRequest = onDismissRequest,
dismissButton = {
Button(
onClick = {
onDismissRequest()
}
) {
Text(text = stringResource(id = R.string.cancel_button))
}
}
)
}

@Composable
@OptIn(ExperimentalLayoutApi::class)
private fun AboutSection(
Expand Down

0 comments on commit 8438aae

Please sign in to comment.