mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
cleanup notifcation channels
This commit is contained in:
parent
41cf1c782d
commit
357978f09e
@ -32,3 +32,19 @@ const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com"
|
|||||||
* Retrofit Instance
|
* Retrofit Instance
|
||||||
*/
|
*/
|
||||||
const val PIPED_API_URL = "https://pipedapi.kavin.rocks/"
|
const val PIPED_API_URL = "https://pipedapi.kavin.rocks/"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notification IDs
|
||||||
|
*/
|
||||||
|
const val PLAYER_NOTIFICATION_ID = 0
|
||||||
|
const val PUSH_NOTIFICATION_ID = 1
|
||||||
|
const val DOWNLOAD_PENDING_NOTIFICATION_ID = 2
|
||||||
|
const val DOWNLOAD_FAILURE_NOTIFICATION_ID = 3
|
||||||
|
const val DOWNLOAD_SUCCESS_NOTIFICATION_ID = 4
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notification Channel IDs
|
||||||
|
*/
|
||||||
|
const val DOWNLOAD_CHANNEL_ID = "download_service"
|
||||||
|
const val BACKGROUND_CHANNEL_ID = "background_mode"
|
||||||
|
const val PUSH_CHANNEL_ID = "notification_worker"
|
||||||
|
@ -66,19 +66,19 @@ class MyApp : Application() {
|
|||||||
*/
|
*/
|
||||||
private fun initializeNotificationChannels() {
|
private fun initializeNotificationChannels() {
|
||||||
createNotificationChannel(
|
createNotificationChannel(
|
||||||
"download_service",
|
DOWNLOAD_CHANNEL_ID,
|
||||||
"Download Service",
|
"Download Service",
|
||||||
"Shows a notification when downloading media.",
|
"Shows a notification when downloading media.",
|
||||||
NotificationManager.IMPORTANCE_NONE
|
NotificationManager.IMPORTANCE_NONE
|
||||||
)
|
)
|
||||||
createNotificationChannel(
|
createNotificationChannel(
|
||||||
"background_mode",
|
BACKGROUND_CHANNEL_ID,
|
||||||
"Background Mode",
|
"Background Mode",
|
||||||
"Shows a notification with buttons to control the audio player",
|
"Shows a notification with buttons to control the audio player",
|
||||||
NotificationManager.IMPORTANCE_LOW
|
NotificationManager.IMPORTANCE_LOW
|
||||||
)
|
)
|
||||||
createNotificationChannel(
|
createNotificationChannel(
|
||||||
"notification_worker",
|
PUSH_CHANNEL_ID,
|
||||||
"Notification Worker",
|
"Notification Worker",
|
||||||
"Shows a notification when new streams are available.",
|
"Shows a notification when new streams are available.",
|
||||||
NotificationManager.IMPORTANCE_DEFAULT
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
|
@ -34,7 +34,9 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.github.libretube.BACKGROUND_CHANNEL_ID
|
||||||
import com.github.libretube.Globals
|
import com.github.libretube.Globals
|
||||||
|
import com.github.libretube.PLAYER_NOTIFICATION_ID
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.activities.MainActivity
|
import com.github.libretube.activities.MainActivity
|
||||||
import com.github.libretube.adapters.ChaptersAdapter
|
import com.github.libretube.adapters.ChaptersAdapter
|
||||||
@ -1518,7 +1520,7 @@ class PlayerFragment : Fragment() {
|
|||||||
mediaSessionConnector.setPlayer(exoPlayer)
|
mediaSessionConnector.setPlayer(exoPlayer)
|
||||||
|
|
||||||
playerNotification = PlayerNotificationManager
|
playerNotification = PlayerNotificationManager
|
||||||
.Builder(c, 1, "background_mode")
|
.Builder(c, PLAYER_NOTIFICATION_ID, BACKGROUND_CHANNEL_ID)
|
||||||
.setMediaDescriptionAdapter(
|
.setMediaDescriptionAdapter(
|
||||||
DescriptionAdapter(title, uploader, thumbnailUrl, requireContext())
|
DescriptionAdapter(title, uploader, thumbnailUrl, requireContext())
|
||||||
)
|
)
|
||||||
|
@ -9,6 +9,8 @@ import android.content.Intent
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.support.v4.media.session.MediaSessionCompat
|
import android.support.v4.media.session.MediaSessionCompat
|
||||||
|
import com.github.libretube.BACKGROUND_CHANNEL_ID
|
||||||
|
import com.github.libretube.PLAYER_NOTIFICATION_ID
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.Streams
|
import com.github.libretube.obj.Streams
|
||||||
import com.github.libretube.preferences.PreferenceHelper
|
import com.github.libretube.preferences.PreferenceHelper
|
||||||
@ -182,7 +184,7 @@ class BackgroundMode : Service() {
|
|||||||
*/
|
*/
|
||||||
private fun initializePlayerNotification() {
|
private fun initializePlayerNotification() {
|
||||||
playerNotification = PlayerNotificationManager
|
playerNotification = PlayerNotificationManager
|
||||||
.Builder(this, 1, "background_mode")
|
.Builder(this, PLAYER_NOTIFICATION_ID, BACKGROUND_CHANNEL_ID)
|
||||||
// set the description of the notification
|
// set the description of the notification
|
||||||
.setMediaDescriptionAdapter(
|
.setMediaDescriptionAdapter(
|
||||||
DescriptionAdapter(
|
DescriptionAdapter(
|
||||||
|
@ -18,6 +18,10 @@ import android.util.Log
|
|||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import com.arthenica.ffmpegkit.FFmpegKit
|
import com.arthenica.ffmpegkit.FFmpegKit
|
||||||
|
import com.github.libretube.DOWNLOAD_CHANNEL_ID
|
||||||
|
import com.github.libretube.DOWNLOAD_FAILURE_NOTIFICATION_ID
|
||||||
|
import com.github.libretube.DOWNLOAD_PENDING_NOTIFICATION_ID
|
||||||
|
import com.github.libretube.DOWNLOAD_SUCCESS_NOTIFICATION_ID
|
||||||
import com.github.libretube.Globals
|
import com.github.libretube.Globals
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.DownloadType
|
import com.github.libretube.obj.DownloadType
|
||||||
@ -199,7 +203,7 @@ class DownloadService : Service() {
|
|||||||
}
|
}
|
||||||
// Creating a notification and setting its various attributes
|
// Creating a notification and setting its various attributes
|
||||||
notification =
|
notification =
|
||||||
NotificationCompat.Builder(this@DownloadService, "download_service")
|
NotificationCompat.Builder(this@DownloadService, DOWNLOAD_CHANNEL_ID)
|
||||||
.setSmallIcon(R.drawable.ic_download)
|
.setSmallIcon(R.drawable.ic_download)
|
||||||
.setContentTitle("LibreTube")
|
.setContentTitle("LibreTube")
|
||||||
.setContentText(getString(R.string.downloading))
|
.setContentText(getString(R.string.downloading))
|
||||||
@ -209,31 +213,31 @@ class DownloadService : Service() {
|
|||||||
.setProgress(100, 0, true)
|
.setProgress(100, 0, true)
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
startForeground(2, notification.build())
|
startForeground(DOWNLOAD_PENDING_NOTIFICATION_ID, notification.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun downloadFailedNotification() {
|
private fun downloadFailedNotification() {
|
||||||
val builder = NotificationCompat.Builder(this@DownloadService, "download_service")
|
val builder = NotificationCompat.Builder(this@DownloadService, DOWNLOAD_CHANNEL_ID)
|
||||||
.setSmallIcon(R.drawable.ic_download)
|
.setSmallIcon(R.drawable.ic_download)
|
||||||
.setContentTitle(resources.getString(R.string.downloadfailed))
|
.setContentTitle(resources.getString(R.string.downloadfailed))
|
||||||
.setContentText(getString(R.string.fail))
|
.setContentText(getString(R.string.fail))
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
with(NotificationManagerCompat.from(this@DownloadService)) {
|
with(NotificationManagerCompat.from(this@DownloadService)) {
|
||||||
// notificationId is a unique int for each notification that you must define
|
// notificationId is a unique int for each notification that you must define
|
||||||
notify(3, builder.build())
|
notify(DOWNLOAD_FAILURE_NOTIFICATION_ID, builder.build())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun downloadSucceededNotification() {
|
private fun downloadSucceededNotification() {
|
||||||
Log.i(TAG, "Download succeeded")
|
Log.i(TAG, "Download succeeded")
|
||||||
val builder = NotificationCompat.Builder(this@DownloadService, "download_service")
|
val builder = NotificationCompat.Builder(this@DownloadService, DOWNLOAD_CHANNEL_ID)
|
||||||
.setSmallIcon(R.drawable.ic_download)
|
.setSmallIcon(R.drawable.ic_download)
|
||||||
.setContentTitle(resources.getString(R.string.success))
|
.setContentTitle(resources.getString(R.string.success))
|
||||||
.setContentText(getString(R.string.fail))
|
.setContentText(getString(R.string.fail))
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
with(NotificationManagerCompat.from(this@DownloadService)) {
|
with(NotificationManagerCompat.from(this@DownloadService)) {
|
||||||
// notificationId is a unique int for each notification that you must define
|
// notificationId is a unique int for each notification that you must define
|
||||||
notify(4, builder.build())
|
notify(DOWNLOAD_SUCCESS_NOTIFICATION_ID, builder.build())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,12 +271,6 @@ class DownloadService : Service() {
|
|||||||
) {
|
) {
|
||||||
// CALLED WHEN SESSION GENERATES STATISTICS
|
// CALLED WHEN SESSION GENERATES STATISTICS
|
||||||
Log.e(TAG + "stat", it.time.toString())
|
Log.e(TAG + "stat", it.time.toString())
|
||||||
/*val progress = it.time/(10*duration!!)
|
|
||||||
if (progress<1){
|
|
||||||
notification
|
|
||||||
.setProgress(progressMax, progress.toInt(), false)
|
|
||||||
service.notify(1,notification.build())
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ import androidx.work.ExistingPeriodicWorkPolicy
|
|||||||
import androidx.work.NetworkType
|
import androidx.work.NetworkType
|
||||||
import androidx.work.PeriodicWorkRequest
|
import androidx.work.PeriodicWorkRequest
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
|
import com.github.libretube.PUSH_CHANNEL_ID
|
||||||
|
import com.github.libretube.PUSH_NOTIFICATION_ID
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.activities.MainActivity
|
import com.github.libretube.activities.MainActivity
|
||||||
import com.github.libretube.preferences.PreferenceHelper
|
import com.github.libretube.preferences.PreferenceHelper
|
||||||
@ -137,9 +139,14 @@ object NotificationHelper {
|
|||||||
val intent = Intent(context, MainActivity::class.java).apply {
|
val intent = Intent(context, MainActivity::class.java).apply {
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
}
|
}
|
||||||
val pendingIntent: PendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
|
val pendingIntent: PendingIntent = PendingIntent.getActivity(
|
||||||
|
context,
|
||||||
|
0,
|
||||||
|
intent,
|
||||||
|
PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
|
||||||
val builder = NotificationCompat.Builder(context, "notification_worker")
|
val builder = NotificationCompat.Builder(context, PUSH_CHANNEL_ID)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setSmallIcon(R.drawable.ic_bell)
|
.setSmallIcon(R.drawable.ic_bell)
|
||||||
.setContentText(description)
|
.setContentText(description)
|
||||||
@ -149,7 +156,7 @@ object NotificationHelper {
|
|||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
with(NotificationManagerCompat.from(context)) {
|
with(NotificationManagerCompat.from(context)) {
|
||||||
// notificationId is a unique int for each notification that you must define
|
// notificationId is a unique int for each notification that you must define
|
||||||
notify(2, builder.build())
|
notify(PUSH_NOTIFICATION_ID, builder.build())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user