Skip to content

Commit

Permalink
LeaderBoardActivity Search Green by UID Resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
anfaas1618 committed Sep 6, 2022
1 parent 1c61faa commit 9c76470
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/src/main/java/com/anfaas/bigeater20/Helper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.anfaas.bigeater20;

public class Helper {
public static String UID;
}
43 changes: 20 additions & 23 deletions app/src/main/java/com/anfaas/bigeater20/LeaderBoardActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class LeaderBoardActivity extends AppCompatActivity {
private static final String TAG = "LeaderBoardActivity";
Expand All @@ -54,6 +55,7 @@ public class LeaderBoardActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences UID= getSharedPreferences("UID", Context.MODE_PRIVATE);
uid_saved = UID.getString("UID", "0");
Helper.UID = uid_saved;
SharedPreferences namePref=getSharedPreferences("NAME",Context.MODE_PRIVATE);
name_Saved=namePref.getString("NAME","user");

Expand Down Expand Up @@ -102,23 +104,22 @@ public void onCancelled(@NonNull DatabaseError databaseError) {
editor.putInt("HIGH_SCORE", scoree);
editor.commit();

} else {
// MenuGameOver gameOver= new MenuGameOver(LeaderBoardActivity.this, scoree,highScore,LeaderBoardActivity.this);
// gameOver.show();
}
FirebaseAuth auth= LoginActivity.myAuth;
} // MenuGameOver gameOver= new MenuGameOver(LeaderBoardActivity.this, scoree,highScore,LeaderBoardActivity.this);
// gameOver.show();

FirebaseAuth auth= LoginActivity.myAuth;
if (uid_saved=="0") {
try {
userAuth = auth.getCurrentUser();
FirebaseDatabase userDatabase = FirebaseDatabase.getInstance();
DatabaseReference userRef = userDatabase.getReference(userAuth.getUid());
userRef.child("score").setValue(highScore);
try {
userAuth = auth.getCurrentUser();
FirebaseDatabase userDatabase = FirebaseDatabase.getInstance();
DatabaseReference userRef = userDatabase.getReference(userAuth.getUid());
userRef.child("score").setValue(highScore);

}
catch (Exception e)
{
Log.i("error",e.toString());
}
}
catch (Exception e)
{
Log.i("error",e.toString());
}

}
else {
Expand All @@ -131,7 +132,7 @@ public void onCancelled(@NonNull DatabaseError databaseError) {
listView=findViewById(R.id.list);
playerScoreList=new ArrayList<PlayerScore>();
userImageslist =new ArrayList<>();
// String Uid= activity.user.Uid;
// String Uid= activity.user.Uid;


FirebaseDatabase firebaseDatabase=FirebaseDatabase.getInstance();
Expand All @@ -141,7 +142,8 @@ public void onCancelled(@NonNull DatabaseError databaseError) {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
PlayerScore playerScore;
user1=dataSnapshot.getValue(User.class);
user1= Objects.requireNonNull(dataSnapshot.getValue(User.class));
user1.Uid = Helper.UID;
SharedPreferences settings = getSharedPreferences("HIGH_SCORE", Context.MODE_PRIVATE);
int highScore = settings.getInt("HIGH_SCORE", 0);
if (uid_saved=="0") {
Expand Down Expand Up @@ -192,7 +194,7 @@ public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

Collections.sort(playerScoreList);
Collections.reverse(playerScoreList);
ScoreAdapter fruitsAdapter=new ScoreAdapter(LeaderBoardActivity.this,playerScoreList,name_Saved);
ScoreAdapter fruitsAdapter=new ScoreAdapter(LeaderBoardActivity.this,playerScoreList,Helper.UID);

listView.setAdapter(fruitsAdapter);

Expand All @@ -217,12 +219,7 @@ public void gohome(View view)
}
public void name(View view)
{


}



public boolean dispatchKeyEvent(KeyEvent event) {

if (event.getAction() == KeyEvent.ACTION_DOWN) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/anfaas/bigeater20/ScoreAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
//Uri imageUri=Uri.parse(score1.getImageurl());
Picasso.get().load(score1.getImageurl()).placeholder(R.drawable.ic_baseline_perm_contact_calendar_24).into(circleImageView);
score.setText(String.valueOf(score1.getScore()));
if (current_player_name.equals(score1.getName())){
if (current_player_name.equals(score1.getUid())){

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ColorStateList csl = new ColorStateList(new int[][]{{}}, new int[]{Color.GREEN});
Expand Down

0 comments on commit 9c76470

Please sign in to comment.