Triviums Mobile App (UPDATE: Show Users)

in #utopian-io6 years ago

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.java class :
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.java class 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
Sort:  

Thank you for your contribution. A nice little update to the project and its good to see you are continually progressing with the app. Few thoughts :

  1. It's always better not to use path like https://github.com/princessdharmy/triviums/pull/16/files#diff-6889d0299409e1fd2600e5bd55d17c7eR49 but to use relative path.
  2. You are showing category even if it is not connected, is that correct? https://github.com/princessdharmy/triviums/pull/16/files#diff-9e6f31efe8684a67503ce75a99bdeeb8R89

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

@codingdefined thank you for your review and comments.
I would like to comment on your thoughts:

  1. I don't understand what the path means, I mean the actual problem.
  2. When a user launches the app after installation, it's ideal not to leave the main screen blank or to exit the app because there is no internet connection. So, this is the reason I persisted it in Firestore for offline query. No other action can be performed after this when there is no internet

I am saying that since you are using the full path as C:......, its better to not use like this and usr a relative path.

Alright thanks. Noted!

Thank you for your review, @codingdefined! Keep up the good work!

Hey, @princessdharmy!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @princessdharmy! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!