Fix notification open handling. Fixes #1439

This commit is contained in:
Phillip Thelen 2021-01-29 15:56:48 +01:00
parent 7c60122452
commit 24c2dd438b
3 changed files with 31 additions and 28 deletions

View file

@ -8,6 +8,11 @@ import com.habitrpg.android.habitica.helpers.notifications.PushNotificationManag
import com.habitrpg.android.habitica.models.Notification
import com.habitrpg.android.habitica.models.notifications.ChallengeWonData
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.fragments.social.challenges.ChallengesOverviewFragmentDirections
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
class NotificationOpenHandler {
@ -15,19 +20,21 @@ class NotificationOpenHandler {
companion object {
fun handleOpenedByNotification(identifier: String, intent: Intent, user: User?) {
when (identifier) {
PushNotificationManager.PARTY_INVITE_PUSH_NOTIFICATION_KEY -> openPartyScreen()
PushNotificationManager.QUEST_BEGUN_PUSH_NOTIFICATION_KEY -> openQuestDetailSCreen(user?.party?.id,
user?.party?.quest?.key)
PushNotificationManager.QUEST_INVITE_PUSH_NOTIFICATION_KEY -> openQuestDetailSCreen(user?.party?.id,
user?.party?.quest?.key)
PushNotificationManager.GUILD_INVITE_PUSH_NOTIFICATION_KEY -> openGuildDetailScreen(intent.getStringExtra("groupID"))
PushNotificationManager.RECEIVED_PRIVATE_MESSAGE_PUSH_NOTIFICATION_KEY -> openPrivateMessageScreen(intent.getStringExtra("replyTo"))
PushNotificationManager.CHANGE_USERNAME_PUSH_NOTIFICATION_KEY -> openSettingsScreen()
PushNotificationManager.GIFT_ONE_GET_ONE_PUSH_NOTIFICATION_KEY -> openSubscriptionScreen()
PushNotificationManager.CHAT_MENTION_NOTIFICATION_KEY -> handleChatMessage(intent.getStringExtra("type"), intent.getStringExtra("groupID"))
PushNotificationManager.GROUP_ACTIVITY_NOTIFICATION_KEY -> handleChatMessage(intent.getStringExtra("type"), intent.getStringExtra("groupID"))
PushNotificationManager.G1G1_PROMO_KEY -> openGiftOneGetOneInfoScreen()
GlobalScope.launch(context = Dispatchers.Main) {
when (identifier) {
PushNotificationManager.PARTY_INVITE_PUSH_NOTIFICATION_KEY -> openPartyScreen()
PushNotificationManager.QUEST_BEGUN_PUSH_NOTIFICATION_KEY -> openQuestDetailSCreen(user?.party?.id,
user?.party?.quest?.key)
PushNotificationManager.QUEST_INVITE_PUSH_NOTIFICATION_KEY -> openQuestDetailSCreen(user?.party?.id,
user?.party?.quest?.key)
PushNotificationManager.GUILD_INVITE_PUSH_NOTIFICATION_KEY -> openGuildDetailScreen(intent.getStringExtra("groupID"))
PushNotificationManager.RECEIVED_PRIVATE_MESSAGE_PUSH_NOTIFICATION_KEY -> openPrivateMessageScreen(intent.getStringExtra("replyTo"))
PushNotificationManager.CHANGE_USERNAME_PUSH_NOTIFICATION_KEY -> openSettingsScreen()
PushNotificationManager.GIFT_ONE_GET_ONE_PUSH_NOTIFICATION_KEY -> openSubscriptionScreen()
PushNotificationManager.CHAT_MENTION_NOTIFICATION_KEY -> handleChatMessage(intent.getStringExtra("type"), intent.getStringExtra("groupID"))
PushNotificationManager.GROUP_ACTIVITY_NOTIFICATION_KEY -> handleChatMessage(intent.getStringExtra("type"), intent.getStringExtra("groupID"))
PushNotificationManager.G1G1_PROMO_KEY -> openGiftOneGetOneInfoScreen()
}
}
}
@ -60,10 +67,10 @@ class NotificationOpenHandler {
private fun openGuildDetailScreen(groupID: String?) {
if (groupID?.isNotEmpty() != true) {
return
MainNavigationController.navigate(R.id.guildsOverviewFragment)
} else {
MainNavigationController.navigate(R.id.guildFragment, bundleOf("groupID" to groupID))
}
MainNavigationController.navigate(R.id.guildFragment, bundleOf("groupID" to groupID))
}
private fun openSettingsScreen() {
@ -72,9 +79,9 @@ class NotificationOpenHandler {
private fun handleChatMessage(type: String?, groupID: String?) {
when (type) {
"party" -> MainNavigationController.navigate(R.id.partyFragment)
"party" -> openPartyScreen()
"tavern" -> MainNavigationController.navigate(R.id.tavernFragment)
"guild" -> MainNavigationController.navigate(R.id.guildFragment, bundleOf("groupID" to groupID))
"guild" -> openGuildDetailScreen(groupID)
}
}
}

View file

@ -139,7 +139,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
var drawerToggle: ActionBarDrawerToggle? = null
private var resumeFromActivity = false
private var userQuestStatus = UserQuestStatus.NO_QUEST
private var lastNotificationOpen: Int? = null
private var lastNotificationOpen: Long? = null
val userID: String
get() = user?.id ?: ""
@ -354,6 +354,9 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
override fun onResume() {
super.onResume()
val navigationController = findNavController(R.id.nav_host_fragment)
MainNavigationController.setup(navigationController)
if(!resumeFromActivity){
retrieveUser()
this.checkMaintenance()
@ -366,8 +369,8 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
putBoolean("preventDailyReminder", false)
}
if (intent.hasExtra("notificationIdentifier") && lastNotificationOpen != intent.getIntExtra("notificationTimeStamp", 0)) {
lastNotificationOpen = intent.getIntExtra("notificationTimeStamp", 0)
if (intent.hasExtra("notificationIdentifier") && lastNotificationOpen != intent.getLongExtra("notificationTimeStamp", 0)) {
lastNotificationOpen = intent.getLongExtra("notificationTimeStamp", 0)
val identifier = intent.getStringExtra("notificationIdentifier") ?: ""
val additionalData = HashMap<String, Any>()
additionalData["identifier"] = identifier
@ -379,8 +382,6 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
launchTrace?.stop()
launchTrace = null
val navigationController = findNavController(R.id.nav_host_fragment)
MainNavigationController.setup(navigationController)
if (binding.toolbarTitle.text?.isNotBlank() != true) {
navigationController.currentDestination?.let { updateToolbarTitle(it, null) }

View file

@ -265,11 +265,6 @@ abstract class BaseTaskViewHolder constructor(itemView: View, var scoreTaskFunc:
onRightActionTouched()
return true
}
} else if ((motionEvent.y > (checkboxHolder.height + 5.dpToPx(context)))) {
if (motionEvent.x <= 72.dpToPx(context)) {
onLeftActionTouched()
return true
}
}
}
}