-
Notifications
You must be signed in to change notification settings - Fork 1
Wryther code review2 #32
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
base: master
Are you sure you want to change the base?
Changes from all commits
64f5484
a99a71c
cd5b697
a160681
2760c77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()) | ||
| var user: User? = null | ||
|
|
||
| private lateinit var firestore: FirebaseFirestore | ||
|
|
@@ -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 | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") } | ||
|
|
||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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" /> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
|
@@ -155,3 +155,4 @@ | |
|
|
||
|
|
||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an end of line for the androidx.constraintlayout.widget.ConstraintLayout block |
||
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.