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

Fix symptom order consistency #175

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
4 changes: 2 additions & 2 deletions app/src/main/java/com/mensinator/app/CalendarScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fun CalendarScreen(
// Fetch symptoms from the database AND update data for calculations in stats screen
LaunchedEffect(Unit) {
updateCalculations() // Call updateCalculations on launch
symptoms = dbHelper.getAllActiveSymptoms()
symptoms = dbHelper.getAllSymptoms().filter { it.isActive }
}

// Update button state based on selected dates
Expand Down Expand Up @@ -560,7 +560,7 @@ fun CalendarScreen(

// Show the SymptomsDialog
if (showSymptomsDialog && selectedDates.value.isNotEmpty()) {
val activeSymptoms = dbHelper.getAllActiveSymptoms()
val activeSymptoms = dbHelper.getAllSymptoms().filter { it.isActive }

SymptomsDialog(
date = selectedDates.value.last(), // Pass the last selected date
Expand Down
14 changes: 4 additions & 10 deletions app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mensinator.app

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -117,11 +116,10 @@ fun ManageSymptomScreen(
if (savedSymptoms.size > 1) {
IconButton(
onClick = {
if (dbHelper.getAllActiveSymptoms().contains(symptom)) {
Log.d("test2", dbHelper.getAllActiveSymptoms().toString())
val activeSymptoms = dbHelper.getAllSymptoms().filter { it.isActive }
if (activeSymptoms.contains(symptom)) {
showDeleteDialog = true
symptomToDelete = symptom

} else {
symptom.let { symptom ->
savedSymptoms = savedSymptoms.filter { it.id != symptom.id }
Expand Down Expand Up @@ -169,10 +167,7 @@ fun ManageSymptomScreen(
)
Icon(
painter = painterResource(id = R.drawable.keyboard_arrow_down_24px),
contentDescription = stringResource(
id =
R.string.selection_color
),
contentDescription = stringResource(id = R.string.selection_color),
modifier = Modifier.wrapContentSize()
)
}
Expand Down Expand Up @@ -273,8 +268,7 @@ fun ManageSymptomScreen(
newSymptom = "", // Pass an empty string for new symptoms
onSave = { newSymptomName ->
dbHelper.createNewSymptom(newSymptomName)
initialSymptoms =
dbHelper.getAllSymptoms() //reset the data to make the new symptom appear
initialSymptoms = dbHelper.getAllSymptoms() //reset the data to make the new symptom appear
savedSymptoms = initialSymptoms
showCreateSymptom.value = false // Close the new symptom dialog
},
Expand Down
24 changes: 0 additions & 24 deletions app/src/main/java/com/mensinator/app/PeriodDatabaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,30 +164,6 @@ class PeriodDatabaseHelper(context: Context) : SQLiteOpenHelper(context, DATABAS
db.close()
}

//This function is used to get all active symptoms from the database
fun getAllActiveSymptoms(): List<Symptom> {
val db = readableDatabase
val symptoms = mutableListOf<Symptom>()
val query =
"SELECT $COLUMN_ID, SUBSTR($COLUMN_SYMPTOM_NAME, 1, 20) AS truncated_name, $COLUMN_SYMPTOM_ACTIVE, color FROM $TABLE_SYMPTOMS WHERE $COLUMN_SYMPTOM_ACTIVE = '1'"

val cursor = db.rawQuery(query, null)
cursor.use {
if (it.moveToFirst()) {
do {
val symptomId = it.getInt(it.getColumnIndexOrThrow(COLUMN_ID))
val symptomName = it.getString(it.getColumnIndexOrThrow("truncated_name"))
val symptomActive = it.getInt(it.getColumnIndexOrThrow(COLUMN_SYMPTOM_ACTIVE))
val color = it.getString(it.getColumnIndexOrThrow("color"))
symptoms.add(Symptom(symptomId, symptomName, symptomActive, color))
} while (it.moveToNext())
}
}
cursor.close()
db.close()
return symptoms
}

//This function is used to get all symptoms from the database
fun getAllSymptoms(): List<Symptom> {
val db = readableDatabase
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/mensinator/app/Symptom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.mensinator.app
data class Symptom(
val id: Int,
val name: String,
val active: Int,
val active: Int, // Active: 1, Inactive: 0
val color: String
)

val Symptom.isActive: Boolean
get() = this.active == 1