diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotificationFactory.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotificationFactory.java index c83ef55f6..c5da1e695 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotificationFactory.java +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotificationFactory.java @@ -17,6 +17,8 @@ public class HabiticaLocalNotificationFactory { return new ReceivedPrivateMessageLocalNotification(); } else if (notificationType.contains(PushNotificationManager.RECEIVED_GEMS_PUSH_NOTIFICATION_KEY)) { return new ReceivedGemsGiftLocalNotification(); + } else if (notificationType.contains(PushNotificationManager.RECEIVED_SUBSCRIPTION_GIFT_PUSH_NOTIFICATION_KEY)) { + return new ReceivedSubscriptionGiftLocalNotification(); } return null; diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PushNotificationManager.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PushNotificationManager.java index 914b4821a..fbfc9d612 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PushNotificationManager.java +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PushNotificationManager.java @@ -26,6 +26,7 @@ public class PushNotificationManager { public static String PARTY_INVITE_PUSH_NOTIFICATION_KEY = "Invited To Party"; public static String RECEIVED_PRIVATE_MESSAGE_PUSH_NOTIFICATION_KEY = "New Message from test33@test.com:"; public static String RECEIVED_GEMS_PUSH_NOTIFICATION_KEY = "Gems"; + public static String RECEIVED_SUBSCRIPTION_GIFT_PUSH_NOTIFICATION_KEY = "Subscription"; @Inject public APIHelper apiHelper; @@ -100,6 +101,8 @@ public class PushNotificationManager { key = "preference_push_received_a_private_message"; } else if (type.contains(RECEIVED_GEMS_PUSH_NOTIFICATION_KEY)) { key = "preference_push_gifted_gems"; + } else if (type.contains(RECEIVED_SUBSCRIPTION_GIFT_PUSH_NOTIFICATION_KEY)) { + key = "preference_push_gifted_subscription"; } return sharedPreferences.getBoolean(key, true); diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedSubscriptionGiftLocalNotification.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedSubscriptionGiftLocalNotification.java new file mode 100644 index 000000000..553ce5796 --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedSubscriptionGiftLocalNotification.java @@ -0,0 +1,42 @@ +package com.habitrpg.android.habitica.helpers.notifications; + +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.media.RingtoneManager; +import android.net.Uri; +import android.support.v4.app.NotificationCompat; + +import com.habitrpg.android.habitica.R; +import com.habitrpg.android.habitica.ui.activities.MainActivity; + +/** + * Created by keithholliday on 7/1/16. + */ +public class ReceivedSubscriptionGiftLocalNotification implements HabiticaLocalNotification { + @Override + public void notifyLocally(Context context, String title, String message) { + Uri path = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); + + NotificationCompat.Builder notificationBuilder = + new NotificationCompat.Builder(context) + .setSmallIcon(R.drawable.ic_gryphon) + .setContentTitle(title) + .setContentText(message) + .setAutoCancel(true) + .setSound(path); + + Intent intent = new Intent(context, MainActivity.class); + PendingIntent pendingIntent = PendingIntent.getActivity( + context, + 3000, + intent, + PendingIntent.FLAG_UPDATE_CURRENT + ); + notificationBuilder.setContentIntent(pendingIntent); + + NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); + notificationManager.notify(10, notificationBuilder.build()); + } +}