Added receive gift subscription notification

This commit is contained in:
Keith Holliday 2016-07-01 13:30:24 -05:00
parent c580a6ad9a
commit 1c45ee87cc
3 changed files with 47 additions and 0 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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());
}
}