improve push notification handling

This commit is contained in:
Phillip Thelen 2018-08-09 18:15:44 +02:00
parent 333d08e11c
commit e6876acea0
26 changed files with 392 additions and 398 deletions

View file

@ -0,0 +1,64 @@
package com.habitrpg.android.habitica.helpers
import android.content.Intent
import com.habitrpg.android.habitica.helpers.notifications.PushNotificationManager
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.activities.MainActivity
import com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment
import com.habitrpg.android.habitica.ui.fragments.social.GuildFragment
import com.habitrpg.android.habitica.ui.fragments.social.InboxFragment
import com.habitrpg.android.habitica.ui.fragments.social.QuestDetailFragment
class NotificationOpenHandler {
companion object {
fun handleOpenedByNotification(identifier: String, intent: Intent, activity: MainActivity, user: User?) {
when (identifier) {
PushNotificationManager.PARTY_INVITE_PUSH_NOTIFICATION_KEY -> openPartyScreen(activity)
PushNotificationManager.QUEST_BEGUN_PUSH_NOTIFICATION_KEY -> openQuestDetailSCreen(activity,
user?.party?.id,
user?.party?.quest?.key)
PushNotificationManager.QUEST_INVITE_PUSH_NOTIFICATION_KEY -> openQuestDetailSCreen(activity,
user?.party?.id,
user?.party?.quest?.key)
PushNotificationManager.GUILD_INVITE_PUSH_NOTIFICATION_KEY -> openGuildDetailScreen(activity,
intent.getStringExtra("groupID"))
PushNotificationManager.RECEIVED_PRIVATE_MESSAGE_PUSH_NOTIFICATION_KEY -> openPrivateMessageScreen(activity,
intent.getStringExtra("replyTo"))
}
}
private fun openPrivateMessageScreen(activity: MainActivity, userID: String?) {
if (userID?.isNotEmpty() == true) {
return
}
val fragment = InboxFragment()
fragment.userId = userID ?: ""
activity.displayFragment(fragment)
}
private fun openPartyScreen(activity: MainActivity) {
activity.selectMenuItem(NavigationDrawerFragment.SIDEBAR_PARTY)
}
private fun openQuestDetailSCreen(activity: MainActivity, partyId: String?, questKey: String?) {
if (partyId?.isNotEmpty() == true || questKey?.isNotEmpty() == true) {
return
}
val fragment = QuestDetailFragment()
fragment.partyId = partyId
fragment.questKey = questKey
activity.displayFragment(fragment)
}
private fun openGuildDetailScreen(activity: MainActivity, groupID: String) {
if (groupID.isEmpty()) {
return
}
val fragment = GuildFragment()
fragment.setGuildId(groupID)
activity.displayFragment(fragment)
}
}
}

View file

@ -0,0 +1,5 @@
package com.habitrpg.android.habitica.helpers.notifications
import android.content.Context
class GenericLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier)

View file

