diff --git a/app/src/main/java/com/mensinator/app/App.kt b/app/src/main/java/com/mensinator/app/App.kt index a1e7bd4..946848c 100644 --- a/app/src/main/java/com/mensinator/app/App.kt +++ b/app/src/main/java/com/mensinator/app/App.kt @@ -1,6 +1,7 @@ package com.mensinator.app import android.app.Application +import com.mensinator.app.business.* import com.mensinator.app.settings.SettingsViewModel import com.mensinator.app.statistics.StatisticsViewModel import org.koin.android.ext.koin.androidContext diff --git a/app/src/main/java/com/mensinator/app/CalculationsHelper.kt b/app/src/main/java/com/mensinator/app/business/CalculationsHelper.kt similarity index 99% rename from app/src/main/java/com/mensinator/app/CalculationsHelper.kt rename to app/src/main/java/com/mensinator/app/business/CalculationsHelper.kt index deb3f69..aab6008 100644 --- a/app/src/main/java/com/mensinator/app/CalculationsHelper.kt +++ b/app/src/main/java/com/mensinator/app/business/CalculationsHelper.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import android.util.Log import com.mensinator.app.extensions.roundToTwoDecimalPoints diff --git a/app/src/main/java/com/mensinator/app/DatabaseUtils.kt b/app/src/main/java/com/mensinator/app/business/DatabaseUtils.kt similarity index 99% rename from app/src/main/java/com/mensinator/app/DatabaseUtils.kt rename to app/src/main/java/com/mensinator/app/business/DatabaseUtils.kt index 5360fd1..5956134 100644 --- a/app/src/main/java/com/mensinator/app/DatabaseUtils.kt +++ b/app/src/main/java/com/mensinator/app/business/DatabaseUtils.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import android.database.sqlite.SQLiteDatabase diff --git a/app/src/main/java/com/mensinator/app/ExportImport.kt b/app/src/main/java/com/mensinator/app/business/ExportImport.kt similarity index 99% rename from app/src/main/java/com/mensinator/app/ExportImport.kt rename to app/src/main/java/com/mensinator/app/business/ExportImport.kt index c69f5ad..5c3ccbb 100644 --- a/app/src/main/java/com/mensinator/app/ExportImport.kt +++ b/app/src/main/java/com/mensinator/app/business/ExportImport.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import android.content.ContentValues import android.content.Context diff --git a/app/src/main/java/com/mensinator/app/ICalculationsHelper.kt b/app/src/main/java/com/mensinator/app/business/ICalculationsHelper.kt similarity index 97% rename from app/src/main/java/com/mensinator/app/ICalculationsHelper.kt rename to app/src/main/java/com/mensinator/app/business/ICalculationsHelper.kt index 354bfe7..30305e7 100644 --- a/app/src/main/java/com/mensinator/app/ICalculationsHelper.kt +++ b/app/src/main/java/com/mensinator/app/business/ICalculationsHelper.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import java.time.LocalDate diff --git a/app/src/main/java/com/mensinator/app/IExportImport.kt b/app/src/main/java/com/mensinator/app/business/IExportImport.kt similarity index 84% rename from app/src/main/java/com/mensinator/app/IExportImport.kt rename to app/src/main/java/com/mensinator/app/business/IExportImport.kt index 0fd77b1..523a6a0 100644 --- a/app/src/main/java/com/mensinator/app/IExportImport.kt +++ b/app/src/main/java/com/mensinator/app/business/IExportImport.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business interface IExportImport { fun getDocumentsExportFilePath(): String diff --git a/app/src/main/java/com/mensinator/app/INotificationScheduler.kt b/app/src/main/java/com/mensinator/app/business/INotificationScheduler.kt similarity index 82% rename from app/src/main/java/com/mensinator/app/INotificationScheduler.kt rename to app/src/main/java/com/mensinator/app/business/INotificationScheduler.kt index 42c4c48..59443cd 100644 --- a/app/src/main/java/com/mensinator/app/INotificationScheduler.kt +++ b/app/src/main/java/com/mensinator/app/business/INotificationScheduler.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import java.time.LocalDate diff --git a/app/src/main/java/com/mensinator/app/IOvulationPrediction.kt b/app/src/main/java/com/mensinator/app/business/IOvulationPrediction.kt similarity index 75% rename from app/src/main/java/com/mensinator/app/IOvulationPrediction.kt rename to app/src/main/java/com/mensinator/app/business/IOvulationPrediction.kt index ab86ae8..09cfdbd 100644 --- a/app/src/main/java/com/mensinator/app/IOvulationPrediction.kt +++ b/app/src/main/java/com/mensinator/app/business/IOvulationPrediction.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import java.time.LocalDate diff --git a/app/src/main/java/com/mensinator/app/IPeriodDatabaseHelper.kt b/app/src/main/java/com/mensinator/app/business/IPeriodDatabaseHelper.kt similarity index 95% rename from app/src/main/java/com/mensinator/app/IPeriodDatabaseHelper.kt rename to app/src/main/java/com/mensinator/app/business/IPeriodDatabaseHelper.kt index 3f6701b..b322d2f 100644 --- a/app/src/main/java/com/mensinator/app/IPeriodDatabaseHelper.kt +++ b/app/src/main/java/com/mensinator/app/business/IPeriodDatabaseHelper.kt @@ -1,7 +1,9 @@ -package com.mensinator.app +package com.mensinator.app.business import android.database.sqlite.SQLiteDatabase import androidx.annotation.WorkerThread +import com.mensinator.app.data.Symptom +import com.mensinator.app.data.Setting import java.time.LocalDate interface IPeriodDatabaseHelper { @@ -39,7 +41,7 @@ interface IPeriodDatabaseHelper { fun updateSymptomDate(dates: List, symptomId: List) // This function is used to get symptoms for a given date - fun getSymptomsFromDate(date: LocalDate): List + fun getActiveSymptomIdsForDate(date: LocalDate): List fun getSymptomColorForDate(date: LocalDate): List diff --git a/app/src/main/java/com/mensinator/app/IPeriodPrediction.kt b/app/src/main/java/com/mensinator/app/business/IPeriodPrediction.kt similarity index 74% rename from app/src/main/java/com/mensinator/app/IPeriodPrediction.kt rename to app/src/main/java/com/mensinator/app/business/IPeriodPrediction.kt index eec35cd..7248048 100644 --- a/app/src/main/java/com/mensinator/app/IPeriodPrediction.kt +++ b/app/src/main/java/com/mensinator/app/business/IPeriodPrediction.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import java.time.LocalDate diff --git a/app/src/main/java/com/mensinator/app/NotificationScheduler.kt b/app/src/main/java/com/mensinator/app/business/NotificationScheduler.kt similarity index 95% rename from app/src/main/java/com/mensinator/app/NotificationScheduler.kt rename to app/src/main/java/com/mensinator/app/business/NotificationScheduler.kt index 5e0f3bf..b6ba713 100644 --- a/app/src/main/java/com/mensinator/app/NotificationScheduler.kt +++ b/app/src/main/java/com/mensinator/app/business/NotificationScheduler.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import android.app.AlarmManager @@ -7,6 +7,7 @@ import android.content.Context import android.content.Intent import android.util.Log import androidx.core.app.NotificationManagerCompat +import com.mensinator.app.NotificationReceiver import java.time.LocalDate import java.time.ZoneId diff --git a/app/src/main/java/com/mensinator/app/OvulationPrediction.kt b/app/src/main/java/com/mensinator/app/business/OvulationPrediction.kt similarity index 98% rename from app/src/main/java/com/mensinator/app/OvulationPrediction.kt rename to app/src/main/java/com/mensinator/app/business/OvulationPrediction.kt index 43fe31f..113a792 100644 --- a/app/src/main/java/com/mensinator/app/OvulationPrediction.kt +++ b/app/src/main/java/com/mensinator/app/business/OvulationPrediction.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import android.util.Log import java.time.LocalDate diff --git a/app/src/main/java/com/mensinator/app/PeriodDatabaseHelper.kt b/app/src/main/java/com/mensinator/app/business/PeriodDatabaseHelper.kt similarity index 99% rename from app/src/main/java/com/mensinator/app/PeriodDatabaseHelper.kt rename to app/src/main/java/com/mensinator/app/business/PeriodDatabaseHelper.kt index 6e26dc7..eeac9e5 100644 --- a/app/src/main/java/com/mensinator/app/PeriodDatabaseHelper.kt +++ b/app/src/main/java/com/mensinator/app/business/PeriodDatabaseHelper.kt @@ -1,10 +1,12 @@ -package com.mensinator.app +package com.mensinator.app.business import android.content.ContentValues import android.content.Context import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper import android.util.Log +import com.mensinator.app.data.Symptom +import com.mensinator.app.data.Setting import java.time.LocalDate /* @@ -295,7 +297,7 @@ class PeriodDatabaseHelper(context: Context) : db.close() } - override fun getSymptomsFromDate(date: LocalDate): List { + override fun getActiveSymptomIdsForDate(date: LocalDate): List { val db = readableDatabase val symptoms = mutableListOf() diff --git a/app/src/main/java/com/mensinator/app/PeriodPrediction.kt b/app/src/main/java/com/mensinator/app/business/PeriodPrediction.kt similarity index 92% rename from app/src/main/java/com/mensinator/app/PeriodPrediction.kt rename to app/src/main/java/com/mensinator/app/business/PeriodPrediction.kt index e959247..064b3ff 100644 --- a/app/src/main/java/com/mensinator/app/PeriodPrediction.kt +++ b/app/src/main/java/com/mensinator/app/business/PeriodPrediction.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.business import java.time.LocalDate diff --git a/app/src/main/java/com/mensinator/app/CalendarScreen.kt b/app/src/main/java/com/mensinator/app/calendar/CalendarScreen.kt similarity index 98% rename from app/src/main/java/com/mensinator/app/CalendarScreen.kt rename to app/src/main/java/com/mensinator/app/calendar/CalendarScreen.kt index 9ad56a4..ebf13a4 100644 --- a/app/src/main/java/com/mensinator/app/CalendarScreen.kt +++ b/app/src/main/java/com/mensinator/app/calendar/CalendarScreen.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.calendar import android.content.Context @@ -30,7 +30,14 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import com.mensinator.app.R +import com.mensinator.app.data.Symptom +import com.mensinator.app.business.INotificationScheduler +import com.mensinator.app.business.IOvulationPrediction +import com.mensinator.app.business.IPeriodDatabaseHelper +import com.mensinator.app.business.IPeriodPrediction import com.mensinator.app.data.ColorSource +import com.mensinator.app.data.isActive import com.mensinator.app.navigation.displayCutoutExcludingStatusBarsPadding import com.mensinator.app.ui.theme.isDarkMode import org.koin.compose.koinInject @@ -611,11 +618,12 @@ fun CalendarScreen() { // Show the SymptomsDialog if (showSymptomsDialog && selectedDates.value.isNotEmpty()) { val activeSymptoms = dbHelper.getAllSymptoms().filter { it.isActive } + val date = selectedDates.value.last() - SymptomsDialog( - date = selectedDates.value.last(), // Pass the last selected date + EditSymptomsForDaysDialog( + date = date, // Pass the last selected date symptoms = activeSymptoms, - dbHelper = dbHelper, + currentlyActiveSymptomIds = dbHelper.getActiveSymptomIdsForDate(date).toSet(), onSave = { selectedSymptoms -> val selectedSymptomIds = selectedSymptoms.map { it.id } val datesToUpdate = selectedDates.value.toList() diff --git a/app/src/main/java/com/mensinator/app/calendar/SymptomDialogs.kt b/app/src/main/java/com/mensinator/app/calendar/SymptomDialogs.kt new file mode 100644 index 0000000..23f8fcb --- /dev/null +++ b/app/src/main/java/com/mensinator/app/calendar/SymptomDialogs.kt @@ -0,0 +1,137 @@ +package com.mensinator.app.calendar + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import com.mensinator.app.settings.ResourceMapper +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.mensinator.app.R +import com.mensinator.app.data.Symptom +import com.mensinator.app.ui.theme.MensinatorTheme +import java.time.LocalDate + +@Composable +fun EditSymptomsForDaysDialog( + date: LocalDate, + symptoms: List, + currentlyActiveSymptomIds: Set, + onSave: (List) -> Unit, + onCancel: () -> Unit, + modifier: Modifier = Modifier, +) { + var selectedSymptoms by remember { + mutableStateOf( + symptoms.filter { it.id in currentlyActiveSymptomIds }.toSet() + ) + } + + AlertDialog( + onDismissRequest = { onCancel() }, + confirmButton = { + Button( + onClick = { + onSave(selectedSymptoms.toList()) + }, + modifier = Modifier.fillMaxWidth() + ) { + Text(text = stringResource(id = R.string.save_symptoms_button)) + } + }, + modifier = modifier, + dismissButton = { + Button( + onClick = { + onCancel() + }, + modifier = Modifier.fillMaxWidth() + ) { + Text(text = stringResource(id = R.string.cancel_button)) + } + }, + title = { + Text(text = stringResource(id = R.string.symptoms_dialog_title, date)) + }, + text = { + Column(modifier = Modifier.verticalScroll(rememberScrollState())) { + symptoms.forEach { symptom -> + val symptomKey = ResourceMapper.getStringResourceId(symptom.name) + val symptomDisplayName = symptomKey?.let { stringResource(id = it) } ?: symptom.name + Row( + modifier = Modifier + .fillMaxWidth() + .padding(8.dp) + .clickable { + selectedSymptoms = if (selectedSymptoms.contains(symptom)) { + selectedSymptoms - symptom + } else { + selectedSymptoms + symptom + } + }, + verticalAlignment = Alignment.CenterVertically + ) { + Checkbox( + checked = selectedSymptoms.contains(symptom), + onCheckedChange = null + ) + Spacer(modifier = Modifier.width(8.dp)) + Text(text = symptomDisplayName) + } + } +// Spacer(modifier = Modifier.height(16.dp)) +// Button( +// onClick = { +// onCreateNewSymptom() +// }, +// modifier = Modifier.fillMaxWidth() +// ) { +// Text(text = stringResource(id = R.string.create_new_symptom_button)) +// } + } + }, + ) +} + +@Preview +@Composable +private fun EditSymptomsForDaysDialog_OneDayPreview() { + val symptoms = listOf( + Symptom(1, "Light", 0, ""), + Symptom(2, "Medium", 1, ""), + ) + MensinatorTheme { + EditSymptomsForDaysDialog( + date = LocalDate.now(), + symptoms = symptoms, + currentlyActiveSymptomIds = setOf(2), + onSave = {}, + onCancel = { }, + ) + } +} + +// TODO: Fix within https://github.com/EmmaTellblom/Mensinator/issues/203 +@Preview +@Composable +private fun EditSymptomsForDaysDialog_MultipleDaysPreview() { + val symptoms = listOf( + Symptom(1, "Light", 0, ""), + Symptom(2, "Medium", 1, ""), + ) + MensinatorTheme { + EditSymptomsForDaysDialog( + date = LocalDate.now(), + symptoms = symptoms, + currentlyActiveSymptomIds = setOf(2), + onSave = {}, + onCancel = { }, + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/mensinator/app/Setting.kt b/app/src/main/java/com/mensinator/app/data/Setting.kt similarity index 80% rename from app/src/main/java/com/mensinator/app/Setting.kt rename to app/src/main/java/com/mensinator/app/data/Setting.kt index 25e4822..2269ce3 100644 --- a/app/src/main/java/com/mensinator/app/Setting.kt +++ b/app/src/main/java/com/mensinator/app/data/Setting.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.data data class Setting( val key: String, diff --git a/app/src/main/java/com/mensinator/app/Symptom.kt b/app/src/main/java/com/mensinator/app/data/Symptom.kt similarity index 85% rename from app/src/main/java/com/mensinator/app/Symptom.kt rename to app/src/main/java/com/mensinator/app/data/Symptom.kt index caa9b45..75ba502 100644 --- a/app/src/main/java/com/mensinator/app/Symptom.kt +++ b/app/src/main/java/com/mensinator/app/data/Symptom.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.data data class Symptom( val id: Int, diff --git a/app/src/main/java/com/mensinator/app/navigation/MensinatorApp.kt b/app/src/main/java/com/mensinator/app/navigation/MensinatorApp.kt index 8567d91..32ea597 100644 --- a/app/src/main/java/com/mensinator/app/navigation/MensinatorApp.kt +++ b/app/src/main/java/com/mensinator/app/navigation/MensinatorApp.kt @@ -25,10 +25,12 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController -import com.mensinator.app.* import com.mensinator.app.R +import com.mensinator.app.business.IPeriodDatabaseHelper +import com.mensinator.app.calendar.CalendarScreen import com.mensinator.app.settings.SettingsScreen import com.mensinator.app.statistics.StatisticsScreen +import com.mensinator.app.symptoms.ManageSymptomScreen import org.koin.compose.koinInject enum class Screen(@StringRes val titleRes: Int) { @@ -166,6 +168,5 @@ fun MensinatorApp( } } } - } diff --git a/app/src/main/java/com/mensinator/app/ExportImportDialog.kt b/app/src/main/java/com/mensinator/app/settings/ExportImportDialog.kt similarity index 98% rename from app/src/main/java/com/mensinator/app/ExportImportDialog.kt rename to app/src/main/java/com/mensinator/app/settings/ExportImportDialog.kt index 0cc7b98..7fd7372 100644 --- a/app/src/main/java/com/mensinator/app/ExportImportDialog.kt +++ b/app/src/main/java/com/mensinator/app/settings/ExportImportDialog.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.settings import android.util.Log import android.widget.Toast @@ -14,6 +14,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview +import com.mensinator.app.R import com.mensinator.app.ui.theme.MensinatorTheme import java.io.File import java.io.FileOutputStream diff --git a/app/src/main/java/com/mensinator/app/FaqDialog.kt b/app/src/main/java/com/mensinator/app/settings/FaqDialog.kt similarity index 98% rename from app/src/main/java/com/mensinator/app/FaqDialog.kt rename to app/src/main/java/com/mensinator/app/settings/FaqDialog.kt index 4c8bdb3..e53ba3f 100644 --- a/app/src/main/java/com/mensinator/app/FaqDialog.kt +++ b/app/src/main/java/com/mensinator/app/settings/FaqDialog.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.settings import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -17,6 +17,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import com.mensinator.app.R import com.mensinator.app.ui.theme.MensinatorTheme diff --git a/app/src/main/java/com/mensinator/app/settings/SettingsScreen.kt b/app/src/main/java/com/mensinator/app/settings/SettingsScreen.kt index ad35dd5..563bdb0 100644 --- a/app/src/main/java/com/mensinator/app/settings/SettingsScreen.kt +++ b/app/src/main/java/com/mensinator/app/settings/SettingsScreen.kt @@ -28,9 +28,6 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.core.app.NotificationManagerCompat import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.mensinator.app.ExportDialog -import com.mensinator.app.FaqDialog -import com.mensinator.app.ImportDialog import com.mensinator.app.R import com.mensinator.app.data.ColorSource import com.mensinator.app.ui.theme.MensinatorTheme diff --git a/app/src/main/java/com/mensinator/app/settings/SettingsViewModel.kt b/app/src/main/java/com/mensinator/app/settings/SettingsViewModel.kt index abb18cb..31d14ab 100644 --- a/app/src/main/java/com/mensinator/app/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/mensinator/app/settings/SettingsViewModel.kt @@ -7,8 +7,8 @@ import android.util.Log import android.widget.Toast import androidx.compose.ui.graphics.Color import androidx.lifecycle.ViewModel -import com.mensinator.app.IExportImport -import com.mensinator.app.IPeriodDatabaseHelper +import com.mensinator.app.business.IExportImport +import com.mensinator.app.business.IPeriodDatabaseHelper import com.mensinator.app.R import com.mensinator.app.data.ColorSource import com.mensinator.app.settings.ColorSetting.* diff --git a/app/src/main/java/com/mensinator/app/statistics/StatisticsViewModel.kt b/app/src/main/java/com/mensinator/app/statistics/StatisticsViewModel.kt index 6696884..6ac3fef 100644 --- a/app/src/main/java/com/mensinator/app/statistics/StatisticsViewModel.kt +++ b/app/src/main/java/com/mensinator/app/statistics/StatisticsViewModel.kt @@ -4,6 +4,10 @@ import android.annotation.SuppressLint import android.content.Context import androidx.lifecycle.ViewModel import com.mensinator.app.* +import com.mensinator.app.business.ICalculationsHelper +import com.mensinator.app.business.IOvulationPrediction +import com.mensinator.app.business.IPeriodDatabaseHelper +import com.mensinator.app.business.IPeriodPrediction import com.mensinator.app.extensions.formatToOneDecimalPoint import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow diff --git a/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt b/app/src/main/java/com/mensinator/app/symptoms/ManageSymptomScreen.kt similarity index 96% rename from app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt rename to app/src/main/java/com/mensinator/app/symptoms/ManageSymptomScreen.kt index f58ee71..5733d7c 100644 --- a/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt +++ b/app/src/main/java/com/mensinator/app/symptoms/ManageSymptomScreen.kt @@ -1,4 +1,4 @@ -package com.mensinator.app +package com.mensinator.app.symptoms import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -19,10 +19,17 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.dp +import com.mensinator.app.* +import com.mensinator.app.R +import com.mensinator.app.business.IPeriodDatabaseHelper import com.mensinator.app.data.ColorSource +import com.mensinator.app.data.Symptom +import com.mensinator.app.data.isActive import com.mensinator.app.settings.ResourceMapper import com.mensinator.app.navigation.displayCutoutExcludingStatusBarsPadding +import com.mensinator.app.settings.SettingsViewModel import com.mensinator.app.ui.theme.isDarkMode +import org.koin.androidx.compose.koinViewModel import org.koin.compose.koinInject @@ -30,6 +37,8 @@ import org.koin.compose.koinInject @Composable fun ManageSymptomScreen( showCreateSymptom: MutableState, + modifier: Modifier = Modifier, + //viewModel: SettingsViewModel = koinViewModel(), ) { val dbHelper: IPeriodDatabaseHelper = koinInject() var initialSymptoms = remember { dbHelper.getAllSymptoms() } @@ -45,7 +54,7 @@ fun ManageSymptomScreen( Column( - modifier = Modifier + modifier = modifier .fillMaxSize() .verticalScroll(rememberScrollState()) // Make the column scrollable .displayCutoutExcludingStatusBarsPadding() diff --git a/app/src/main/java/com/mensinator/app/SymptomDialogs.kt b/app/src/main/java/com/mensinator/app/symptoms/ManageSymptomsDialogs.kt similarity index 53% rename from app/src/main/java/com/mensinator/app/SymptomDialogs.kt rename to app/src/main/java/com/mensinator/app/symptoms/ManageSymptomsDialogs.kt index d6d0f68..47d5dd0 100644 --- a/app/src/main/java/com/mensinator/app/SymptomDialogs.kt +++ b/app/src/main/java/com/mensinator/app/symptoms/ManageSymptomsDialogs.kt @@ -1,104 +1,16 @@ -package com.mensinator.app +package com.mensinator.app.symptoms -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.* +import androidx.compose.foundation.layout.Column +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.material3.TextField import androidx.compose.runtime.* -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview -import com.mensinator.app.settings.ResourceMapper -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp +import com.mensinator.app.R import com.mensinator.app.ui.theme.MensinatorTheme -import java.time.LocalDate - - -@Composable -fun SymptomsDialog( - date: LocalDate, - symptoms: List, - dbHelper: IPeriodDatabaseHelper, - onSave: (List) -> Unit, - onCancel: () -> Unit, - modifier: Modifier = Modifier, -) { - var selectedSymptoms by remember { mutableStateOf(emptySet()) } - - LaunchedEffect(date) { - val symptomIdsForDate = dbHelper.getSymptomsFromDate(date).toSet() - selectedSymptoms = symptoms.filter { it.id in symptomIdsForDate }.toSet() - } - - AlertDialog( - onDismissRequest = { onCancel() }, - confirmButton = { - Button( - onClick = { - onSave(selectedSymptoms.toList()) - }, - modifier = Modifier.fillMaxWidth() - ) { - Text(text = stringResource(id = R.string.save_symptoms_button)) - } - }, - modifier = modifier, - dismissButton = { - Button( - onClick = { - onCancel() - }, - modifier = Modifier.fillMaxWidth() - ) { - Text(text = stringResource(id = R.string.cancel_button)) - } - }, - title = { - Text(text = stringResource(id = R.string.symptoms_dialog_title, date)) - }, - text = { - Column(modifier = Modifier.verticalScroll(rememberScrollState())) { - symptoms.forEach { symptom -> - val symptomKey = ResourceMapper.getStringResourceId(symptom.name) - val symptomDisplayName = symptomKey?.let { stringResource(id = it) } ?: symptom.name - Row( - modifier = Modifier - .fillMaxWidth() - .padding(8.dp) - .clickable { - selectedSymptoms = if (selectedSymptoms.contains(symptom)) { - selectedSymptoms - symptom - } else { - selectedSymptoms + symptom - } - }, - verticalAlignment = Alignment.CenterVertically - ) { - Checkbox( - checked = selectedSymptoms.contains(symptom), - onCheckedChange = null - ) - Spacer(modifier = Modifier.width(8.dp)) - Text(text = symptomDisplayName, fontSize = 16.sp) - } - } -// Spacer(modifier = Modifier.height(16.dp)) -// Button( -// onClick = { -// onCreateNewSymptom() -// }, -// modifier = Modifier.fillMaxWidth() -// ) { -// Text(text = stringResource(id = R.string.create_new_symptom_button)) -// } - } - }, - ) -} - @Composable fun CreateNewSymptomDialog( @@ -108,7 +20,6 @@ fun CreateNewSymptomDialog( modifier: Modifier = Modifier, ) { var symptomName by remember { mutableStateOf(newSymptom) } - //val symptomKey = ResourceMapper.getStringResourceId(symptomName) AlertDialog( onDismissRequest = onCancel, diff --git a/app/src/main/java/com/mensinator/app/symptoms/ManageSymptomsViewModel.kt b/app/src/main/java/com/mensinator/app/symptoms/ManageSymptomsViewModel.kt new file mode 100644 index 0000000..3a1ffc8 --- /dev/null +++ b/app/src/main/java/com/mensinator/app/symptoms/ManageSymptomsViewModel.kt @@ -0,0 +1,41 @@ +package com.mensinator.app.symptoms + +import android.annotation.SuppressLint +import android.content.Context +import androidx.lifecycle.ViewModel +import com.mensinator.app.* +import com.mensinator.app.business.ICalculationsHelper +import com.mensinator.app.business.IOvulationPrediction +import com.mensinator.app.business.IPeriodDatabaseHelper +import com.mensinator.app.business.IPeriodPrediction +import com.mensinator.app.extensions.formatToOneDecimalPoint +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import java.time.format.DateTimeFormatter +import java.time.format.FormatStyle + +class ManageSymptomsViewModel( + @SuppressLint("StaticFieldLeak") private val appContext: Context, + private val periodDatabaseHelper: IPeriodDatabaseHelper, +) : ViewModel() { + + + private val _viewState = MutableStateFlow( + ViewState() + ) + val viewState: StateFlow = _viewState.asStateFlow() + + data class ViewState( + val trackedPeriods: String? = null, + ) + + fun refreshData() { + _viewState.update { + it.copy( + trackedPeriods = periodDatabaseHelper.getPeriodCount().toString(), + ) + } + } +} diff --git a/app/src/test/java/com/mensinator/app/PeriodPredictionTest.kt b/app/src/test/java/com/mensinator/app/PeriodPredictionTest.kt index 2df8e3d..927c85d 100644 --- a/app/src/test/java/com/mensinator/app/PeriodPredictionTest.kt +++ b/app/src/test/java/com/mensinator/app/PeriodPredictionTest.kt @@ -1,5 +1,9 @@ package com.mensinator.app +import com.mensinator.app.business.ICalculationsHelper +import com.mensinator.app.business.IPeriodDatabaseHelper +import com.mensinator.app.business.IPeriodPrediction +import com.mensinator.app.business.PeriodPrediction import io.mockk.MockKAnnotations import io.mockk.every import io.mockk.impl.annotations.MockK