Loading app/src/main/java/com/example/game2d/FirebaseActivity.java +5 −3 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class FirebaseActivity extends AppCompatActivity { int bestChalk; float percent; String username = "temp userame"; String username = "scrub mommy"; //access the average accuracy data from nameResultActivity (does not work) Loading Loading @@ -109,7 +109,9 @@ public class FirebaseActivity extends AppCompatActivity { public void onClick(View view) { // switch back to main activity Intent intent = new Intent(FirebaseActivity.this, LeaderboardActivity.class); intent.putExtra("scoreboard_object", big_userScoreMap); startActivity(intent); } }); //--------------------------------------------------------------------------------- Loading @@ -127,7 +129,7 @@ public class FirebaseActivity extends AppCompatActivity { //db.collection("users").document("new33").set(user2); String userId = "e9kSCVavuhpXiIGNMkAh"; String userId = "e9kSCVavuhpXiIGNMkAhhh"; DocumentReference userRef = db.collection("leaderboard").document(userId); userRef.set(user2, SetOptions.merge()); Loading Loading @@ -161,7 +163,7 @@ public class FirebaseActivity extends AppCompatActivity { else { //else it's the username Log.d(TAG,"the username: "+scoreObj.toString()); } big_userScoreMap.add(scoreObj.toString(),score); // add <username,score> into the big big_userScoreMap.scoreboard.put(scoreObj.toString(), score); } } Loading app/src/main/java/com/example/game2d/LeaderboardActivity.java +21 −1 Original line number Diff line number Diff line package com.example.game2d; import static com.example.game2d.MapUtil.sortByValue; //import static com.example.game2d.FirebaseActivity.; //import static com.example.game2d.Scoreboard import android.annotation.SuppressLint; import android.content.Intent; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; Loading Loading @@ -38,6 +39,10 @@ public class LeaderboardActivity extends AppCompatActivity { scoreListLayout = findViewById(R.id.score_list_layout); // Create map to store usernames and scores Intent intent = getIntent(); Scoreboard scoreboardObj = (Scoreboard) intent.getSerializableExtra("scoreboard_object"); HashMap<String, Integer> scoreMap = new HashMap<String, Integer>(); scoreMap.put("Bob", 75); scoreMap.put("Dave", 50); Loading @@ -62,6 +67,19 @@ public class LeaderboardActivity extends AppCompatActivity { HashMap<String, Integer> sortedScoreMap = new HashMap<String, Integer>(); sortedScoreMap = (HashMap<String, Integer>) sortByValue(scoreMap); for (String username : scoreboardObj.scoreboard.keySet()) { Log.d("SCORETEXT", username + String.valueOf(scoreboardObj.scoreboard.get("scrub daddy"))); // Create a textview for the username and score TextView scoreView = new TextView(this); scoreView.setTextSize(20); scoreView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); scoreView.setFontFeatureSettings("press_start_2p"); scoreView.setText(String.format("%s: %d", username, scoreboardObj.scoreboard.get("scrub daddy"))); // Add the TextView to the LinearLayout scoreListLayout.addView(scoreView); } /* // Loop through keys (usernames) and add username and score to the layout for (String username : sortedScoreMap.keySet()) { // Create a textview for the username and score Loading @@ -73,5 +91,7 @@ public class LeaderboardActivity extends AppCompatActivity { // Add the TextView to the LinearLayout scoreListLayout.addView(scoreView); } */ } } app/src/main/java/com/example/game2d/Scoreboard.java +6 −1 Original line number Diff line number Diff line package com.example.game2d; import java.io.Serializable; import java.util.HashMap; import java.util.Map; public class Scoreboard { public class Scoreboard implements Serializable { public Map<String, Long> scoreboard; Scoreboard() { scoreboard = new HashMap<String, Long>(); } public void add(String username, long score) { if (scoreboard != null) { scoreboard.put(username,score); Loading Loading
app/src/main/java/com/example/game2d/FirebaseActivity.java +5 −3 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class FirebaseActivity extends AppCompatActivity { int bestChalk; float percent; String username = "temp userame"; String username = "scrub mommy"; //access the average accuracy data from nameResultActivity (does not work) Loading Loading @@ -109,7 +109,9 @@ public class FirebaseActivity extends AppCompatActivity { public void onClick(View view) { // switch back to main activity Intent intent = new Intent(FirebaseActivity.this, LeaderboardActivity.class); intent.putExtra("scoreboard_object", big_userScoreMap); startActivity(intent); } }); //--------------------------------------------------------------------------------- Loading @@ -127,7 +129,7 @@ public class FirebaseActivity extends AppCompatActivity { //db.collection("users").document("new33").set(user2); String userId = "e9kSCVavuhpXiIGNMkAh"; String userId = "e9kSCVavuhpXiIGNMkAhhh"; DocumentReference userRef = db.collection("leaderboard").document(userId); userRef.set(user2, SetOptions.merge()); Loading Loading @@ -161,7 +163,7 @@ public class FirebaseActivity extends AppCompatActivity { else { //else it's the username Log.d(TAG,"the username: "+scoreObj.toString()); } big_userScoreMap.add(scoreObj.toString(),score); // add <username,score> into the big big_userScoreMap.scoreboard.put(scoreObj.toString(), score); } } Loading
app/src/main/java/com/example/game2d/LeaderboardActivity.java +21 −1 Original line number Diff line number Diff line package com.example.game2d; import static com.example.game2d.MapUtil.sortByValue; //import static com.example.game2d.FirebaseActivity.; //import static com.example.game2d.Scoreboard import android.annotation.SuppressLint; import android.content.Intent; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; Loading Loading @@ -38,6 +39,10 @@ public class LeaderboardActivity extends AppCompatActivity { scoreListLayout = findViewById(R.id.score_list_layout); // Create map to store usernames and scores Intent intent = getIntent(); Scoreboard scoreboardObj = (Scoreboard) intent.getSerializableExtra("scoreboard_object"); HashMap<String, Integer> scoreMap = new HashMap<String, Integer>(); scoreMap.put("Bob", 75); scoreMap.put("Dave", 50); Loading @@ -62,6 +67,19 @@ public class LeaderboardActivity extends AppCompatActivity { HashMap<String, Integer> sortedScoreMap = new HashMap<String, Integer>(); sortedScoreMap = (HashMap<String, Integer>) sortByValue(scoreMap); for (String username : scoreboardObj.scoreboard.keySet()) { Log.d("SCORETEXT", username + String.valueOf(scoreboardObj.scoreboard.get("scrub daddy"))); // Create a textview for the username and score TextView scoreView = new TextView(this); scoreView.setTextSize(20); scoreView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); scoreView.setFontFeatureSettings("press_start_2p"); scoreView.setText(String.format("%s: %d", username, scoreboardObj.scoreboard.get("scrub daddy"))); // Add the TextView to the LinearLayout scoreListLayout.addView(scoreView); } /* // Loop through keys (usernames) and add username and score to the layout for (String username : sortedScoreMap.keySet()) { // Create a textview for the username and score Loading @@ -73,5 +91,7 @@ public class LeaderboardActivity extends AppCompatActivity { // Add the TextView to the LinearLayout scoreListLayout.addView(scoreView); } */ } }
app/src/main/java/com/example/game2d/Scoreboard.java +6 −1 Original line number Diff line number Diff line package com.example.game2d; import java.io.Serializable; import java.util.HashMap; import java.util.Map; public class Scoreboard { public class Scoreboard implements Serializable { public Map<String, Long> scoreboard; Scoreboard() { scoreboard = new HashMap<String, Long>(); } public void add(String username, long score) { if (scoreboard != null) { scoreboard.put(username,score); Loading