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

Improve package structure, refactor manage symptoms screen #204

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions app/src/main/java/com/mensinator/app/App.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

import android.util.Log
import com.mensinator.app.extensions.roundToTwoDecimalPoints
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

import android.database.sqlite.SQLiteDatabase

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

import android.content.ContentValues
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

import java.time.LocalDate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

interface IExportImport {
fun getDocumentsExportFilePath(): String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

import java.time.LocalDate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

import java.time.LocalDate

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -39,7 +41,7 @@ interface IPeriodDatabaseHelper {
fun updateSymptomDate(dates: List<LocalDate>, symptomId: List<Int>)

// This function is used to get symptoms for a given date
fun getSymptomsFromDate(date: LocalDate): List<Int>
fun getActiveSymptomIdsForDate(date: LocalDate): List<Int>

fun getSymptomColorForDate(date: LocalDate): List<String>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

import java.time.LocalDate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business


import android.app.AlarmManager
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

import android.util.Log
import java.time.LocalDate
Expand Down
Original file line number Diff line number Diff line change
@@ -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

/*
Expand Down Expand Up @@ -295,7 +297,7 @@ class PeriodDatabaseHelper(context: Context) :
db.close()
}

override fun getSymptomsFromDate(date: LocalDate): List<Int> {
override fun getActiveSymptomIdsForDate(date: LocalDate): List<Int> {
val db = readableDatabase
val symptoms = mutableListOf<Int>()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.business

import java.time.LocalDate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.calendar


import android.content.Context
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
137 changes: 137 additions & 0 deletions app/src/main/java/com/mensinator/app/calendar/SymptomDialogs.kt
Original file line number Diff line number Diff line change
@@ -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<Symptom>,
currentlyActiveSymptomIds: Set<Int>,
onSave: (List<Symptom>) -> 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 = { },
)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.data

data class Setting(
val key: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.data

data class Symptom(
val id: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -166,6 +168,5 @@ fun MensinatorApp(
}
}
}

}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mensinator.app
package com.mensinator.app.settings

import android.util.Log
import android.widget.Toast
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading