Created
May 22, 2019 13:16
-
-
Save tmaxxdd/bdc237f67e0a06aed43cd96224ad9171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get path to data according to selected tab | |
val databaseRef = FirebaseDatabase.getInstance().getReference(ref) | |
val topics = ArrayList<Topic>() | |
databaseRef.orderByChild("index").addValueEventListener(object : ValueEventListener { | |
override fun onDataChange(data: DataSnapshot) { | |
/* | |
In the database a child contains more fields | |
than Topic model. So we have to choose which one we want to match. | |
*/ | |
data.children.forEach { | |
val item = Topic( | |
it.child("name").value?.toString(), | |
it.child("image").value?.toString(), | |
it.child("description").value?.toString() | |
) | |
topics.add(item) | |
} | |
callback.onSuccess(topics) | |
} | |
override fun onCancelled(error: DatabaseError) { | |
error.let { | |
callback.onFailure(error.toException().fillInStackTrace()) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment