From 119899220b0417c4981b7ae48296958e33b6fef5 Mon Sep 17 00:00:00 2001 From: wryther Date: Sun, 5 Mar 2023 15:15:01 -0500 Subject: [PATCH 1/8] Renamed query to better describe its function --- app/src/main/java/com/medmapper/v33001/dao/MedicineDAO.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/medmapper/v33001/dao/MedicineDAO.kt b/app/src/main/java/com/medmapper/v33001/dao/MedicineDAO.kt index 271f155..14691aa 100644 --- a/app/src/main/java/com/medmapper/v33001/dao/MedicineDAO.kt +++ b/app/src/main/java/com/medmapper/v33001/dao/MedicineDAO.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow @Dao interface MedicineDAO { @Query("SELECT * FROM Medicine ORDER BY name ASC") - fun getAlphabetizedMedicine(): Flow> + fun getAllAlphabetizedMedicine(): Flow> @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insert(medicine: Medicine) From be5579e8a4999bd00838c4e5ac5a21dd9cc77647 Mon Sep 17 00:00:00 2001 From: wryther Date: Sun, 5 Mar 2023 19:02:54 -0500 Subject: [PATCH 2/8] Corrected spelling, replaced top comments with Kdoc --- .../v33001/repository/MedicineRepository.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/medmapper/v33001/repository/MedicineRepository.kt b/app/src/main/java/com/medmapper/v33001/repository/MedicineRepository.kt index c2f8470..b3f1ff4 100644 --- a/app/src/main/java/com/medmapper/v33001/repository/MedicineRepository.kt +++ b/app/src/main/java/com/medmapper/v33001/repository/MedicineRepository.kt @@ -5,17 +5,21 @@ import com.medmapper.v33001.dao.MedicineDAO import com.medmapper.v33001.dto.Medicine import kotlinx.coroutines.flow.Flow -// Declares teh DAO as private property in the constructor. Pass in the DAO -// instead of the whole database, because you only need access to the DAO +/** + * Declares the DAO as private property in the constructor. + * Pass in the DAO instead of the whole database, because you only need access to the DAO + */ class MedicineRepository(private val medicineDAO: MedicineDAO) { - // Room executes all queries on a separate thread. - // Observed Flow will notify the observer when the data has changed. - val allMedicines: Flow> = medicineDAO.getAlphabetizedMedicine() + // Room executes all queries on a separate thread. + // Observed Flow will notify the observer when the data has changed. + + val allMedicines: Flow> = medicineDAO.getAllAlphabetizedMedicine() + + // By default Room runs suspend queries off the main thread, therefore + // we don't need to implement anything else to ensure we're not doing + // long running database work off the main thread - // By default Room runs suspend queries off the main thread, therefore - // we don't need to implement anything else to ensure we're not doing - // long running database work off the main thread @Suppress("RedundantSuspendModifier") @WorkerThread suspend fun insert(medicine: Medicine) { From 7bb7a8006c16fef5dd30189c697bd381192a901c Mon Sep 17 00:00:00 2001 From: wryther Date: Sun, 5 Mar 2023 19:03:07 -0500 Subject: [PATCH 3/8] Replaced top comments with Kdoc --- .../java/com/medmapper/v33001/room/MedicineRoomDatabase.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/medmapper/v33001/room/MedicineRoomDatabase.kt b/app/src/main/java/com/medmapper/v33001/room/MedicineRoomDatabase.kt index a37fcf9..9d2e1ce 100644 --- a/app/src/main/java/com/medmapper/v33001/room/MedicineRoomDatabase.kt +++ b/app/src/main/java/com/medmapper/v33001/room/MedicineRoomDatabase.kt @@ -13,7 +13,9 @@ public abstract class MedicineRoomDatabase : RoomDatabase() { abstract fun medicineDao(): MedicineDAO companion object { - // Singleton prevents multiple instances of database opening at the same time. + /** + * Singleton prevents multiple instances of database opening at the same time. + */ @Volatile private var INSTANCE: MedicineRoomDatabase? = null fun getDatabase(context: Context): MedicineRoomDatabase { From f673eae954ca854b0fceb20ec96478199803cd22 Mon Sep 17 00:00:00 2001 From: wryther Date: Sun, 5 Mar 2023 19:12:28 -0500 Subject: [PATCH 4/8] Changed how room-compiler was being called by kapt --- app/build.gradle | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index acbca27..388d687 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,8 @@ dependencies { debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version" // Add Room Database Dependencies - implementation "androidx.room:room-runtime:2.5.0" - kapt "androidx.room:room-compiler:2.5.0" - implementation "androidx.room:room-ktx:2.5.0" + def room_version = "2.5.0" + implementation "androidx.room:room-runtime:$room_version" + kapt("androidx.room:room-compiler:$room_version") + implementation "androidx.room:room-ktx:$room_version" } \ No newline at end of file From c9a6a62bcd9a4eb0c79cce0a35cea914bd10124d Mon Sep 17 00:00:00 2001 From: wryther Date: Sun, 5 Mar 2023 19:14:44 -0500 Subject: [PATCH 5/8] Revert "Changed how room-compiler was being called by kapt" This reverts commit f673eae954ca854b0fceb20ec96478199803cd22. --- app/build.gradle | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 388d687..acbca27 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,8 +63,7 @@ dependencies { debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version" // Add Room Database Dependencies - def room_version = "2.5.0" - implementation "androidx.room:room-runtime:$room_version" - kapt("androidx.room:room-compiler:$room_version") - implementation "androidx.room:room-ktx:$room_version" + implementation "androidx.room:room-runtime:2.5.0" + kapt "androidx.room:room-compiler:2.5.0" + implementation "androidx.room:room-ktx:2.5.0" } \ No newline at end of file From 3196b6ddf55cb018b76a1b049f87a4c614e07bc8 Mon Sep 17 00:00:00 2001 From: wryther Date: Sun, 5 Mar 2023 19:17:26 -0500 Subject: [PATCH 6/8] Added version var for room database dependencies --- app/build.gradle | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index acbca27..2866797 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,8 @@ dependencies { debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version" // Add Room Database Dependencies - implementation "androidx.room:room-runtime:2.5.0" - kapt "androidx.room:room-compiler:2.5.0" - implementation "androidx.room:room-ktx:2.5.0" + def room_version = "2.5.0" + implementation "androidx.room:room-runtime:$room_version" + kapt "androidx.room:room-compiler:$room_version" + implementation "androidx.room:room-ktx:$room_version" } \ No newline at end of file From e3129d2b5370933145c158c707744d17af6cce5d Mon Sep 17 00:00:00 2001 From: wryther Date: Sun, 5 Mar 2023 19:23:51 -0500 Subject: [PATCH 7/8] Added non null data --- app/src/main/java/com/medmapper/v33001/dto/Medicine.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/medmapper/v33001/dto/Medicine.kt b/app/src/main/java/com/medmapper/v33001/dto/Medicine.kt index 8094740..d1a7293 100644 --- a/app/src/main/java/com/medmapper/v33001/dto/Medicine.kt +++ b/app/src/main/java/com/medmapper/v33001/dto/Medicine.kt @@ -1,5 +1,6 @@ package com.medmapper.v33001.dto +import androidx.annotation.NonNull import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey @@ -7,9 +8,9 @@ import androidx.room.PrimaryKey @Entity(tableName = "Medicine") data class Medicine( @PrimaryKey(autoGenerate = true) val medID: Int, - @ColumnInfo(name = "name") val name: String?, + @NonNull @ColumnInfo(name = "name") val name: String, @ColumnInfo(name = "strength") val strength: String?, - @ColumnInfo(name = "start date") val startDate: String?, - @ColumnInfo(name = "prescription length") val lengthInDays: Int + @NonNull @ColumnInfo(name = "start date") val startDate: String, + @NonNull @ColumnInfo(name = "prescription length") val lengthInDays: Int //,@ColumnInfo() val endDate: Date = startDate ) \ No newline at end of file From b77bdf1f96649fe2c4f29d1dc73b4bf2490864d4 Mon Sep 17 00:00:00 2001 From: wryther Date: Sun, 5 Mar 2023 19:39:37 -0500 Subject: [PATCH 8/8] Swtiched blank kdoc to the top and put comment back above companion --- .../java/com/medmapper/v33001/room/MedicineRoomDatabase.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/medmapper/v33001/room/MedicineRoomDatabase.kt b/app/src/main/java/com/medmapper/v33001/room/MedicineRoomDatabase.kt index 9d2e1ce..3d069e2 100644 --- a/app/src/main/java/com/medmapper/v33001/room/MedicineRoomDatabase.kt +++ b/app/src/main/java/com/medmapper/v33001/room/MedicineRoomDatabase.kt @@ -7,15 +7,16 @@ import androidx.room.RoomDatabase import com.medmapper.v33001.dao.MedicineDAO import com.medmapper.v33001.dto.Medicine +/** + * + */ @Database(entities = arrayOf(Medicine::class), version = 1, exportSchema = false) public abstract class MedicineRoomDatabase : RoomDatabase() { abstract fun medicineDao(): MedicineDAO + //Singleton prevents multiple instances of database opening at the same time. companion object { - /** - * Singleton prevents multiple instances of database opening at the same time. - */ @Volatile private var INSTANCE: MedicineRoomDatabase? = null fun getDatabase(context: Context): MedicineRoomDatabase {