Skip to content

Commit

Permalink
Merge pull request #17 from Bouquet2/develop
Browse files Browse the repository at this point in the history
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
vbouquet authored Mar 9, 2017
2 parents bb799ab + d2b5d11 commit eebd2b4
Show file tree
Hide file tree
Showing 26 changed files with 1,197 additions and 13 deletions.
6 changes: 5 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ dependencies {
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.firebase:firebase-storage:10.0.1'
compile 'com.firebaseui:firebase-ui-storage:0.6.0'

//Agenda api
compile 'com.github.alamkanak:android-week-view:1.2.6'
compile 'com.squareup.retrofit:retrofit:1.9.0'
}

// Enable coverage for AndroidTests and UnitTests
Expand All @@ -68,7 +72,7 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'crea

def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
def mainSrc = "${project.projectDir}/src/agenda_main_menu/java"

sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
</intent-filter>
</activity>
<activity android:name=".ui.activites.SignUpActivity" />
<activity android:name=".ui.activites.LoginActivity"></activity>
<activity android:name=".ui.activites.AssociationDashboardActivity"></activity>
<activity android:name=".ui.activites.LoginActivity" />
<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 @@ -34,7 +34,6 @@ public void createAssociation(String associationName, String associationUniversi
}
}

//TODO vérifier que le nom de l'association n'est pas déjà pris
public boolean validateAssociationName(String associationName) {
return associationName != null && !associationName.isEmpty() && associationName.length() >= 3;
}
Expand Down
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));
}
}
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();
}
}
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);
}
});
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void onClick(DialogInterface dialog, int id) {
//Skip upload if no image is set
if (imagePreview == null) {

//Redirection to main fragment
//Redirection to agenda_main_menu fragment
Fragment associationMainFragment = AssociationMainFragment.newInstance();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction
Expand Down Expand Up @@ -259,7 +259,7 @@ public void uploadImage() {
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
imagePreview = null;

//Redirection to main fragment
//Redirection to agenda_main_menu fragment
Fragment associationMainFragment = AssociationMainFragment.newInstance();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction
Expand Down
Loading

0 comments on commit eebd2b4

Please sign in to comment.