From 39db6f8f76cf519100e6638ddec5c1f4753ed10f Mon Sep 17 00:00:00 2001 From: Hamlix Date: Tue, 14 Mar 2017 12:55:39 +0100 Subject: [PATCH 01/14] Create of association page --- app/src/main/AndroidManifest.xml | 7 +- .../ui/activites/ShowAssociationActivity.java | 71 +++++++++++++++++++ .../ui/fragment/AssociationMainFragment.java | 14 ++++ .../res/layout/activity_show_association.xml | 49 +++++++++++++ 4 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/activites/ShowAssociationActivity.java create mode 100644 app/src/main/res/layout/activity_show_association.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9602e12..ca7c6f3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,10 +19,11 @@ - + - - + + + \ No newline at end of file diff --git a/app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/activites/ShowAssociationActivity.java b/app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/activites/ShowAssociationActivity.java new file mode 100644 index 0000000..5b43950 --- /dev/null +++ b/app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/activites/ShowAssociationActivity.java @@ -0,0 +1,71 @@ +package fr.paris10.projet.assogenda.assogenda.ui.activites; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.widget.TextView; + +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.database.ValueEventListener; + + +import fr.paris10.projet.assogenda.assogenda.R; +import fr.paris10.projet.assogenda.assogenda.model.Association; +import fr.paris10.projet.assogenda.assogenda.model.User; + +public class ShowAssociationActivity extends AppCompatActivity { + private String associationID; + private Association association; + private User president; + private TextView nameAsso; + private TextView descAsso; + private TextView namePrez; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_show_association); + nameAsso = (TextView) findViewById(R.id.activity_show_association_name_asso); + descAsso = (TextView) findViewById(R.id.activity_show_association_description_asso); + namePrez = (TextView) findViewById(R.id.activity_show_association_name_president); + associationID = (String) getIntent().getExtras().get("associationID"); + DatabaseReference reference = FirebaseDatabase.getInstance().getReference("association"); + reference.child(associationID).addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if (dataSnapshot.exists()) { + association = dataSnapshot.getValue(Association.class); + nameAsso.setText(association.name); + descAsso.setText(association.description); + namePrez.setText(" "); + DatabaseReference references = FirebaseDatabase.getInstance().getReference("users"); + references.child(association.president).addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if (dataSnapshot.exists()) { + president = dataSnapshot.getValue(User.class); + namePrez.setText(president.firstName+" "+president.lastName); + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + + + + + } +} diff --git a/app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/fragment/AssociationMainFragment.java b/app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/fragment/AssociationMainFragment.java index fa1561a..737b6ec 100644 --- a/app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/fragment/AssociationMainFragment.java +++ b/app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/fragment/AssociationMainFragment.java @@ -2,12 +2,14 @@ import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.Button; import android.widget.ListView; @@ -23,6 +25,8 @@ import fr.paris10.projet.assogenda.assogenda.R; import fr.paris10.projet.assogenda.assogenda.model.Association; +import fr.paris10.projet.assogenda.assogenda.ui.activites.EventInfosActivity; +import fr.paris10.projet.assogenda.assogenda.ui.activites.ShowAssociationActivity; import fr.paris10.projet.assogenda.assogenda.ui.adapter.CustomAssociationAdapter; /** @@ -64,6 +68,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public void onChildAdded(DataSnapshot snapshot, String previousChild) { Association association = snapshot.getValue(Association.class); + association.id=snapshot.getKey(); items.add(association); associationAdapter.notifyDataSetChanged(); } @@ -97,6 +102,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, View v = inflater.inflate(R.layout.fragment_association_main, container, false); listView = (ListView) v.findViewById(R.id.fragment_association_main_listView); listView.setAdapter(associationAdapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Intent intent = new Intent(view.getContext(), ShowAssociationActivity.class); + Association association = items.get(position); + intent.putExtra("associationID", association.id); + startActivity(intent); + } + }); Button createAssociationButton = (Button) v.findViewById(R.id.fragment_association_main_button_create_association); createAssociationButton.setOnClickListener(this); diff --git a/app/src/main/res/layout/activity_show_association.xml b/app/src/main/res/layout/activity_show_association.xml new file mode 100644 index 0000000..caf3266 --- /dev/null +++ b/app/src/main/res/layout/activity_show_association.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + +