-
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 #17 from Bouquet2/develop
Merge features for 0.2.0 release. Features: - Generate a calendar based on list of events - List available events on AssoGenda platform
- Loading branch information
Showing
26 changed files
with
1,197 additions
and
13 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
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
29 changes: 29 additions & 0 deletions
29
app/src/main/java/fr/paris10/projet/assogenda/assogenda/model/Agenda.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,29 @@ | ||
package fr.paris10.projet.assogenda.assogenda.model; | ||
|
||
public class Agenda { | ||
|
||
public int dayStart; | ||
public int yearStart; | ||
public int hourStart; | ||
public int minStart; | ||
|
||
public int monthEnd; | ||
public int dayEnd; | ||
public int yearEnd; | ||
public int hourEnd; | ||
public int minEnd; | ||
|
||
public void initDate(String dateStart, String dateEnd) { | ||
|
||
dayStart = Integer.parseInt(dateStart.substring(6, 8)); | ||
yearStart = Integer.parseInt(dateStart.substring(12, 16)); | ||
hourStart = Integer.parseInt(dateStart.substring(0, 2)); | ||
minStart = Integer.parseInt(dateStart.substring(3, 5)); | ||
|
||
monthEnd = Integer.parseInt(dateEnd.substring(9, 11)); | ||
dayEnd = Integer.parseInt(dateEnd.substring(6, 8)); | ||
yearEnd = Integer.parseInt(dateEnd.substring(12, 16)); | ||
hourEnd = Integer.parseInt(dateEnd.substring(0, 2)); | ||
minEnd = Integer.parseInt(dateEnd.substring(3, 5)); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
app/src/main/java/fr/paris10/projet/assogenda/assogenda/model/Event.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,111 @@ | ||
package fr.paris10.projet.assogenda.assogenda.model; | ||
|
||
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; | ||
|
||
|
||
/** | ||
* 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 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; | ||
this.type=type; | ||
this.description=description; | ||
this.location=location; | ||
this.price=price; | ||
this.bail=bail; | ||
this.seat_number=seat_number; | ||
this.seat_free=seat_number; | ||
this.logo=logo; | ||
this.association=association; | ||
} | ||
|
||
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; | ||
this.type=type; | ||
this.location=location; | ||
this.price=price; | ||
this.seat_free=seat_number; | ||
this.seat_number=seat_number; | ||
this.description=description; | ||
} | ||
|
||
/** | ||
* Two methods to control the number of seats available | ||
*/ | ||
public void reserveSeat(){ | ||
seat_free -= seat_free; | ||
} | ||
|
||
public void freeSeat(){ | ||
seat_free += seat_free; | ||
} | ||
|
||
/** | ||
* Define how data will be stored in database | ||
*/ | ||
@Exclude | ||
public Map<String, Object> toMap() { | ||
Map<String, Object> result = new HashMap<>(); | ||
result.put("name", name); | ||
result.put("description", description); | ||
result.put("type", type); | ||
//result.put("association", association.name); | ||
result.put("location", location); | ||
result.put("price", price); | ||
result.put("seats number", seat_number); | ||
result.put("seats free", seat_free); | ||
result.put("start", start); | ||
result.put("end", end); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("name= ").append(name).append("\n"); | ||
//sb.append("association= ").append(association.name).append("\n"); | ||
sb.append("start= ").append(start).append("\n"); | ||
sb.append("end= ").append(end).append("\n"); | ||
return sb.toString(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/fr/paris10/projet/assogenda/assogenda/ui/activites/AgendaActivity.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,27 @@ | ||
package fr.paris10.projet.assogenda.assogenda.ui.activites; | ||
|
||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
|
||
import fr.paris10.projet.assogenda.assogenda.R; | ||
|
||
public class AgendaActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_agenda); | ||
|
||
Button agendaButton = (Button) findViewById(R.id.activity_agenda_generate_button); | ||
agendaButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Intent intent = new Intent(view.getContext(), AgendaGeneratorActivity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
...main/java/fr/paris10/projet/assogenda/assogenda/ui/activites/AgendaGeneratorActivity.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,142 @@ | ||
package fr.paris10.projet.assogenda.assogenda.ui.activites; | ||
|
||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.widget.Toast; | ||
|
||
import com.alamkanak.weekview.WeekViewEvent; | ||
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.Calendar; | ||
import java.util.List; | ||
|
||
import fr.paris10.projet.assogenda.assogenda.R; | ||
import fr.paris10.projet.assogenda.assogenda.model.Event; | ||
import fr.paris10.projet.assogenda.assogenda.model.Agenda; | ||
import retrofit.Callback; | ||
import retrofit.RetrofitError; | ||
import retrofit.client.Response; | ||
|
||
/** | ||
* Events loader. | ||
*/ | ||
public class AgendaGeneratorActivity extends WeekViewActivity implements Callback<List<Event>> { | ||
|
||
public int monthStart; | ||
public Agenda agenda; | ||
public WeekViewEvent event; | ||
public Menu menu; | ||
|
||
private List<WeekViewEvent> events = new ArrayList<>(); | ||
public boolean isDisplayed = false; | ||
public static int color; | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
this.menu = menu; | ||
return super.onCreateOptionsMenu(menu); | ||
} | ||
|
||
@Override | ||
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) { | ||
|
||
if (!isDisplayed) { | ||
loadEventInBackground(); | ||
isDisplayed = true; | ||
} | ||
List<WeekViewEvent> matchedEvents = new ArrayList<>(); | ||
for (WeekViewEvent event : events) { | ||
if (eventMatches(event, newYear, newMonth - 1)) { | ||
matchedEvents.add(event); | ||
} | ||
} | ||
return matchedEvents; | ||
} | ||
|
||
private boolean eventMatches(WeekViewEvent event, int year, int month) { | ||
return (event.getStartTime().get(Calendar.YEAR) == year && event.getStartTime().get(Calendar.MONTH) == month) || (event.getEndTime().get(Calendar.YEAR) == year && event.getEndTime().get(Calendar.MONTH) == month); | ||
} | ||
|
||
@Override | ||
public void success(List<Event> events, Response response) { | ||
events.clear(); | ||
for (Event event : events) { | ||
events.add(event); | ||
} | ||
getWeekView().notifyDatasetChanged(); | ||
} | ||
|
||
@Override | ||
public void failure(RetrofitError error) { | ||
error.printStackTrace(); | ||
Toast.makeText(this, "Error while loading events", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
public void loadEventInBackground() { | ||
|
||
DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("events"); | ||
isDisplayed = false; | ||
color = 0; | ||
reference.addListenerForSingleValueEvent(new ValueEventListener() { | ||
@Override | ||
public void onDataChange(DataSnapshot dataSnapshot) { | ||
if (dataSnapshot.exists()) { | ||
for (DataSnapshot events : dataSnapshot.getChildren()) { | ||
Event event = events.getValue(Event.class); | ||
monthStart = Integer.parseInt(event.start.substring(9, 11)); | ||
agenda = new Agenda(); | ||
agenda.initDate(event.start, event.end); | ||
setEvents(event.name); | ||
} | ||
} | ||
//Refresh after all events are ready | ||
onOptionsItemSelected(menu.findItem(R.id.action_today)); | ||
} | ||
|
||
@Override | ||
public void onCancelled(DatabaseError databaseError) { | ||
Log.e("Error : ", "onCancelled", databaseError.toException()); | ||
} | ||
}); | ||
} | ||
|
||
public void setEvents(String title) { | ||
Calendar startTime; | ||
Calendar endTime; | ||
|
||
startTime = Calendar.getInstance(); | ||
startTime.set(Calendar.DAY_OF_MONTH, agenda.dayStart); | ||
startTime.set(Calendar.MONTH, monthStart - 1); | ||
startTime.set(Calendar.YEAR, agenda.yearStart); | ||
startTime.set(Calendar.HOUR_OF_DAY, agenda.hourStart); | ||
startTime.set(Calendar.MINUTE, agenda.minStart); | ||
endTime = (Calendar) startTime.clone(); | ||
endTime.set(Calendar.DAY_OF_MONTH, agenda.dayEnd); | ||
endTime.set(Calendar.MONTH, monthStart - 1); | ||
endTime.set(Calendar.YEAR, agenda.yearEnd); | ||
endTime.set(Calendar.HOUR_OF_DAY, agenda.hourEnd); | ||
endTime.set(Calendar.MINUTE, agenda.minEnd); | ||
endTime.set(Calendar.HOUR_OF_DAY, agenda.hourEnd); | ||
|
||
event = new WeekViewEvent(color++, title, startTime, endTime); | ||
|
||
//Deprecated depuis API 23 | ||
if (color % 5 == 1) { | ||
event.setColor(getResources().getColor(R.color.event_color_01)); | ||
} else if (color % 5 == 2) { | ||
event.setColor(getResources().getColor(R.color.event_color_02)); | ||
} else if (color % 5 == 3) { | ||
event.setColor(getResources().getColor(R.color.event_color_03)); | ||
} else if (color % 5 == 4) { | ||
event.setColor(getResources().getColor(R.color.event_color_04)); | ||
} else { | ||
event.setColor(getResources().getColor(R.color.event_color_05)); | ||
} | ||
events.add(event); | ||
} | ||
} |
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.