Skip to content

Commit

Permalink
Merge pull request #109 from GeekLord04/maxConsis
Browse files Browse the repository at this point in the history
Issue #93 fixed - Uploading Max Consistency
  • Loading branch information
maityamit committed Feb 26, 2022
2 parents 14dfe44 + 8fb465f commit dae6c7f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .idea/gradle.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.ismaeldivita.chipnavigation.ChipNavigationBar;
import com.squareup.picasso.Picasso;

import java.util.Map;
import java.util.Objects;

import achivementtrackerbyamit.example.achivetracker.archive.ArchiveGoalFragment;
Expand All @@ -35,7 +36,7 @@ public class HomeActivity extends AppCompatActivity {

ChipNavigationBar chipNavigationBar;
String currentUserID;
DatabaseReference RootRef;
DatabaseReference RootRef,NewRef;
ImageView profile_button;

public static int confirmation = 0;
Expand Down Expand Up @@ -77,6 +78,42 @@ private void InitializeMethods() {
FirebaseAuth mAuth = FirebaseAuth.getInstance();
currentUserID = Objects.requireNonNull(mAuth.getCurrentUser()).getUid ();
RootRef= FirebaseDatabase.getInstance ().getReference ().child("Users").child(currentUserID).child("Goals").child("Active");
NewRef = FirebaseDatabase.getInstance().getReference().child("Topper").child(currentUserID);
RootRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
int max =0;
String max_con = String.valueOf(max);
String GoalName = "goal";
Topper topper = new Topper(GoalName,max_con);
NewRef.setValue(topper);
for (DataSnapshot ds : snapshot.getChildren()){
try {
Map<String,Object> map = (Map<String, Object>) ds.getValue();
Object goal_name = map.get("GoalName");
Object consis = map.get("Consistency");
int maxConsis = Integer.parseInt(String.valueOf(consis));
if (maxConsis>max) {
max = maxConsis;
GoalName = (String) goal_name;
}
}
catch (Exception e){
Toast.makeText(getApplicationContext(), ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
String goalname = GoalName;
String max_consis = String.valueOf(max);
NewRef.child("consistency").setValue(goalname);
NewRef.child("goal_Name").setValue(max_consis);
Toast.makeText(getApplicationContext(), "Pushed!", Toast.LENGTH_SHORT).show();
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package achivementtrackerbyamit.example.achivetracker;

public class Topper {
String Goal_Name;
String Consistency;

public Topper(String goal_Name, String consistency) {
Goal_Name = goal_Name;
Consistency = consistency;
}

public String getGoal_Name() {
return Goal_Name;
}

public String getConsistency() {
return Consistency;
}
}

0 comments on commit dae6c7f

Please sign in to comment.