Conversation
| package com.medmapper.v33001.dao | ||
|
|
||
| import androidx.room.TypeConverter | ||
| import java.util.Date | ||
|
|
||
| class DateConverter { | ||
| @TypeConverter | ||
| fun fromTimestamp(value: Long?): Date? { | ||
| return value?.let { Date(it) } | ||
| } | ||
|
|
||
| @TypeConverter | ||
| fun dateToTimestamp(date: Date?): Long? { | ||
| return date?.time | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Added the DateConverter.kt class file to enable Room to store and retrieve Date objects from the database (refer Medicine.kt). This ensures proper storage and retrieval of dates from the database. This is a common practice in Android development when working with Room databases.
Source: https://developer.android.com/training/data-storage/room/referencing-data#type-converters
| @Delete | ||
| suspend fun delete(medicine: Medicine) | ||
|
|
||
| @Update | ||
| suspend fun update(medicine: Medicine) | ||
|
|
There was a problem hiding this comment.
Room provides specific annotations for DELETE and UPDATE. Using @delete and @update annotations instead of @query can make the code more concise and easier to read.
Source: https://developer.android.com/training/data-storage/room/accessing-data
| @ColumnInfo(name = "name") val name: String?, | ||
| @ColumnInfo(name = "strength") val strength: String?, | ||
| @ColumnInfo(name = "start date") val startDate: String?, | ||
| @ColumnInfo(name = "start_date") val startDate: String?, |
There was a problem hiding this comment.
Column names should be lowercase, with words separated by underscores ("_").
Source: https://developer.android.com/training/data-storage/room/defining-data
| import com.medmapper.v33001.dao.DateConverter | ||
|
|
||
| @Entity(tableName = "Medicine") | ||
| @TypeConverters(DateConverter::class) |
There was a problem hiding this comment.
Room does not support non-primitive data types such as Date, so we need to define a TypeConverter to convert them to and from primitive data types that Room can handle. The @TypeConverter annotation can convert a custom type to a supported database type
Source: https://developer.android.com/training/data-storage/room/referencing-data.html#type-converters
| import com.medmapper.v33001.dto.Medicine | ||
|
|
||
| @Database(entities = arrayOf(Medicine::class), version = 1, exportSchema = false) | ||
| @Database(entities = [Medicine::class], version = 1, exportSchema = false) |
There was a problem hiding this comment.
The spread operator * is preferred over arrayOf when passing vararg arguments because it avoids the overhead of creating an additional array.
Source: https://kotlinlang.org/docs/functions.html#variable-number-of-arguments-varargs
| val allMedicine: Flow<List<Medicine>> = medicineDAO.getAlphabetizedMedicine() | ||
|
|
||
| fun getMedicineList(): Flow<List<Medicine>> { | ||
| return medicineDAO.getAlphabetizedMedicine() | ||
| } | ||
|
|
||
| suspend fun insert(medicine: Medicine) { | ||
| medicineDAO.insert(medicine) | ||
| } | ||
| } No newline at end of file | ||
|
|
||
| suspend fun delete(medicine: Medicine) { | ||
| medicineDAO.delete(medicine) | ||
| } | ||
|
|
||
| suspend fun update(medicine: Medicine) { | ||
| medicineDAO.update(medicine) | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Added these functions to provide access to the data stored in the database and to allow for inserting, deleting, and updating Medicine objects in the database.
| @@ -0,0 +1,7 @@ | |||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | |||
There was a problem hiding this comment.
Remove this file, as:
- This file does not belong here. Manifest should be in app/manifests directory.
- This file is incomplete.
|
Good suggestions and citations here. I recommend that the group review these suggestions, test them, and consider merging this branch. |
Analysis of the program:
The program is a medicine tracking app that uses Room database to store medicine information. It consists of several files including the entity class, DAO, database, repository, and view model. The app follows the MVVM architecture pattern and uses Kotlin coroutines and Flow for asynchronous operations.
Was the program available in UC Github on time?
Yes
Is the program documented/commented well enough for you to understand?
Overall, the program was documented well enough for me to understand the code and make the suggested improvements.
Does the program compile?
I had to make some adjustments to make it compile.
Rationale behind your changes:
The suggestions I provided aim to improve the code's readability, maintainability, and performance. For example, using the @TypeConverters annotation and specifying the class name of the DateConverter class would ensure that Room can convert Date objects to a format that can be stored in the database. Using the @insert, @delete, and @update annotations instead of @query for database operations would make the code more readable and maintainable. Using the suspend keyword for all database operations that could potentially block the UI thread ensures that these operations are executed asynchronously and do not block the UI thread, thus improving the app's performance. I have included single comments for every change I made, and can be viewed in the Files changed section.
Sources:
Links to three specific commits that you made to your own group's GitHub repository before the end of sprint deadline.
Three specific technical concepts that you learned from this code review: