-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from rkozyak/Brian
Made display for Challenges
- Loading branch information
Showing
5 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
HealthTrack/app/src/main/java/com/example/healthtrack/view/CommunityChallengeAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.example.healthtrack.view; | ||
import android.content.Context; | ||
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> { | ||
private Context context; | ||
private ArrayList<String> list; | ||
|
||
public CommunityChallengeAdapter(@NonNull Context context, ArrayList<String> list) { | ||
this.context = context; | ||
this.list = list; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public CommunityChallengeAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
View v = LayoutInflater.from(context).inflate(R.layout.challenge_item, parent, false); | ||
return new MyViewHolder(v); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull CommunityChallengeAdapter.MyViewHolder holder, int position) { | ||
String challengeID = list.get(position); | ||
DatabaseReference database = ChallengeDatabase.getInstance().getDatabaseReference().child(challengeID); | ||
database.addValueEventListener(new ValueEventListener() { | ||
@Override | ||
public void onDataChange(@NonNull DataSnapshot snapshot) { | ||
HashMap<String, String> data = (HashMap<String, String>) snapshot.getValue(); | ||
holder.userID.setText(data.get("userId")); | ||
holder.challengeName.setText(data.get("name")); | ||
} | ||
|
||
@Override | ||
public void onCancelled(@NonNull DatabaseError error) { | ||
|
||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return list.size(); | ||
} | ||
|
||
public static class MyViewHolder extends RecyclerView.ViewHolder { | ||
private TextView userID; | ||
private TextView challengeName; | ||
|
||
public MyViewHolder(@NonNull View itemView) { | ||
super(itemView); | ||
|
||
userID = itemView.findViewById(R.id.challengeUser); | ||
challengeName = itemView.findViewById(R.id.challengeName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.cardview.widget.CardView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:cardElevation="10dp" | ||
app:cardCornerRadius="0dp"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/challengeName" | ||
android:fontFamily="@font/federo" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="25dp" | ||
android:text="WORKOUT PLAN" | ||
android:textColor="@color/black" | ||
android:textSize="30sp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<TextView | ||
android:id="@+id/challengeUser" | ||
android:fontFamily="@font/darker_grotesque_semibold" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="24dp" | ||
android:layout_marginTop="10dp" | ||
android:layout_marginEnd="24dp" | ||
android:hint="Author" | ||
android:textSize="16sp" | ||
app:layout_constraintEnd_toEndOf="@+id/challengeName" | ||
app:layout_constraintStart_toStartOf="@id/challengeName" | ||
app:layout_constraintTop_toBottomOf="@id/challengeName" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</androidx.cardview.widget.CardView> |