Browse Source

Implement Events Rest API

Philippe-Adrien Nousse 3 years ago
parent
commit
7ccfa5d8db
100 changed files with 410 additions and 238 deletions
  1. 0 0
      .gitignore
  2. 0 0
      .idea/gradle.xml
  3. 0 0
      .idea/runConfigurations.xml
  4. 0 0
      app/.gitignore
  5. 5 0
      app/build.gradle
  6. 0 0
      app/google-services.json
  7. 0 0
      app/keystore.jks
  8. 0 0
      app/proguard-rules.pro
  9. 0 0
      app/release/output.json
  10. 0 0
      app/src/androidTest/java/fr/wildcodeschool/steeryfit/ExampleInstrumentedTest.java
  11. 0 0
      app/src/debug/res/values/google_maps_api.xml
  12. 2 1
      app/src/main/AndroidManifest.xml
  13. 0 0
      app/src/main/ic_launcher-web.png
  14. 7 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/AuthController.java
  15. 3 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/ConversationsController.java
  16. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/EventsDetailsController.java
  17. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/EventsQuery.java
  18. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/LocationController.java
  19. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/MessagesController.java
  20. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/UserController.java
  21. 153 178
      app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/UserEventsController.java
  22. 39 39
      app/src/main/java/fr/wildcodeschool/steeryfit/Models/ConversationModel.java
  23. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Models/EventModel.java
  24. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Models/MessageModel.java
  25. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Models/Sports.java
  26. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Models/UserModel.java
  27. 39 10
      app/src/main/java/fr/wildcodeschool/steeryfit/Services/NotificationsService.java
  28. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Services/TokenService.java
  29. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/ConversationsActivity.java
  30. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/EditoActivity.java
  31. 1 1
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/MainActivity.java
  32. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/MessagesActivity.java
  33. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/ModifyEventActivity.java
  34. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/PhoneConfirmationActivity.java
  35. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/SignInActivity.java
  36. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/SignInMailActivity.java
  37. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/SignUpMailActivity.java
  38. 48 5
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/Splashscreen.java
  39. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/ConversationsAdapter.java
  40. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/EventAdapter.java
  41. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/MessagesAdapter.java
  42. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/ParticipantsAdapter.java
  43. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/PlaceAutocompleteAdapter.java
  44. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/SwipeDeckAdapter.java
  45. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/CreateEvent/CreateEventActivityPart1.java
  46. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/CreateEvent/CreateEventActivityPart2.java
  47. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/CreateEvent/CreateEventFragment.java
  48. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/Behaviors/AvatarBehavior.java
  49. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/Behaviors/RecyclerViewBehavior.java
  50. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/ConversationsFragment.java
  51. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/LocationPickerFragment.java
  52. 4 2
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/MainFragment.java
  53. 15 1
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/MessagesFragment.java
  54. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/PlanningFragment.java
  55. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/LevelPickerDialogFragment.java
  56. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserAliasConfigurationActivity.java
  57. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserAvatarConfigurationActivity.java
  58. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserDateOfBirthConfigurationActivity.java
  59. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserEmailConfigurationActivity.java
  60. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserFirstnameConfigurationActivity.java
  61. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserGenderConfigurationActivity.java
  62. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserLastnameConfigurationActivity.java
  63. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserLocationConfigurationActivity.java
  64. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserPasswordConfigurationActivity.java
  65. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserPhoneConfigurationActivity.java
  66. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserSportsConfirgurationActivity.java
  67. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Utils/Constants.java
  68. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Utils/FirebaseGlideModule.java
  69. 1 1
      app/src/main/java/fr/wildcodeschool/steeryfit/Utils/FirebaseHelper.java
  70. 93 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Utils/HttpRequest.java
  71. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Utils/UserConfigurationHelper.java
  72. 0 0
      app/src/main/java/fr/wildcodeschool/steeryfit/Utils/Utils.java
  73. 0 0
      app/src/main/res/drawable-hdpi/blank_avatar.png
  74. 0 0
      app/src/main/res/drawable-hdpi/event_arm.png
  75. 0 0
      app/src/main/res/drawable-hdpi/event_ball.png
  76. 0 0
      app/src/main/res/drawable-hdpi/event_bike.png
  77. 0 0
      app/src/main/res/drawable-hdpi/event_calendar.png
  78. 0 0
      app/src/main/res/drawable-hdpi/event_clock.png
  79. 0 0
      app/src/main/res/drawable-hdpi/event_gender_female.png
  80. 0 0
      app/src/main/res/drawable-hdpi/event_gender_male.png
  81. 0 0
      app/src/main/res/drawable-hdpi/event_gender_mixed.png
  82. 0 0
      app/src/main/res/drawable-hdpi/event_golf.png
  83. 0 0
      app/src/main/res/drawable-hdpi/event_level_1.png
  84. 0 0
      app/src/main/res/drawable-hdpi/event_level_2.png
  85. 0 0
      app/src/main/res/drawable-hdpi/event_level_3.png
  86. 0 0
      app/src/main/res/drawable-hdpi/event_racket.png
  87. 0 0
      app/src/main/res/drawable-hdpi/event_running.png
  88. 0 0
      app/src/main/res/drawable-hdpi/event_sandclock.png
  89. 0 0
      app/src/main/res/drawable-hdpi/googlemaps_icon.png
  90. 0 0
      app/src/main/res/drawable-hdpi/ic_back_arrow.png
  91. 0 0
      app/src/main/res/drawable-hdpi/ic_ball.png
  92. 0 0
      app/src/main/res/drawable-hdpi/ic_bike.png
  93. 0 0
      app/src/main/res/drawable-hdpi/ic_golf.png
  94. 0 0
      app/src/main/res/drawable-hdpi/ic_magnify.png
  95. 0 0
      app/src/main/res/drawable-hdpi/ic_not_valid_edit_text.png
  96. 0 0
      app/src/main/res/drawable-hdpi/ic_racket.png
  97. 0 0
      app/src/main/res/drawable-hdpi/ic_recycler_view_button.png
  98. 0 0
      app/src/main/res/drawable-hdpi/ic_run.png
  99. 0 0
      app/src/main/res/drawable-hdpi/ic_stat_name.png
  100. 0 0
      app/src/main/res/drawable-hdpi/ic_valid_edit_text.png

+ 0 - 0
.gitignore


+ 0 - 0
.idea/gradle.xml


+ 0 - 0
.idea/runConfigurations.xml


+ 0 - 0
app/.gitignore


+ 5 - 0
app/build.gradle

@@ -79,5 +79,10 @@ dependencies {
     // Notifications Badge
     compile 'com.nex3z:notification-badge:0.3.0'
 
+    // Async Http Client
+    compile 'com.loopj.android:android-async-http:1.4.9'
+
+    // Gson
+    compile 'com.google.code.gson:gson:2.8.2'
 }
 apply plugin: 'com.google.gms.google-services'

+ 0 - 0
app/google-services.json


+ 0 - 0
app/keystore.jks


+ 0 - 0
app/proguard-rules.pro


+ 0 - 0
app/release/output.json


+ 0 - 0
app/src/androidTest/java/fr/wildcodeschool/steeryfit/ExampleInstrumentedTest.java


+ 0 - 0
app/src/debug/res/values/google_maps_api.xml


+ 2 - 1
app/src/main/AndroidManifest.xml

@@ -127,7 +127,8 @@
             android:name=".UI.Activities.ConversationsActivity">
         </activity>
         <activity
-            android:name=".UI.Activities.MessagesActivity">
+            android:name=".UI.Activities.MessagesActivity"
+            android:noHistory="true">
         </activity>
         <activity
             android:name=".UI.Activities.ModifyEventActivity">

+ 0 - 0
app/src/main/ic_launcher-web.png


+ 7 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/AuthController.java

