Commit 9cb2be1d authored by Sajal Narang's avatar Sajal Narang

Implement event reminder notifications

parent 31795ae7
...@@ -110,6 +110,20 @@ ...@@ -110,6 +110,20 @@
</intent-filter> </intent-filter>
</activity> </activity>
<service
android:name=".notifications.NotificationIntentService"
android:enabled="true"
android:exported="false" />
<receiver android:name=".notifications.NotificationEventReceiver" />
<receiver android:name=".notifications.NotificationServiceStarterReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>
<receiver <receiver
android:name="com.google.android.gms.gcm.GcmReceiver" android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true" android:exported="true"
......
...@@ -6,6 +6,9 @@ public class Constants { ...@@ -6,6 +6,9 @@ public class Constants {
public static final int MY_PERMISSIONS_REQUEST_LOCATION = 3; public static final int MY_PERMISSIONS_REQUEST_LOCATION = 3;
public static final int RESULT_LOAD_IMAGE = 11; public static final int RESULT_LOAD_IMAGE = 11;
public static final String NOTIFICATIONS_RESPONSE_JSON = "notifications_json"; public static final String NOTIFICATIONS_RESPONSE_JSON = "notifications_json";
public static final String EVENT_ID = "event_id";
public static final String EVENT_LATITUDE = "event_latitude";
public static final String EVENT_LONGITUDE = "event_longitude";
public static final String EVENT_JSON = "event_json"; public static final String EVENT_JSON = "event_json";
public static final String EVENT_LIST_JSON = "event_list_json"; public static final String EVENT_LIST_JSON = "event_list_json";
public static final String USER_ID = "user_id"; public static final String USER_ID = "user_id";
......
...@@ -26,10 +26,12 @@ import com.squareup.picasso.Picasso; ...@@ -26,10 +26,12 @@ import com.squareup.picasso.Picasso;
import app.insti.api.UnsafeOkHttpClient; import app.insti.api.UnsafeOkHttpClient;
import app.insti.data.Body; import app.insti.data.Body;
import app.insti.data.Event;
import app.insti.data.User; import app.insti.data.User;
import app.insti.fragment.BackHandledFragment; import app.insti.fragment.BackHandledFragment;
import app.insti.fragment.BodyFragment; import app.insti.fragment.BodyFragment;
import app.insti.fragment.CalendarFragment; import app.insti.fragment.CalendarFragment;
import app.insti.fragment.EventFragment;
import app.insti.fragment.ExploreFragment; import app.insti.fragment.ExploreFragment;
import app.insti.fragment.FeedFragment; import app.insti.fragment.FeedFragment;
import app.insti.fragment.MapFragment; import app.insti.fragment.MapFragment;
...@@ -42,10 +44,12 @@ import app.insti.fragment.ProfileFragment; ...@@ -42,10 +44,12 @@ import app.insti.fragment.ProfileFragment;
import app.insti.fragment.QuickLinksFragment; import app.insti.fragment.QuickLinksFragment;
import app.insti.fragment.SettingsFragment; import app.insti.fragment.SettingsFragment;
import app.insti.fragment.TrainingBlogFragment; import app.insti.fragment.TrainingBlogFragment;
import app.insti.notifications.NotificationEventReceiver;
import static app.insti.Constants.MY_PERMISSIONS_REQUEST_ACCESS_LOCATION; import static app.insti.Constants.MY_PERMISSIONS_REQUEST_ACCESS_LOCATION;
import static app.insti.Constants.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE; import static app.insti.Constants.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE;
import static app.insti.Constants.RESULT_LOAD_IMAGE; import static app.insti.Constants.RESULT_LOAD_IMAGE;
import static app.insti.notifications.NotificationIntentService.ACTION_OPEN_EVENT;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, BackHandledFragment.BackHandlerInterface { public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, BackHandledFragment.BackHandlerInterface {
...@@ -80,8 +84,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -80,8 +84,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
feedFragment = new FeedFragment(); feedFragment = new FeedFragment();
updateFragment(feedFragment); updateFragment(feedFragment);
Intent appLinkIntent = getIntent(); Intent intent = getIntent();
handleIntent(appLinkIntent); if (intent != null) {
if (intent.getAction() != null && intent.getAction().equals(ACTION_OPEN_EVENT)) {
EventFragment eventFragment = new EventFragment();
Bundle bundle = new Bundle();
bundle.putString(Constants.EVENT_JSON, intent.getStringExtra(Constants.EVENT_JSON));
eventFragment.setArguments(bundle);
updateFragment(eventFragment);
} else {
handleIntent(intent);
}
}
NotificationEventReceiver.setupAlarm(getApplicationContext());
} }
private void handleIntent(Intent appLinkIntent) { private void handleIntent(Intent appLinkIntent) {
......
...@@ -36,11 +36,16 @@ public class SessionManager { ...@@ -36,11 +36,16 @@ public class SessionManager {
editor = pref.edit(); editor = pref.edit();
editor.putBoolean(Constants.IS_LOGGED_IN, true); editor.putBoolean(Constants.IS_LOGGED_IN, true);
editor.putString(Constants.GCM_ID, gcmId); editor.putString(Constants.GCM_ID, gcmId);
editor.putString(Constants.USER_ID, currentUser.getUserID());
editor.putString(Constants.CURRENT_USER, currentUser.toString()); editor.putString(Constants.CURRENT_USER, currentUser.toString());
editor.putString(Constants.SESSION_ID, sessionID); editor.putString(Constants.SESSION_ID, sessionID);
editor.commit(); editor.commit();
} }
public String getUserID() {
return pref.getString(Constants.USER_ID, "");
}
public String getSessionID() { public String getSessionID() {
return pref.getString(Constants.SESSION_ID, ""); return pref.getString(Constants.SESSION_ID, "");
} }
......
...@@ -40,12 +40,12 @@ public interface RetrofitInterface { ...@@ -40,12 +40,12 @@ public interface RetrofitInterface {
@GET("events") @GET("events")
Call<NewsFeedResponse> getNewsFeed(@Header("Cookie") String sessionId); Call<NewsFeedResponse> getNewsFeed(@Header("Cookie") String sessionId);
@GET("locations")
Call<List<Venue>> getAllVenues();
@GET("events") @GET("events")
Call<NewsFeedResponse> getEventsBetweenDates(@Header("Cookie") String sessionId, @Query("start") String start, @Query("end") String end); Call<NewsFeedResponse> getEventsBetweenDates(@Header("Cookie") String sessionId, @Query("start") String start, @Query("end") String end);
@GET("locations")
Call<List<Venue>> getAllVenues();
@GET("users/{uuid}") @GET("users/{uuid}")
Call<User> getUser(@Header("Cookie") String sessionId, @Path("uuid") String uuid); Call<User> getUser(@Header("Cookie") String sessionId, @Path("uuid") String uuid);
......
...@@ -5,6 +5,7 @@ import android.arch.persistence.room.Entity; ...@@ -5,6 +5,7 @@ import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey; import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -210,4 +211,9 @@ public class Event { ...@@ -210,4 +211,9 @@ public class Event {
public void setEventUserUes(int eventUserUes) { public void setEventUserUes(int eventUserUes) {
this.eventUserUes = eventUserUes; this.eventUserUes = eventUserUes;
} }
@Override
public String toString() {
return new Gson().toJson(this);
}
} }
package com.iitb.moodindigo.mi2016; package app.insti.notifications;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
...@@ -15,14 +15,13 @@ NotificationEventReceiver extends WakefulBroadcastReceiver { ...@@ -15,14 +15,13 @@ NotificationEventReceiver extends WakefulBroadcastReceiver {
private static final String ACTION_START_NOTIFICATION_SERVICE = "ACTION_START_NOTIFICATION_SERVICE"; private static final String ACTION_START_NOTIFICATION_SERVICE = "ACTION_START_NOTIFICATION_SERVICE";
private static final String ACTION_DELETE_NOTIFICATION = "ACTION_DELETE_NOTIFICATION"; private static final String ACTION_DELETE_NOTIFICATION = "ACTION_DELETE_NOTIFICATION";
private static final int NOTIFICATIONS_INTERVAL_IN_HOURS = 1;
public static void setupAlarm(Context context) { public static void setupAlarm(Context context) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent alarmIntent = getStartPendingIntent(context); PendingIntent alarmIntent = getStartPendingIntent(context);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
getTriggerAt(new Date()), getTriggerAt(new Date()),
1000 * 60 * 15, //Change this to 1000 * 60 for testing => runs every minute 1000 * 60 * 10, //Change this to 1000 * 60 for testing => runs every minute
alarmIntent); alarmIntent);
} }
......
package com.iitb.moodindigo.mi2016; package app.insti.notifications;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment