Skip to content

Commit

Permalink
Merge pull request #176 from rkozyak/CheckSttyle
Browse files Browse the repository at this point in the history
Fixed CheckStyle
  • Loading branch information
sha0xy authored Jul 26, 2024
2 parents 4bdd19e + 0a48b55 commit fc22ff9
Show file tree
Hide file tree
Showing 11 changed files with 7,417 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public void addParticipant(String userId) {
participants.add(userId);
}

public String getNotes() { return notes; }
public String getNotes() {
return notes;
}

public void addObserver(Observer observer) {
observers.add(observer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
package com.example.healthtrack.model;

import androidx.annotation.NonNull;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class NameSortStrategy implements SortingStrategy {
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public static ArrayList<WorkoutPlan> filter(SortingStrategy strategy,
return strategy.sort(list);
}

public static ArrayList<String> challengeFilter(SortingStrategy strategy, ArrayList<String> list) {
public static ArrayList<String> challengeFilter(SortingStrategy strategy,
ArrayList<String> list) {
return strategy.challengeSort(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ public void onCancelled(@NonNull DatabaseError error) {
}
});

finishOnCreate();
}

public void finishOnCreate() {
dialog = new Dialog(AddWorkoutCommunity.this);
dialog.setContentView(R.layout.workout_plan_popout);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -78,14 +76,15 @@ protected void onCreate(Bundle savedInstanceState) {
String userId = user.getUid();

challengeId = getIntent().getStringExtra("challengeId");
DatabaseReference database = ChallengeDatabase.getInstance().getDatabaseReference().child(challengeId);
DatabaseReference database = ChallengeDatabase.getInstance().getDatabaseReference().
child(challengeId);
database.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
HashMap<String, Object> data = (HashMap<String, Object>) snapshot.getValue();
challenger = data.get("userId").toString();
deadline = data.get("deadlineMonth").toString() + "/" + data.get("deadlineDay").toString()
+ "/" + data.get("deadlineYear").toString();
deadline = data.get("deadlineMonth").toString() + "/" + data.get("deadlineDay").
toString() + "/" + data.get("deadlineYear").toString();
desc = data.get("notes").toString();
name = data.get("name").toString();
challengerNameView.setText(challenger);
Expand All @@ -102,7 +101,8 @@ public void onCancelled(@NonNull DatabaseError error) {

database.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
public void onChildAdded(@NonNull DataSnapshot snapshot,
@Nullable String previousChildName) {
if (snapshot.getKey().equals("workoutPlans")) {
ArrayList<HashMap<String, Object>> data =
(ArrayList<HashMap<String, Object>>) snapshot.getValue();
Expand All @@ -116,12 +116,14 @@ public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previo
int sets = Integer.parseInt(dataMap.get("sets").toString());
String notes = (String) dataMap.get("notes");
int time = Integer.parseInt(dataMap.get("time").toString());
WorkoutPlan workoutPlan = new WorkoutPlan(userId, name, calsPerSet, sets, repsPerSet, time, notes);
WorkoutPlan workoutPlan = new WorkoutPlan(userId, name, calsPerSet, sets,
repsPerSet, time, notes);

workoutPlanArrayList.add(workoutPlan);
}
} else if (snapshot.getKey().equals("participants")) {
HashMap<String, String> participantData = (HashMap<String, String>) snapshot.getValue();
HashMap<String, String> participantData =
(HashMap<String, String>) snapshot.getValue();
ArrayList<String> participantArray = new ArrayList<>(participantData.values());

for (int i = 0; i < participantArray.size(); i++) {
Expand All @@ -130,7 +132,8 @@ public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previo
}
}
} else if (snapshot.getKey().equals("completed")) {
HashMap<String, String> completedData = (HashMap<String, String>) snapshot.getValue();
HashMap<String, String> completedData =
(HashMap<String, String>) snapshot.getValue();
ArrayList<String> completedArray = new ArrayList<>(completedData.values());
for (int i = 0; i < completedArray.size(); i++) {
if (!completed.contains(completedArray.get(i))) {
Expand All @@ -140,13 +143,16 @@ public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previo
}
participantView.setAdapter(new UserAdapter(ChallengeDetails.this, participants));
completedView.setAdapter(new UserAdapter(ChallengeDetails.this, completed));
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this, workoutPlanArrayList));
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this,
workoutPlanArrayList));
}

@Override
public void onChildChanged(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
public void onChildChanged(@NonNull DataSnapshot snapshot,
@Nullable String previousChildName) {
if (snapshot.getKey().equals("participants")) {
HashMap<String, String> participantData = (HashMap<String, String>) snapshot.getValue();
HashMap<String, String> participantData =
(HashMap<String, String>) snapshot.getValue();
ArrayList<String> participantArray = new ArrayList<>(participantData.values());

for (int i = 0; i < participantArray.size(); i++) {
Expand All @@ -155,7 +161,8 @@ public void onChildChanged(@NonNull DataSnapshot snapshot, @Nullable String prev
}
}
} else if (snapshot.getKey().equals("completed")) {
HashMap<String, String> completedData = (HashMap<String, String>) snapshot.getValue();
HashMap<String, String> completedData =
(HashMap<String, String>) snapshot.getValue();
ArrayList<String> completedArray = new ArrayList<>(completedData.values());
for (int i = 0; i < completedArray.size(); i++) {
if (!completed.contains(completedArray.get(i))) {
Expand All @@ -165,26 +172,33 @@ public void onChildChanged(@NonNull DataSnapshot snapshot, @Nullable String prev
}
participantView.setAdapter(new UserAdapter(ChallengeDetails.this, participants));
completedView.setAdapter(new UserAdapter(ChallengeDetails.this, completed));
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this, workoutPlanArrayList));
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this,
workoutPlanArrayList));
}

@Override
public void onChildRemoved(@NonNull DataSnapshot snapshot) {
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this, workoutPlanArrayList));
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this,
workoutPlanArrayList));
}

@Override
public void onChildMoved(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this, workoutPlanArrayList));
public void onChildMoved(@NonNull DataSnapshot snapshot,
@Nullable String previousChildName) {
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this,
workoutPlanArrayList));
}

@Override
public void onCancelled(@NonNull DatabaseError error) {
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this, workoutPlanArrayList));
workoutView.setAdapter(new WorkoutPlanAdapter(ChallengeDetails.this,
workoutPlanArrayList));
}
});
finishOnCreate(userId);
}


public void finishOnCreate(String userId) {
Button addChallengeButton = findViewById(R.id.addChallengeButton);
addChallengeButton.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -268,6 +282,4 @@ public void onClick(View v) {
}
});
}


}
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
package com.example.healthtrack.view;
import static androidx.core.content.ContextCompat.startActivity;

import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;

import com.example.healthtrack.R;
import com.example.healthtrack.model.ChallengeDatabase;
import com.example.healthtrack.model.CommunityChallenge;
import com.example.healthtrack.model.Workout;
import com.example.healthtrack.model.WorkoutPlan;
import com.example.healthtrack.viewModel.WorkoutViewModel;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.HashMap;

public class CommunityChallengeAdapter extends RecyclerView.Adapter<CommunityChallengeAdapter.MyViewHolder> {
public class CommunityChallengeAdapter
extends RecyclerView.Adapter<CommunityChallengeAdapter.MyViewHolder> {
private Context context;
private ArrayList<String> list;

Expand All @@ -46,10 +32,12 @@ public CommunityChallengeAdapter(@NonNull Context context, ArrayList<String> lis

@NonNull
@Override
public CommunityChallengeAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
public CommunityChallengeAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.challenge_item, parent, false);

CommunityChallengeAdapter.MyViewHolder myViewHolder = new CommunityChallengeAdapter.MyViewHolder(v);
CommunityChallengeAdapter.MyViewHolder myViewHolder =
new CommunityChallengeAdapter.MyViewHolder(v);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -63,9 +51,11 @@ public void onClick(View v) {
}

@Override
public void onBindViewHolder(@NonNull CommunityChallengeAdapter.MyViewHolder holder, int position) {
public void onBindViewHolder(@NonNull CommunityChallengeAdapter.MyViewHolder holder,
int position) {
String challengeId = list.get(position);
DatabaseReference database = ChallengeDatabase.getInstance().getDatabaseReference().child(challengeId);
DatabaseReference database =
ChallengeDatabase.getInstance().getDatabaseReference().child(challengeId);
database.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
Expand All @@ -39,14 +35,10 @@
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class CommunityScreen extends AppCompatActivity implements Observer {
// instance variables
Expand Down Expand Up @@ -98,7 +90,8 @@ protected void onCreate(Bundle savedInstanceState) {

db.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
public void onChildAdded(@NonNull DataSnapshot snapshot,
@Nullable String previousChildName) {
String workoutId = snapshot.getKey();
HashMap<String, Object> data = (HashMap<String, Object>) snapshot.getValue();
int year = Integer.parseInt(data.get("deadlineYear").toString());
Expand All @@ -121,34 +114,41 @@ public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previo
unfilteredList.add(workoutId);
}
nameList.add(data.get("name").toString());
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this, challengeList));
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this,
challengeList));
}

@Override
public void onChildChanged(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
public void onChildChanged(@NonNull DataSnapshot snapshot,
@Nullable String previousChildName) {
String workoutId = snapshot.getKey();
HashMap<String, Object> data = (HashMap<String, Object>) snapshot.getValue();
nameList.add(data.get("name").toString());
challengeList.clear();
unfilteredList.clear();
challengeList.add(workoutId);
unfilteredList.add(workoutId);
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this, challengeList));
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this,
challengeList));
}

