Commit e5aa863f authored by Leonardo Aramaki's avatar Leonardo Aramaki

If api level under 23 (N) then show the MainActivity - at first

parent a1793f89
......@@ -21,6 +21,7 @@ import android.support.v4.app.RemoteInput
import android.text.Html
import android.text.Spanned
import chat.rocket.android.R
import chat.rocket.android.main.ui.MainActivity
import chat.rocket.android.server.domain.GetAccountInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.siteName
......@@ -292,13 +293,9 @@ class PushManager @Inject constructor(
val replyRemoteInput = android.app.RemoteInput.Builder(REMOTE_INPUT_REPLY)
.setLabel(replyTextHint)
.build()
//TODO: Implement this when we have sendMessage call
val replyIntent = Intent(context, DirectReplyReceiver::class.java)
replyIntent.action = ACTION_REPLY
replyIntent.putExtra(EXTRA_PUSH_MESSAGE, pushMessage as Parcelable)
val filter = IntentFilter().apply {
addAction(ACTION_REPLY)
}
replyIntent.putExtra(EXTRA_PUSH_MESSAGE, pushMessage)
val pendingIntent = PendingIntent.getBroadcast(
context, randomizer.nextInt(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val replyAction = Notification.Action.Builder(
......@@ -316,15 +313,7 @@ class PushManager @Inject constructor(
val replyRemoteInput = RemoteInput.Builder(REMOTE_INPUT_REPLY)
.setLabel(replyTextHint)
.build()
//TODO: Implement when we have sendMessage call
val replyIntent = Intent(context, DirectReplyReceiver::class.java)
replyIntent.action = ACTION_REPLY
replyIntent.putExtra(EXTRA_PUSH_MESSAGE, pushMessage as Parcelable)
val filter = IntentFilter().apply {
addAction(ACTION_REPLY)
}
val pendingIntent = PendingIntent.getBroadcast(
context, randomizer.nextInt(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val pendingIntent = getReplyPendingIntent(pushMessage)
val replyAction = NotificationCompat.Action.Builder(R.drawable.ic_reply_black_24px, replyTextHint, pendingIntent)
.addRemoteInput(replyRemoteInput)
.setAllowGeneratedReplies(true)
......@@ -334,6 +323,38 @@ class PushManager @Inject constructor(
return this
}
private fun getReplyIntent(pushMessage: PushMessage): Intent {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Intent(context, DirectReplyReceiver::class.java)
} else {
Intent(context, MainActivity::class.java).also {
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
}.also {
it.action = ACTION_REPLY
it.putExtra(EXTRA_PUSH_MESSAGE, pushMessage)
}
}
private fun getReplyPendingIntent(pushMessage: PushMessage): PendingIntent {
val replyIntent = getReplyIntent(pushMessage)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
PendingIntent.getBroadcast(
context,
randomizer.nextInt(),
replyIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
} else {
PendingIntent.getActivity(
context,
randomizer.nextInt(),
replyIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
}
}
private fun NotificationCompat.Builder.setMessageNotification(): NotificationCompat.Builder {
val alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val res = context.resources
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment