Android App - Gym League Table

This is an application which I created in Android Studio and wrote in Java to improve my programming abilities. 

How the app works

Step 1 -logging in or signing up
Under the surface:
The app loads the intent filter (MainActivity) which then goes to onResume and checks if user is logged in by check if  FirebaseAuth.getInstance().id is not null - If null this will start AcrtivityLogIn

User:
When a user signs up the app will take four videos to prove your lifts in the gym:
1. Bench Press 
2. Squat
3. Deadlift
4. Over Head Press

Step 2 - displaying and updating user data 
Under the surface:
The videos are stored in different files for each compound lift with the key being the FirebaseAuth.getInstance().id. Adding and removing listeners on the current logged in user data. 

User:
The above user input information is then stored in Firebase Cloud Firestore and can be accessed and updated in the profile activity/page. 


Step 3 - Creating a league 
Under the surface:
In ActivityMain there is a fragment called "FragmentStrengthLeagues" this holds two buttons to create or join a league as well as recycler view display the all the leagues you are part of regardless if you created or joined them. 

Creating a league:
1. In the alert dialog enter a league name of your choice
2a. leagueModelSingleton.setLeagueTable(nameOfLeague, callback) 
2b.GetLeagueTable(callback) returns a list of all the league pins you are part of regardless if you created or join them. If you are not part of any returns empty arrayList.
2c. Add the new league pin you just created to the current list from step 2b 
3d. Get leagues only you created and the new league pin to this list.
3e. Write the newly created league to the collection called "allLeagueTables" the document id is the league pin.
- league name
-league pin
- start date
- userId of the creator 
3f. Write and override arraylist with new data added to the old arraylist to the collection "userLeagueTables" 
- flagged users in this league (ArrayList)
-leagueMasterId (FirebaseAuth.id)
-leaguesCreated (all leagues you are part of regardless if you created or joined) (ArrayList)
-OnlyLeaguesYouCreated (ArrayList)

User:
Once you're on the ActivityMain after signing up or logging in successfully. You're now able to:
 - Create a league which would make you the league admin. 
- You're now able to join a league but you would not be an admin.
- This updates UI in real time as we are adding and removing database listeners 

Step 4 - Joining a league 
Under the surface:
1a. Enter the league pin of the league you would like to join. leagueModelSingleton.addToLeague(pin)
1b. Check if this user already has this pin in the leaguesCreated - if so then stop user joining
1c. Get the league from the collection "allUserLeagues" with the pin the user entered - to check if league is valid
2. Add league pin to user
2a. Get all the leagues you are part of "leaguesCreated"regardless if you created or joined and add the league pin you entered to this list
2b. override the document in the collection "userLeagueTables" with the new list to leaguesCreated. Because you have listeners this will update the UI in real time.

Step 5- Display the leagues you are part of
1. go to "userLeagueTables" and get all pins from "leaguesCreated" (every league you are part of)
2. go to collection "allLeaguePins"and get every league pin and iterate through them and see if what pins match the pins from "leaguesCreated"
3. When they match get all league data (name, date, userId) and put in an object called createdLeague add that to an arraylist and return to UI and pass data into adapter

Step 6- Display league participants 
1. Get all documents in "userLeagueTables" and loop through them
1a. Get the String from the field "leagueMasterId" (this is the user auth id)
1b. Get the list of league pins from the field "leaguesCreated" (this is all league pins the user is part of)
1c. Check if the list of league pins contains the league pin that was passed in when starting this activity - if it does then add the "leagueMasterId" to the return array
1d. returns the list of  "leagueMasterId" (auth ids)

2. Get all documents from the collection "workoutProfiles" and loop through them all
2a. Get the pin (pin is auth id)
2a. Inner loop of "leagueMasterId"(auth id) from above in 1
2b. If the pin (auth id) from "workoutProfiles" match leagueMasterId then get the workout profile for that user and add tot eh arrayList that will be returned and put into the adapter

Step 7 - Filtering 
1. Press filter icon which starts filter activity with a startActivityForResult
2. Filter activity returns an id (int) and according to that int the list of participants in the league is sorted which then sets the adaptor.
3. The type (int) sets the highlighted filter choice.

Step 8 - Flagging 
1. If you are the league creator only you will be bale to see a flag on each league participant
2. In collection "allLeagueTables" if you flag a user there userId will be added to the flags list and to remove flag the user id will be removed from the flag list.

Step 9 - Making a claim
1. Updating a lift with a new video and new number input. The new video will override the old video in the storage. No video history is saved.

Step 10 - Leave a league which you created
1. You can not leave a league you created unless you are the only participant. Check only your userid in "userLeagueTable" has that league pin.
2. If you are the only user in the league then you may leave. This will delete the document in "allLeagueTables" because no user will be using it. Also deletes document in "userLeagueTables" as you are not a part of any league.
3.If you are part of multiple leagues but want to delete one of them which only you are in, this will delete the document in "allLeagueTables" and then remove the league pin from both "leaguesCreated" and "onlyLeaguesYouCreated"

Step 11 - Leave a league which you joined
1.Get the leagues you participate in "leaguesCreated" remove the league pin from this list and then send the list back to the database.
2. If you leave a league you joined and your not part of any other leagues, the document from "userLeagueTables" will be deleted

Comments

Popular posts from this blog

Basic Overview of Microsoft Azure?

Understanding the basics of REST API with HTTP and JSON