Skip to content

Commit c33fce0

Browse files
alperozturk96tobiasKaminsky
authored andcommitted
make media folder detection worker silent
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent a7c8600 commit c33fce0

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

app/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import android.content.Context
2121
import android.content.Intent
2222
import android.content.res.Resources
2323
import android.graphics.BitmapFactory
24-
import android.media.RingtoneManager
2524
import android.text.TextUtils
2625
import androidx.core.app.NotificationCompat
2726
import androidx.work.Worker
@@ -49,7 +48,7 @@ import com.owncloud.android.utils.theme.ViewThemeUtils
4948
import java.util.Random
5049

5150
@Suppress("LongParameterList") // dependencies injection
52-
class MediaFoldersDetectionWork constructor(
51+
class MediaFoldersDetectionWork(
5352
private val context: Context,
5453
params: WorkerParameters,
5554
private val resources: Resources,
@@ -195,13 +194,15 @@ class MediaFoldersDetectionWork constructor(
195194
@Suppress("LongMethod")
196195
private fun sendNotification(contentTitle: String, subtitle: String, user: User, path: String, type: Int) {
197196
val notificationId = randomIdGenerator.nextInt()
198-
val context = context
199-
val intent = Intent(context, SyncedFoldersActivity::class.java)
200-
intent.putExtra(NOTIFICATION_ID, notificationId)
201-
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
202-
intent.putExtra(NotificationWork.KEY_NOTIFICATION_ACCOUNT, user.accountName)
203-
intent.putExtra(KEY_MEDIA_FOLDER_PATH, path)
204-
intent.putExtra(KEY_MEDIA_FOLDER_TYPE, type)
197+
198+
val intent = Intent(context, SyncedFoldersActivity::class.java).apply {
199+
putExtra(NOTIFICATION_ID, notificationId)
200+
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
201+
putExtra(NotificationWork.KEY_NOTIFICATION_ACCOUNT, user.accountName)
202+
putExtra(KEY_MEDIA_FOLDER_PATH, path)
203+
putExtra(KEY_MEDIA_FOLDER_TYPE, type)
204+
}
205+
205206
val pendingIntent = PendingIntent.getActivity(
206207
context,
207208
0,
@@ -217,41 +218,50 @@ class MediaFoldersDetectionWork constructor(
217218
.setSubText(user.accountName)
218219
.setContentTitle(contentTitle)
219220
.setContentText(subtitle)
220-
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
221221
.setAutoCancel(true)
222+
.setSound(null)
223+
.setVibrate(null)
224+
.setOnlyAlertOnce(true)
225+
.setSilent(true)
222226
.setContentIntent(pendingIntent)
223227

224228
viewThemeUtils.androidx.themeNotificationCompatBuilder(context, notificationBuilder)
225229

226-
val disableDetection = Intent(context, NotificationReceiver::class.java)
227-
disableDetection.putExtra(NOTIFICATION_ID, notificationId)
228-
disableDetection.action = DISABLE_DETECTION_CLICK
230+
val disableDetection = Intent(context, NotificationReceiver::class.java).apply {
231+
putExtra(NOTIFICATION_ID, notificationId)
232+
action = DISABLE_DETECTION_CLICK
233+
}
234+
229235
val disableIntent = PendingIntent.getBroadcast(
230236
context,
231237
notificationId,
232238
disableDetection,
233239
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
234240
)
241+
235242
notificationBuilder.addAction(
236243
NotificationCompat.Action(
237244
R.drawable.ic_close,
238245
context.getString(R.string.disable_new_media_folder_detection_notifications),
239246
disableIntent
240247
)
241248
)
249+
242250
val configureIntent = PendingIntent.getActivity(
243251
context,
244252
notificationId,
245253
intent,
246254
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
247255
)
256+
248257
notificationBuilder.addAction(
249258
NotificationCompat.Action(
250259
R.drawable.ic_settings,
251260
context.getString(R.string.configure_new_media_folder_detection_notifications),
252261
configureIntent
253262
)
254263
)
264+
255265
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
256266
notificationManager.notify(notificationId, notificationBuilder.build())
257267
}

0 commit comments

Comments
 (0)