-
Notifications
You must be signed in to change notification settings - Fork 5
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 #16 from Hamlix/list-events
Add list events
- Loading branch information
Showing
10 changed files
with
466 additions
and
12 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
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
96 changes: 96 additions & 0 deletions
96
app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/activites/EventInfosActivity.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,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()); | ||
} | ||
}); | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/activites/ListEventsActivity.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,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()); | ||
} | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.