@ -1,50 +0,0 @@
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 com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.receivers.LocalNotificationActionReceiver;
/**
* Created by keithholliday on 7/1/16.
*/
public class GuildInviteLocalNotification extends HabiticaLocalNotification {
@Override
public void notifyLocally(Context context, String title, String message) {
super.notifyLocally(context, title, message);
this.setNotificationActions();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(10, notificationBuilder.build());
}
protected void setNotificationActions() {
Resources res = context.getResources();
Intent acceptInviteIntent = new Intent(context, LocalNotificationActionReceiver.class);
acceptInviteIntent.setAction(res.getString(R.string.accept_guild_invite));
acceptInviteIntent.putExtra("groupID", this.data.get("groupID"));
PendingIntent pendingIntentAccept = PendingIntent.getBroadcast(
context,
3000,
acceptInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.addAction(0, "Accept", pendingIntentAccept);
Intent rejectInviteIntent = new Intent(context, LocalNotificationActionReceiver.class);
rejectInviteIntent.setAction(res.getString(R.string.reject_guild_invite));
rejectInviteIntent.putExtra("groupID", this.data.get("groupID"));
PendingIntent pendingIntentReject = PendingIntent.getBroadcast(
context,
2000,
rejectInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.addAction(0, "Reject", pendingIntentReject);
}
}

View file

@ -0,0 +1,46 @@
package com.habitrpg.android.habitica.helpers.notifications
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.receivers.LocalNotificationActionReceiver
/**
* Created by keithholliday on 7/1/16.
*/
class GuildInviteLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier) {
override fun configureMainIntent(intent: Intent) {
super.configureMainIntent(intent)
intent.putExtra("groupID", data?.get("groupID"))
}
override fun setNotificationActions() {
super.setNotificationActions()
val res = context.resources
val acceptInviteIntent = Intent(context, LocalNotificationActionReceiver::class.java)
acceptInviteIntent.action = res.getString(R.string.accept_guild_invite)
acceptInviteIntent.putExtra("groupID", this.data?.get("groupID"))
val pendingIntentAccept = PendingIntent.getBroadcast(
context,
3000,
acceptInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
notificationBuilder.addAction(0, "Accept", pendingIntentAccept)
val rejectInviteIntent = Intent(context, LocalNotificationActionReceiver::class.java)
rejectInviteIntent.action = res.getString(R.string.reject_guild_invite)
rejectInviteIntent.putExtra("groupID", this.data?.get("groupID"))
val pendingIntentReject = PendingIntent.getBroadcast(
context,
2000,
rejectInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
notificationBuilder.addAction(0, "Reject", pendingIntentReject)
}
}

View file

@ -1,47 +0,0 @@
package com.habitrpg.android.habitica.helpers.notifications;
import android.content.Context;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.annotation.CallSuper;
import android.support.v4.app.NotificationCompat;
import com.habitrpg.android.habitica.R;
import java.util.Map;
/**
* Created by keithholliday on 6/28/16.
*/
public abstract class HabiticaLocalNotification {
protected Map<String, String> data;
protected Context context;
protected String title;
protected String message;
protected NotificationCompat.Builder notificationBuilder;
@CallSuper
public void notifyLocally(Context context, String title, String message) {
this.context = context;
this.title = title;
this.message = message;
Uri path = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
this.notificationBuilder =
new NotificationCompat.Builder(context, "default")
.setSmallIcon(R.drawable.ic_gryphon_white)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(path);
}
public void setExtras(Map<String, String> data) {
this.data = data;
}
protected abstract void setNotificationActions();
}

View file

@ -0,0 +1,70 @@
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.support.annotation.CallSuper
import android.support.v4.app.NotificationCompat
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.ui.activities.MainActivity
/**
* Created by keithholliday on 6/28/16.
*/
abstract class HabiticaLocalNotification(protected var context: Context, protected var identifier: String) {
protected var data: Map<String, String>? = null
protected var title: String? = null
protected var message: String? = null
protected var notificationBuilder = NotificationCompat.Builder(context, "default")
@CallSuper
open fun notifyLocally(title: String?, message: String?) {
this.title = title
this.message = message
val path = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
this.notificationBuilder = notificationBuilder
.setSmallIcon(R.drawable.ic_gryphon_white)
.setAutoCancel(true)
.setSound(path)
if (title != null) {
notificationBuilder = notificationBuilder.setContentTitle(title)
}
if (message != null) {
notificationBuilder = notificationBuilder.setContentText(message)
}
this.setNotificationActions()
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
notificationManager?.notify(getNotificationID(), notificationBuilder.build())
}
fun setExtras(data: Map<String, String>) {
this.data = data
}
protected open fun setNotificationActions() {
val intent = Intent(context, MainActivity::class.java)
intent.putExtra("notificationIdentifier", identifier)
configureMainIntent(intent)
val pendingIntent = PendingIntent.getActivity(
context,
3000,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
)
notificationBuilder.setContentIntent(pendingIntent)
}
protected open fun configureMainIntent(intent: Intent) {
}
protected open fun getNotificationID(): Int = 10
}

View file

@ -1,35 +1,32 @@
package com.habitrpg.android.habitica.helpers.notifications;
import android.content.Context;
/**
* Created by keithholliday on 6/28/16.
*/
public class HabiticaLocalNotificationFactory {
//use getShape method to get object of type shape
public HabiticaLocalNotification build(String notificationType) {
if (notificationType == null) {
return null;
}
public HabiticaLocalNotification build(String notificationType, Context context) {
if (notificationType.equalsIgnoreCase(PushNotificationManager.PARTY_INVITE_PUSH_NOTIFICATION_KEY)) {
return new PartyInviteLocalNotification();
return new PartyInviteLocalNotification(context, notificationType);
} else if (notificationType.contains(PushNotificationManager.RECEIVED_PRIVATE_MESSAGE_PUSH_NOTIFICATION_KEY)) {
return new ReceivedPrivateMessageLocalNotification();
return new ReceivedPrivateMessageLocalNotification(context, notificationType);
} else if (notificationType.contains(PushNotificationManager.RECEIVED_GEMS_PUSH_NOTIFICATION_KEY)) {
return new ReceivedGemsGiftLocalNotification();
return new ReceivedGemsGiftLocalNotification(context, notificationType);
} else if (notificationType.contains(PushNotificationManager.RECEIVED_SUBSCRIPTION_GIFT_PUSH_NOTIFICATION_KEY)) {
return new ReceivedSubscriptionGiftLocalNotification();
return new ReceivedSubscriptionGiftLocalNotification(context, notificationType);
} else if (notificationType.contains(PushNotificationManager.GUILD_INVITE_PUSH_NOTIFICATION_KEY)) {
return new GuildInviteLocalNotification();
return new GuildInviteLocalNotification(context, notificationType);
} else if (notificationType.contains(PushNotificationManager.QUEST_INVITE_PUSH_NOTIFICATION_KEY)) {
return new QuestInviteLocalNotification();
return new QuestInviteLocalNotification(context, notificationType);
} else if (notificationType.contains(PushNotificationManager.QUEST_BEGUN_PUSH_NOTIFICATION_KEY)) {
return new QuestBegunLocalNotification();
return new QuestBegunLocalNotification(context, notificationType);
} else if (notificationType.contains(PushNotificationManager.WON_CHALLENGE_PUSH_NOTIFICATION_KEY)) {
return new WonChallengeLocalNotification();
return new WonChallengeLocalNotification(context, notificationType);
} else {
return new GenericLocalNotification(context, notificationType);
}
return null;
}
}

View file

@ -1,47 +0,0 @@
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 com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.receivers.LocalNotificationActionReceiver;
/**
* Created by keithholliday on 6/28/16.
*/
public class PartyInviteLocalNotification extends HabiticaLocalNotification {
public void notifyLocally(Context context, String title, String message) {
super.notifyLocally(context, title, message);
this.setNotificationActions();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(10, notificationBuilder.build());
}
protected void setNotificationActions() {
Resources res = context.getResources();
Intent acceptInviteIntent = new Intent(context, LocalNotificationActionReceiver.class);
acceptInviteIntent.setAction(res.getString(R.string.accept_party_invite));
PendingIntent pendingIntentAccept = PendingIntent.getBroadcast(
context,
3000,
acceptInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.addAction(0, "Accept", pendingIntentAccept);
Intent rejectInviteIntent = new Intent(context, LocalNotificationActionReceiver.class);
rejectInviteIntent.setAction(res.getString(R.string.reject_party_invite));
PendingIntent pendingIntentReject = PendingIntent.getBroadcast(
context,
2000,
rejectInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.addAction(0, "Reject", pendingIntentReject);
}
}

View file

@ -0,0 +1,39 @@
package com.habitrpg.android.habitica.helpers.notifications
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.receivers.LocalNotificationActionReceiver
/**
* Created by keithholliday on 6/28/16.
*/
class PartyInviteLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier) {
override fun setNotificationActions() {
super.setNotificationActions()
val res = context.resources
val acceptInviteIntent = Intent(context, LocalNotificationActionReceiver::class.java)
acceptInviteIntent.action = res.getString(R.string.accept_party_invite)
val pendingIntentAccept = PendingIntent.getBroadcast(
context,
3000,
acceptInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
notificationBuilder.addAction(0, "Accept", pendingIntentAccept)
val rejectInviteIntent = Intent(context, LocalNotificationActionReceiver::class.java)
rejectInviteIntent.action = res.getString(R.string.reject_party_invite)
val pendingIntentReject = PendingIntent.getBroadcast(
context,
2000,
rejectInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
notificationBuilder.addAction(0, "Reject", pendingIntentReject)
}
}

View file

@ -15,14 +15,14 @@ import java.util.Map;
public class PushNotificationManager {
static final String PARTY_INVITE_PUSH_NOTIFICATION_KEY = "invitedParty";
static final String RECEIVED_PRIVATE_MESSAGE_PUSH_NOTIFICATION_KEY = "newPM";
static final String RECEIVED_GEMS_PUSH_NOTIFICATION_KEY = "giftedGems";
static final String RECEIVED_SUBSCRIPTION_GIFT_PUSH_NOTIFICATION_KEY = "giftedSubscription";
static final String GUILD_INVITE_PUSH_NOTIFICATION_KEY = "invitedGuild";
static final String QUEST_INVITE_PUSH_NOTIFICATION_KEY = "questInvitation";
static final String QUEST_BEGUN_PUSH_NOTIFICATION_KEY = "questStarted";
static final String WON_CHALLENGE_PUSH_NOTIFICATION_KEY = "wonChallenge";
public static final String PARTY_INVITE_PUSH_NOTIFICATION_KEY = "invitedParty";
public static final String RECEIVED_PRIVATE_MESSAGE_PUSH_NOTIFICATION_KEY = "newPM";
public static final String RECEIVED_GEMS_PUSH_NOTIFICATION_KEY = "giftedGems";
public static final String RECEIVED_SUBSCRIPTION_GIFT_PUSH_NOTIFICATION_KEY = "giftedSubscription";
public static final String GUILD_INVITE_PUSH_NOTIFICATION_KEY = "invitedGuild";
public static final String QUEST_INVITE_PUSH_NOTIFICATION_KEY = "questInvitation";
public static final String QUEST_BEGUN_PUSH_NOTIFICATION_KEY = "questStarted";
public static final String WON_CHALLENGE_PUSH_NOTIFICATION_KEY = "wonChallenge";
private static final String DEVICE_TOKEN_PREFERENCE_KEY = "device-token-preference";
private final Context context;
public ApiClient apiClient;
@ -100,10 +100,10 @@ public class PushNotificationManager {
String remoteMessageIdentifier = remoteMessage.getData().get("identifier");
HabiticaLocalNotificationFactory notificationFactory = new HabiticaLocalNotificationFactory();
HabiticaLocalNotification notification = notificationFactory.build(remoteMessageIdentifier);
HabiticaLocalNotification notification = notificationFactory.build(remoteMessageIdentifier, context);
if (userIsSubscribedToNotificationType(remoteMessageIdentifier) && notification != null) {
notification.setExtras(remoteMessage.getData());
notification.notifyLocally(this.context, remoteMessage.getData().get("title"), remoteMessage.getData().get("body"));
notification.notifyLocally(remoteMessage.getData().get("title"), remoteMessage.getData().get("body"));
}
}

View file

@ -1,32 +0,0 @@
package com.habitrpg.android.habitica.helpers.notifications;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
/**
* Created by keithholliday on 7/1/16.
*/
public class QuestBegunLocalNotification extends HabiticaLocalNotification {
@Override
public void notifyLocally(Context context, String title, String message) {
super.notifyLocally(context, title, message);
this.setNotificationActions();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(10000, notificationBuilder.build());
}
protected void setNotificationActions() {
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
context,
3000,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(pendingIntent);
}
}

View file

@ -0,0 +1,15 @@
package com.habitrpg.android.habitica.helpers.notifications
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.habitrpg.android.habitica.ui.activities.MainActivity
/**
* Created by keithholliday on 7/1/16.
*/
class QuestBegunLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier) {
override fun getNotificationID(): Int = 1000
}

View file

@ -1,47 +0,0 @@
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 com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.receivers.LocalNotificationActionReceiver;
/**
* Created by keithholliday on 7/1/16.
*/
public class QuestInviteLocalNotification extends HabiticaLocalNotification {
@Override
public void notifyLocally(Context context, String title, String message) {
super.notifyLocally(context, title, message);
this.setNotificationActions();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(10000, notificationBuilder.build());
}
protected void setNotificationActions() {
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(0, "Accept", pendingIntentAccept);
Intent rejectInviteIntent = new Intent(context, LocalNotificationActionReceiver.class);
rejectInviteIntent.setAction(res.getString(R.string.reject_quest_invite));
PendingIntent pendingIntentReject = PendingIntent.getBroadcast(
context,
2000,
rejectInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.addAction(0, "Reject", pendingIntentReject);
}
}

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 com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.receivers.LocalNotificationActionReceiver
/**
* Created by keithholliday on 7/1/16.
*/
class QuestInviteLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier) {
override fun getNotificationID(): Int = 1000
override fun setNotificationActions() {
super.setNotificationActions()
val res = context.resources
val acceptInviteIntent = Intent(context, LocalNotificationActionReceiver::class.java)
acceptInviteIntent.action = res.getString(R.string.accept_quest_invite)
val pendingIntentAccept = PendingIntent.getBroadcast(
context,
3000,
acceptInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
notificationBuilder.addAction(0, "Accept", pendingIntentAccept)
val rejectInviteIntent = Intent(context, LocalNotificationActionReceiver::class.java)
rejectInviteIntent.action = res.getString(R.string.reject_quest_invite)
val pendingIntentReject = PendingIntent.getBroadcast(
context,
2000,
rejectInviteIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
notificationBuilder.addAction(0, "Reject", pendingIntentReject)
}
}

View file

@ -1,32 +0,0 @@
package com.habitrpg.android.habitica.helpers.notifications;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
/**
* Created by keithholliday on 7/1/16.
*/
public class ReceivedGemsGiftLocalNotification extends HabiticaLocalNotification {
@Override
public void notifyLocally(Context context, String title, String message) {
super.notifyLocally(context, title, message);
this.setNotificationActions();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(10, notificationBuilder.build());
}
protected void setNotificationActions() {
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
context,
3000,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(pendingIntent);
}
}

View file

@ -0,0 +1,13 @@
package com.habitrpg.android.habitica.helpers.notifications
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.habitrpg.android.habitica.ui.activities.MainActivity
/**
* Created by keithholliday on 7/1/16.
*/
class ReceivedGemsGiftLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier)

View file

@ -1,34 +0,0 @@
package com.habitrpg.android.habitica.helpers.notifications;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
/**
* Created by keithholliday on 7/1/16.
*/
public class ReceivedPrivateMessageLocalNotification extends HabiticaLocalNotification {
@Override
public void notifyLocally(Context context, String title, String message) {
super.notifyLocally(context, title, message);
this.setNotificationActions();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.notify(10, notificationBuilder.build());
}
protected void setNotificationActions() {
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
context,
3000,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(pendingIntent);
}
}

View file

@ -0,0 +1,13 @@
package com.habitrpg.android.habitica.helpers.notifications
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.habitrpg.android.habitica.ui.activities.MainActivity
/**
* Created by keithholliday on 7/1/16.
*/
class ReceivedPrivateMessageLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier)

View file

@ -1,32 +0,0 @@
package com.habitrpg.android.habitica.helpers.notifications;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
/**
* Created by keithholliday on 7/1/16.
*/
public class ReceivedSubscriptionGiftLocalNotification extends HabiticaLocalNotification {
@Override
public void notifyLocally(Context context, String title, String message) {
super.notifyLocally(context, title, message);
this.setNotificationActions();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.notify(10, notificationBuilder.build());
}
protected void setNotificationActions() {
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
context,
3000,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(pendingIntent);
}
}

View file

@ -0,0 +1,13 @@
package com.habitrpg.android.habitica.helpers.notifications
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.habitrpg.android.habitica.ui.activities.MainActivity
/**
* Created by keithholliday on 7/1/16.
*/
class ReceivedSubscriptionGiftLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier)

View file

@ -1,32 +0,0 @@
package com.habitrpg.android.habitica.helpers.notifications;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
/**
* Created by keithholliday on 7/2/16.
*/
public class WonChallengeLocalNotification extends HabiticaLocalNotification {
@Override
public void notifyLocally(Context context, String title, String message) {
super.notifyLocally(context, title, message);
this.setNotificationActions();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.notify(10, notificationBuilder.build());
}
protected void setNotificationActions() {
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
context,
3000,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(pendingIntent);
}
}

View file

@ -0,0 +1,12 @@
package com.habitrpg.android.habitica.helpers.notifications
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.habitrpg.android.habitica.ui.activities.MainActivity
/**
* Created by keithholliday on 7/2/16.
*/
class WonChallengeLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier)

View file

@ -24,6 +24,7 @@ import android.support.v4.widget.DrawerLayout
import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.app.AlertDialog
import android.support.v7.widget.Toolbar
import android.util.Log
import android.util.TypedValue
import android.view.*
import android.widget.FrameLayout
@ -217,7 +218,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
drawerFragment = supportFragmentManager.findFragmentById(R.id.navigation_drawer) as? NavigationDrawerFragment
drawerFragment?.setUp(R.id.navigation_drawer, drawerLayout)
drawerFragment?.setSelection(NavigationDrawerFragment.SIDEBAR_TASKS, true)
selectMenuItem(NavigationDrawerFragment.SIDEBAR_TASKS)
drawerToggle = object : ActionBarDrawerToggle(
this, /* host Activity */
@ -244,6 +245,11 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
drawerToggle?.syncState()
}
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
super.onRestoreInstanceState(savedInstanceState)
Log.e("RESTORED:", savedInstanceState.toString())
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
drawerToggle?.onConfigurationChanged(newConfig)
@ -289,8 +295,17 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
selection = this.sharedPreferences.getString("lastActivePosition", NavigationDrawerFragment.SIDEBAR_TASKS)
} catch (ignored: java.lang.RuntimeException) {
}
if (selection != null) {
selectMenuItem(selection)
}
}
drawerFragment?.setSelection(selection, true)
if (intent.hasExtra("notificationIdentifier")) {
val identifier = intent.getStringExtra("notificationIdentifier")
val additionalData = HashMap<String, Any>()
additionalData["identifier"] = identifier
AmplitudeManager.sendEvent("open notification", AmplitudeManager.EVENT_CATEGORY_BEHAVIOUR, AmplitudeManager.EVENT_HITTYPE_EVENT, additionalData)
NotificationOpenHandler.handleOpenedByNotification(identifier, intent, this, user)
}
}
@ -372,7 +387,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
if (activeFragment != null && activeFragment?.get() != null) {
activeFragment?.get()?.updateUserData(user)
} else {
drawerFragment?.setSelection(NavigationDrawerFragment.SIDEBAR_TASKS, true)
selectMenuItem(NavigationDrawerFragment.SIDEBAR_TASKS)
}
}
@ -448,8 +463,9 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
fun setActiveFragment(fragment: BaseMainFragment?) {
this.activeFragment = WeakReference<BaseMainFragment>(fragment)
setTranslatedFragmentTitle(fragment)
if (activeFragment?.get() != null) {
this.drawerFragment?.setSelection(this.activeFragment?.get()?.fragmentSidebarIdentifier, false)
val identifier = activeFragment?.get()?.fragmentSidebarIdentifier
if (identifier != null) {
selectMenuItem(identifier, false)
}
}
@ -920,6 +936,10 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
}, RxErrorHandler.handleEmptyError())
}
public fun selectMenuItem(identifier: String, openSelection: Boolean = true) {
drawerFragment?.setSelection(identifier, openSelection)
}
companion object {
const val SELECT_CLASS_RESULT = 11

View file

@ -163,11 +163,17 @@ class ChatRecyclerViewAdapter(data: OrderedRealmCollection<ChatMessage>?, autoUp
avatarView.visibility = View.GONE
itemView.setPadding(64.dpToPx(context), itemView.paddingTop, itemView.paddingRight, itemView.paddingBottom)
} else {
avatarView.visibility = View.VISIBLE
itemView.setPadding(16.dpToPx(context), itemView.paddingTop, itemView.paddingRight, itemView.paddingBottom)
msg.userStyles.notNull {
avatarView.setAvatar(it)
val displayMetrics = res.displayMetrics
val dpWidth = displayMetrics.widthPixels / displayMetrics.density
if (dpWidth > 350) {
avatarView.visibility = View.VISIBLE
msg.userStyles.notNull {
avatarView.setAvatar(it)
}
} else {
avatarView.visibility = View.GONE
}
itemView.setPadding(16.dpToPx(context), itemView.paddingTop, itemView.paddingRight, itemView.paddingBottom)
}
messageText.text = chatMessage?.parsedText

View file

@ -90,14 +90,6 @@ abstract class BaseFragment : DialogFragment() {
}
}, RxErrorHandler.handleEmptyError())
}
val displayedClassName = this.displayedClassName
if (displayedClassName != null) {
val additionalData = HashMap<String, Any>()
additionalData["page"] = displayedClassName
AmplitudeManager.sendEvent("navigate", AmplitudeManager.EVENT_CATEGORY_NAVIGATION, AmplitudeManager.EVENT_HITTYPE_PAGEVIEW, additionalData)
}
}
}

View file

@ -106,8 +106,8 @@ class GuildsOverviewFragment : BaseMainFragment(), View.OnClickListener, SwipeRe
publicGuildsFragment.memberGuildIDs = this.guildIDs
fragment = publicGuildsFragment
} else {
val guildIndex = (v.parent as ViewGroup).indexOfChild(v)
val guildId = this.guilds?.get(guildIndex)?.id ?: return
val guildIndex = (v.parent as? ViewGroup)?.indexOfChild(v)
val guildId = this.guilds?.get(guildIndex ?: 0)?.id ?: return
val guildFragment = GuildFragment()
guildFragment.setGuildId(guildId)
guildFragment.isMember = true