Add dismiss/share actions for "recording available" notification

Remove first approach with the dialog inside the ChatController.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-02-24 15:09:17 +01:00
parent 0f3662cd82
commit 36de155c44
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
9 changed files with 317 additions and 209 deletions

View File

@ -198,6 +198,8 @@
<receiver android:name=".receivers.DirectReplyReceiver" /> <receiver android:name=".receivers.DirectReplyReceiver" />
<receiver android:name=".receivers.MarkAsReadReceiver" /> <receiver android:name=".receivers.MarkAsReadReceiver" />
<receiver android:name=".receivers.DismissRecordingAvailableReceiver" />
<receiver android:name=".receivers.ShareRecordingToChatReceiver" />
<service <service
android:name=".utils.SyncService" android:name=".utils.SyncService"

View File

@ -388,17 +388,6 @@ class MainActivity : BaseActivity(), ActionBarProvider {
) )
logRouterBackStack(router!!) logRouterBackStack(router!!)
} }
} else if (intent.hasExtra(BundleKeys.KEY_NOTIFICATION_RECORDING_NOTIFICATION)) {
logRouterBackStack(router!!)
remapChatController(
router!!,
intent.getParcelableExtra<User>(KEY_USER_ENTITY)!!.id!!,
intent.getStringExtra(KEY_ROOM_TOKEN)!!,
intent.extras!!,
true,
true
)
logRouterBackStack(router!!)
} }
} }

View File

@ -126,7 +126,6 @@ import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.callbacks.MentionAutocompleteCallback import com.nextcloud.talk.callbacks.MentionAutocompleteCallback
import com.nextcloud.talk.controllers.base.BaseController import com.nextcloud.talk.controllers.base.BaseController
import com.nextcloud.talk.controllers.util.viewBinding import com.nextcloud.talk.controllers.util.viewBinding
import com.nextcloud.talk.data.NotificationDialogData
import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.ControllerChatBinding import com.nextcloud.talk.databinding.ControllerChatBinding
import com.nextcloud.talk.events.UserMentionClickEvent import com.nextcloud.talk.events.UserMentionClickEvent
@ -185,7 +184,6 @@ import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil
import com.nextcloud.talk.utils.remapchat.ConductorRemapping import com.nextcloud.talk.utils.remapchat.ConductorRemapping
import com.nextcloud.talk.utils.remapchat.RemapChatModel import com.nextcloud.talk.utils.remapchat.RemapChatModel
import com.nextcloud.talk.utils.rx.DisposableSet import com.nextcloud.talk.utils.rx.DisposableSet
import com.nextcloud.talk.utils.rx.SendCommonRequestUtil
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder
import com.nextcloud.talk.utils.text.Spans import com.nextcloud.talk.utils.text.Spans
import com.nextcloud.talk.webrtc.WebSocketConnectionHelper import com.nextcloud.talk.webrtc.WebSocketConnectionHelper
@ -269,7 +267,6 @@ class ChatController(args: Bundle) :
private var lookingIntoFuture = false private var lookingIntoFuture = false
var newMessagesCount = 0 var newMessagesCount = 0
var startCallFromNotification: Boolean? = null var startCallFromNotification: Boolean? = null
private var recordingAvailableNotification: NotificationDialogData? = null
var startCallFromRoomSwitch: Boolean = false var startCallFromRoomSwitch: Boolean = false
val roomId: String val roomId: String
val voiceOnly: Boolean val voiceOnly: Boolean
@ -346,10 +343,6 @@ class ChatController(args: Bundle) :
startCallFromNotification = args.getBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL) startCallFromNotification = args.getBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)
} }
if (args.containsKey(BundleKeys.KEY_NOTIFICATION_RECORDING_NOTIFICATION)) {
recordingAvailableNotification = args.getParcelable(BundleKeys.KEY_NOTIFICATION_RECORDING_NOTIFICATION)
}
if (args.containsKey(BundleKeys.KEY_SWITCH_TO_ROOM_AND_START_CALL)) { if (args.containsKey(BundleKeys.KEY_SWITCH_TO_ROOM_AND_START_CALL)) {
startCallFromRoomSwitch = args.getBoolean(BundleKeys.KEY_SWITCH_TO_ROOM_AND_START_CALL) startCallFromRoomSwitch = args.getBoolean(BundleKeys.KEY_SWITCH_TO_ROOM_AND_START_CALL)
} }
@ -933,33 +926,6 @@ class ChatController(args: Bundle) :
getRoomInfo() getRoomInfo()
} }
} }
if (recordingAvailableNotification != null) {
binding?.root?.context?.let { context ->
val dialogBuilder = MaterialAlertDialogBuilder(context)
recordingAvailableNotification?.let {
dialogBuilder.setTitle(it.title)
dialogBuilder.setMessage(it.text)
val requestUtil = SendCommonRequestUtil(ncApi, credentials!!)
dialogBuilder.setPositiveButton(it.primaryActionDescription) { _, _ ->
requestUtil.sendRequest(it.primaryActionMethod, it.primaryActionUrl)
}
dialogBuilder.setNegativeButton(it.secondaryActionDescription) { _, _ ->
requestUtil.sendRequest(it.secondaryActionMethod, it.secondaryActionUrl)
}
}
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)
}
}
super.onViewBound(view) super.onViewBound(view)
} }

