Skip to content

Commit

Permalink
Merge pull request #16 from Hamlix/list-events
Browse files Browse the repository at this point in the history
Add list events
  • Loading branch information
vbouquet authored Mar 9, 2017
2 parents 2b73b84 + 0469223 commit a547b46
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 12 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<activity android:name=".ui.activites.AssociationDashboardActivity" />
<activity android:name=".ui.activites.AgendaGeneratorActivity" />
<activity android:name=".ui.activites.AgendaActivity"></activity>
<activity android:name=".ui.activites.ListEventsActivity" />
<activity android:name=".ui.activites.EventInfosActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,45 @@

import com.google.firebase.database.Exclude;

import java.text.DateFormat;
import java.util.HashMap;
import java.util.Map;
import com.google.firebase.database.Exclude;

import java.util.HashMap;
import java.util.Map;

public class Event {

/**
* Created by wilpiron on 28/02/2017.
*/


public class Event {
public String id;
public String name;
public String start;
public String end;
public String description;
public String location;
public String type;
public String uid;
public float price;
public int bail;
public int seat_number;
public int seat_free;
public Association association;
public int logo;

public static DateFormat dateFormat =
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

public Event(){
}

public Event(String name, String start, String end, String type, String description, String location,
public Event(String uid,String name, String start, String end, String type, String description, String location,
float price, int bail, int seat_number, Association association, int logo){
this.uid=uid;
this.name=name;
this.start=start;
this.end=end;
Expand All @@ -40,8 +55,9 @@ public Event(String name, String start, String end, String type, String descript
this.association=association;
}

public Event(String name, String start, String end, String type, String location,
public Event(String uid, String name, String start, String end, String type, String location,
float price, int seat_number, String description){
this.uid = uid;
this.name=name;
this.start=start;
this.end=end;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package fr.paris10.projet.assogenda.assogenda.ui.activites;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.SimpleAdapter;
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 java.util.ArrayList;
import java.util.HashMap;

import fr.paris10.projet.assogenda.assogenda.R;
import fr.paris10.projet.assogenda.assogenda.model.Event;

public class EventInfosActivity extends AppCompatActivity {
private ListView listInfos;
private ArrayList<HashMap<String,Object>> listValues = new ArrayList<>();
private SimpleAdapter adapter;
private String eventUID;
private Event event;
TextView nameEvent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event_infos);
eventUID = (String) getIntent().getExtras().get("eventUID");
nameEvent = (TextView) findViewById(R.id.activity_event_infos_name_event);
loadEventInfoInBackground();
}

public void loadEventInfoInBackground() {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("events");
reference.child(eventUID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
event = dataSnapshot.getValue(Event.class);
event.uid=eventUID;
nameEvent.setText(event.name);
HashMap<String,Object> hashMapValueDateBegin = new HashMap<>();
hashMapValueDateBegin.put("title_info","Date de début : ");
hashMapValueDateBegin.put("content_info",event.start);
HashMap<String,Object> hashMapValueDateEnd = new HashMap<>();
hashMapValueDateEnd.put("title_info","Date de fin : ");
hashMapValueDateEnd.put("content_info",event.end);
HashMap<String,Object> hashMapValuePrice = new HashMap<>();
hashMapValuePrice.put("title_info","Prix : ");
hashMapValuePrice.put("content_info",event.price);
HashMap<String,Object> hashMapValueSpace = new HashMap<>();
hashMapValueSpace.put("title_info","Places disponible : ");
hashMapValueSpace.put("content_info",event.seat_free);
HashMap<String,Object> hashMapValueBail = new HashMap<>();
hashMapValueBail.put("title_info","Caution : ");
hashMapValueBail.put("content_info",event.bail);
HashMap<String,Object> hashMapValuePlace = new HashMap<>();
hashMapValuePlace.put("title_info","Lieu : ");
hashMapValuePlace.put("content_info",event.location);
HashMap<String,Object> hashMapValueDescription = new HashMap<>();
hashMapValueDescription.put("title_info","Description : ");
hashMapValueDescription.put("content_info",event.description);
HashMap<String,Object> hashMapValueCategorie = new HashMap<>();
hashMapValueCategorie.put("title_info","Categorie : ");
hashMapValueCategorie.put("content_info",event.type);

listValues.add(hashMapValueDateBegin);
listValues.add(hashMapValueDateEnd);
listValues.add(hashMapValuePrice);
listValues.add(hashMapValueSpace);
listValues.add(hashMapValueBail);
listValues.add(hashMapValuePlace);
listValues.add(hashMapValueDescription);
listValues.add(hashMapValueCategorie);

String[] from = new String[] {"title_info","content_info"};
int[] to = new int[] {R.id.content_infos_event_title_info,R.id.content_infos_event_content_info};

listInfos = (ListView) findViewById(R.id.activity_event_infos_list);
adapter = new SimpleAdapter(EventInfosActivity.this,listValues,R.layout.content_infos_event,from,to);
listInfos.setAdapter(adapter);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("Error : ", "onCancelled", databaseError.toException());
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package fr.paris10.projet.assogenda.assogenda.ui.activites;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

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 java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import fr.paris10.projet.assogenda.assogenda.R;
import fr.paris10.projet.assogenda.assogenda.model.Event;

public class ListEventsActivity extends AppCompatActivity {
private ListView listEvents;
private ArrayList<HashMap<String,Object>> listValuesEvents = new ArrayList<>();
private SimpleAdapter adapter;
private List<Event> listeEvenements = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_events);
loadEventInBackground();
}

public void launchEventPage(){
listEvents.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getApplicationContext(),EventInfosActivity.class);
Event event = listeEvenements.get(position);

intent.putExtra("eventUID", event.uid);
startActivity(intent);
}
});
}

private Boolean convertToDate(String eventDate) {
DateFormat dateFormatter = new SimpleDateFormat("kk:mm dd/MM/yyyy");
Date start;
Date today;
Calendar c = Calendar.getInstance();
try {
start = dateFormatter.parse(eventDate);
today = dateFormatter.parse(dateFormatter.format(c.getTime()));
if (start.after(today)){
return true;
}
} catch (ParseException e) {
e.printStackTrace();
return false;
}
return false;
}

private Boolean compareDate(String event1, String event2) {
DateFormat dateFormatter = new SimpleDateFormat("kk:mm dd/MM/yyyy");
Date myEvent;
Date eventNext;
try {
myEvent = dateFormatter.parse(event1);
eventNext = dateFormatter.parse(event2);
if (myEvent.before(eventNext)){
return true;
}
} catch (ParseException e) {
e.printStackTrace();
return false;
}
return false;
}

public void loadEventInBackground() {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("events");
reference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
List<Event> listEventSort = new ArrayList<>();
int tailleList;
int nbEvent;
int eventRestant;
if (dataSnapshot.exists()) {
for (DataSnapshot e : dataSnapshot.getChildren()) {
Event event = e.getValue(Event.class);
event.uid=e.getKey();
if(convertToDate(event.start) || convertToDate(event.end)){
listeEvenements.add(event);
}
}
eventRestant = listeEvenements.size();
while(eventRestant>0) {
tailleList = listeEvenements.size();
for (int i = 0; i < tailleList; i++) {
nbEvent = 1;
for (int j = 0; j < tailleList; j++) {
if (i != j) {
if (compareDate(listeEvenements.get(i).start, listeEvenements.get(j).start)) {
nbEvent++;
}
}
}
if (nbEvent == eventRestant) {
listEventSort.add(listeEvenements.get(i));
eventRestant--;
}
}
}

for(Event event : listEventSort){
HashMap<String,Object> hashMapValuesEvent = new HashMap<>();
hashMapValuesEvent.put("nameEvent",event.name);
if(event.association==null)
hashMapValuesEvent.put("association","Nom asso");
else
hashMapValuesEvent.put("association",event.association);
hashMapValuesEvent.put("dateEventBegin",event.start);
hashMapValuesEvent.put("dateEventEnd",event.end);
hashMapValuesEvent.put("locationEvent",event.location);
hashMapValuesEvent.put("tagsEvent",event.type);
listValuesEvents.add(hashMapValuesEvent);
}
String[] from = new String[] {"nameEvent","association","dateEventBegin","dateEventEnd","locationEvent","tagsEvent"};
int[] to = new int[] {R.id.content_list_events_name_event,R.id.content_list_events_name_association,R.id.content_list_events_date_event_begin,R.id.content_list_events_date_event_end,R.id.content_list_events_location_event,R.id.content_list_events_tags_event};

listEvents = (ListView) findViewById(R.id.activity_list_events_list);
adapter = new SimpleAdapter(ListEventsActivity.this,listValuesEvents,R.layout.content_list_events,from,to);
listEvents.setAdapter(adapter);
launchEventPage();

}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("Error : ", "onCancelled", databaseError.toException());
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import fr.paris10.projet.assogenda.assogenda.daos.DAOUser;

public class MainActivity extends AppCompatActivity {

private DAOUser daoUser;

@Override
Expand Down Expand Up @@ -46,6 +45,17 @@ public void onClick(View view) {
startActivity(intent);
}
});

Button listEventButton = (Button) findViewById(R.id.main_list_events_button);
listEventButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),ListEventsActivity.class);
startActivity(intent);
}
});


}

@Override
Expand Down
Loading

0 comments on commit a547b46

Please sign in to comment.