@Override
public void onChildRemoved(@NonNull DataSnapshot snapshot) {
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this, challengeList));
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this,
challengeList));
}

@Override
public void onChildMoved(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this, challengeList));
public void onChildMoved(@NonNull DataSnapshot snapshot,
@Nullable String previousChildName) {
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this,
challengeList));
}

@Override
public void onCancelled(@NonNull DatabaseError error) {
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this, challengeList));
recyclerView.setAdapter(new CommunityChallengeAdapter(CommunityScreen.this,
challengeList));
}
});

Expand Down Expand Up @@ -197,18 +197,26 @@ public void onClick(View v) {
}
});

finishOnCreate();

}

public void finishOnCreate() {
// Add Challenge Button
Button addChallengeButton = findViewById(R.id.addChallengeButton);
addChallengeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.show();
TextView workoutPlanDisplay = dialog.findViewById(R.id.workoutPlanDisplay);
String workoutPlanString = "Workout Plans: ";
// if (AddWorkoutCommunity.returnList != null && !AddWorkoutCommunity.returnList.isEmpty()) {
// for (WorkoutPlan plan : AddWorkoutCommunity.returnList) {
// workoutPlanString = String.join(", ", workoutPlanString, plan.getName());
// }
// }
/*
if (AddWorkoutCommunity.returnList != null
&& !AddWorkoutCommunity.returnList.isEmpty()) {
for (WorkoutPlan plan : AddWorkoutCommunity.returnList) {
workoutPlanString = String.join(", ", workoutPlanString, plan.getName());
}
}
*/
workoutPlanDisplay.setText(workoutPlanString);
}
});
Expand Down Expand Up @@ -287,12 +295,9 @@ public void onClick(View v) {
dialog.dismiss();
}
});

}




@Override
public void update(String message) {
// Update UI components with the new status
Expand Down
Loading

0 comments on commit fc22ff9

Please sign in to comment.