Conversation
…y, it only changes a TextView based on data from Firestore in the activity main in order to test it. To test, click on a tab beside home, then click back on home, and the TextView should change.
| fun setText(textView: TextView) { | ||
| db.collection(collectionName).document(testDoc).get() | ||
| .addOnSuccessListener { | ||
| val tempStr = it.get("description") | ||
| if(tempStr is String) | ||
| textView.text = tempStr | ||
| else println("Value from Firestore is not of type String") | ||
| } | ||
| } |
There was a problem hiding this comment.
I'm a little fuzzy on what is going on in this function, especially in light of what is in the MainActivity. It appears that this function gets a document from the collection then sets the textView's text to the description from the document. It seems like a lot of what is in this file is just proof of concept that you can get data from the DB. I'm however hesitant to accept it into the repo in that state. The DatabaseManager should just be reading and writing from the DB. We should probably have models for each item type such as Event. Then in the MainActivity you would have something like
R.id.navigation_events -> {
textMessage.setText("Events")
textMessage.text = event.get("description")
return@OnNavigationItemSelectedListener true
}
As a rule of thumb also avoid variable names like tmpStr I'm fine with something being a temp variable, but tell me what it is temporarily storing (e.g. tmpDescription). Descriptive variable naming helps for a better comment/code sturcture. Your code should tell me "what" (in a pretty clear way) and your comments should tell me "why".
Sorry about the length of this comment, I just want to make sure we get the data modeling set up well at the start since it is the core to the whole application.
Currently, it only changes a TextView based on data from Firestore in the activity main in order to test it. To test, click on a tab beside home, then click back on home, and the TextView should change.