Skip to content
Open
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
6 changes: 3 additions & 3 deletions app/src/main/java/com/medmapper/v33001/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MainViewModel(var medicineService : IMedicineService) /*= MedicineService(

internal val NEW_MEDICATION = "New Medication"
var medicine : MutableLiveData<List<Medicine>> = MutableLiveData<List<Medicine>>()
var selectedMedicine by mutableStateOf(Medicine())
private var selectedMedicine by mutableStateOf(Medicine())
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the mutableStateOf variable private makes sure changes to it are in one class only.

(https://developer.android.com/kotlin/coroutines/coroutines-best-practices)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A mutableState object will likely be accessed by an Activity class, as that's the nature of having a mutableState in the first place. private will hide this access. I urge caution when changing an access modifier in a ViewModel.

var user: User? = null

private lateinit var firestore: FirebaseFirestore
Expand Down Expand Up @@ -67,14 +67,14 @@ class MainViewModel(var medicineService : IMedicineService) /*= MedicineService(
user?.let {
user ->
val document =
if (selectedMedicine.medicationID == null || selectedMedicine.medicationID.isEmpty()) {
if (selectedMedicine.id == null || selectedMedicine.id.isEmpty()) {
// create a new medicine
firestore.collection("users").document(user.uid).collection("medications").document()
} else {
// update an existing specimen
firestore.collection("users").document(user.uid).collection("medications").document()
}
selectedMedicine.medicationID = document.id
selectedMedicine.id = document.id
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed selectedMedicine.medicationID to id to reflect the existing constructor/attribute that is in the Medicine DTO

Copy link
Copy Markdown

@discospiff discospiff Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either one works. No significant change to technical debt.

val handle = document.set(selectedMedicine)
handle.addOnSuccessListener { Log.d("Firebase", "Document Saved") }
handle.addOnFailureListener { Log.d("Firebase", "Save failed $it") }
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/medmapper/v33001/dto/Medicine.kt
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the constructors set to val, or read only, was causing a compiling error when trying to run the program. Making it writable resolved the error.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package com.medmapper.v33001.dto
import java.time.LocalDate

data class Medicine(
val id: String = "",
val uid: String = "",
val name: String = "",
val quantity: Int = 0,
val prescriptionStrength: String = "",
val startDate: LocalDate = LocalDate.now(),
val prescriptionLength: String = "",
val time: Long = 0,
var id: String = "",
var uid: String = "",
var name: String = "",
var quantity: Int = 0,
var prescriptionStrength: String = "",
var startDate: LocalDate = LocalDate.now(),
var prescriptionLength: String = "",
var time: Long = 0,
// Frequency per 24 hours
val frequency: Int = 0) {
var frequency: Int = 0) {
Comment on lines -6 to +15
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave this as it were. Assume variables are immutable (val), unless we have a very good reason for reassigning them.

override fun toString(): String {
return "$name, $quantity , $prescriptionStrength"
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/layout3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
android:id="@+id/button10"
android:layout_width="234dp"
android:layout_height="78dp"
android:text="Add new Medicine "
android:text="Add new Medication "
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -93,7 +93,7 @@
android:text="Name"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="100dp"
tools:text="Medicine Name" />
tools:text="Medication Name" />
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed Medicine lines to Medication. Medication was used more frequently in the app then medicine was, so making this change made the UI more consistent.


<EditText
android:id="@+id/editTextTextEmailAddress2"
Expand Down Expand Up @@ -155,3 +155,4 @@


</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an end of line for the androidx.constraintlayout.widget.ConstraintLayout block