2022-02-01 21:22:06 +05:30
|
|
|
package com.github.libretube
|
2021-12-14 21:45:53 +05:30
|
|
|
|
|
|
|
import android.app.Application
|
2022-09-17 15:57:24 +05:30
|
|
|
import androidx.core.app.NotificationChannelCompat
|
|
|
|
import androidx.core.app.NotificationManagerCompat
|
2022-07-30 14:38:28 +05:30
|
|
|
import androidx.work.ExistingPeriodicWorkPolicy
|
2023-01-31 21:13:39 +05:30
|
|
|
import com.github.libretube.helpers.ImageHelper
|
|
|
|
import com.github.libretube.helpers.NotificationHelper
|
|
|
|
import com.github.libretube.helpers.PreferenceHelper
|
|
|
|
import com.github.libretube.helpers.ProxyHelper
|
|
|
|
import com.github.libretube.helpers.ShortcutHelper
|
2023-01-31 22:27:24 +05:30
|
|
|
import com.github.libretube.util.ExceptionHandler
|
2021-12-14 21:45:53 +05:30
|
|
|
|
2022-09-17 15:57:24 +05:30
|
|
|
class LibreTubeApp : Application() {
|
2022-05-20 17:50:26 +05:30
|
|
|
override fun onCreate() {
|
|
|
|
super.onCreate()
|
2023-01-31 21:16:36 +05:30
|
|
|
instance = this
|
2022-05-20 17:50:26 +05:30
|
|
|
|
2022-07-17 20:49:55 +05:30
|
|
|
/**
|
2022-09-17 15:57:24 +05:30
|
|
|
* Initialize the needed notification channels for DownloadService and BackgroundMode
|
2022-07-17 20:49:55 +05:30
|
|
|
*/
|
2022-05-20 17:50:26 +05:30
|
|
|
initializeNotificationChannels()
|
2022-07-17 20:49:55 +05:30
|
|
|
|
|
|
|
/**
|
2022-08-15 13:11:30 +05:30
|
|
|
* Initialize the [PreferenceHelper]
|
2022-07-17 20:49:55 +05:30
|
|
|
*/
|
2022-08-26 12:12:13 +05:30
|
|
|
PreferenceHelper.initialize(applicationContext)
|
2022-07-18 22:45:35 +05:30
|
|
|
|
2022-07-28 18:15:29 +05:30
|
|
|
/**
|
2022-08-13 23:34:07 +05:30
|
|
|
* Set the api and the auth api url
|
2022-07-28 18:15:29 +05:30
|
|
|
*/
|
2022-09-08 22:59:35 +05:30
|
|
|
ImageHelper.initializeImageLoader(this)
|
2022-07-28 18:15:29 +05:30
|
|
|
|
2022-07-28 16:09:56 +05:30
|
|
|
/**
|
2022-08-13 23:34:07 +05:30
|
|
|
* Initialize the notification listener in the background
|
2022-07-28 16:09:56 +05:30
|
|
|
*/
|
2022-11-06 14:51:37 +05:30
|
|
|
NotificationHelper.enqueueWork(
|
|
|
|
context = this,
|
2023-06-24 23:27:00 +05:30
|
|
|
existingPeriodicWorkPolicy = ExistingPeriodicWorkPolicy.KEEP
|
2022-08-26 02:06:07 +05:30
|
|
|
)
|
|
|
|
|
2022-11-21 18:42:46 +05:30
|
|
|
/**
|
|
|
|
* Fetch the image proxy URL for local playlists and the watch history
|
|
|
|
*/
|
|
|
|
ProxyHelper.fetchProxyUrl()
|
|
|
|
|
2022-08-01 14:52:08 +05:30
|
|
|
/**
|
|
|
|
* Handler for uncaught exceptions
|
|
|
|
*/
|
2022-08-02 16:35:27 +05:30
|
|
|
val defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
|
|
|
|
val exceptionHandler = ExceptionHandler(defaultExceptionHandler)
|
2022-08-01 14:52:08 +05:30
|
|
|
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler)
|
2023-01-17 23:35:22 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* Dynamically create App Shortcuts
|
|
|
|
*/
|
|
|
|
ShortcutHelper.createShortcuts(this)
|
2022-05-20 17:50:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-17 15:57:24 +05:30
|
|
|
* Initializes the required notification channels for the app.
|
2022-05-20 17:50:26 +05:30
|
|
|
*/
|
|
|
|
private fun initializeNotificationChannels() {
|
2022-09-18 14:14:37 +05:30
|
|
|
val downloadChannel = NotificationChannelCompat.Builder(
|
2024-01-22 00:26:07 +05:30
|
|
|
PLAYLIST_DOWNLOAD_ENQUEUE_CHANNEL_NAME,
|
|
|
|
NotificationManagerCompat.IMPORTANCE_LOW
|
|
|
|
)
|
|
|
|
.setName(getString(R.string.download_playlist))
|
|
|
|
.setDescription(getString(R.string.enqueue_playlist_description))
|
|
|
|
.build()
|
|
|
|
val playlistDownloadEnqueueChannel = NotificationChannelCompat.Builder(
|
2023-09-10 16:21:03 +05:30
|
|
|
DOWNLOAD_CHANNEL_NAME,
|
2023-06-24 23:27:00 +05:30
|
|
|
NotificationManagerCompat.IMPORTANCE_LOW
|
2022-09-18 14:14:37 +05:30
|
|
|
)
|
2022-09-17 15:57:24 +05:30
|
|
|
.setName(getString(R.string.download_channel_name))
|
|
|
|
.setDescription(getString(R.string.download_channel_description))
|
|
|
|
.build()
|
2023-08-10 02:26:57 +05:30
|
|
|
val playerChannel = NotificationChannelCompat.Builder(
|
2023-09-10 16:21:03 +05:30
|
|
|
PLAYER_CHANNEL_NAME,
|
2023-06-24 23:27:00 +05:30
|
|
|
NotificationManagerCompat.IMPORTANCE_LOW
|
2022-09-18 14:14:37 +05:30
|
|
|
)
|
2023-08-10 02:26:57 +05:30
|
|
|
.setName(getString(R.string.player_channel_name))
|
|
|
|
.setDescription(getString(R.string.player_channel_description))
|
2022-09-17 15:57:24 +05:30
|
|
|
.build()
|
2022-09-18 14:14:37 +05:30
|
|
|
val pushChannel = NotificationChannelCompat.Builder(
|
2023-09-10 16:21:03 +05:30
|
|
|
PUSH_CHANNEL_NAME,
|
2023-06-24 23:27:00 +05:30
|
|
|
NotificationManagerCompat.IMPORTANCE_DEFAULT
|
2022-09-18 14:14:37 +05:30
|
|
|
)
|
2022-09-17 15:57:24 +05:30
|
|
|
.setName(getString(R.string.push_channel_name))
|
|
|
|
.setDescription(getString(R.string.push_channel_description))
|
|
|
|
.build()
|
2022-05-20 17:50:26 +05:30
|
|
|
|
2022-09-17 15:57:24 +05:30
|
|
|
val notificationManager = NotificationManagerCompat.from(this)
|
2022-09-18 14:14:37 +05:30
|
|
|
notificationManager.createNotificationChannelsCompat(
|
|
|
|
listOf(
|
|
|
|
downloadChannel,
|
2024-01-22 00:26:07 +05:30
|
|
|
playlistDownloadEnqueueChannel,
|
2023-08-10 02:26:57 +05:30
|
|
|
pushChannel,
|
|
|
|
playerChannel
|
2023-06-24 23:27:00 +05:30
|
|
|
)
|
2022-09-18 14:14:37 +05:30
|
|
|
)
|
2022-05-20 17:50:26 +05:30
|
|
|
}
|
2023-01-31 21:16:36 +05:30
|
|
|
|
|
|
|
companion object {
|
|
|
|
lateinit var instance: LibreTubeApp
|
2023-09-10 16:21:03 +05:30
|
|
|
|
|
|
|
const val DOWNLOAD_CHANNEL_NAME = "download_service"
|
2024-01-22 00:26:07 +05:30
|
|
|
const val PLAYLIST_DOWNLOAD_ENQUEUE_CHANNEL_NAME = "playlist_download_enqueue"
|
2023-09-10 16:21:03 +05:30
|
|
|
const val PLAYER_CHANNEL_NAME = "player_mode"
|
|
|
|
const val PUSH_CHANNEL_NAME = "notification_worker"
|
2023-01-31 21:16:36 +05:30
|
|
|
}
|
2022-05-20 17:50:26 +05:30
|
|
|
}
|