mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
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:
parent
0f3662cd82
commit
36de155c44
@ -198,6 +198,8 @@
|
||||
|
||||
<receiver android:name=".receivers.DirectReplyReceiver" />
|
||||
<receiver android:name=".receivers.MarkAsReadReceiver" />
|
||||
<receiver android:name=".receivers.DismissRecordingAvailableReceiver" />
|
||||
<receiver android:name=".receivers.ShareRecordingToChatReceiver" />
|
||||
|
||||
<service
|
||||
android:name=".utils.SyncService"
|
||||
|
@ -388,17 +388,6 @@ class MainActivity : BaseActivity(), ActionBarProvider {
|
||||
)
|
||||
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!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,6 @@ import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.callbacks.MentionAutocompleteCallback
|
||||
import com.nextcloud.talk.controllers.base.BaseController
|
||||
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.databinding.ControllerChatBinding
|
||||
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.RemapChatModel
|
||||
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.text.Spans
|
||||
import com.nextcloud.talk.webrtc.WebSocketConnectionHelper
|
||||
@ -269,7 +267,6 @@ class ChatController(args: Bundle) :
|
||||
private var lookingIntoFuture = false
|
||||
var newMessagesCount = 0
|
||||
var startCallFromNotification: Boolean? = null
|
||||
private var recordingAvailableNotification: NotificationDialogData? = null
|
||||
var startCallFromRoomSwitch: Boolean = false
|
||||
val roomId: String
|
||||
val voiceOnly: Boolean
|
||||
@ -346,10 +343,6 @@ class ChatController(args: Bundle) :
|
||||
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)) {
|
||||
startCallFromRoomSwitch = args.getBoolean(BundleKeys.KEY_SWITCH_TO_ROOM_AND_START_CALL)
|
||||
}
|
||||
@ -933,33 +926,6 @@ class ChatController(args: Bundle) :
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -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
|
@ -4,7 +4,7 @@
|
||||
* @author Andy Scherzinger
|
||||
* @author Mario Danic
|
||||
* @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) 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.Companion.sharedApplication
|
||||
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager
|
||||
import com.nextcloud.talk.data.NotificationDialogData
|
||||
import com.nextcloud.talk.models.SignatureVerification
|
||||
import com.nextcloud.talk.models.json.chat.ChatUtils.Companion.getParsedMessage
|
||||
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.NotificationUser
|
||||
import com.nextcloud.talk.receivers.DirectReplyReceiver
|
||||
import com.nextcloud.talk.receivers.DismissRecordingAvailableReceiver
|
||||
import com.nextcloud.talk.receivers.MarkAsReadReceiver
|
||||
import com.nextcloud.talk.receivers.ShareRecordingToChatReceiver
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.DoNotDisturbUtils.shouldPlaySound
|
||||
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.PushUtils
|
||||
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_INTERNAL_USER_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_RECORDING_NOTIFICATION
|
||||
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_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_USER_ENTITY
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||
@ -183,7 +185,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
if (pushMessage.notificationId != Long.MIN_VALUE) {
|
||||
getNcDataAndShowNotification(mainActivityIntent)
|
||||
} else {
|
||||
showNotification(mainActivityIntent)
|
||||
showNotification(mainActivityIntent, null)
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,8 +315,8 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
val ncNotification = notificationOverall.ocs!!.notification
|
||||
if (ncNotification != null) {
|
||||
enrichPushMessageByNcNotificationData(ncNotification)
|
||||
val newIntent = enrichIntentByNcNotificationData(intent, ncNotification)
|
||||
showNotification(newIntent)
|
||||
// val newIntent = enrichIntentByNcNotificationData(intent, ncNotification)
|
||||
showNotification(intent, ncNotification)
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,29 +336,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
): 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
|
||||
}
|
||||
|
||||
@ -417,7 +396,10 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
private fun showNotification(intent: Intent) {
|
||||
private fun showNotification(
|
||||
intent: Intent,
|
||||
ncNotification: com.nextcloud.talk.models.json.notifications.Notification?
|
||||
) {
|
||||
var category = ""
|
||||
when (pushMessage.type) {
|
||||
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!!)
|
||||
}
|
||||
|
||||
val autoCancelOnClick = TYPE_RECORDING != pushMessage.type
|
||||
|
||||
val notificationBuilder = NotificationCompat.Builder(context!!, "1")
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
.setCategory(category)
|
||||
@ -458,7 +442,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
.setWhen(pushMessage.timestamp)
|
||||
.setShowWhen(true)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setAutoCancel(true)
|
||||
.setAutoCancel(autoCancelOnClick)
|
||||
.setColor(context!!.resources.getColor(R.color.colorPrimary))
|
||||
|
||||
val notificationInfoBundle = Bundle()
|
||||
@ -511,25 +495,17 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
|
||||
TYPE_RECORDING == pushMessage.type &&
|
||||
pushMessage.notificationUser != null
|
||||
ncNotification != null
|
||||
) {
|
||||
prepareChatNotification(notificationBuilder, activeStatusBarNotification, systemNotificationId)
|
||||
// addDiscardRecordingAvailableAction(notificationBuilder, systemNotificationId)
|
||||
// addShareRecordingToChatAction(notificationBuilder, systemNotificationId)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
|
||||
TYPE_RECORDING == pushMessage.type &&
|
||||
pushMessage.notificationUser != null // null
|
||||
) {
|
||||
prepareChatNotification(notificationBuilder, activeStatusBarNotification, systemNotificationId)
|
||||
addDismissRecordingAvailableAction(notificationBuilder, systemNotificationId, ncNotification)
|
||||
addShareRecordingToChatAction(notificationBuilder, systemNotificationId, ncNotification)
|
||||
}
|
||||
sendNotification(systemNotificationId, notificationBuilder.build())
|
||||
}
|
||||
|
||||
private fun getLargeIcon(): Bitmap {
|
||||
val largeIcon: Bitmap
|
||||
if (pushMessage.type == "recording") {
|
||||
if (pushMessage.type == TYPE_RECORDING) {
|
||||
largeIcon = ContextCompat.getDrawable(context!!, R.drawable.ic_baseline_videocam_24)?.toBitmap()!!
|
||||
} else {
|
||||
when (conversationType) {
|
||||
@ -662,50 +638,82 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
notificationBuilder.addAction(replyAction)
|
||||
}
|
||||
|
||||
// @RequiresApi(api = Build.VERSION_CODES.N)
|
||||
// private fun addDiscardRecordingAvailableAction(notificationBuilder: NotificationCompat.Builder,
|
||||
// systemNotificationId:
|
||||
// Int) {
|
||||
// val replyLabel = context!!.resources.getString(R.string.nc_reply)
|
||||
// val remoteInput = RemoteInput.Builder(NotificationUtils.KEY_DIRECT_REPLY)
|
||||
// .setLabel(replyLabel)
|
||||
// .build()
|
||||
//
|
||||
// val replyPendingIntent = buildIntentForAction(
|
||||
// DirectReplyReceiver::class.java,
|
||||
// systemNotificationId,
|
||||
// 0
|
||||
// )
|
||||
// val replyAction = NotificationCompat.Action.Builder(R.drawable.ic_reply, replyLabel, replyPendingIntent)
|
||||
// .setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY)
|
||||
// .setShowsUserInterface(false)
|
||||
// .setAllowGeneratedReplies(true)
|
||||
// .addRemoteInput(remoteInput)
|
||||
// .build()
|
||||
// notificationBuilder.addAction(replyAction)
|
||||
// }
|
||||
//
|
||||
// @RequiresApi(api = Build.VERSION_CODES.N)
|
||||
// private fun addShareRecordingToChatAction(notificationBuilder: NotificationCompat.Builder, systemNotificationId:
|
||||
// Int) {
|
||||
// val replyLabel = context!!.resources.getString(R.string.nc_reply)
|
||||
// val remoteInput = RemoteInput.Builder(NotificationUtils.KEY_DIRECT_REPLY)
|
||||
// .setLabel(replyLabel)
|
||||
// .build()
|
||||
//
|
||||
// val replyPendingIntent = buildIntentForAction(
|
||||
// DirectReplyReceiver::class.java,
|
||||
// systemNotificationId,
|
||||
// 0
|
||||
// )
|
||||
// val replyAction = NotificationCompat.Action.Builder(R.drawable.ic_reply, replyLabel, replyPendingIntent)
|
||||
// .setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY)
|
||||
// .setShowsUserInterface(false)
|
||||
// .setAllowGeneratedReplies(true)
|
||||
// .addRemoteInput(remoteInput)
|
||||
// .build()
|
||||
// notificationBuilder.addAction(replyAction)
|
||||
// }
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
private fun addDismissRecordingAvailableAction(
|
||||
notificationBuilder: NotificationCompat.Builder,
|
||||
systemNotificationId: Int,
|
||||
ncNotification: com.nextcloud.talk.models.json.notifications.Notification
|
||||
) {
|
||||
var dismissLabel = ""
|
||||
var dismissRecordingUrl = ""
|
||||
|
||||
for (action in ncNotification.actions!!) {
|
||||
if (!action.primary) {
|
||||
dismissLabel = action.label.orEmpty()
|
||||
dismissRecordingUrl = action.link.orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
val dismissIntent = Intent(context, DismissRecordingAvailableReceiver::class.java)
|
||||
dismissIntent.putExtra(KEY_SYSTEM_NOTIFICATION_ID, systemNotificationId)
|
||||
dismissIntent.putExtra(KEY_DISMISS_RECORDING_URL, dismissRecordingUrl)
|
||||
|
||||
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 dismissPendingIntent = PendingIntent.getBroadcast(context, systemNotificationId, dismissIntent, intentFlag)
|
||||
|
||||
val dismissAction = NotificationCompat.Action.Builder(R.drawable.ic_delete, dismissLabel, dismissPendingIntent)
|
||||
.setShowsUserInterface(false)
|
||||
.setAllowGeneratedReplies(true)
|
||||
.build()
|
||||
notificationBuilder.addAction(dismissAction)
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
private fun addShareRecordingToChatAction(
|
||||
notificationBuilder: NotificationCompat.Builder,
|
||||
systemNotificationId: Int,
|
||||
ncNotification: com.nextcloud.talk.models.json.notifications.Notification
|
||||
) {
|
||||
var shareToChatLabel = ""
|
||||
var shareToChatUrl = ""
|
||||
|
||||
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)
|
||||
private fun getStyle(person: Person, style: NotificationCompat.MessagingStyle?): NotificationCompat.MessagingStyle {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
@ -82,6 +82,7 @@ object BundleKeys {
|
||||
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_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_DISMISS_RECORDING_URL = "KEY_DISMISS_RECORDING_URL"
|
||||
const val KEY_SHARE_RECORDING_TO_CHAT_URL = "KEY_SHARE_RECORDING_TO_CHAT_URL"
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user