I am developing an app in Kotlin and have already set up my Firebase database. I am able to write data to my database, however, I am unable to read data from it. Here is an image of my database :
I would like to retrieve a list of all the headings in either Basics
, Functions
or Loops
. For more context, this is an app to teach people how to code in Kotlin and under the progress tab, I'm basically listing all the topics which the user has completed in my app. So, how can I query my database to retrieve a list of all the headings listed under say Basics
? I would want preferably juts a list of strings containing strings Condition
and Datatype
. I just need the names of the topics which they have completed for that particular section (in this case is Basics
). So basically, I need the child names of Basics
, Functions
and Loops
.
My progress class:
package nus.is3261.kotlinapp
import com.google.firebase.database.IgnoreExtraProperties
@IgnoreExtraProperties
class Progress {
var completed: String? = null
constructor() {
// Default constructor required for calls to DataSnapshot.getValue(Post.class)
}
constructor(time: String) {
this.completed = time
}
}
How I write data to my db:
/**
* For firebase database
*/
private fun submitProgress(str: String, chapter: Int) {
val currentUser = mAuth!!.currentUser
// if user is not logged in, don't write
currentUser?:return
val time = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().time)
val progress = Progress(time)
when(chapter){
1 -> mProgressReference!!.child(currentUser.uid!!).child("Progress").child("Basics").child(str).setValue(progress)
2 -> mProgressReference!!.child(currentUser.uid!!).child("Progress").child("Loops").child(str).setValue(progress)
3 -> mProgressReference!!.child(currentUser.uid!!).child("Progress").child("Functions").child(str).setValue(progress)
}
}