Published: 03 Dec 2018 › Updated: 03 Dec 2018
Triviums Mobile App (UPDATE: Show Users)
Repository
https://github.com/princessdharmy/triviums
History
Fixes
One of the major problems Android Developers encounter is App Crash with some Exceptions. In order to tackle this problem, here is my implementation:
- Firstly, I added a NetworkBoundResource class
FirestoreResultResponse.javato encapsulate both the data and state
public class FirestoreResultResponse {
Map<String, Object> data;
String error;
public FirestoreResultResponse() {
}
public FirestoreResultResponse(Map<String, Object> data, String error) {
this.data = data;
this.error = error;
}
}
- Secondly, I had some issues while fetching data from Firestore; once there is a bad internet connection, the app crashes. So, in order to avoid the FirebaseFirestoreException, I used a try-catch in the
StageRepository.javaclass :
private void fetchProgress(String categoryName, ProgressCallback callback) {
...
docRef.get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
}
try {
callback.onCallback(new FirestoreResultResponse(task.getResult().getData(), null));
} catch (Exception e) {
if (e instanceof FirebaseFirestoreException) {
callback.onCallback(new FirestoreResultResponse(null, e.getLocalizedMessage()));
}
e.printStackTrace();
}
})
.addOnFailureListener(error -> {
callback.onCallback(new FirestoreResultResponse(null, error.toString()));
});
}
New Features
- Show Users
As stated in the roadmap of my previous post, it's somewhat interesting to know how many people are playing the game you are involved in. So, I decided to get and display all users that are using the app or playing the game.
Implementation
- This code snippet fetches all the users in the database - Firestore in the
LeaderboardRepository.java
private void fetchUsers(UserCallback callback){
CollectionReference collection = firestore.collection("users");
collection.get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
document = task.getResult().getDocuments();
}
try {
callback.onCallback(document);
} catch (Exception e) {
if (e instanceof FirebaseFirestoreException) {
}
e.printStackTrace();
}
})
.addOnFailureListener(error -> {
});
}
- The
LeaderboardFragment.javaclass gets the user data and display
public void getUsers() {
viewModel.getUsers().observe(getViewLifecycleOwner(), response -> {
binding.loader.setVisibility(View.GONE);
binding.peopleRecyclerview.setVisibility(View.VISIBLE);
if (response != null) {
adapter.updateData(response);
}
});
}
Important resources
Roadmap
- Leaderboard implementation:
Display all users
Add users to compete
Remove users from competition - Display of users' quiz achievements
Leave Triviums Mobile App (UPDATE: Show Users) to:
Read more #utopian-io posts
Best Posts From princessdharmy
We have not curated any of princessdharmy's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From princessdharmy
- Triviums Mobile App (UPDATE: Show Users)
- Triviums Mobile App
- Simple steps to make up to $100 with free airdrop
- Reimplementing Android Quiz App (UPDATE 2: Update and Delete Data)
- Reimplementing Android Quiz App (UPDATE: Play Quiz)
- Reimplementing Android Quiz App
- Reimplementing CrytpoNews in Native Android(UPDATE #4: Share News Functionality)
- WHALESHARES Community is Awesome - Make a Trial today!
- Reimplementing CrytpoNews in Native Android(UPDATE: Storing News in DB)
- Zumba Challenge - Mas Tembleque