From e6876acea06aa5c035b4965a0a266297bcb8280d Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Thu, 9 Aug 2018 18:15:44 +0200 Subject: [PATCH] improve push notification handling --- .../helpers/NotificationOpenHandler.kt | 64 +++++++++++++++++ .../notifications/GenericLocalNotification.kt | 5 ++ .../GuildInviteLocalNotification.java | 50 ------------- .../GuildInviteLocalNotification.kt | 46 ++++++++++++ .../HabiticaLocalNotification.java | 47 ------------- .../HabiticaLocalNotification.kt | 70 +++++++++++++++++++ .../HabiticaLocalNotificationFactory.java | 29 ++++---- .../PartyInviteLocalNotification.java | 47 ------------- .../PartyInviteLocalNotification.kt | 39 +++++++++++ .../PushNotificationManager.java | 20 +++--- .../QuestBegunLocalNotification.java | 32 --------- .../QuestBegunLocalNotification.kt | 15 ++++ .../QuestInviteLocalNotification.java | 47 ------------- .../QuestInviteLocalNotification.kt | 42 +++++++++++ .../ReceivedGemsGiftLocalNotification.java | 32 --------- .../ReceivedGemsGiftLocalNotification.kt | 13 ++++ ...ceivedPrivateMessageLocalNotification.java | 34 --------- ...ReceivedPrivateMessageLocalNotification.kt | 13 ++++ ...ivedSubscriptionGiftLocalNotification.java | 32 --------- ...ceivedSubscriptionGiftLocalNotification.kt | 13 ++++ .../WonChallengeLocalNotification.java | 32 --------- .../WonChallengeLocalNotification.kt | 12 ++++ .../habitica/ui/activities/MainActivity.kt | 30 ++++++-- .../adapter/social/ChatRecyclerViewAdapter.kt | 14 ++-- .../habitica/ui/fragments/BaseFragment.kt | 8 --- .../social/GuildsOverviewFragment.kt | 4 +- 26 files changed, 392 insertions(+), 398 deletions(-) create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationOpenHandler.kt create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GenericLocalNotification.kt delete mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GuildInviteLocalNotification.java create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GuildInviteLocalNotification.kt delete mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotification.java create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotification.kt delete mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PartyInviteLocalNotification.java create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PartyInviteLocalNotification.kt delete mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestBegunLocalNotification.java create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestBegunLocalNotification.kt delete mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestInviteLocalNotification.java create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestInviteLocalNotification.kt delete mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedGemsGiftLocalNotification.java create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedGemsGiftLocalNotification.kt delete mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedPrivateMessageLocalNotification.java create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedPrivateMessageLocalNotification.kt delete mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedSubscriptionGiftLocalNotification.java create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedSubscriptionGiftLocalNotification.kt delete mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/WonChallengeLocalNotification.java create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/WonChallengeLocalNotification.kt diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationOpenHandler.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationOpenHandler.kt new file mode 100644 index 000000000..42e646237 --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationOpenHandler.kt @@ -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) + } + } +} \ No newline at end of file diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GenericLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GenericLocalNotification.kt new file mode 100644 index 000000000..136a553af --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GenericLocalNotification.kt @@ -0,0 +1,5 @@ +package com.habitrpg.android.habitica.helpers.notifications + +import android.content.Context + +class GenericLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier) \ No newline at end of file diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GuildInviteLocalNotification.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GuildInviteLocalNotification.java deleted file mode 100644 index 87d65af7f..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GuildInviteLocalNotification.java +++ /dev/null @@ -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); - } -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GuildInviteLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GuildInviteLocalNotification.kt new file mode 100644 index 000000000..86c9b959c --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/GuildInviteLocalNotification.kt @@ -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) + } +} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotification.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotification.java deleted file mode 100644 index 7dfe6ed1c..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotification.java +++ /dev/null @@ -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 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 data) { - this.data = data; - } - - protected abstract void setNotificationActions(); -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotification.kt new file mode 100644 index 000000000..1d9d52e15 --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaLocalNotification.kt @@ -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? = 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) { + 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 +} 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 b82b6bd35..2aa61a3f0 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 @@ -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; } - } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PartyInviteLocalNotification.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PartyInviteLocalNotification.java deleted file mode 100644 index e441d0ff3..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PartyInviteLocalNotification.java +++ /dev/null @@ -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); - } -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PartyInviteLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PartyInviteLocalNotification.kt new file mode 100644 index 000000000..15473077c --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PartyInviteLocalNotification.kt @@ -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) + } +} 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 8310efb1d..d07279e5d 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 @@ -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")); } } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestBegunLocalNotification.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestBegunLocalNotification.java deleted file mode 100644 index a454af5ef..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestBegunLocalNotification.java +++ /dev/null @@ -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); - } -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestBegunLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestBegunLocalNotification.kt new file mode 100644 index 000000000..6c233a62d --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestBegunLocalNotification.kt @@ -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 +} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestInviteLocalNotification.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestInviteLocalNotification.java deleted file mode 100644 index 6813577f7..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestInviteLocalNotification.java +++ /dev/null @@ -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); - } -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestInviteLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestInviteLocalNotification.kt new file mode 100644 index 000000000..2fd33c8e9 --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/QuestInviteLocalNotification.kt @@ -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) + } +} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedGemsGiftLocalNotification.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedGemsGiftLocalNotification.java deleted file mode 100644 index e3c81c2d8..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedGemsGiftLocalNotification.java +++ /dev/null @@ -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); - } -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedGemsGiftLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedGemsGiftLocalNotification.kt new file mode 100644 index 000000000..a408a2319 --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedGemsGiftLocalNotification.kt @@ -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) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedPrivateMessageLocalNotification.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedPrivateMessageLocalNotification.java deleted file mode 100644 index d236ef612..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedPrivateMessageLocalNotification.java +++ /dev/null @@ -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); - } -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedPrivateMessageLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedPrivateMessageLocalNotification.kt new file mode 100644 index 000000000..121606fd5 --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedPrivateMessageLocalNotification.kt @@ -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) 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 deleted file mode 100644 index bf4cfc192..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedSubscriptionGiftLocalNotification.java +++ /dev/null @@ -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); - } -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedSubscriptionGiftLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedSubscriptionGiftLocalNotification.kt new file mode 100644 index 000000000..35b254caf --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/ReceivedSubscriptionGiftLocalNotification.kt @@ -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) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/WonChallengeLocalNotification.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/WonChallengeLocalNotification.java deleted file mode 100644 index 0d25f873f..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/WonChallengeLocalNotification.java +++ /dev/null @@ -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); - } -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/WonChallengeLocalNotification.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/WonChallengeLocalNotification.kt new file mode 100644 index 000000000..be8305e96 --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/WonChallengeLocalNotification.kt @@ -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) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/MainActivity.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/MainActivity.kt index 9882d946e..440b530b7 100755 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/MainActivity.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/MainActivity.kt @@ -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() + 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(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 diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/social/ChatRecyclerViewAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/social/ChatRecyclerViewAdapter.kt index 4c0265922..68efc7e45 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/social/ChatRecyclerViewAdapter.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/social/ChatRecyclerViewAdapter.kt @@ -163,11 +163,17 @@ class ChatRecyclerViewAdapter(data: OrderedRealmCollection?, 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 diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/BaseFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/BaseFragment.kt index 5578627dd..03f4b2991 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/BaseFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/BaseFragment.kt @@ -90,14 +90,6 @@ abstract class BaseFragment : DialogFragment() { } }, RxErrorHandler.handleEmptyError()) } - - val displayedClassName = this.displayedClassName - - if (displayedClassName != null) { - val additionalData = HashMap() - additionalData["page"] = displayedClassName - AmplitudeManager.sendEvent("navigate", AmplitudeManager.EVENT_CATEGORY_NAVIGATION, AmplitudeManager.EVENT_HITTYPE_PAGEVIEW, additionalData) - } } } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/GuildsOverviewFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/GuildsOverviewFragment.kt index ddc0a7172..61249c90d 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/GuildsOverviewFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/GuildsOverviewFragment.kt @@ -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