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 ...@@ -21,6 +21,7 @@ import android.support.v4.app.RemoteInput
import android.text.Html import android.text.Html
import android.text.Spanned import android.text.Spanned
import chat.rocket.android.R 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.GetAccountInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.siteName import chat.rocket.android.server.domain.siteName
...@@ -292,13 +293,9 @@ class PushManager @Inject constructor( ...@@ -292,13 +293,9 @@ class PushManager @Inject constructor(
val replyRemoteInput = android.app.RemoteInput.Builder(REMOTE_INPUT_REPLY) val replyRemoteInput = android.app.RemoteInput.Builder(REMOTE_INPUT_REPLY)
.setLabel(replyTextHint) .setLabel(replyTextHint)
.build() .build()
//TODO: Implement this when we have sendMessage call
val replyIntent = Intent(context, DirectReplyReceiver::class.java) val replyIntent = Intent(context, DirectReplyReceiver::class.java)
replyIntent.action = ACTION_REPLY replyIntent.action = ACTION_REPLY
replyIntent.putExtra(EXTRA_PUSH_MESSAGE, pushMessage as Parcelable) replyIntent.putExtra(EXTRA_PUSH_MESSAGE, pushMessage)
val filter = IntentFilter().apply {
addAction(ACTION_REPLY)
}
val pendingIntent = PendingIntent.getBroadcast( val pendingIntent = PendingIntent.getBroadcast(
context, randomizer.nextInt(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT) context, randomizer.nextInt(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val replyAction = Notification.Action.Builder( val replyAction = Notification.Action.Builder(
...@@ -316,15 +313,7 @@ class PushManager @Inject constructor( ...@@ -316,15 +313,7 @@ class PushManager @Inject constructor(
val replyRemoteInput = RemoteInput.Builder(REMOTE_INPUT_REPLY) val replyRemoteInput = RemoteInput.Builder(REMOTE_INPUT_REPLY)
.setLabel(replyTextHint) .setLabel(replyTextHint)
.build() .build()
//TODO: Implement when we have sendMessage call val pendingIntent = getReplyPendingIntent(pushMessage)
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 replyAction = NotificationCompat.Action.Builder(R.drawable.ic_reply_black_24px, replyTextHint, pendingIntent) val replyAction = NotificationCompat.Action.Builder(R.drawable.ic_reply_black_24px, replyTextHint, pendingIntent)
.addRemoteInput(replyRemoteInput) .addRemoteInput(replyRemoteInput)
.setAllowGeneratedReplies(true) .setAllowGeneratedReplies(true)
...@@ -334,6 +323,38 @@ class PushManager @Inject constructor( ...@@ -334,6 +323,38 @@ class PushManager @Inject constructor(
return this 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 { private fun NotificationCompat.Builder.setMessageNotification(): NotificationCompat.Builder {
val alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) val alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val res = context.resources 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