From a96f96a59ac40150d124778005a942d6547fa149 Mon Sep 17 00:00:00 2001 From: Carsten Hagemann Date: Thu, 7 Nov 2024 21:46:55 +0100 Subject: [PATCH 1/2] Fix symptom order consistency --- .../java/com/mensinator/app/CalendarScreen.kt | 4 ++-- .../com/mensinator/app/ManageSymptomScreen.kt | 13 ++++------ .../mensinator/app/PeriodDatabaseHelper.kt | 24 ------------------- .../main/java/com/mensinator/app/Symptom.kt | 5 +++- 4 files changed, 10 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/mensinator/app/CalendarScreen.kt b/app/src/main/java/com/mensinator/app/CalendarScreen.kt index 84fc179..cc0e528 100644 --- a/app/src/main/java/com/mensinator/app/CalendarScreen.kt +++ b/app/src/main/java/com/mensinator/app/CalendarScreen.kt @@ -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 @@ -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 diff --git a/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt b/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt index 2e31c36..1268f6e 100644 --- a/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt +++ b/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt @@ -117,11 +117,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 } @@ -169,10 +168,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() ) } @@ -273,8 +269,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 }, diff --git a/app/src/main/java/com/mensinator/app/PeriodDatabaseHelper.kt b/app/src/main/java/com/mensinator/app/PeriodDatabaseHelper.kt index f367f19..b1dcce6 100644 --- a/app/src/main/java/com/mensinator/app/PeriodDatabaseHelper.kt +++ b/app/src/main/java/com/mensinator/app/PeriodDatabaseHelper.kt @@ -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 { - val db = readableDatabase - val symptoms = mutableListOf() - 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 { val db = readableDatabase diff --git a/app/src/main/java/com/mensinator/app/Symptom.kt b/app/src/main/java/com/mensinator/app/Symptom.kt index f3a8006..caa9b45 100644 --- a/app/src/main/java/com/mensinator/app/Symptom.kt +++ b/app/src/main/java/com/mensinator/app/Symptom.kt @@ -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 \ No newline at end of file From b82624950bead9023461a50c9e2544a2766da9e5 Mon Sep 17 00:00:00 2001 From: Carsten Hagemann Date: Thu, 7 Nov 2024 21:48:46 +0100 Subject: [PATCH 2/2] Fix import --- app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt b/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt index 1268f6e..4b5c61e 100644 --- a/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt +++ b/app/src/main/java/com/mensinator/app/ManageSymptomScreen.kt @@ -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