Skip to content
Extraits de code Groupes Projets
Valider c42d061b rédigé par Rémy Mathieu's avatar Rémy Mathieu
Parcourir les fichiers

Added friends activity w layout + patch account activity

parent 32312add
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!32Remy
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="be.lepl1509group13.workoutwarrior" >
package="be.lepl1509group13.workoutwarrior">
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
......@@ -9,7 +11,10 @@
android:label="@string/app_name"
android:roundIcon="@drawable/logo"
android:supportsRtl="true"
android:theme="@style/Theme.WorkoutWarrior" >
android:theme="@style/Theme.WorkoutWarrior">
<activity
android:name=".AddFriendActivity"
android:exported="false" />
<activity
android:name=".AccountActivity"
android:exported="false" />
......@@ -20,7 +25,7 @@
<activity android:name=".ProgramCreationActivity" />
<activity
android:name=".MainActivity"
android:exported="true" >
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......@@ -32,6 +37,5 @@
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
<uses-permission android:name="android.permission.VIBRATE"/>
</manifest>
\ No newline at end of file
package be.lepl1509group13.workoutwarrior;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.Intent;
......@@ -30,12 +33,11 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class AccountActivity extends AppCompatActivity {
public class AccountActivity extends AppCompatActivity implements FriendsAdapter.OnItemClickListener{
private FirebaseAuth mAuth;
private final FirebaseDatabase firebaseDb = FirebaseDatabase.getInstance();
private DatabaseReference db;
private Button logout;
private TextView title;
@SuppressLint("MissingInflatedId")
......@@ -48,18 +50,24 @@ public class AccountActivity extends AppCompatActivity {
FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser != null){
db = firebaseDb.getReference("Account_pseudo");
//get which button is clicked in the navigation
Intent intent = this.getIntent();
String item = intent.getStringExtra("item");
if(Objects.equals(item, "Mon compte")){
//todo
setContentView(R.layout.activity_account);
getPseudo(currentUser);
} else if (Objects.equals(item, "Mes amis")) {
//todo
}
setContentView(R.layout.activity_account);
setContentView(R.layout.activity_account_friends);
db = firebaseDb.getReference("Account_pseudo");
getPseudo(currentUser);
Button add_friend = findViewById(R.id.friends_add);
add_friend.setOnClickListener(view -> addFriend());
db = firebaseDb.getReference("Friends");
getFriends("remy");
}
}else{
setContentView(R.layout.activity_account_login);
......@@ -77,9 +85,47 @@ public class AccountActivity extends AppCompatActivity {
ImageButton return_btn = findViewById(R.id.return_from_account);
return_btn.setOnClickListener(view -> finish());
}
private void addFriend() {
Intent intent = new Intent(AccountActivity.this, AddFriendActivity.class);
startActivity(intent);
}
public void onItemClick(String friend_pseudo) {
//todo when a friend is clicked
Log.d("friend_pseudo", "onItemClick: " + friend_pseudo);
}
logout = findViewById(R.id.logout);
logout.setOnClickListener(view -> logout());
private void getFriends(String pseudo) {
db.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String[][] friendsData = new String[(int) dataSnapshot.getChildrenCount()][];
int i = 0;
for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
String pseudo = childSnapshot.getKey();
String friend_pseudo = childSnapshot.getValue(String.class);
Log.d("TAG", "Key: " + pseudo + " Value: " + friend_pseudo + " & id :"+i);
friendsData[i] = new String[]{pseudo, friend_pseudo};
i ++;
}
RecyclerView recyclerView = findViewById(R.id.friends_view_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(AccountActivity.this));
FriendsAdapter adapter = new FriendsAdapter(friendsData);
adapter.setOnItemClickListener(AccountActivity.this);
recyclerView.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
// Failed to read value
}
});
}
private void getPseudo(FirebaseUser currentUser) {
......@@ -99,7 +145,7 @@ public class AccountActivity extends AppCompatActivity {
String pseudo = data.getValue().toString();
title.setText("Vous êtes connecté !\n" + currentUser.getEmail() + " & " + id_user + " & " + pseudo);
title.setText("Vous êtes connecté en tant que :\n" + pseudo + "\n avec l'adresse mail :\n" + currentUser.getEmail());
field_pseudo_layout.setVisibility(View.INVISIBLE);
register.setVisibility(View.INVISIBLE);
} catch (Exception e){
......
package be.lepl1509group13.workoutwarrior;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.widget.Button;
import android.widget.ImageButton;
import com.google.android.material.textfield.TextInputEditText;
public class AddFriendActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_friend);
getSupportActionBar().hide();
ImageButton back = findViewById(R.id.return_from_add_friend);
back.setOnClickListener(view -> finish());
Button add = findViewById(R.id.add_friend_activity_btn);
add.setOnClickListener(view -> addFriend());
}
private void addFriend() {
TextInputEditText pseudo_input = findViewById(R.id.add_friend_pseudo);
Editable pseudo_string = pseudo_input.getText();
Log.d("TRYING TO:", "addFriend: " + pseudo_string);
}
}
\ No newline at end of file
package be.lepl1509group13.workoutwarrior;
import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class FriendsAdapter extends RecyclerView.Adapter<FriendsAdapter.MyViewHolder>{
private final String[][] friendData;
private OnItemClickListener mListener;
public FriendsAdapter(String[][] data) {friendData = data;}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.friends_item, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, @SuppressLint("RecyclerView") int position) {
// Parcourir la liste et afficher le contenu de chaque tableau
String[] friend_data = friendData[position];
holder.pseudo.setText(friend_data[1]);
//holder.edit.setText(friend_data[1]);
holder.edit.setOnClickListener(view -> {
if (mListener != null) {
mListener.onItemClick(friend_data[1]);
}
});
}
@Override
public int getItemCount() {
return friendData.length;
}
public void setOnItemClickListener(OnItemClickListener listener) {
mListener = listener;
}
public interface OnItemClickListener {
void onItemClick(String friend_pseudo);
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
public TextView pseudo;
public ImageView edit;
public MyViewHolder(View itemView) {
super(itemView);
pseudo = itemView.findViewById(R.id.friend_pseudo);
edit = itemView.findViewById(R.id.friend_edit);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AccountActivity">
<TextView
android:id="@+id/account_friends_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingHorizontal="20dp"
android:textAlignment="center"
android:textSize="20sp"
android:text="@string/friends_list"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/relativeLayout" />
<ScrollView
android:id="@+id/scrollView_friends"
android:layout_width="match_parent"
android:layout_height="500dp"
android:padding="10dp"
android:fillViewport="true"
app:layout_constraintBottom_toTopOf="@+id/button_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/account_friends_title">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/friends_view_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</ScrollView>
<LinearLayout
android:id="@+id/button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:gravity="center"
android:layout_marginBottom="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="@+id/friends_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/friends_add" />
</LinearLayout>
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@color/orange"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/return_from_account"
android:layout_width="66dp"
android:layout_height="61dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:background="@color/orange"
android:paddingLeft="10dp"
android:paddingTop="1dp"
android:paddingRight="10dp"
android:paddingBottom="4dp"
android:scaleType="fitCenter"
android:src="@drawable/return_button"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AddFriendActivity">
<TextView
android:id="@+id/account_friends_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingHorizontal="20dp"
android:textAlignment="center"
android:textSize="20sp"
android:text="@string/add_friend_activity_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/relativeLayout" />
<RelativeLayout
android:id="@+id/add_friend_activity_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginTop="35dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/account_friends_title">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/add_friend_pseudo_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/add_friend_pseudo"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:hint="Pseudo" />
</com.google.android.material.textfield.TextInputLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/add_friend_activity_field">
<Button
android:id="@+id/add_friend_activity_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_friend_activity_btn_text" />
</LinearLayout>
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@color/orange"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/return_from_add_friend"
android:layout_width="66dp"
android:layout_height="61dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:background="@color/orange"
android:paddingLeft="10dp"
android:paddingTop="1dp"
android:paddingRight="10dp"
android:paddingBottom="4dp"
android:scaleType="fitCenter"
android:src="@drawable/return_button"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/friend_layout"
android:layout_width="325dp"
android:layout_height="70dp"
android:layout_marginTop="25dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="@color/light_grey"
android:padding="15dp">
<TextView
android:id="@+id/friend_pseudo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins"
android:text="Pseudo"
android:textColor="@color/white"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/friend_edit"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:src="@drawable/edit"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -18,5 +18,9 @@
<string name="welcome">"Welcome !"</string>
<string name="invalid_username">Not a valid username</string>
<string name="invalid_password">Password must be >5 characters</string>
<string name="login_failed">"Login failed"</string>
<string name="login_failed">Login failed</string>
<string name="friends_list">Voici la liste de vos amis</string>
<string name="friends_add">Ajouter des amis</string>
<string name="add_friend_activity_title">Entrez le pseudo de l\'ami à ajouter</string>
<string name="add_friend_activity_btn_text">Ajouter</string>
</resources>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter