Merge pull request #254 from vector-im/feature/enhance_notif_pre_n

Better summary for pre N devices
This commit is contained in:
Valere 2019-07-01 20:38:02 +02:00 committed by GitHub
commit fb1f107911
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 5 deletions

View file

@ -20,13 +20,13 @@ import android.content.Context
import android.graphics.Bitmap
import androidx.core.app.NotificationCompat
import androidx.core.app.Person
import im.vector.matrix.android.api.Matrix
import im.vector.matrix.android.api.session.content.ContentUrlResolver
import im.vector.riotredesign.BuildConfig
import im.vector.riotredesign.R
import im.vector.riotredesign.core.di.ActiveSessionHolder
import im.vector.riotredesign.core.utils.SecretStoringUtils
import im.vector.riotredesign.features.settings.PreferencesManager
import me.gujun.android.span.span
import timber.log.Timber
import java.io.File
import java.io.FileInputStream
@ -275,9 +275,32 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
}
try {
val summaryLine = context.resources.getQuantityString(
R.plurals.notification_compat_summary_line_for_room, events.size, roomName, events.size)
summaryInboxStyle.addLine(summaryLine)
if (events.size == 1) {
val event = events[0]
if (roomEventGroupInfo.isDirect) {
val line = span {
span {
textStyle = "bold"
+String.format("%s: ", event.senderName)
}
+(event.description ?: "")
}
summaryInboxStyle.addLine(line)
} else {
val line = span {
span {
textStyle = "bold"
+String.format("%s: %s ", roomName, event.senderName)
}
+(event.description ?: "")
}
summaryInboxStyle.addLine(line)
}
} else {
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
Timber.v("%%%%%%%% REFRESH NOTIFICATION DRAWER failed to resolve string")
@ -343,6 +366,11 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
val sumTitle = context.resources.getQuantityString(
R.plurals.notification_compat_summary_title, nbEvents, nbEvents)
summaryInboxStyle.setBigContentTitle(sumTitle)
//TODO get latest event?
.setSummaryText(
context.resources
.getQuantityString(R.plurals.notification_unread_notified_messages, nbEvents, nbEvents))
NotificationUtils.buildSummaryListNotification(
context,
summaryInboxStyle,

View file

@ -606,7 +606,7 @@ object NotificationUtils {
* Build the summary notification
*/
fun buildSummaryListNotification(context: Context,
style: NotificationCompat.Style,
style: NotificationCompat.InboxStyle,
compatSummary: String,
noisy: Boolean,
lastMessageTimestamp: Long): Notification? {