mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 03:29:28 +01:00
remove class level notification property
Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parent
d6201cf796
commit
d63fc58a62
@ -2,7 +2,9 @@
|
|||||||
* Nextcloud Talk application
|
* Nextcloud Talk application
|
||||||
*
|
*
|
||||||
* @author Marcel Hibbe
|
* @author Marcel Hibbe
|
||||||
|
* @author Parneet Singh
|
||||||
* Copyright (C) 2021-2022 Marcel Hibbe <dev@mhibbe.de>
|
* Copyright (C) 2021-2022 Marcel Hibbe <dev@mhibbe.de>
|
||||||
|
* Copyright (C) 2024-2025 Parneet Singh <gurayaparneet@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -22,7 +24,6 @@ package com.nextcloud.talk.jobs
|
|||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.Notification
|
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@ -86,7 +87,6 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
|||||||
|
|
||||||
private var mNotifyManager: NotificationManager? = null
|
private var mNotifyManager: NotificationManager? = null
|
||||||
private var mBuilder: NotificationCompat.Builder? = null
|
private var mBuilder: NotificationCompat.Builder? = null
|
||||||
private lateinit var notification: Notification
|
|
||||||
private var notificationId: Int = 0
|
private var notificationId: Int = 0
|
||||||
|
|
||||||
lateinit var roomToken: String
|
lateinit var roomToken: String
|
||||||
@ -196,12 +196,12 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onTransferProgress(percentage: Int) {
|
override fun onTransferProgress(percentage: Int) {
|
||||||
notification = mBuilder!!
|
val progressUpdateNotification = mBuilder!!
|
||||||
.setProgress(HUNDRED_PERCENT, percentage, false)
|
.setProgress(HUNDRED_PERCENT, percentage, false)
|
||||||
.setContentText(getNotificationContentText(percentage))
|
.setContentText(getNotificationContentText(percentage))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
mNotifyManager!!.notify(notificationId, notification)
|
mNotifyManager!!.notify(notificationId, progressUpdateNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStopped() {
|
override fun onStopped() {
|
||||||
@ -223,8 +223,8 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initNotificationWithPercentage() {
|
private fun initNotificationWithPercentage() {
|
||||||
notification = mBuilder!!
|
val initNotification = mBuilder!!
|
||||||
.setContentTitle(getResourceString(context, R.string.nc_upload_in_progess))
|
.setContentTitle(context.resources.getString(R.string.nc_upload_in_progess))
|
||||||
.setContentText(getNotificationContentText(ZERO_PERCENT))
|
.setContentText(getNotificationContentText(ZERO_PERCENT))
|
||||||
.setSmallIcon(R.drawable.upload_white)
|
.setSmallIcon(R.drawable.upload_white)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
@ -233,14 +233,14 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
|||||||
.setGroup(NotificationUtils.KEY_UPLOAD_GROUP)
|
.setGroup(NotificationUtils.KEY_UPLOAD_GROUP)
|
||||||
.setContentIntent(getIntentToOpenConversation())
|
.setContentIntent(getIntentToOpenConversation())
|
||||||
.addAction(
|
.addAction(
|
||||||
R.drawable.ic_cancel_white_24dp, getResourceString(context, R.string.nc_cancel),
|
R.drawable.ic_cancel_white_24dp,
|
||||||
|
getResourceString(context, R.string.nc_cancel),
|
||||||
getCancelUploadIntent()
|
getCancelUploadIntent()
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
|
||||||
notificationId = SystemClock.uptimeMillis().toInt()
|
notificationId = SystemClock.uptimeMillis().toInt()
|
||||||
mNotifyManager!!.notify(notificationId, notification)
|
mNotifyManager!!.notify(notificationId, initNotification)
|
||||||
// only need one summary notification but multiple upload worker can call it more than once but it is safe
|
// only need one summary notification but multiple upload worker can call it more than once but it is safe
|
||||||
// because of the same notification object config and id.
|
// because of the same notification object config and id.
|
||||||
makeSummaryNotification()
|
makeSummaryNotification()
|
||||||
@ -249,7 +249,8 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
|||||||
private fun makeSummaryNotification() {
|
private fun makeSummaryNotification() {
|
||||||
// summary notification encapsulating the group of notifications
|
// summary notification encapsulating the group of notifications
|
||||||
val summaryNotification = NotificationCompat.Builder(
|
val summaryNotification = NotificationCompat.Builder(
|
||||||
context, NotificationUtils.NotificationChannels
|
context,
|
||||||
|
NotificationUtils.NotificationChannels
|
||||||
.NOTIFICATION_CHANNEL_UPLOADS.name
|
.NOTIFICATION_CHANNEL_UPLOADS.name
|
||||||
).setSmallIcon(R.drawable.upload_white)
|
).setSmallIcon(R.drawable.upload_white)
|
||||||
.setGroup(NotificationUtils.KEY_UPLOAD_GROUP)
|
.setGroup(NotificationUtils.KEY_UPLOAD_GROUP)
|
||||||
@ -261,13 +262,18 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
|||||||
|
|
||||||
private fun getActiveUploadNotifications(): Int? {
|
private fun getActiveUploadNotifications(): Int? {
|
||||||
// filter out active notifications that are upload notifications using group
|
// filter out active notifications that are upload notifications using group
|
||||||
return mNotifyManager?.activeNotifications?.filter { notification.group == NotificationUtils.KEY_UPLOAD_GROUP }?.size
|
return mNotifyManager?.activeNotifications?.filter {
|
||||||
|
it.notification.group == NotificationUtils
|
||||||
|
.KEY_UPLOAD_GROUP
|
||||||
|
}?.size
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cancelNotification() {
|
private fun cancelNotification() {
|
||||||
mNotifyManager?.cancel(notificationId)
|
mNotifyManager?.cancel(notificationId)
|
||||||
// summary notification would not get dismissed automatically if child notifications are cancelled programmatically
|
// summary notification would not get dismissed automatically
|
||||||
// so check if only 1 notification left if yes then cancel it because that would be summary notification
|
// if child notifications are cancelled programmatically
|
||||||
|
// so check if only 1 notification left if yes
|
||||||
|
// then cancel it (which is summary notification)
|
||||||
if (getActiveUploadNotifications() == 1) {
|
if (getActiveUploadNotifications() == 1) {
|
||||||
mNotifyManager?.cancel(NotificationUtils.GROUP_SUMMARY_NOTIFICATION_ID)
|
mNotifyManager?.cancel(NotificationUtils.GROUP_SUMMARY_NOTIFICATION_ID)
|
||||||
}
|
}
|
||||||
@ -322,7 +328,8 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
|||||||
fileName
|
fileName
|
||||||
)
|
)
|
||||||
val failureNotification = NotificationCompat.Builder(
|
val failureNotification = NotificationCompat.Builder(
|
||||||
context, NotificationUtils.NotificationChannels
|
context,
|
||||||
|
NotificationUtils.NotificationChannels
|
||||||
.NOTIFICATION_CHANNEL_UPLOADS.name
|
.NOTIFICATION_CHANNEL_UPLOADS.name
|
||||||
)
|
)
|
||||||
.setContentTitle(failureTitle)
|
.setContentTitle(failureTitle)
|
||||||
|
@ -71,6 +71,7 @@ object NotificationUtils {
|
|||||||
// notification group keys
|
// notification group keys
|
||||||
const val KEY_UPLOAD_GROUP = "com.nextcloud.talk.utils.KEY_UPLOAD_GROUP"
|
const val KEY_UPLOAD_GROUP = "com.nextcloud.talk.utils.KEY_UPLOAD_GROUP"
|
||||||
const val GROUP_SUMMARY_NOTIFICATION_ID = -1
|
const val GROUP_SUMMARY_NOTIFICATION_ID = -1
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.O)
|
@TargetApi(Build.VERSION_CODES.O)
|
||||||
private fun createNotificationChannel(
|
private fun createNotificationChannel(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
Loading…
Reference in New Issue
Block a user