Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Cleaning and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Feb 4, 2019
1 parent c068f13 commit 032cbc2
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 407 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Improvements:
- Better wording in notification for video call (#1421)
- Improve widget banner (#2129)
- Icon for Oreo (#2169)
- Notification reliability and Messaging Style.
- Notification settings re-organization, added bing rule troubleshoot
- Kotlin Code Improvement in VectorSettingsPreferencesFragment.kt
- Remove redundant !! , Replace it with null safe operators in VectorSettingsPreferencesFragment.kt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* Copyright 2015 Google Inc. All Rights Reserved.
* Copyright 2017 Vector Creations Ltd
* Copyright 2018 New Vector Ltd
* Copyright 2019 New Vector Ltd
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion vector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@

<!-- Exported false, should only be accessible from this app!! -->
<receiver
android:name=".receiver.ReplyNotificationBroadcastReceiver"
android:name=".receiver.NotificationBroadcastReceiver"
android:enabled="true"
android:exported="false" />

Expand Down
2 changes: 1 addition & 1 deletion vector/src/main/java/im/vector/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void onLiveEventsChunkProcessed(String fromToken, String toToken) {
mRefreshUnreadCounter = false;

Log.d(LOG_TAG, "onLiveEventsChunkProcessed ");
EventStreamService.checkDisplayedNotifications();
//EventStreamService.checkDisplayedNotifications();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ class NotificationDrawerManager(val context: Context) {
private var currentRoomId: String? = null


/*
* Should be called as soon as a new event is ready to be displayed.
* The notification corresponding to this event will not be displayed until
* #refreshNotificationDrawer() is called.
* Events might be grouped and there might not be one notification per event!
*
/**
Should be called as soon as a new event is ready to be displayed.
The notification corresponding to this event will not be displayed until
#refreshNotificationDrawer() is called.
Events might be grouped and there might not be one notification per event!
*/
fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent, userId: String, userDisplayName: String?) {
//If we support multi session, event list should be per userId
Expand Down Expand Up @@ -98,8 +97,8 @@ class NotificationDrawerManager(val context: Context) {
}
}

/*
* Clear all known events and refresh the notification drawer
/**
Clear all known events and refresh the notification drawer
*/
fun clearAllEvents() {
synchronized(this) {
Expand All @@ -108,9 +107,7 @@ class NotificationDrawerManager(val context: Context) {
refreshNotificationDrawer(null)
}

/*
* Clear all known message events for this room and refresh the notification drawer
*/
/** Clear all known message events for this room and refresh the notification drawer */
fun clearMessageEventOfRoom(roomId: String?) {
if (roomId != null) {
eventList.removeAll { e ->
Expand All @@ -125,8 +122,8 @@ class NotificationDrawerManager(val context: Context) {
}

/**
* Should be called when the application is currently opened and showing timeline for the given roomId.
* Used to ignore events related to that room (no need to display notification) and clean any existing notification on this room.
Should be called when the application is currently opened and showing timeline for the given roomId.
Used to ignore events related to that room (no need to display notification) and clean any existing notification on this room.
*/
fun setCurrentRoom(roomId: String?) {
var hasChanged = false
Expand Down Expand Up @@ -173,7 +170,7 @@ class NotificationDrawerManager(val context: Context) {
roomIdToEventMap[roomId] = roomEvents
}

if (shouldIgnoreMessageEventInRoom(roomId)|| outdatedDetector?.isMessageOutdated(event) == true) {
if (shouldIgnoreMessageEventInRoom(roomId) || outdatedDetector?.isMessageOutdated(event) == true) {
//forget this event
eventIterator.remove()
} else {
Expand Down Expand Up @@ -233,7 +230,8 @@ class NotificationDrawerManager(val context: Context) {
}

try {
val summaryLine = context.resources.getQuantityString(R.plurals.notification_compat_summary_line_for_room, events.size, roomName, events.size)
val summaryLine = context.resources.getQuantityString(
R.plurals.notification_compat_summary_line_for_room, events.size, roomName, events.size)
summaryInboxStyle.addLine(summaryLine)
} catch (e: Throwable) {
//String not found or bad format
Expand Down Expand Up @@ -303,7 +301,8 @@ class NotificationDrawerManager(val context: Context) {
// turn the screen on for 3 seconds
if (Matrix.getInstance(VectorApp.getInstance())!!.pushManager.isScreenTurnedOn) {
val pm = VectorApp.getInstance().getSystemService(Context.POWER_SERVICE) as PowerManager
val wl = pm.newWakeLock(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or PowerManager.ACQUIRE_CAUSES_WAKEUP, "riot:manageNotificationSound")
val wl = pm.newWakeLock(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or PowerManager.ACQUIRE_CAUSES_WAKEUP,
"riot:manageNotificationSound")
wl.acquire(3000)
wl.release()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import im.vector.activity.JoinRoomActivity
import im.vector.activity.LockScreenActivity
import im.vector.activity.VectorHomeActivity
import im.vector.activity.VectorRoomActivity
import im.vector.receiver.ReplyNotificationBroadcastReceiver
import im.vector.receiver.NotificationBroadcastReceiver
import im.vector.ui.themes.ThemeUtils
import im.vector.util.PreferencesManager
import im.vector.util.startNotificationChannelSettingsIntent
Expand Down Expand Up @@ -757,7 +757,7 @@ object NotificationUtils {
if (!roomInfo.hasSmartReplyError) {
buildQuickReplyIntent(context, roomInfo.roomId, senderDisplayNameForReplyCompat)?.let { replyPendingIntent ->
var replyLabel: String = context.getString(R.string.action_quick_reply)
var remoteInput: RemoteInput = RemoteInput.Builder(ReplyNotificationBroadcastReceiver.KEY_TEXT_REPLY).run {
var remoteInput: RemoteInput = RemoteInput.Builder(NotificationBroadcastReceiver.KEY_TEXT_REPLY).run {
setLabel(replyLabel)
build()
}
Expand All @@ -778,8 +778,8 @@ object NotificationUtils {
setLargeIcon(largeIcon)
}

val intent = Intent(context, ReplyNotificationBroadcastReceiver::class.java)
intent.putExtra(ReplyNotificationBroadcastReceiver.KEY_ROOM_ID, roomInfo.roomId)
val intent = Intent(context, NotificationBroadcastReceiver::class.java)
intent.putExtra(NotificationBroadcastReceiver.KEY_ROOM_ID, roomInfo.roomId)
intent.action = DISMISS_ROOM_NOTIF_ACTION
val pendingIntent = PendingIntent.getBroadcast(context.applicationContext,
System.currentTimeMillis().toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
Expand Down Expand Up @@ -898,9 +898,9 @@ object NotificationUtils {
private fun buildQuickReplyIntent(context: Context, roomId: String, senderName: String?): PendingIntent? {
val intent: Intent
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent = Intent(context, ReplyNotificationBroadcastReceiver::class.java)
intent = Intent(context, NotificationBroadcastReceiver::class.java)
intent.action = "${SMART_REPLY_ACTION}_$roomId"
intent.putExtra(ReplyNotificationBroadcastReceiver.KEY_ROOM_ID, roomId)
intent.putExtra(NotificationBroadcastReceiver.KEY_ROOM_ID, roomId)
return PendingIntent.getBroadcast(context, System.currentTimeMillis().toInt(), intent,
PendingIntent.FLAG_UPDATE_CURRENT)
} else {
Expand Down Expand Up @@ -954,7 +954,7 @@ object NotificationUtils {
}

private fun getDismissSummaryPendingIntent(context: Context): PendingIntent {
val intent = Intent(context, ReplyNotificationBroadcastReceiver::class.java)
val intent = Intent(context, NotificationBroadcastReceiver::class.java)
intent.action = DISMISS_SUMMARY_ACTION
intent.data = Uri.parse("foobar://deleteSummary")
val pendingIntent = PendingIntent.getBroadcast(context.applicationContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/*
* Copyright 2016 OpenMarket Ltd
/**
* Copyright 2019 New Vector Ltd
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package im.vector.receiver

import android.content.BroadcastReceiver
Expand All @@ -34,15 +38,15 @@ import org.matrix.androidsdk.rest.model.MatrixError
import org.matrix.androidsdk.rest.model.message.Message
import org.matrix.androidsdk.util.Log

class ReplyNotificationBroadcastReceiver : BroadcastReceiver() {
class NotificationBroadcastReceiver : BroadcastReceiver() {

override fun onReceive(context: Context?, intent: Intent?) {
if (intent == null || context == null) return
Log.d(LOG_TAG, "ReplyNotificationBroadcastReceiver received : $intent")
val action = intent.action
if (action != null) {
if (action.startsWith(NotificationUtils.SMART_REPLY_ACTION)) {
handleSmartReply(intent,context)
handleSmartReply(intent, context)
} else if (action == NotificationUtils.DISMISS_ROOM_NOTIF_ACTION) {
intent.getStringExtra(KEY_ROOM_ID)?.let {
VectorApp.getInstance().notificationDrawerManager.clearMessageEventOfRoom(it)
Expand Down Expand Up @@ -86,12 +90,13 @@ class ReplyNotificationBroadcastReceiver : BroadcastReceiver() {
false,
System.currentTimeMillis(),
session.myUser?.displayname
?: "Me",
?: "",
message,
roomId,
room.getRoomDisplayName(context))
notifiableMessageEvent.outGoingMessage = true
VectorApp.getInstance().notificationDrawerManager.onNotifiableEventReceived(notifiableMessageEvent, session.myUserId, session.myUser.displayname)
VectorApp.getInstance().notificationDrawerManager.onNotifiableEventReceived(
notifiableMessageEvent, session.myUserId, session.myUser.displayname)
VectorApp.getInstance().notificationDrawerManager.refreshNotificationDrawer(null)
}

Expand Down Expand Up @@ -123,14 +128,15 @@ class ReplyNotificationBroadcastReceiver : BroadcastReceiver() {
false,
System.currentTimeMillis(),
session.myUser?.displayname
?: "Me",
?: "",
message,
roomId,
room.getRoomDisplayName(context))
notifiableMessageEvent.outGoingMessage = true
notifiableMessageEvent.outGoingMessageFailed = true

VectorApp.getInstance().notificationDrawerManager.onNotifiableEventReceived(notifiableMessageEvent, session.myUserId, session.myUser.displayname)
VectorApp.getInstance().notificationDrawerManager.onNotifiableEventReceived(
notifiableMessageEvent, session.myUserId, session.myUser.displayname)
VectorApp.getInstance().notificationDrawerManager.refreshNotificationDrawer(null)
}
})
Expand All @@ -148,10 +154,10 @@ class ReplyNotificationBroadcastReceiver : BroadcastReceiver() {
}

companion object {
val KEY_ROOM_ID = "roomID"
val KEY_TEXT_REPLY = "key_text_reply"
val EXTRA_MATRIX_ID = "EXTRA_MATRIX_ID"
const val KEY_ROOM_ID = "roomID"
const val KEY_TEXT_REPLY = "key_text_reply"
const val EXTRA_MATRIX_ID = "EXTRA_MATRIX_ID"

val LOG_TAG = ReplyNotificationBroadcastReceiver::class.java.name
val LOG_TAG = NotificationBroadcastReceiver::class.java.name
}
}
Loading

0 comments on commit 032cbc2

Please sign in to comment.