Added quest begun, invite to party and invite to guild local notifications

This commit is contained in:
Keith Holliday 2016-07-01 14:20:42 -05:00
parent 1c45ee87cc
commit c834d020ac
6 changed files with 175 additions and 2 deletions

View file

@ -377,6 +377,10 @@ To start, which parts of your life do you want to improve?</string>
<!-- Local notification actions -->
<string name="accept_party_invite">ACCEPT_PARTY_INVITE</string>
<string name="reject_party_invite">ACCEPT_PARTY_INVITE</string>
<string name="reject_party_invite">REJECT_PARTY_INVITE</string>
<string name="accept_guild_invite">ACCEPT_GUILD_INVITE</string>
<string name="reject_guild_invite">REJECT_GUILD_INVITE</string>
<string name="accept_quest_invite">ACCEPT_QUEST_INVITE</string>
<string name="reject_quest_invite">REJECT_QUEST_INVITE</string>
</resources>

View file

@ -0,0 +1,56 @@
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.content.res.Resources;
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.receivers.LocalNotificationActionReceiver;
/**
* Created by keithholliday on 7/1/16.
*/
public class GuildInviteLocalNotification 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);
Resources res = context.getResources();
Intent acceptInviteIntent = new Intent(context, LocalNotificationActionReceiver.class);
acceptInviteIntent.setAction(res.getString(R.string.accept_guild_invite));
PendingIntent pendingIntentAccept = PendingIntent.getBroadcast(
context,
3000,
acceptInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.addAction(R.drawable.ic_gryphon, "Accept", pendingIntentAccept);
Intent rejectInviteIntent = new Intent();
rejectInviteIntent.setAction(res.getString(R.string.reject_guild_invite));
PendingIntent pendingIntentReject = PendingIntent.getBroadcast(
context,
2000,
acceptInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.addAction(R.drawable.ic_gryphon, "Reject", pendingIntentReject);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.notify(10, notificationBuilder.build());
}
}

View file

@ -19,6 +19,12 @@ public class HabiticaLocalNotificationFactory {
return new ReceivedGemsGiftLocalNotification();
} else if (notificationType.contains(PushNotificationManager.RECEIVED_SUBSCRIPTION_GIFT_PUSH_NOTIFICATION_KEY)) {
return new ReceivedSubscriptionGiftLocalNotification();
} else if (notificationType.contains(PushNotificationManager.GUILD_INVITE_PUSH_NOTIFICATION_KEY)) {
return new GuildInviteLocalNotification();
} else if (notificationType.contains(PushNotificationManager.QUEST_INVITE_PUSH_NOTIFICATION_KEY)) {
return new QuestInviteLocalNotification();
} else if (notificationType.contains(PushNotificationManager.QUEST_BEGUN_PUSH_NOTIFICATION_KEY)) {
return new QuestBegunLocalNotification();
}
return null;

View file

@ -24,9 +24,12 @@ public class PushNotificationManager {
private static PushNotificationManager instance = null;
private static String DEVICE_TOKEN_PREFERENCE_STRING = "device-token-preference-string";
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_PRIVATE_MESSAGE_PUSH_NOTIFICATION_KEY = "New Message from";
public static String RECEIVED_GEMS_PUSH_NOTIFICATION_KEY = "Gems";
public static String RECEIVED_SUBSCRIPTION_GIFT_PUSH_NOTIFICATION_KEY = "Subscription";
public static String GUILD_INVITE_PUSH_NOTIFICATION_KEY = "Guild";
public static String QUEST_INVITE_PUSH_NOTIFICATION_KEY = "Quest Invitation";
public static String QUEST_BEGUN_PUSH_NOTIFICATION_KEY = "Your Quest has Begun";
@Inject
public APIHelper apiHelper;
@ -103,6 +106,12 @@ public class PushNotificationManager {
key = "preference_push_gifted_gems";
} else if (type.contains(RECEIVED_SUBSCRIPTION_GIFT_PUSH_NOTIFICATION_KEY)) {
key = "preference_push_gifted_subscription";
} else if (type.contains(GUILD_INVITE_PUSH_NOTIFICATION_KEY)) {
key = "preference_push_invited_to_guild";
} else if (type.contains(QUEST_INVITE_PUSH_NOTIFICATION_KEY)) {
key = "preference_push_invited_to_quest";
} else if (type.contains(QUEST_BEGUN_PUSH_NOTIFICATION_KEY)) {
key = "preference_push_your_quest_has_begun";
}
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 QuestBegunLocalNotification 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());
}
}

View file

@ -0,0 +1,56 @@
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.content.res.Resources;
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.receivers.LocalNotificationActionReceiver;
/**
* Created by keithholliday on 7/1/16.
*/
public class QuestInviteLocalNotification 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);
Resources res = context.getResources();
Intent acceptInviteIntent = new Intent(context, LocalNotificationActionReceiver.class);
acceptInviteIntent.setAction(res.getString(R.string.accept_quest_invite));
PendingIntent pendingIntentAccept = PendingIntent.getBroadcast(
context,
3000,
acceptInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.addAction(R.drawable.ic_gryphon, "Accept", pendingIntentAccept);
Intent rejectInviteIntent = new Intent();
rejectInviteIntent.setAction(res.getString(R.string.reject_quest_invite));
PendingIntent pendingIntentReject = PendingIntent.getBroadcast(
context,
2000,
acceptInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.addAction(R.drawable.ic_gryphon, "Reject", pendingIntentReject);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.notify(10, notificationBuilder.build());
}
}