View File

@ -1,16 +0,0 @@
package com.nextcloud.talk.data
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
@Parcelize
data class NotificationDialogData(
var title: String = "",
var text: String = "",
var primaryActionDescription: String = "",
var primaryActionUrl: String = "",
var primaryActionMethod: String = "",
var secondaryActionDescription: String = "",
var secondaryActionUrl: String = "",
var secondaryActionMethod: String = ""
) : Parcelable

View File

@ -4,7 +4,7 @@
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Mario Danic * @author Mario Danic
* @author Marcel Hibbe * @author Marcel Hibbe
* Copyright (C) 2022 Marcel Hibbe <dev@mhibbe.de> * Copyright (C) 2022-2023 Marcel Hibbe <dev@mhibbe.de>
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de> * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com> * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
* *
@ -58,7 +58,6 @@ import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager
import com.nextcloud.talk.data.NotificationDialogData
import com.nextcloud.talk.models.SignatureVerification import com.nextcloud.talk.models.SignatureVerification
import com.nextcloud.talk.models.json.chat.ChatUtils.Companion.getParsedMessage import com.nextcloud.talk.models.json.chat.ChatUtils.Companion.getParsedMessage
import com.nextcloud.talk.models.json.conversations.RoomOverall import com.nextcloud.talk.models.json.conversations.RoomOverall
@ -68,7 +67,9 @@ import com.nextcloud.talk.models.json.participants.ParticipantsOverall
import com.nextcloud.talk.models.json.push.DecryptedPushMessage import com.nextcloud.talk.models.json.push.DecryptedPushMessage
import com.nextcloud.talk.models.json.push.NotificationUser import com.nextcloud.talk.models.json.push.NotificationUser
import com.nextcloud.talk.receivers.DirectReplyReceiver import com.nextcloud.talk.receivers.DirectReplyReceiver
import com.nextcloud.talk.receivers.DismissRecordingAvailableReceiver
import com.nextcloud.talk.receivers.MarkAsReadReceiver import com.nextcloud.talk.receivers.MarkAsReadReceiver
import com.nextcloud.talk.receivers.ShareRecordingToChatReceiver
import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DoNotDisturbUtils.shouldPlaySound import com.nextcloud.talk.utils.DoNotDisturbUtils.shouldPlaySound
import com.nextcloud.talk.utils.NotificationUtils import com.nextcloud.talk.utils.NotificationUtils
@ -80,14 +81,15 @@ import com.nextcloud.talk.utils.NotificationUtils.getMessageRingtoneUri
import com.nextcloud.talk.utils.NotificationUtils.loadAvatarSync import com.nextcloud.talk.utils.NotificationUtils.loadAvatarSync
import com.nextcloud.talk.utils.PushUtils import com.nextcloud.talk.utils.PushUtils
import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_DISMISS_RECORDING_URL
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FROM_NOTIFICATION_START_CALL import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FROM_NOTIFICATION_START_CALL
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_MESSAGE_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_MESSAGE_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NOTIFICATION_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NOTIFICATION_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NOTIFICATION_RECORDING_NOTIFICATION
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NOTIFICATION_RESTRICT_DELETION import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NOTIFICATION_RESTRICT_DELETION
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NOTIFICATION_TIMESTAMP import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NOTIFICATION_TIMESTAMP
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SHARE_RECORDING_TO_CHAT_URL
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SYSTEM_NOTIFICATION_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SYSTEM_NOTIFICATION_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
import com.nextcloud.talk.utils.preferences.AppPreferences import com.nextcloud.talk.utils.preferences.AppPreferences
@ -183,7 +185,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
if (pushMessage.notificationId != Long.MIN_VALUE) { if (pushMessage.notificationId != Long.MIN_VALUE) {
getNcDataAndShowNotification(mainActivityIntent) getNcDataAndShowNotification(mainActivityIntent)
} else { } else {
showNotification(mainActivityIntent) showNotification(mainActivityIntent, null)
} }
} }
@ -313,8 +315,8 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
val ncNotification = notificationOverall.ocs!!.notification val ncNotification = notificationOverall.ocs!!.notification
if (ncNotification != null) { if (ncNotification != null) {
enrichPushMessageByNcNotificationData(ncNotification) enrichPushMessageByNcNotificationData(ncNotification)
val newIntent = enrichIntentByNcNotificationData(intent, ncNotification) // val newIntent = enrichIntentByNcNotificationData(intent, ncNotification)
showNotification(newIntent) showNotification(intent, ncNotification)
} }
} }
@ -334,29 +336,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
): Intent { ): Intent {
val newIntent = Intent(intent) val newIntent = Intent(intent)
if ("recording" == ncNotification.objectType) {
val notificationDialogData = NotificationDialogData()
notificationDialogData.title = pushMessage.subject
notificationDialogData.text = pushMessage.text.orEmpty()
for (action in ncNotification.actions!!) {
if (action.primary) {
notificationDialogData.primaryActionDescription = action.label.orEmpty()
notificationDialogData.primaryActionMethod = action.type.orEmpty()
notificationDialogData.primaryActionUrl = action.link.orEmpty()
} else {
notificationDialogData.secondaryActionDescription = action.label.orEmpty()
notificationDialogData.secondaryActionMethod = action.type.orEmpty()
notificationDialogData.secondaryActionUrl = action.link.orEmpty()
}
}
val bundle = Bundle()
bundle.putParcelable(KEY_NOTIFICATION_RECORDING_NOTIFICATION, notificationDialogData)
newIntent.putExtras(bundle)
}
return newIntent return newIntent
} }
@ -417,7 +396,10 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
} }
@Suppress("MagicNumber") @Suppress("MagicNumber")
private fun showNotification(intent: Intent) { private fun showNotification(
intent: Intent,
ncNotification: com.nextcloud.talk.models.json.notifications.Notification?
) {
var category = "" var category = ""
when (pushMessage.type) { when (pushMessage.type) {
TYPE_CHAT, TYPE_ROOM, TYPE_RECORDING -> category = Notification.CATEGORY_MESSAGE TYPE_CHAT, TYPE_ROOM, TYPE_RECORDING -> category = Notification.CATEGORY_MESSAGE
@ -447,6 +429,8 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
contentText = EmojiCompat.get().process(pushMessage.text!!) contentText = EmojiCompat.get().process(pushMessage.text!!)
} }
val autoCancelOnClick = TYPE_RECORDING != pushMessage.type
val notificationBuilder = NotificationCompat.Builder(context!!, "1") val notificationBuilder = NotificationCompat.Builder(context!!, "1")
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(category) .setCategory(category)
@ -458,7 +442,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
.setWhen(pushMessage.timestamp) .setWhen(pushMessage.timestamp)
.setShowWhen(true) .setShowWhen(true)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setAutoCancel(true) .setAutoCancel(autoCancelOnClick)
.setColor(context!!.resources.getColor(R.color.colorPrimary)) .setColor(context!!.resources.getColor(R.color.colorPrimary))
val notificationInfoBundle = Bundle() val notificationInfoBundle = Bundle()
@ -511,25 +495,17 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
TYPE_RECORDING == pushMessage.type && TYPE_RECORDING == pushMessage.type &&
pushMessage.notificationUser != null ncNotification != null
) { ) {
prepareChatNotification(notificationBuilder, activeStatusBarNotification, systemNotificationId) addDismissRecordingAvailableAction(notificationBuilder, systemNotificationId, ncNotification)
// addDiscardRecordingAvailableAction(notificationBuilder, systemNotificationId) addShareRecordingToChatAction(notificationBuilder, systemNotificationId, ncNotification)
// addShareRecordingToChatAction(notificationBuilder, systemNotificationId)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
TYPE_RECORDING == pushMessage.type &&
pushMessage.notificationUser != null // null
) {
prepareChatNotification(notificationBuilder, activeStatusBarNotification, systemNotificationId)
} }
sendNotification(systemNotificationId, notificationBuilder.build()) sendNotification(systemNotificationId, notificationBuilder.build())
} }
private fun getLargeIcon(): Bitmap { private fun getLargeIcon(): Bitmap {
val largeIcon: Bitmap val largeIcon: Bitmap
if (pushMessage.type == "recording") { if (pushMessage.type == TYPE_RECORDING) {
largeIcon = ContextCompat.getDrawable(context!!, R.drawable.ic_baseline_videocam_24)?.toBitmap()!! largeIcon = ContextCompat.getDrawable(context!!, R.drawable.ic_baseline_videocam_24)?.toBitmap()!!
} else { } else {
when (conversationType) { when (conversationType) {
@ -662,50 +638,82 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
notificationBuilder.addAction(replyAction) notificationBuilder.addAction(replyAction)
} }
// @RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
// private fun addDiscardRecordingAvailableAction(notificationBuilder: NotificationCompat.Builder, private fun addDismissRecordingAvailableAction(
// systemNotificationId: notificationBuilder: NotificationCompat.Builder,
// Int) { systemNotificationId: Int,
// val replyLabel = context!!.resources.getString(R.string.nc_reply) ncNotification: com.nextcloud.talk.models.json.notifications.Notification
// val remoteInput = RemoteInput.Builder(NotificationUtils.KEY_DIRECT_REPLY) ) {
// .setLabel(replyLabel) var dismissLabel = ""
// .build() var dismissRecordingUrl = ""
//
// val replyPendingIntent = buildIntentForAction( for (action in ncNotification.actions!!) {
// DirectReplyReceiver::class.java, if (!action.primary) {
// systemNotificationId, dismissLabel = action.label.orEmpty()
// 0 dismissRecordingUrl = action.link.orEmpty()
// ) }
// val replyAction = NotificationCompat.Action.Builder(R.drawable.ic_reply, replyLabel, replyPendingIntent) }
// .setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY)
// .setShowsUserInterface(false) val dismissIntent = Intent(context, DismissRecordingAvailableReceiver::class.java)
// .setAllowGeneratedReplies(true) dismissIntent.putExtra(KEY_SYSTEM_NOTIFICATION_ID, systemNotificationId)
// .addRemoteInput(remoteInput) dismissIntent.putExtra(KEY_DISMISS_RECORDING_URL, dismissRecordingUrl)
// .build()
// notificationBuilder.addAction(replyAction) val intentFlag: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// } PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
// } else {
// @RequiresApi(api = Build.VERSION_CODES.N) PendingIntent.FLAG_UPDATE_CURRENT
// private fun addShareRecordingToChatAction(notificationBuilder: NotificationCompat.Builder, systemNotificationId: }
// Int) { val dismissPendingIntent = PendingIntent.getBroadcast(context, systemNotificationId, dismissIntent, intentFlag)
// val replyLabel = context!!.resources.getString(R.string.nc_reply)
// val remoteInput = RemoteInput.Builder(NotificationUtils.KEY_DIRECT_REPLY) val dismissAction = NotificationCompat.Action.Builder(R.drawable.ic_delete, dismissLabel, dismissPendingIntent)
// .setLabel(replyLabel) .setShowsUserInterface(false)
// .build() .setAllowGeneratedReplies(true)
// .build()
// val replyPendingIntent = buildIntentForAction( notificationBuilder.addAction(dismissAction)
// DirectReplyReceiver::class.java, }
// systemNotificationId,
// 0 @RequiresApi(api = Build.VERSION_CODES.N)
// ) private fun addShareRecordingToChatAction(
// val replyAction = NotificationCompat.Action.Builder(R.drawable.ic_reply, replyLabel, replyPendingIntent) notificationBuilder: NotificationCompat.Builder,
// .setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY) systemNotificationId: Int,
// .setShowsUserInterface(false) ncNotification: com.nextcloud.talk.models.json.notifications.Notification
// .setAllowGeneratedReplies(true) ) {
// .addRemoteInput(remoteInput) var shareToChatLabel = ""
// .build() var shareToChatUrl = ""
// notificationBuilder.addAction(replyAction)
// } for (action in ncNotification.actions!!) {
if (action.primary) {
shareToChatLabel = action.label.orEmpty()
shareToChatUrl = action.link.orEmpty()
}
}
val shareRecordingIntent = Intent(context, ShareRecordingToChatReceiver::class.java)
shareRecordingIntent.putExtra(KEY_SYSTEM_NOTIFICATION_ID, systemNotificationId)
shareRecordingIntent.putExtra(KEY_SHARE_RECORDING_TO_CHAT_URL, shareToChatUrl)
val intentFlag: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
val shareRecordingPendingIntent = PendingIntent.getBroadcast(
context,
systemNotificationId,
shareRecordingIntent,
intentFlag
)
val shareRecordingAction = NotificationCompat.Action.Builder(
R.drawable.ic_delete,
shareToChatLabel,
shareRecordingPendingIntent
)
.setShowsUserInterface(false)
.setAllowGeneratedReplies(true)
.build()
notificationBuilder.addAction(shareRecordingAction)
}
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
private fun getStyle(person: Person, style: NotificationCompat.MessagingStyle?): NotificationCompat.MessagingStyle { private fun getStyle(person: Person, style: NotificationCompat.MessagingStyle?): NotificationCompat.MessagingStyle {

View File

@ -0,0 +1,109 @@
/*
* Nextcloud Talk application
*
* @author Marcel Hibbe
* Copyright (C) 2022-2023 Marcel Hibbe <dev@mhibbe.de>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.receivers
import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import autodagger.AutoInjector
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SYSTEM_NOTIFICATION_ID
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class)
class DismissRecordingAvailableReceiver : BroadcastReceiver() {
@Inject
lateinit var userManager: UserManager
@Inject
lateinit var ncApi: NcApi
lateinit var context: Context
lateinit var currentUser: User
private var systemNotificationId: Int? = null
private var link: String? = null
init {
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
}
override fun onReceive(receiveContext: Context, intent: Intent?) {
context = receiveContext
// NOTE - systemNotificationId is an internal ID used on the device only.
// It is NOT the same as the notification ID used in communication with the server.
systemNotificationId = intent!!.getIntExtra(KEY_SYSTEM_NOTIFICATION_ID, 0)
link = intent.getStringExtra(BundleKeys.KEY_DISMISS_RECORDING_URL)
val id = intent.getLongExtra(KEY_INTERNAL_USER_ID, userManager.currentUser.blockingGet().id!!)
currentUser = userManager.getUserWithId(id).blockingGet()
dismissNcRecordingAvailableNotification()
}
private fun dismissNcRecordingAvailableNotification() {
val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token)
ncApi.sendCommonDeleteRequest(credentials, link)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onNext(genericOverall: GenericOverall) {
cancelNotification(systemNotificationId!!)
}
override fun onError(e: Throwable) {
Log.e(TAG, "Failed to send dismiss for recording available", e)
}
override fun onComplete() {
// unused atm
}
})
}
private fun cancelNotification(notificationId: Int) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(notificationId)
}
companion object {
private val TAG = DismissRecordingAvailableReceiver::class.java.simpleName
}
}

View File

@ -0,0 +1,109 @@
/*
* Nextcloud Talk application
*
* @author Marcel Hibbe
* Copyright (C) 2022-2023 Marcel Hibbe <dev@mhibbe.de>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.receivers
import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import autodagger.AutoInjector
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SYSTEM_NOTIFICATION_ID
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class)
class ShareRecordingToChatReceiver : BroadcastReceiver() {
@Inject
lateinit var userManager: UserManager
@Inject
lateinit var ncApi: NcApi
lateinit var context: Context
lateinit var currentUser: User
private var systemNotificationId: Int? = null
private var link: String? = null
init {
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
}
override fun onReceive(receiveContext: Context, intent: Intent?) {
context = receiveContext
// NOTE - systemNotificationId is an internal ID used on the device only.
// It is NOT the same as the notification ID used in communication with the server.
systemNotificationId = intent!!.getIntExtra(KEY_SYSTEM_NOTIFICATION_ID, 0)
link = intent.getStringExtra(BundleKeys.KEY_SHARE_RECORDING_TO_CHAT_URL)
val id = intent.getLongExtra(KEY_INTERNAL_USER_ID, userManager.currentUser.blockingGet().id!!)
currentUser = userManager.getUserWithId(id).blockingGet()
shareRecordingToChat()
}
private fun shareRecordingToChat() {
val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token)
ncApi.sendCommonPostRequest(credentials, link)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onNext(genericOverall: GenericOverall) {
cancelNotification(systemNotificationId!!)
}
override fun onError(e: Throwable) {
Log.e(TAG, "Failed to share recording to chat request", e)
}
override fun onComplete() {
// unused atm
}
})
}
private fun cancelNotification(notificationId: Int) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(notificationId)
}
companion object {
private val TAG = ShareRecordingToChatReceiver::class.java.simpleName
}
}

View File

@ -82,6 +82,7 @@ object BundleKeys {
const val KEY_IS_MODERATOR = "KEY_IS_MODERATOR" const val KEY_IS_MODERATOR = "KEY_IS_MODERATOR"
const val KEY_SWITCH_TO_ROOM_AND_START_CALL = "KEY_SWITCH_TO_ROOM_AND_START_CALL" const val KEY_SWITCH_TO_ROOM_AND_START_CALL = "KEY_SWITCH_TO_ROOM_AND_START_CALL"
const val KEY_IS_BREAKOUT_ROOM = "KEY_IS_BREAKOUT_ROOM" const val KEY_IS_BREAKOUT_ROOM = "KEY_IS_BREAKOUT_ROOM"
const val KEY_NOTIFICATION_RECORDING_NOTIFICATION = "KEY_NOTIFICATION_RECORDING_NOTIFICATION"
const val KEY_NOTIFICATION_RESTRICT_DELETION = "KEY_NOTIFICATION_RESTRICT_DELETION" const val KEY_NOTIFICATION_RESTRICT_DELETION = "KEY_NOTIFICATION_RESTRICT_DELETION"
const val KEY_DISMISS_RECORDING_URL = "KEY_DISMISS_RECORDING_URL"
const val KEY_SHARE_RECORDING_TO_CHAT_URL = "KEY_SHARE_RECORDING_TO_CHAT_URL"
} }

View File

@ -1,60 +0,0 @@
package com.nextcloud.talk.utils.rx
import android.util.Log
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.models.json.generic.GenericOverall
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
class SendCommonRequestUtil(val ncApi: NcApi, val credentials: String) {
fun sendRequest(type: String, link: String) {
if (type == "POST") {
ncApi.sendCommonPostRequest(credentials, link)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onNext(genericOverall: GenericOverall) {
}
override fun onError(e: Throwable) {
Log.e(TAG, "Request failed", e)
}
override fun onComplete() {
// unused atm
}
})
} else if (type == "DELETE") {
ncApi.sendCommonDeleteRequest(credentials, link)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onNext(genericOverall: GenericOverall) {
}
override fun onError(e: Throwable) {
Log.e(TAG, "Request failed", e)
}
override fun onComplete() {
// unused atm
}
})
}
}
companion object {
private val TAG = SendCommonRequestUtil::class.java.simpleName
}
}