Skip to content

Commit 6d0f279

Browse files
authored
Update VideoDownloadManager.kt
1 parent 8ea74d6 commit 6d0f279

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -216,28 +216,22 @@ object VideoDownloadManager {
216216
service.startForeground(1, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
217217
}
218218

219-
private fun createNotificationChannel(context: Context) {
220-
if (SDK_INT >= Build.VERSION_CODES.O) {
221-
val channel = NotificationChannel(
222-
DOWNLOAD_CHANNEL_ID,
223-
DOWNLOAD_CHANNEL_NAME,
224-
NotificationManager.IMPORTANCE_DEFAULT
225-
).apply {
226-
description = DOWNLOAD_CHANNEL_DESCRIPT
219+
private fun Context.createNotificationChannel() {
220+
hasCreatedNotChanel = true
221+
// Create the NotificationChannel, but only on API 26+ because
222+
// the NotificationChannel class is new and not in the support library
223+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
224+
val name = DOWNLOAD_CHANNEL_NAME //getString(R.string.channel_name)
225+
val descriptionText = DOWNLOAD_CHANNEL_DESCRIPT//getString(R.string.channel_description)
226+
val importance = NotificationManager.IMPORTANCE_DEFAULT
227+
val channel = NotificationChannel(DOWNLOAD_CHANNEL_ID, name, importance).apply {
228+
description = descriptionText
227229
}
228-
val notificationManager = context.getSystemService(NotificationManager::class.java)
230+
// Register the channel with the system
231+
val notificationManager: NotificationManager =
232+
this.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
229233
notificationManager.createNotificationChannel(channel)
230234
}
231-
hasCreatedNotChanel = true
232-
}
233-
234-
private fun createNotification(context: Context): Notification {
235-
val builder = NotificationCompat.Builder(context, DOWNLOAD_CHANNEL_ID)
236-
.setContentTitle("Downloading Video")
237-
.setContentText("Your video is downloading in the background.")
238-
239-
// Add actions (e.g., Resume, Pause, Stop) if needed
240-
return builder.build()
241235
}
242236

243237
///** Will return IsDone if not found or error */
@@ -503,7 +497,7 @@ object VideoDownloadManager {
503497
}
504498

505499
if (!hasCreatedNotChanel) {
506-
createNotificationChannel(context)
500+
context.createNotificationChannel()
507501
}
508502

509503
val notification = builder.build()
@@ -2038,4 +2032,4 @@ object VideoDownloadManager {
20382032
@JsonProperty("ep") val ep: DownloadEpisodeMetadata,
20392033
@JsonProperty("links") val links: List<ExtractorLink>
20402034
)
2041-
}
2035+
}

0 commit comments

Comments
 (0)