Conversation
… Also removed lateinit from firestore variable as it was unnecessary.
…ted data hiding on hasCameraPermission() and hasExternalStoragePermission(). I also changed incidentInfo from var -> val since it seems to be immutable.
…rom Retrofit.Builder().
… a value of this type.
…he comment on line 10.
…ightly reduce technical debt.
|
Analysis of the program: Was the program available in UC Github on time? Is the program documented/commented well enough for you to understand? Does the program compile? Rationale behind your changes. Redundancy: Renaming: Visibility Modifiers: Links to three specific commits that you made to your own group's GitHub repository before the end of sprint deadline. Next, list three specific technical concepts that you learned from this code review. Sources: |
| @JvmField | ||
| val AppModule = module { | ||
| viewModel { MainViewModel() } | ||
| viewModel { MainViewModel(get()) } |
There was a problem hiding this comment.
I added this as per the request of the comment on line 10. If this is unnecessary or not what you meant, omit it please!
There was a problem hiding this comment.
It looks like the MVM constructor requires a parameter... the question is, does Koin know about the parameter type? Is that also defined in Koin?
| val incidentInfo = Incident().apply { | ||
|
|
||
| stateId = 0 | ||
| stateName = inStateName |
There was a problem hiding this comment.
Data within incidentInfo is seems immutable, so I changed it to a val instead of a var.
There was a problem hiding this comment.
Good idea. Default to val. Only use var if you know you need to.
| var permissionGranted = false | ||
| resultsMap.forEach { | ||
| if (it.value == true) { | ||
| if (it.value) { |
There was a problem hiding this comment.
Removed redundancy. == true was not necessary.
| fun hasCameraPermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) | ||
| fun hasExternalStoragePermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
| private fun hasCameraPermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) | ||
| private fun hasExternalStoragePermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) |
There was a problem hiding this comment.
Implemented data hiding on these functions as they are only being used in MainActivity,kt
| firebaseUser = FirebaseAuth.getInstance().currentUser | ||
| firebaseUser?.let { | ||
| val user = com.ucmobiledevelopment.freeways.dto.User(it.uid, it.displayName) | ||
| val user = User(it.uid, it.displayName) |
There was a problem hiding this comment.
Path was redundant as it was already imported.
|
|
||
| class MainViewModel(var incidentService : IIncidentService = IncidentService()) : ViewModel(){ | ||
| internal val NEW_INCIDENT = "New Incident" | ||
| private val NEW_INCIDENT = "New Incident" |
There was a problem hiding this comment.
Changed internal -> private as it is only being used here and is deeply immutable. If you plan on using NEW_INCIDENT somewhere else, ignore this.
| private lateinit var firestore: FirebaseFirestore | ||
| private var firestore: FirebaseFirestore = FirebaseFirestore.getInstance() | ||
|
|
||
| init{ | ||
| firestore = FirebaseFirestore.getInstance() |
There was a problem hiding this comment.
lateinit seemed unnecessary, so I removed the lateinit modifier and got the instance as the var was declared.
There was a problem hiding this comment.
Either way works. I'd probably go with what the reviewer recommends here.
| super.onCreate(savedInstanceState) | ||
| setContent { | ||
| FreeWaysTheme() { | ||
| FreeWaysTheme { |
There was a problem hiding this comment.
Small change, but these parentheses are not necessary here.
| val context = LocalContext.current | ||
| ExtendedFloatingActionButton ( | ||
| text = { Text(text = "Back") }, | ||
| text = { Text(text = "Back") }, |
There was a problem hiding this comment.
Incredibly small change, just removed an extra space because I happened to notice it.
| val FATALS: String? = "", | ||
| val LATITUDE: String? = "", | ||
| val LONGITUD: String? = "", | ||
| val LONGITUDE: String? = "", |
There was a problem hiding this comment.
Fixed typo on LONGITUDE.
| newIncident.stateName = it.STATENAME ?: "" | ||
| newIncident.latitude = it.LATITUDE ?: "" | ||
| newIncident.longitude = it.LONGITUD ?: "" | ||
| newIncident.longitude = it.LONGITUDE ?: "" |
There was a problem hiding this comment.
Fixed typo on LONGITUDE reference.
| if (retrofit == null) { | ||
| // create it | ||
| retrofit = retrofit2.Retrofit.Builder() | ||
| retrofit = Retrofit.Builder() |
There was a problem hiding this comment.
I understand this is boilerplate, but specifying retrofit2 is not necessary as it has already been imported.
| if(result.Results[0].isNotEmpty()){ | ||
| result.Results[0].forEach{ | ||
| val newIncident: Incident = Incident() | ||
| val newIncident = Incident() |
There was a problem hiding this comment.
Redundancy on newIncident. Shortened it up.
| var hasCaseId400434 = false | ||
| allIncidents!!.forEach { | ||
| if(it.caseId.equals("400434")){ | ||
| if(it.caseId == "400434"){ |
There was a problem hiding this comment.
Shifted this over to a binary operator to reduce technical debt.
| private val DarkColorPalette = darkColors( | ||
| private val darkColorPalette = darkColors( | ||
| primary = Purple200, | ||
| primaryVariant = Purple700, | ||
| secondary = Teal200 | ||
| ) | ||
|
|
||
| private val LightColorPalette = lightColors( | ||
| private val lightColorPalette = lightColors( |
There was a problem hiding this comment.
Changed these to fit Kotlin naming conventions. Camel Case seems appropriate considering the data that these values hold.
| DarkColorPalette | ||
| darkColorPalette | ||
| } else { | ||
| LightColorPalette | ||
| lightColorPalette |
There was a problem hiding this comment.
Changed the names when called to fix errors caused by renaming.
|
Several good suggestions here that reduce technical debt. I recommend the group merge this branch. |
Description of the project:
FreeWays is an application that pulls live traffic / accident data to help you and others stay safe while on the road. It also helps you plan efficient driving routes.
What I learned:
From this code review, I learned quite a bit about cleaning up code. There were quite a few redundancies in the code that I was able to fix and hopefully these suggestions warrant a merge. I also used my previous knowledge of Kotlin naming conventions to fix some various issues that I found within the naming of certain variables. Finally, I learned about function visibility.