@@ -70,6 +70,8 @@ public class AuthController {
     private String mPassword;
     private String mConfirmPassword;
 
+    private String mAuthTokenId = "";
+
     /**
      * Private Constructor of the UserController AuthController
      */
@@ -118,6 +120,10 @@ public class AuthController {
                 mUser = firebaseAuth.getCurrentUser();
                 if (mUser != null) {
                     // User is signed in
+                    mUser.getIdToken(true).addOnSuccessListener(getTokenResult -> {
+                        mAuthTokenId = getTokenResult.getToken();
+                        Log.d(TAG, "onAuthStateChanged: TokenId: " + mAuthTokenId);
+                    });
                     Log.d(TAG, "onAuthStateChanged:signed_in UID:" + mUser.getUid());
                     Log.d(TAG, "onAuthStateChanged:signed_in Phone Number:" + mUser.getPhoneNumber());
                     mUser = mAuth.getCurrentUser();
@@ -127,6 +133,7 @@ public class AuthController {
                         connectionSuccess(false);
                     }
                     else {
+
                         connectionSuccess(false);
                     }
 

+ 3 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/ConversationsController.java

@@ -296,6 +296,9 @@ public class ConversationsController {
     public static void destroy(){
         sInstance = null;
     }
+    public static boolean isInstanciated() {
+        return sInstance != null;
+    }
 
     private void getUnreadMessagesCount(ConversationModel conversation) {
         mDatabase.getReference(MESSAGES_ENTRY).child(conversation.getUid())

+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/EventsDetailsController.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/EventsQuery.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/LocationController.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/MessagesController.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/UserController.java


+ 153 - 178
app/src/main/java/fr/wildcodeschool/steeryfit/Controllers/UserEventsController.java

@@ -17,29 +17,34 @@ import com.google.firebase.database.DatabaseReference;
 import com.google.firebase.database.FirebaseDatabase;
 import com.google.firebase.database.ValueEventListener;
 import com.google.firebase.storage.StorageReference;
+import com.google.gson.Gson;
 
 import java.util.HashMap;
-import java.util.Map;
 
+import fr.wildcodeschool.steeryfit.Models.ConversationModel;
 import fr.wildcodeschool.steeryfit.Models.EventModel;
 import fr.wildcodeschool.steeryfit.Models.Sports;
 import fr.wildcodeschool.steeryfit.Models.UserModel;
 import fr.wildcodeschool.steeryfit.Utils.FirebaseHelper;
+import fr.wildcodeschool.steeryfit.Utils.HttpRequest;
 import fr.wildcodeschool.steeryfit.Utils.Utils;
 
 import static fr.wildcodeschool.steeryfit.Utils.Constants.EVENTS_ENTRY;
-import static fr.wildcodeschool.steeryfit.Utils.Constants.EVENTS_PARTICIPANTS_ENTRY;
 import static fr.wildcodeschool.steeryfit.Utils.Constants.EVENTS_PREVIEW_ENTRY;
 import static fr.wildcodeschool.steeryfit.Utils.Constants.USERS_EVENTS_ENTRY;
+import static fr.wildcodeschool.steeryfit.Utils.HttpRequest.EVENT_CANCEL;
+import static fr.wildcodeschool.steeryfit.Utils.HttpRequest.EVENT_CONFIRM;
+import static fr.wildcodeschool.steeryfit.Utils.HttpRequest.EVENT_DELETE;
+import static fr.wildcodeschool.steeryfit.Utils.HttpRequest.EVENT_MATCH;
+import static fr.wildcodeschool.steeryfit.Utils.HttpRequest.EVENT_REJECT;
 
 /**
  * Created by apprenti on 11/16/17.
  */
 
-public class UserEventsController implements OnSuccessListener, OnFailureListener{
-    private final String TAG = Utils.getTAG(this);
+public class UserEventsController implements OnSuccessListener, OnFailureListener {
     private static volatile UserEventsController sInstance = null;
-
+    private final String TAG = Utils.getTAG(this);
     private FirebaseDatabase mDatabase;
     private DatabaseReference mEventsRef;
     private DatabaseReference mUsersEventsReference;
@@ -56,10 +61,79 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
     // Listeners
     private EventsListener mEventsListener = null;
     private UpdateEventListener mUpdateEventListener = null;
+    private OnEventMatchedListener mOnEventMatchedListener = null;
+    private ValueEventListener mGlobalEventsListener = new ValueEventListener() {
+        @Override
+        public void onDataChange(DataSnapshot snapshot) {
+            EventModel event = snapshot.getValue(EventModel.class);
+            if (event == null) {
+                mUserEventsReferenceMap.remove(snapshot.getKey());
+            } else {
+                mUserEvents.put(event.getUid(), event);
+            }
+
+        }
+
+        @Override
+        public void onCancelled(DatabaseError error) {
+
+        }
+    };
+    private ChildEventListener mDatabaseUserEventsListener = new ChildEventListener() {
+        @Override
+        public void onChildAdded(DataSnapshot snapshot, String s) {
+            Log.d(TAG, "onChildAdded() called with: snapshot = [" + snapshot + "], s = [" + s + "]");
+            // Set in the event's references's map
+            String eventUid = snapshot.getKey();
+            final Boolean valid = snapshot.getValue(Boolean.class);
+            mUserEventsReferenceMap.put(eventUid, valid);
+
+            if (valid) {
+                // Start listening on Event changes
+                mEventsRef.child(eventUid).addValueEventListener(mGlobalEventsListener);
+            }
+        }
+
+        @Override
+        public void onChildChanged(DataSnapshot snapshot, String s) {
+            Log.d(TAG, "onChildChanged() called with: snapshot = [" + snapshot + "], s = [" + s + "]");
+            String eventUid = snapshot.getKey();
+            Boolean valid = snapshot.getValue(Boolean.class);
+            mUserEventsReferenceMap.put(eventUid, valid);
+            if (!valid) {
+                mEventsRef.child(eventUid).removeEventListener(mGlobalEventsListener);
+                EventModel event = mUserEvents.remove(eventUid);
+                if (mEventsListener != null) {
+                    mEventsListener.onEventRemoved(event);
+                }
+            }
+        }
+
+        @Override
+        public void onChildRemoved(DataSnapshot snapshot) {
+            Log.d(TAG, "onChildRemoved() called with: snapshot = [" + snapshot + "]");
+            String eventUid = snapshot.getKey();
+            mUserEventsReferenceMap.remove(snapshot.getKey());
+            if (mEventsListener != null) {
+                mEventsListener.onEventRemoved(mUserEvents.get(eventUid));
+            }
+            mUserEvents.remove(eventUid);
+        }
+
+        @Override
+        public void onChildMoved(DataSnapshot snapshot, String s) {
+
+        }
+
+        @Override
+        public void onCancelled(DatabaseError error) {
+
+        }
+    };
 
     private UserEventsController() {
         // Prevent from the reflection API.
-        if(sInstance != null) {
+        if (sInstance != null) {
             throw new RuntimeException("Use getInstance() to get the single instance of this class.");
         }
 
@@ -74,13 +148,15 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
         mUserEventsRef.addChildEventListener(mDatabaseUserEventsListener);
     }
 
+    // Pick Events Actions
+
     public static UserEventsController getInstance() {
         // Check for the first time
-        if(sInstance == null) {
+        if (sInstance == null) {
             // Check for the second time
             synchronized (UserEventsController.class) {
                 // If no Instance available create new One
-                if(sInstance == null) {
+                if (sInstance == null) {
                     sInstance = new UserEventsController();
                 }
             }
@@ -92,55 +168,47 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
         sInstance = null;
     }
 
-    // Pick Events Actions
+    public static boolean isInstanciated() {
+        return sInstance != null;
+    }
+
+
+    // Events Administration Actions
+
     /**
      * Method handling the User Matching an Event(Swipe event card right)
+     *
      * @param event
      */
     public void matchEvent(EventModel event) {
-        // Add User to Global Events Table
-        String globalEventPath = String.format("%s/%s/%s/%s", EVENTS_ENTRY, event.getUid(),
-                EVENTS_PARTICIPANTS_ENTRY, mUserUid);
-
-        // Add event in this events Table
-        String userEventPath = String.format("%s/%s/%s", USERS_EVENTS_ENTRY, mUserUid, event.getUid());
-        Map<String, Object> data = new HashMap<>();
-        // Waiting for confirmation
-        data.put(globalEventPath, false);
-        // Applying to Event
-        data.put(userEventPath, true);
-        mDatabase.getReference().updateChildren(data).addOnSuccessListener(this).addOnFailureListener(this);
-
-        mSelectedEvent = event;
-        mUserEvents.put(event.getUid(), event);
-        // Create the Conversation
-        ConversationsController conversationsController = ConversationsController.getInstance();
-        conversationsController.startConversation(event);
+        new HttpRequest.Builder().path(EVENT_MATCH)
+                .addEventId(event.getUid()).get((resultString, e) -> {
+            Log.d(TAG, "matchEvent: " + resultString);
+            mUserEvents.put(event.getUid(), event);
+            Gson gson = new Gson();
+            ConversationModel conversation = gson.fromJson(resultString, ConversationModel.class);
+            if(mOnEventMatchedListener != null) {
+                mOnEventMatchedListener.onEventMatched(conversation);
+            }
+        });
     }
 
     /**
      * A User cancel his willing to participate to an event
      * or cancel his participation to an event
+     *
      * @param event
      */
     public void cancelEventParticipation(EventModel event) {
-        String uid = event.getUid();
-        ConversationsController.getInstance().deleteConversation(event);
-        HashMap<String, Object> data = new HashMap<>();
-        // Remove User from Events Table
-        mEventsRef.child(uid).removeEventListener(mGlobalEventsListener);
-        String userEventPath = Utils.getReferencePath(mEventsRef.child(uid).child(EVENTS_PARTICIPANTS_ENTRY).child(mUserUid));
-        data.put(userEventPath, null);
-        // Mark Event as unavailable in User's Events Table
-        String userPath = Utils.getReferencePath(mUserEventsRef.child(uid));
-        data.put(userPath, false);
-        mDatabase.getReference().updateChildren(data).addOnSuccessListener(this).addOnFailureListener(this);
+        new HttpRequest.Builder().path(EVENT_CANCEL)
+                .addEventId(event.getUid()).get(((resultString, e) -> {
+            Log.d(TAG, "cancelEventParticipation() " + resultString);
+        }));
     }
 
-
-    // Events Administration Actions
     /**
      * Method to send an event to firebase Events Entry
+     *
      * @param event
      */
     public void createEvent(final EventModel event, Bitmap mapPreview) {
@@ -162,14 +230,14 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
                         // Write in User's Event Table
                         mUserEventsRef.child(eventUid).setValue(true);
                         mEventBuilder = null;
-                        if(mUpdateEventListener != null) {
+                        if (mUpdateEventListener != null) {
                             mUpdateEventListener.onUpdateEventResult(true, null);
                         }
                     }
 
                     @Override
                     public void onFailure(String error) {
-                        if(mUpdateEventListener != null) {
+                        if (mUpdateEventListener != null) {
                             mUpdateEventListener.onUpdateEventResult(false, new Exception(error));
                         }
                     }
@@ -179,66 +247,32 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
 
     /**
      * Method handling the user cancelling an event that he created.
+     *
      * @param event
      */
     public void cancelEvent(EventModel event) {
-        String uid = event.getUid();
-        ConversationsController conversationsController = ConversationsController.getInstance();
-        conversationsController.deleteConversation(event);
-
-        mEventsRef.child(uid).removeEventListener(mGlobalEventsListener);
-        HashMap<String, Object> deletionMap = new HashMap<>();
-        // Remove in Global Events Table
-        String globalEventPath = Utils.getReferencePath(mEventsRef.child(uid));
-        deletionMap.put(globalEventPath, null);
-
-        // Remove in author table
-        String authorEventPath = Utils.getReferencePath(mUserEventsRef.child(uid));
-        deletionMap.put(authorEventPath, null);
-
-        // Remove in each User Events Table
-        HashMap<String, Boolean> participants = event.getParticipants();
-        for(String userUid : participants.keySet()) {
-            String userEventPath = Utils.getReferencePath(mDatabase.getReference(USERS_EVENTS_ENTRY).child(userUid)
-                    .child(uid));
-            deletionMap.put(userEventPath, null);
-        }
-        mDatabase.getReference().updateChildren(deletionMap)
-                .addOnSuccessListener(this).addOnFailureListener(this);
+        new HttpRequest.Builder().path(EVENT_DELETE).addEventId(event.getUid())
+                .get((resultString, e) -> Log.d(TAG, "cancelEvent() " + resultString));
     }
 
     /**
      * Method handling the validation of a user participation
+     *
      * @param event
      */
     public void acceptEventUserParticipation(EventModel event, String userUid) {
-        HashMap<String, Object> data = new HashMap<>();
-        // Accept in Global Events Table
-        String path = Utils.getReferencePath(
-                mEventsRef.child(event.getUid()).child(EVENTS_PARTICIPANTS_ENTRY).child(userUid));
-        data.put(path, true);
-        mDatabase.getReference().updateChildren(data)
-                .addOnSuccessListener(this).addOnFailureListener(this);
+        new HttpRequest.Builder().path(EVENT_CONFIRM).addEventId(event.getUid()).addUserId(userUid)
+                .get((resultString, e) -> Log.d(TAG, "acceptEventUserParticipation() " + resultString));
     }
 
     /**
      * Method that reject the user's participation
+     *
      * @param event
      */
     public void rejectEventUserParticipation(EventModel event, String userUid) {
-        // Delete Conversation
-        ConversationsController.getInstance().deleteConversation(event);
-
-        HashMap<String, Object> deletionMap = new HashMap<>();
-        // Remove User From Global Events Table
-        String globalEventPath = Utils.getReferencePath(mEventsRef
-                .child(event.getUid()).child(EVENTS_PARTICIPANTS_ENTRY).child(userUid));
-        deletionMap.put(globalEventPath, null);
-        // Set to False in user's event Table
-        String userEventPath = Utils.getReferencePath(mUsersEventsReference.child(userUid).child(event.getUid()));
-        deletionMap.put(userEventPath, false);
-        mDatabase.getReference().updateChildren(deletionMap)
-                .addOnSuccessListener(this).addOnFailureListener(this);
+        new HttpRequest.Builder().path(EVENT_REJECT).addEventId(event.getUid()).addUserId(userUid)
+                .get((resultString, e) -> Log.d(TAG, "rejectEventUserParticipation() " + resultString));
     }
 
     public HashMap<String, EventModel> getUserEvents() {
@@ -249,58 +283,6 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
         return mSelectedEvent;
     }
 
-    private ChildEventListener mDatabaseUserEventsListener = new ChildEventListener() {
-        @Override
-        public void onChildAdded(DataSnapshot snapshot, String s) {
-            Log.d(TAG, "onChildAdded() called with: snapshot = [" + snapshot + "], s = [" + s + "]");
-            // Set in the event's references's map
-            String eventUid = snapshot.getKey();
-            final Boolean valid = snapshot.getValue(Boolean.class);
-            mUserEventsReferenceMap.put(eventUid, valid);
-
-            if(valid) {
-                // Start listening on Event changes
-                mEventsRef.child(eventUid).addValueEventListener(mGlobalEventsListener);
-            }
-        }
-
-        @Override
-        public void onChildChanged(DataSnapshot snapshot, String s) {
-            Log.d(TAG, "onChildChanged() called with: snapshot = [" + snapshot + "], s = [" + s + "]");
-            String eventUid = snapshot.getKey();
-            Boolean valid = snapshot.getValue(Boolean.class);
-            mUserEventsReferenceMap.put(eventUid, valid);
-            if(!valid) {
-                mEventsRef.child(eventUid).removeEventListener(mGlobalEventsListener);
-                EventModel event = mUserEvents.remove(eventUid);
-                if(mEventsListener != null) {
-                    mEventsListener.onEventRemoved(event);
-                }
-            }
-        }
-
-        @Override
-        public void onChildRemoved(DataSnapshot snapshot) {
-            Log.d(TAG, "onChildRemoved() called with: snapshot = [" + snapshot + "]");
-            String eventUid = snapshot.getKey();
-            mUserEventsReferenceMap.remove(snapshot.getKey());
-            if(mEventsListener != null) {
-                mEventsListener.onEventRemoved(mUserEvents.get(eventUid));
-            }
-            mUserEvents.remove(eventUid);
-        }
-
-        @Override
-        public void onChildMoved(DataSnapshot snapshot, String s) {
-
-        }
-
-        @Override
-        public void onCancelled(DatabaseError error) {
-
-        }
-    };
-
     public void setSelectedEvent(EventModel selectedEvent) {
         mSelectedEvent = selectedEvent;
     }
@@ -312,69 +294,66 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
     /**
      * Method returning the User's Event's reference map.
      * The hashmap contains the Event's reference and a boolean:
-     *      true if the event is pending or accepted
-     *      false if the event was refused or canceled.
+     * true if the event is pending or accepted
+     * false if the event was refused or canceled.
+     *
      * @return
      */
     public HashMap<String, Boolean> getUserEventsReferenceMap() {
         return mUserEventsReferenceMap;
     }
 
-    public interface EventsListener {
-        void onEventAdded(EventModel event);
-        void onEventRemoved(EventModel event);
-        void onEventChanged(EventModel event);
-        void onEventError(String error);
-    }
-
     public void setUpdateEventListener(UpdateEventListener updateEventListener) {
         mUpdateEventListener = updateEventListener;
     }
 
-    public interface UpdateEventListener {
-        void onUpdateEventResult(boolean success, @Nullable Exception e);
+    public void setOnEventMatchedListener(OnEventMatchedListener onEventMatchedListener) {
+        mOnEventMatchedListener = onEventMatchedListener;
     }
 
-    private ValueEventListener mGlobalEventsListener = new ValueEventListener() {
-        @Override
-        public void onDataChange(DataSnapshot snapshot) {
-            EventModel event = snapshot.getValue(EventModel.class);
-            if(event == null) {
-                mUserEventsReferenceMap.remove(snapshot.getKey());
-            }
-            else {
-                mUserEvents.put(event.getUid(), event);
-            }
-
-        }
-
-        @Override
-        public void onCancelled(DatabaseError error) {
-
-        }
-    };
-
     @Override
     public void onSuccess(Object o) {
-        if(mUpdateEventListener != null) {
+        if (mUpdateEventListener != null) {
             mUpdateEventListener.onUpdateEventResult(true, null);
         }
     }
 
     @Override
     public void onFailure(@NonNull Exception e) {
-        if(mUpdateEventListener != null) {
+        if (mUpdateEventListener != null) {
             mUpdateEventListener.onUpdateEventResult(false, e);
         }
     }
 
     public EventBuilder getEventBuilder() {
-        if(mEventBuilder == null) {
+        if (mEventBuilder == null) {
             mEventBuilder = new EventBuilder();
         }
         return mEventBuilder;
     }
 
+    public UpdateEventBuilder getUpdateEventBuilder(EventModel mEvent) {
+        return new UpdateEventBuilder(mEvent);
+    }
+
+    public interface EventsListener {
+        void onEventAdded(EventModel event);
+
+        void onEventRemoved(EventModel event);
+
+        void onEventChanged(EventModel event);
+
+        void onEventError(String error);
+    }
+
+    public interface UpdateEventListener {
+        void onUpdateEventResult(boolean success, @Nullable Exception e);
+    }
+
+    public interface OnEventMatchedListener {
+        void onEventMatched(ConversationModel conversation);
+    }
+
     public class EventBuilder {
 
         private Sports.Type mSport;
@@ -460,10 +439,6 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
         }
     }
 
-    public UpdateEventBuilder getUpdateEventBuilder(EventModel mEvent) {
-        return new UpdateEventBuilder(mEvent);
-    }
-
     public class UpdateEventBuilder {
         EventModel mEvent = null;
         HashMap<String, Object> mUpdateMap = null;
@@ -535,9 +510,9 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
         }
 
         public UpdateEventBuilder build() {
-            if(mUpdateMap.containsKey("bitmap")){
+            if (mUpdateMap.containsKey("bitmap")) {
                 StorageReference previewReference = FirebaseHelper.getsStorage().getReference().child(EVENTS_PREVIEW_ENTRY).child(mEvent.getUid());
-                FirebaseHelper.uploadImage(previewReference,(Bitmap)mUpdateMap.get("bitmap")).setUploadImageListener(new FirebaseHelper.UploadImageListener() {
+                FirebaseHelper.uploadImage(previewReference, (Bitmap) mUpdateMap.get("bitmap")).setUploadImageListener(new FirebaseHelper.UploadImageListener() {
                     @Override
                     public void onSuccess(Uri imageUri) {
                         mUpdateMap.remove("bitmap");
@@ -550,12 +525,12 @@ public class UserEventsController implements OnSuccessListener, OnFailureListene
                             }
                         });
                     }
+
                     @Override
                     public void onFailure(String error) {
                     }
                 });
-            }
-            else {
+            } else {
                 mEventsRef.child(mEvent.getUid()).updateChildren(mUpdateMap).addOnCompleteListener(new OnCompleteListener<Void>() {
                     @Override
                     public void onComplete(@NonNull Task<Void> task) {

+ 39 - 39
app/src/main/java/fr/wildcodeschool/steeryfit/Models/ConversationModel.java

@@ -9,12 +9,12 @@ import java.util.HashMap;
  */
 
 public class ConversationModel {
-    private String mUid;
-    private String mEventUid = "";
-    private HashMap<String, Boolean> mUsers = new HashMap<>();
-    private MessageModel mLastMessage = null;
+    private String uid;
+    private String eventUid = "";
+    private HashMap<String, Boolean> users = new HashMap<>();
+    private MessageModel lastMessage = null;
 
-    private HashMap<String, User> mUsersData = new HashMap<>();
+    private HashMap<String, User> usersData = new HashMap<>();
 
     @Exclude
     public int unreadCount = 0;
@@ -23,102 +23,102 @@ public class ConversationModel {
     }
 
     public ConversationModel(String conversationUid) {
-        mUid = conversationUid;
+        uid = conversationUid;
     }
 
     public ConversationModel(String conversationUid, String userUid, String userOtherUid) {
-        mUid = conversationUid;
-        mUsers.put(userUid, true);
-        mUsers.put(userOtherUid, true);
+        uid = conversationUid;
+        users.put(userUid, true);
+        users.put(userOtherUid, true);
     }
 
     public void addUserData(String uid, String name, String avatar) {
-        mUsersData.put(uid, new User(name, avatar));
+        usersData.put(uid, new User(name, avatar));
     }
 
     public User getUserData(String uid) {
-        return mUsersData.get(uid);
+        return usersData.get(uid);
     }
 
     public HashMap<String, User> getUsersData() {
-        return mUsersData;
+        return usersData;
     }
 
     public void setUsersData(HashMap<String, User> usersData) {
-        mUsersData = usersData;
+        this.usersData = usersData;
     }
 
     public void addUser(String userUid) {
-        mUsers.put(userUid, true);
+        users.put(userUid, true);
     }
 
     public static class User {
-        private String mName = "";
-        private String mAvatar = "";
+        private String name = "";
+        private String avatar = "";
 
         public User() {
         }
 
         public User(String name, String avatar) {
-            mName = name;
-            mAvatar = avatar;
+            this.name = name;
+            this.avatar = avatar;
         }
 
         public String getName() {
-            return mName;
+            return name;
         }
 
         public void setName(String name) {
-            mName = name;
+            this.name = name;
         }
 
         public String getAvatar() {
-            return mAvatar;
+            return avatar;
         }
 
         public void setAvatar(String avatar) {
-            mAvatar = avatar;
+            this.avatar = avatar;
         }
 
         @Override
         public String toString() {
             return "User{" +
-                    "mName='" + mName + '\'' +
-                    ", mAvatar='" + mAvatar + '\'' +
+                    "name='" + name + '\'' +
+                    ", avatar='" + avatar + '\'' +
                     '}';
         }
     }
 
     public String getUid() {
-        return mUid;
+        return uid;
     }
 
     public void setUid(String uid) {
-        mUid = uid;
+        this.uid = uid;
     }
 
     public HashMap<String, Boolean> getUsers() {
-        return mUsers;
+        return users;
     }
 
     public void setUsers(HashMap<String, Boolean> users) {
-        mUsers = users;
+        this.users = users;
     }
 
     public MessageModel getLastMessage() {
-        return mLastMessage;
+        return lastMessage;
     }
 
     public void setLastMessage(MessageModel lastMessage) {
-        mLastMessage = lastMessage;
+        this.lastMessage = lastMessage;
     }
 
     public String getEventUid() {
-        return mEventUid;
+        return eventUid;
     }
 
     public void setEventUid(String eventUid) {
-        mEventUid = eventUid;
+        this.eventUid = eventUid;
     }
 
     @Override
@@ -128,22 +128,22 @@ public class ConversationModel {
 
         ConversationModel that = (ConversationModel) o;
 
-        return mUid != null ? mUid.equals(that.mUid) : that.mUid == null;
+        return uid != null ? uid.equals(that.uid) : that.uid == null;
     }
 
     @Override
     public int hashCode() {
-        return mUid != null ? mUid.hashCode() : 0;
+        return uid != null ? uid.hashCode() : 0;
     }
 
     @Override
     public String toString() {
         return "ConversationModel{" +
-                "mUid='" + mUid + '\'' +
-                ", mEventUid='" + mEventUid + '\'' +
-                ", mUsers=" + mUsers +
-                ", mLastMessage=" + mLastMessage +
-                ", mUsersData=" + mUsersData +
+                "uid='" + uid + '\'' +
+                ", eventUid='" + eventUid + '\'' +
+                ", users=" + users +
+                ", lastMessage=" + lastMessage +
+                ", usersData=" + usersData +
                 '}';
     }
 }

+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Models/EventModel.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Models/MessageModel.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Models/Sports.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Models/UserModel.java


+ 39 - 10
app/src/main/java/fr/wildcodeschool/steeryfit/Services/NotificationsService.java

@@ -2,6 +2,8 @@ package fr.wildcodeschool.steeryfit.Services;
 
 import android.app.Notification;
 import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Intent;
 import android.graphics.Color;
 import android.media.RingtoneManager;
 import android.util.Log;
@@ -10,13 +12,19 @@ import com.google.firebase.messaging.FirebaseMessagingService;
 import com.google.firebase.messaging.RemoteMessage;
 
 import java.util.Map;
+import java.util.UUID;
 
 import fr.wildcodeschool.steeryfit.Controllers.ConversationsController;
+import fr.wildcodeschool.steeryfit.Controllers.UserEventsController;
 import fr.wildcodeschool.steeryfit.Models.ConversationModel;
 import fr.wildcodeschool.steeryfit.R;
+import fr.wildcodeschool.steeryfit.UI.Activities.MessagesActivity;
+import fr.wildcodeschool.steeryfit.UI.Activities.Splashscreen;
 import fr.wildcodeschool.steeryfit.UI.Fragments.MessagesFragment;
 import fr.wildcodeschool.steeryfit.Utils.Utils;
 
+import static fr.wildcodeschool.steeryfit.Utils.Constants.CONVERSATIONS_ENTRY;
+
 /**
  * Created by adphi on 12/12/17.
  */
@@ -62,35 +70,56 @@ public class NotificationsService extends FirebaseMessagingService {
                         return;
                     }
                 }
-                sendNotification(title, message, "", type);
+                sendNotification(title, message, "", type, uid);
+            }
+            else if (type.equals(EVENT)) {
+                sendNotification(title, message, "", type, uid);
             }
         }
     }
 
 
-    private void sendNotification(String title, String content, String subText, String type) {
+    private void sendNotification(String title, String content, String subText, String type, String uid) {
 
-        NotificationManager notificationManager =
-                (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
         Notification.Builder builder = new Notification.Builder(NotificationsService.this);
         builder.setContentTitle(title)
                 .setContentText(content)
                 .setSubText(title)
-                //.setContentIntent(PendingIntent.getActivity(getApplicationContext(), UUID.randomUUID().hashCode(), new Intent(NotificationsService.this, MainActivity.class), 0))
                 .setWhen(System.currentTimeMillis())
                 .setPriority(Notification.PRIORITY_DEFAULT)
                 .setAutoCancel(true)
-                //.setDefaults(Notification.DEFAULT_ALL)
                 .setVibrate(new long[]{0, 1000, 200, 1000})
                 .setLights(Color.RED, 500, 500)
                 .setSmallIcon(R.drawable.ic_stat_name)
                 .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
 
-        Notification ntf = builder.build();
-        /*ntf.flags = Notification.DEFAULT_ALL;
-        ntf.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
-        ntf.flags |= Notification.FLAG_AUTO_CANCEL;*/
+        if(type.equals(MESSAGE)) {
+            // MESSAGE
+            Log.d(TAG, "sendNotification: Conversation Controller available: "
+                    + ConversationsController.isInstanciated());
+            if(ConversationsController.isInstanciated()) {
+                Intent intent = new Intent(NotificationsService.this, MessagesActivity.class);
+                intent.putExtra(CONVERSATIONS_ENTRY, uid);
+                builder.setContentIntent(PendingIntent.getActivity(this, UUID.randomUUID().hashCode(),
+                        intent, 0));
+            }
+            // TODO: ?? What if the notification is clicked after the application was closed ??
+            else {
+                Intent intent = new Intent(NotificationsService.this, Splashscreen.class);
+                intent.putExtra(CONVERSATIONS_ENTRY, uid);
+                builder.setContentIntent(PendingIntent.getActivity(this, UUID.randomUUID()
+                        .hashCode(), intent, 0));
+            }
+        }
+        else {
+            // EVENT
+            Log.d(TAG, "sendNotification: UserEvents Controller available: "
+                    + UserEventsController.isInstanciated());
+            // TODO: ?? What should we do ? ??
+        }
 
+        Notification ntf = builder.build();
+        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
         notificationManager.notify(type.hashCode(), ntf);
     }
 }

+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Services/TokenService.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/ConversationsActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/EditoActivity.java


+ 1 - 1
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/MainActivity.java

@@ -92,7 +92,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
         mConversationsController = ConversationsController.getInstance();
         mConversationsController.setOnUnreadCountChangedListener(count -> {
             if(mTextViewNotificationBadge != null) {
-                setupBadge();
+                runOnUiThread(this::setupBadge);
             }
         });
 

+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/MessagesActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/ModifyEventActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/PhoneConfirmationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/SignInActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/SignInMailActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/SignUpMailActivity.java


+ 48 - 5
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Activities/Splashscreen.java

@@ -4,6 +4,7 @@ import android.content.Intent;
 import android.os.Bundle;
 import android.os.Handler;
 import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
 import android.view.WindowManager;
 
 import com.google.firebase.auth.FirebaseUser;
@@ -17,6 +18,8 @@ import fr.wildcodeschool.steeryfit.R;
 import fr.wildcodeschool.steeryfit.Utils.UserConfigurationHelper;
 import fr.wildcodeschool.steeryfit.Utils.Utils;
 
+import static fr.wildcodeschool.steeryfit.Utils.Constants.CONVERSATIONS_ENTRY;
+
 public class Splashscreen extends AppCompatActivity {
 
     private final String TAG = Utils.getTAG(this);
@@ -26,10 +29,12 @@ public class Splashscreen extends AppCompatActivity {
 
     private AuthController mAuthController;
     private UserController mUserController;
+    private ConversationsController mConversationsController;
     private FirebaseUser mUser;
 
     private Handler mHandler;
     private boolean mLoaded = false;
+    private String mConversationUid;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -37,6 +42,35 @@ public class Splashscreen extends AppCompatActivity {
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
         setContentView(R.layout.activity_splashscreen);
 
+        // TODO: Remove
+        /*// Utility getting KEYHASH for Facebook Auth
+        PackageInfo info = null;
+        try {
+            info = getPackageManager().getPackageInfo("fr.wildcodeschool.steeryfit", PackageManager.GET_SIGNATURES);
+            for (Signature signature : info.signatures) {
+                MessageDigest md = MessageDigest.getInstance("SHA");
+                md.update(signature.toByteArray());
+                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
+            }
+        } catch (PackageManager.NameNotFoundException e) {
+            e.printStackTrace();
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }*/
+
+        // Check if launched by NotificationsService's Notification
+        Intent intentFrom = getIntent();
+        mConversationUid = intentFrom.getStringExtra(CONVERSATIONS_ENTRY);
+        if(mConversationUid != null && ConversationsController.isInstanciated()) {
+            Log.d(TAG, "init: Launching Messenger");
+            Intent intent = new Intent(this, MessagesActivity.class);
+            intent.putExtra(CONVERSATIONS_ENTRY, mConversationUid);
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+            startActivity(intent);
+            finish();
+            return;
+        }
+
         mAuthController = AuthController.getInstance(this);
         mAuthController.setAuthListener(new AuthController.AuthListener() {
             @Override
@@ -88,7 +122,7 @@ public class Splashscreen extends AppCompatActivity {
 
     private void init() {
         UserEventsController.getInstance();
-        ConversationsController.getInstance();
+        mConversationsController = ConversationsController.getInstance();
         mLoaded = true;
         if(!mHandler.hasMessages(0)) {
             goToNextActivity();
@@ -96,10 +130,19 @@ public class Splashscreen extends AppCompatActivity {
     }
 
     private void goToNextActivity(){
-        UserModel userModel = mUserController.getUser();
-        Intent intent = UserConfigurationHelper.getNextActivity(userModel, Splashscreen.this);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
-        startActivity(intent);
+        if(mConversationUid != null) {
+            Log.d(TAG, "init: Launching Messenger");
+            Intent intent = new Intent(this, MessagesActivity.class);
+            intent.putExtra(CONVERSATIONS_ENTRY, mConversationUid);
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+            startActivity(intent);
+        }
+        else {
+            UserModel userModel = mUserController.getUser();
+            Intent intent = UserConfigurationHelper.getNextActivity(userModel, Splashscreen.this);
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+            startActivity(intent);
+        }
         finish();
     }
 

+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/ConversationsAdapter.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/EventAdapter.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/MessagesAdapter.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/ParticipantsAdapter.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/PlaceAutocompleteAdapter.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Adapters/SwipeDeckAdapter.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/CreateEvent/CreateEventActivityPart1.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/CreateEvent/CreateEventActivityPart2.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/CreateEvent/CreateEventFragment.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/Behaviors/AvatarBehavior.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/Behaviors/RecyclerViewBehavior.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/ConversationsFragment.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/LocationPickerFragment.java


+ 4 - 2
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/MainFragment.java

@@ -89,8 +89,10 @@ public class MainFragment extends Fragment {
             public void onViewSwipedToRight(int position) {
                 Log.d(TAG, "onViewSwipedToRight() called with: position = [" + position + "]");
                 mUserEventsController.matchEvent(mProposedEvents.get(position));
-                ConversationsController.getInstance().setConversationCreatedListener(
-                        conversation -> startActivity(new Intent(getActivity(), MessagesActivity.class)));
+                mUserEventsController.setOnEventMatchedListener(conversation -> {
+                    ConversationsController.getInstance().setSelectedConversation(conversation);
+                    startActivity(new Intent(getActivity(), MessagesActivity.class));
+                });
             }
 
             @Override

+ 15 - 1
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/MessagesFragment.java

@@ -32,6 +32,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 
 import de.hdodenhof.circleimageview.CircleImageView;
+import fr.wildcodeschool.steeryfit.Controllers.AuthController;
 import fr.wildcodeschool.steeryfit.Controllers.ConversationsController;
 import fr.wildcodeschool.steeryfit.Controllers.MessagesController;
 import fr.wildcodeschool.steeryfit.Controllers.UserController;
@@ -46,6 +47,7 @@ import fr.wildcodeschool.steeryfit.UI.Adapters.MessagesAdapter;
 import fr.wildcodeschool.steeryfit.Utils.Utils;
 
 import static fr.wildcodeschool.steeryfit.Models.EventModel.State.PARTICIPATING;
+import static fr.wildcodeschool.steeryfit.Utils.Constants.CONVERSATIONS_ENTRY;
 
 
 public class MessagesFragment extends Fragment implements MessagesController.MessagesListener,
@@ -101,10 +103,22 @@ public class MessagesFragment extends Fragment implements MessagesController.Mes
                              Bundle savedInstanceState) {
         View view = inflater.inflate(R.layout.fragment_messages, container, false);
 
+        Intent intent = getActivity().getIntent();
+        String conversationUid = intent.getStringExtra(CONVERSATIONS_ENTRY);
+
+        // Security call
+        AuthController.getInstance(getActivity());
         // Controller
         mUserEventsController = UserEventsController.getInstance();
         mConversationsController = ConversationsController.getInstance();
-        mConversation = mConversationsController.getSelectedConversation();
+        // Check if launched from Notification
+        if(conversationUid != null) {
+            mConversation = mConversationsController.getConversations().get(conversationUid);
+            mConversationsController.setSelectedConversation(mConversation);
+        }
+        else {
+            mConversation = mConversationsController.getSelectedConversation();
+        }
         mMessagesController = new MessagesController(mConversation);
         mMessagesController.setMessagesListener(this);
         mConversationsController.setConversationsListener(this);

+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/Fragments/PlanningFragment.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/LevelPickerDialogFragment.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserAliasConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserAvatarConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserDateOfBirthConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserEmailConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserFirstnameConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserGenderConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserLastnameConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserLocationConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserPasswordConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserPhoneConfigurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/UI/ProfileConfiguration/UserSportsConfirgurationActivity.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Utils/Constants.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Utils/FirebaseGlideModule.java


+ 1 - 1
app/src/main/java/fr/wildcodeschool/steeryfit/Utils/FirebaseHelper.java

@@ -40,7 +40,7 @@ public class FirebaseHelper {
     public static FirebaseDatabase getDatabase(){
         if(sDatabase == null) {
             sDatabase = FirebaseDatabase.getInstance();
-            //sDatabase.setPersistenceEnabled(true);
+            sDatabase.setPersistenceEnabled(true);
         }
         return sDatabase;
     }

+ 93 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Utils/HttpRequest.java

@@ -0,0 +1,93 @@
+package fr.wildcodeschool.steeryfit.Utils;
+
+import android.support.annotation.Nullable;
+
+import com.loopj.android.http.AsyncHttpClient;
+import com.loopj.android.http.RequestParams;
+import com.loopj.android.http.TextHttpResponseHandler;
+
+import cz.msebera.android.httpclient.Header;
+import fr.wildcodeschool.steeryfit.Controllers.AuthController;
+
+/**
+ * Created by adphi on 05/01/18.
+ */
+
+public class HttpRequest {
+
+    public static final String EVENT_MATCH = "event/match";
+    public static final String EVENT_DELETE = "event/delete";
+    public static final String EVENT_CANCEL = "/event/cancel";
+    public static final String EVENT_CONFIRM = "/event/confirm";
+    public static final String EVENT_REJECT = "/event/reject";
+
+    // Private
+    private static final String BASE_URL = "https://us-central1-steeryfit-3999d.cloudfunctions.net/app/";
+    private static final String AUTH_PREFIX = "Bearer ";
+    private static final String AUTHORISATION = "authorization";
+    private static final String EVENT_ID_KEY = "id";
+    private static final String USER_ID_KEY = "user";
+
+    private static AsyncHttpClient sClient = null;
+    private static String sTokenId;
+
+    public static class Builder {
+        private RequestParams mParams;
+        private String mUrl = "";
+
+        public Builder() {
+            if(sClient == null) {
+                sClient = new AsyncHttpClient();
+                sClient.setEnableRedirects(true, true, true);
+            }
+            mParams = new RequestParams();
+        }
+
+        public Builder path(String path) {
+            mUrl = BASE_URL + path;
+            return this;
+        }
+
+        public Builder addParam(String key, String value) {
+            mParams.add(key, value);
+            return this;
+        }
+
+        public Builder addEventId(String eventId) {
+            mParams.add(EVENT_ID_KEY, eventId);
+            return this;
+        }
+
+        public Builder addUserId(String userId) {
+            mParams.add(USER_ID_KEY, userId);
+            return this;
+        }
+
+        public Builder get(OnCompleteListener onCompleteListener) {
+            if(mUrl.isEmpty()) {
+                throw new RuntimeException("Cannot send Request without path.");
+            }
+            AuthController.getInstance().getUser().getIdToken(true)
+                .addOnSuccessListener(getTokenResult -> {
+                    sTokenId = AUTH_PREFIX + getTokenResult.getToken();
+                    sClient.addHeader(AUTHORISATION, sTokenId);
+                    sClient.get(mUrl, mParams, new TextHttpResponseHandler() {
+                        @Override
+                        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
+                            onCompleteListener.onCompleteListener(responseString, new Exception(throwable));
+                        }
+
+                        @Override
+                        public void onSuccess(int statusCode, Header[] headers, String responseString) {
+                            onCompleteListener.onCompleteListener(responseString, null);
+                        }
+                    });
+                });
+            return this;
+        }
+    }
+
+    public interface OnCompleteListener {
+        void onCompleteListener(@Nullable String resultString, @Nullable Exception e);
+    }
+}

+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Utils/UserConfigurationHelper.java


+ 0 - 0
app/src/main/java/fr/wildcodeschool/steeryfit/Utils/Utils.java


+ 0 - 0
app/src/main/res/drawable-hdpi/blank_avatar.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_arm.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_ball.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_bike.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_calendar.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_clock.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_gender_female.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_gender_male.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_gender_mixed.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_golf.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_level_1.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_level_2.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_level_3.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_racket.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_running.png


+ 0 - 0
app/src/main/res/drawable-hdpi/event_sandclock.png


+ 0 - 0
app/src/main/res/drawable-hdpi/googlemaps_icon.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_back_arrow.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_ball.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_bike.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_golf.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_magnify.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_not_valid_edit_text.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_racket.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_recycler_view_button.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_run.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_stat_name.png


+ 0 - 0
app/src/main/res/drawable-hdpi/ic_valid_edit_text.png


Some files were not shown because too many files changed in this diff