Commit 39e719ce authored by Leonardo Aramaki's avatar Leonardo Aramaki

Rename intent extra constants

parent 59e7f90f
...@@ -11,7 +11,6 @@ import java.util.List; ...@@ -11,7 +11,6 @@ import java.util.List;
import chat.rocket.android.LaunchUtil; import chat.rocket.android.LaunchUtil;
import chat.rocket.android.RocketChatCache; import chat.rocket.android.RocketChatCache;
import chat.rocket.android.helper.Logger; import chat.rocket.android.helper.Logger;
import chat.rocket.android.push.PushConstants;
import chat.rocket.android.push.PushManager; import chat.rocket.android.push.PushManager;
import chat.rocket.android.service.ConnectivityManager; import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.core.models.ServerInfo; import chat.rocket.core.models.ServerInfo;
...@@ -57,16 +56,16 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity { ...@@ -57,16 +56,16 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
return; return;
} }
if (intent.hasExtra(PushConstants.HOSTNAME)) { if (intent.hasExtra(PushManager.EXTRA_HOSTNAME)) {
String hostname = intent.getStringExtra(PushConstants.HOSTNAME); String hostname = intent.getStringExtra(PushManager.EXTRA_HOSTNAME);
HttpUrl url = HttpUrl.parse(hostname); HttpUrl url = HttpUrl.parse(hostname);
if (url != null) { if (url != null) {
String hostnameFromPush = url.host(); String hostnameFromPush = url.host();
String loginHostname = rocketChatCache.getSiteUrlFor(hostnameFromPush); String loginHostname = rocketChatCache.getSiteUrlFor(hostnameFromPush);
rocketChatCache.setSelectedServerHostname(loginHostname); rocketChatCache.setSelectedServerHostname(loginHostname);
if (intent.hasExtra(PushConstants.ROOM_ID)) { if (intent.hasExtra(PushManager.EXTRA_ROOM_ID)) {
rocketChatCache.setSelectedRoomId(intent.getStringExtra(PushConstants.ROOM_ID)); rocketChatCache.setSelectedRoomId(intent.getStringExtra(PushManager.EXTRA_ROOM_ID));
} }
} }
PushManager.INSTANCE.clearHostNotifications(hostname); PushManager.INSTANCE.clearHostNotifications(hostname);
...@@ -74,9 +73,9 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity { ...@@ -74,9 +73,9 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
updateHostnameIfNeeded(rocketChatCache.getSelectedServerHostname()); updateHostnameIfNeeded(rocketChatCache.getSelectedServerHostname());
} }
if (intent.hasExtra(PushConstants.NOT_ID)) { if (intent.hasExtra(PushManager.EXTRA_NOT_ID)) {
isNotification = true; isNotification = true;
int notificationId = intent.getIntExtra(PushConstants.NOT_ID, 0); int notificationId = intent.getIntExtra(PushManager.EXTRA_NOT_ID, 0);
PushManager.INSTANCE.clearNotificationIdStack(notificationId); PushManager.INSTANCE.clearNotificationIdStack(notificationId);
} }
} }
......
...@@ -43,8 +43,12 @@ typealias TupleRoomUser = Pair<Room, User> ...@@ -43,8 +43,12 @@ typealias TupleRoomUser = Pair<Room, User>
typealias TupleGroupIdMessageCount = Pair<Int, AtomicInteger> typealias TupleGroupIdMessageCount = Pair<Int, AtomicInteger>
object PushManager { object PushManager {
const val REPLY_LABEL = "REPLY" const val EXTRA_NOT_ID = "chat.rocket.android.EXTRA_NOT_ID"
const val REMOTE_INPUT_REPLY = "REMOTE_INPUT_REPLY" const val EXTRA_HOSTNAME = "chat.rocket.android.EXTRA_HOSTNAME"
const val EXTRA_PUSH_MESSAGE = "chat.rocket.android.EXTRA_PUSH_MESSAGE"
const val EXTRA_ROOM_ID = "chat.rocket.android.EXTRA_ROOM_ID"
private const val REPLY_LABEL = "REPLY"
private const val REMOTE_INPUT_REPLY = "REMOTE_INPUT_REPLY"
// Map associating a notification id to a list of corresponding messages ie. an id corresponds // Map associating a notification id to a list of corresponding messages ie. an id corresponds
// to a user and the corresponding list is all the messages sent by him. // to a user and the corresponding list is all the messages sent by him.
...@@ -367,18 +371,18 @@ object PushManager { ...@@ -367,18 +371,18 @@ object PushManager {
private fun getDismissIntent(context: Context, pushMessage: PushMessage): PendingIntent { private fun getDismissIntent(context: Context, pushMessage: PushMessage): PendingIntent {
val deleteIntent = Intent(context, DeleteReceiver::class.java) val deleteIntent = Intent(context, DeleteReceiver::class.java)
deleteIntent.putExtra("notId", pushMessage.notificationId.toInt()) deleteIntent.putExtra(EXTRA_NOT_ID, pushMessage.notificationId.toInt())
deleteIntent.putExtra("host", pushMessage.host) deleteIntent.putExtra(EXTRA_HOSTNAME, pushMessage.host)
return PendingIntent.getBroadcast(context, pushMessage.notificationId.toInt(), deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT) return PendingIntent.getBroadcast(context, pushMessage.notificationId.toInt(), deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT)
} }
private fun getContentIntent(context: Context, notificationId: Int, pushMessage: PushMessage, singleConversation: Boolean = true): PendingIntent { private fun getContentIntent(context: Context, notificationId: Int, pushMessage: PushMessage, singleConversation: Boolean = true): PendingIntent {
val notificationIntent = Intent(context, MainActivity::class.java) val notificationIntent = Intent(context, MainActivity::class.java)
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
notificationIntent.putExtra(PushConstants.NOT_ID, notificationId) notificationIntent.putExtra(EXTRA_NOT_ID, notificationId)
notificationIntent.putExtra(PushConstants.HOSTNAME, pushMessage.host) notificationIntent.putExtra(EXTRA_HOSTNAME, pushMessage.host)
if (singleConversation) { if (singleConversation) {
notificationIntent.putExtra(PushConstants.ROOM_ID, pushMessage.rid) notificationIntent.putExtra(EXTRA_ROOM_ID, pushMessage.rid)
} }
return PendingIntent.getActivity(context, randomizer.nextInt(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT) return PendingIntent.getActivity(context, randomizer.nextInt(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
} }
...@@ -429,7 +433,7 @@ object PushManager { ...@@ -429,7 +433,7 @@ object PushManager {
.setLabel(REPLY_LABEL) .setLabel(REPLY_LABEL)
.build() .build()
val replyIntent = Intent(context, ReplyReceiver::class.java) val replyIntent = Intent(context, ReplyReceiver::class.java)
replyIntent.putExtra("push", pushMessage as Serializable) replyIntent.putExtra(EXTRA_PUSH_MESSAGE, pushMessage as Serializable)
val pendingIntent = PendingIntent.getBroadcast( val pendingIntent = PendingIntent.getBroadcast(
context, randomizer.nextInt(), replyIntent, 0) context, randomizer.nextInt(), replyIntent, 0)
val replyAction = val replyAction =
...@@ -457,14 +461,15 @@ object PushManager { ...@@ -457,14 +461,15 @@ object PushManager {
return this return this
} }
private data class PushMessage(val title: String, private data class PushMessage(
val message: String, val title: String,
val image: String?, val message: String,
val ejson: String, val image: String?,
val count: String, val ejson: String,
val notificationId: String, val count: String,
val summaryText: String, val notificationId: String,
val style: String) : Serializable { val summaryText: String,
val style: String) : Serializable {
val host: String val host: String
val rid: String val rid: String
val type: String val type: String
...@@ -501,8 +506,8 @@ object PushManager { ...@@ -501,8 +506,8 @@ object PushManager {
*/ */
class DeleteReceiver : BroadcastReceiver() { class DeleteReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) { override fun onReceive(context: Context?, intent: Intent?) {
val notificationId = intent?.extras?.getInt("notId") val notificationId = intent?.extras?.getInt(EXTRA_NOT_ID)
val host = intent?.extras?.getString("host") val host = intent?.extras?.getString(EXTRA_HOSTNAME)
notificationId?.let { notificationId?.let {
clearNotificationIdStack(notificationId) clearNotificationIdStack(notificationId)
} }
...@@ -527,7 +532,7 @@ object PushManager { ...@@ -527,7 +532,7 @@ object PushManager {
synchronized(this) { synchronized(this) {
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val message: CharSequence? = extractMessage(intent) val message: CharSequence? = extractMessage(intent)
val pushMessage = intent?.extras?.getSerializable("push") as PushMessage? val pushMessage = intent?.extras?.getSerializable(EXTRA_PUSH_MESSAGE) as PushMessage?
pushMessage?.let { pushMessage?.let {
val userNotId = pushMessage.notificationId.toInt() val userNotId = pushMessage.notificationId.toInt()
......
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