diff --git a/app/src/main/java/com/github/libretube/LibreTubeApp.kt b/app/src/main/java/com/github/libretube/LibreTubeApp.kt index 08cb2046b..b8e04d82a 100644 --- a/app/src/main/java/com/github/libretube/LibreTubeApp.kt +++ b/app/src/main/java/com/github/libretube/LibreTubeApp.kt @@ -4,9 +4,6 @@ import android.app.Application import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationManagerCompat import androidx.work.ExistingPeriodicWorkPolicy -import com.github.libretube.constants.DOWNLOAD_CHANNEL_ID -import com.github.libretube.constants.PLAYER_CHANNEL_ID -import com.github.libretube.constants.PUSH_CHANNEL_ID import com.github.libretube.helpers.ImageHelper import com.github.libretube.helpers.NotificationHelper import com.github.libretube.helpers.PreferenceHelper @@ -65,21 +62,21 @@ class LibreTubeApp : Application() { */ private fun initializeNotificationChannels() { val downloadChannel = NotificationChannelCompat.Builder( - DOWNLOAD_CHANNEL_ID, + DOWNLOAD_CHANNEL_NAME, NotificationManagerCompat.IMPORTANCE_LOW ) .setName(getString(R.string.download_channel_name)) .setDescription(getString(R.string.download_channel_description)) .build() val playerChannel = NotificationChannelCompat.Builder( - PLAYER_CHANNEL_ID, + PLAYER_CHANNEL_NAME, NotificationManagerCompat.IMPORTANCE_LOW ) .setName(getString(R.string.player_channel_name)) .setDescription(getString(R.string.player_channel_description)) .build() val pushChannel = NotificationChannelCompat.Builder( - PUSH_CHANNEL_ID, + PUSH_CHANNEL_NAME, NotificationManagerCompat.IMPORTANCE_DEFAULT ) .setName(getString(R.string.push_channel_name)) @@ -98,5 +95,9 @@ class LibreTubeApp : Application() { companion object { lateinit var instance: LibreTubeApp + + const val DOWNLOAD_CHANNEL_NAME = "download_service" + const val PLAYER_CHANNEL_NAME = "player_mode" + const val PUSH_CHANNEL_NAME = "notification_worker" } } diff --git a/app/src/main/java/com/github/libretube/api/ExternalApi.kt b/app/src/main/java/com/github/libretube/api/ExternalApi.kt index 89fbcba6a..42d837fa2 100644 --- a/app/src/main/java/com/github/libretube/api/ExternalApi.kt +++ b/app/src/main/java/com/github/libretube/api/ExternalApi.kt @@ -2,14 +2,15 @@ package com.github.libretube.api import com.github.libretube.api.obj.Instances import com.github.libretube.api.obj.SubmitSegmentResponse -import com.github.libretube.constants.GITHUB_API_URL -import com.github.libretube.constants.SB_SUBMIT_API_URL import com.github.libretube.obj.update.UpdateInfo import retrofit2.http.GET import retrofit2.http.POST import retrofit2.http.Query import retrofit2.http.Url +private const val GITHUB_API_URL = "https://api.github.com/repos/libre-tube/LibreTube/releases/latest" +private const val SB_SUBMIT_API_URL = "https://sponsor.ajay.app/api/skipSegments" + interface ExternalApi { // only for fetching servers list @GET diff --git a/app/src/main/java/com/github/libretube/api/InstanceHelper.kt b/app/src/main/java/com/github/libretube/api/InstanceHelper.kt index 20863b49c..d481d4c39 100644 --- a/app/src/main/java/com/github/libretube/api/InstanceHelper.kt +++ b/app/src/main/java/com/github/libretube/api/InstanceHelper.kt @@ -3,12 +3,13 @@ package com.github.libretube.api import android.content.Context import com.github.libretube.R import com.github.libretube.api.obj.Instances -import com.github.libretube.constants.FALLBACK_INSTANCES_URL -import com.github.libretube.constants.PIPED_INSTANCES_URL import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext object InstanceHelper { + private const val PIPED_INSTANCES_URL = "https://piped-instances.kavin.rocks" + private const val FALLBACK_INSTANCES_URL = "https://instances.tokhmi.xyz" + /** * fetch official public instances from kavin.rocks as well as tokhmi.xyz as fallback */ diff --git a/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt b/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt index fe94eb1a3..a146a7a0f 100644 --- a/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt +++ b/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt @@ -7,7 +7,6 @@ import com.github.libretube.api.obj.Playlist import com.github.libretube.api.obj.Playlists import com.github.libretube.api.obj.StreamItem import com.github.libretube.constants.PreferenceKeys -import com.github.libretube.constants.YOUTUBE_FRONTEND_URL import com.github.libretube.db.DatabaseHolder import com.github.libretube.db.obj.LocalPlaylist import com.github.libretube.enums.PlaylistType @@ -18,6 +17,7 @@ import com.github.libretube.helpers.ProxyHelper import com.github.libretube.obj.FreeTubeImportPlaylist import com.github.libretube.obj.FreeTubeVideo import com.github.libretube.obj.PipedImportPlaylist +import com.github.libretube.ui.dialogs.ShareDialog.Companion.YOUTUBE_FRONTEND_URL import com.github.libretube.util.deArrow import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async diff --git a/app/src/main/java/com/github/libretube/api/RetrofitInstance.kt b/app/src/main/java/com/github/libretube/api/RetrofitInstance.kt index 12bec7bde..07d2dc5b1 100644 --- a/app/src/main/java/com/github/libretube/api/RetrofitInstance.kt +++ b/app/src/main/java/com/github/libretube/api/RetrofitInstance.kt @@ -1,6 +1,5 @@ package com.github.libretube.api -import com.github.libretube.constants.PIPED_API_URL import com.github.libretube.constants.PreferenceKeys import com.github.libretube.helpers.PreferenceHelper import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory @@ -9,6 +8,7 @@ import retrofit2.Retrofit import retrofit2.create object RetrofitInstance { + private const val PIPED_API_URL = "https://pipedapi.kavin.rocks" private val url get() = PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, PIPED_API_URL) private val authUrl get() = when ( diff --git a/app/src/main/java/com/github/libretube/constants/Constants.kt b/app/src/main/java/com/github/libretube/constants/Constants.kt deleted file mode 100644 index 36e6271b4..000000000 --- a/app/src/main/java/com/github/libretube/constants/Constants.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.github.libretube.constants - -/** - * API link for the update checker - */ -const val GITHUB_API_URL = "https://api.github.com/repos/libre-tube/LibreTube/releases/latest" -const val SB_SUBMIT_API_URL = "https://sponsor.ajay.app/api/skipSegments" - -/** - * Links for the about fragment - */ -const val WEBSITE_URL = "https://libre-tube.github.io/" -const val GITHUB_URL = "https://github.com/libre-tube/LibreTube" -const val PIPED_GITHUB_URL = "https://github.com/TeamPiped/Piped" -const val WEBLATE_URL = "https://hosted.weblate.org/projects/libretube/libretube/" -const val LICENSE_URL = "https://gnu.org/" -const val FAQ_URL = "https://libre-tube.github.io/#faq" - -/** - * Social media links for the help activity - */ -const val MATRIX_URL = "https://matrix.to/#/#LibreTube:matrix.org" -const val MASTODON_URL = "https://fosstodon.org/@libretube" -const val LEMMY_URL = "https://feddit.rocks/c/libretube" - -/** - * Share Dialog - */ -const val PIPED_FRONTEND_URL = "https://piped.video" -const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com" - -/** - * Retrofit Instance - */ -const val PIPED_API_URL = "https://pipedapi.kavin.rocks" -const val PIPED_INSTANCES_URL = "https://piped-instances.kavin.rocks" -const val FALLBACK_INSTANCES_URL = "https://instances.tokhmi.xyz" - -/** - * Notification IDs - */ -const val PLAYER_NOTIFICATION_ID = 1 -const val DOWNLOAD_PROGRESS_NOTIFICATION_ID = 2 - -/** - * Notification Channel IDs - */ -const val DOWNLOAD_CHANNEL_ID = "download_service" -const val PLAYER_CHANNEL_ID = "player_mode" -const val PUSH_CHANNEL_ID = "notification_worker" - -/** - * Database - */ -const val DATABASE_NAME = "LibreTubeDatabase" - -/** - * New Streams notifications - */ -const val NOTIFICATION_WORK_NAME = "NotificationService" diff --git a/app/src/main/java/com/github/libretube/db/DatabaseHolder.kt b/app/src/main/java/com/github/libretube/db/DatabaseHolder.kt index b931cfeb3..7253b82e6 100644 --- a/app/src/main/java/com/github/libretube/db/DatabaseHolder.kt +++ b/app/src/main/java/com/github/libretube/db/DatabaseHolder.kt @@ -4,9 +4,10 @@ import androidx.room.Room import androidx.room.migration.Migration import androidx.sqlite.db.SupportSQLiteDatabase import com.github.libretube.LibreTubeApp -import com.github.libretube.constants.DATABASE_NAME object DatabaseHolder { + private const val DATABASE_NAME = "LibreTubeDatabase" + private val MIGRATION_11_12 = object : Migration(11, 12) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL( diff --git a/app/src/main/java/com/github/libretube/helpers/NotificationHelper.kt b/app/src/main/java/com/github/libretube/helpers/NotificationHelper.kt index a5c3d861e..e262e21d8 100644 --- a/app/src/main/java/com/github/libretube/helpers/NotificationHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NotificationHelper.kt @@ -6,12 +6,13 @@ import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.NetworkType import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager -import com.github.libretube.constants.NOTIFICATION_WORK_NAME import com.github.libretube.constants.PreferenceKeys import com.github.libretube.workers.NotificationWorker import java.util.concurrent.TimeUnit object NotificationHelper { + private const val NOTIFICATION_WORK_NAME = "NotificationService" + /** * Enqueue the work manager task */ diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index d47c5c773..2caeee182 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -16,11 +16,10 @@ import androidx.core.util.set import androidx.core.util.valueIterator import androidx.lifecycle.LifecycleService import androidx.lifecycle.lifecycleScope +import com.github.libretube.LibreTubeApp.Companion.DOWNLOAD_CHANNEL_NAME import com.github.libretube.R import com.github.libretube.api.CronetHelper import com.github.libretube.api.RetrofitInstance -import com.github.libretube.constants.DOWNLOAD_CHANNEL_ID -import com.github.libretube.constants.DOWNLOAD_PROGRESS_NOTIFICATION_ID import com.github.libretube.constants.IntentData import com.github.libretube.db.DatabaseHolder.Database import com.github.libretube.db.obj.Download @@ -390,7 +389,7 @@ class DownloadService : LifecycleService() { notificationManager = getSystemService()!! summaryNotificationBuilder = NotificationCompat - .Builder(this, DOWNLOAD_CHANNEL_ID) + .Builder(this, DOWNLOAD_CHANNEL_NAME) .setSmallIcon(R.drawable.ic_launcher_lockscreen) .setContentTitle(getString(R.string.downloading)) .setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE) @@ -409,7 +408,7 @@ class DownloadService : LifecycleService() { .getActivity(this@DownloadService, 0, intent, FLAG_CANCEL_CURRENT, false) return NotificationCompat - .Builder(this, DOWNLOAD_CHANNEL_ID) + .Builder(this, DOWNLOAD_CHANNEL_NAME) .setContentTitle("[${item.type}] ${item.fileName}") .setProgress(0, 0, true) .setOngoing(true) @@ -522,6 +521,7 @@ class DownloadService : LifecycleService() { } companion object { + private const val DOWNLOAD_PROGRESS_NOTIFICATION_ID = 2 private const val DOWNLOAD_NOTIFICATION_GROUP = "download_notification_group" const val ACTION_SERVICE_STARTED = "com.github.libretube.services.DownloadService.ACTION_SERVICE_STARTED" diff --git a/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt index 17fcb390e..b1676de31 100644 --- a/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt @@ -10,10 +10,9 @@ import androidx.media3.common.C import androidx.media3.common.MediaItem import androidx.media3.exoplayer.ExoPlayer import androidx.media3.exoplayer.trackselection.DefaultTrackSelector +import com.github.libretube.LibreTubeApp.Companion.PLAYER_CHANNEL_NAME import com.github.libretube.R import com.github.libretube.constants.IntentData -import com.github.libretube.constants.PLAYER_CHANNEL_ID -import com.github.libretube.constants.PLAYER_NOTIFICATION_ID import com.github.libretube.db.DatabaseHolder import com.github.libretube.db.obj.DownloadWithItems import com.github.libretube.enums.FileType @@ -23,6 +22,7 @@ import com.github.libretube.helpers.PlayerHelper import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams import com.github.libretube.obj.PlayerNotificationData import com.github.libretube.util.NowPlayingNotification +import com.github.libretube.util.NowPlayingNotification.Companion.PLAYER_NOTIFICATION_ID import kotlin.io.path.exists import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -38,7 +38,7 @@ class OfflinePlayerService : LifecycleService() { override fun onCreate() { super.onCreate() - val notification = NotificationCompat.Builder(this, PLAYER_CHANNEL_ID) + val notification = NotificationCompat.Builder(this, PLAYER_CHANNEL_NAME) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.playingOnBackground)) .setSmallIcon(R.drawable.ic_launcher_lockscreen) diff --git a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt index 99318f244..5ad297c75 100644 --- a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt @@ -19,14 +19,13 @@ import androidx.media3.common.PlaybackException import androidx.media3.common.Player import androidx.media3.exoplayer.ExoPlayer import androidx.media3.exoplayer.trackselection.DefaultTrackSelector +import com.github.libretube.LibreTubeApp.Companion.PLAYER_CHANNEL_NAME import com.github.libretube.R import com.github.libretube.api.JsonHelper import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.obj.Segment import com.github.libretube.api.obj.Streams import com.github.libretube.constants.IntentData -import com.github.libretube.constants.PLAYER_CHANNEL_ID -import com.github.libretube.constants.PLAYER_NOTIFICATION_ID import com.github.libretube.db.DatabaseHelper import com.github.libretube.db.DatabaseHolder.Database import com.github.libretube.db.obj.WatchPosition @@ -41,6 +40,7 @@ import com.github.libretube.helpers.ProxyHelper import com.github.libretube.obj.PlayerNotificationData import com.github.libretube.parcelable.PlayerData import com.github.libretube.util.NowPlayingNotification +import com.github.libretube.util.NowPlayingNotification.Companion.PLAYER_NOTIFICATION_ID import com.github.libretube.util.PlayingQueue import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -109,7 +109,7 @@ class OnlinePlayerService : LifecycleService() { override fun onCreate() { super.onCreate() - val notification = NotificationCompat.Builder(this, PLAYER_CHANNEL_ID) + val notification = NotificationCompat.Builder(this, PLAYER_CHANNEL_NAME) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.playingOnBackground)) .setSmallIcon(R.drawable.ic_launcher_lockscreen) diff --git a/app/src/main/java/com/github/libretube/ui/activities/AboutActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/AboutActivity.kt index ada5df55c..c18061a6f 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/AboutActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/AboutActivity.kt @@ -6,11 +6,6 @@ import android.os.Bundle import androidx.core.text.HtmlCompat import androidx.core.text.parseAsHtml import com.github.libretube.R -import com.github.libretube.constants.GITHUB_URL -import com.github.libretube.constants.LICENSE_URL -import com.github.libretube.constants.PIPED_GITHUB_URL -import com.github.libretube.constants.WEBLATE_URL -import com.github.libretube.constants.WEBSITE_URL import com.github.libretube.databinding.ActivityAboutBinding import com.github.libretube.helpers.ClipboardHelper import com.github.libretube.helpers.IntentHelper @@ -111,4 +106,12 @@ class AboutActivity : BaseActivity() { .setPositiveButton(R.string.okay, null) .show() } + + companion object { + private const val WEBSITE_URL = "https://libre-tube.github.io/" + private const val GITHUB_URL = "https://github.com/libre-tube/LibreTube" + private const val PIPED_GITHUB_URL = "https://github.com/TeamPiped/Piped" + private const val WEBLATE_URL = "https://hosted.weblate.org/projects/libretube/libretube/" + private const val LICENSE_URL = "https://gnu.org/" + } } diff --git a/app/src/main/java/com/github/libretube/ui/activities/HelpActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/HelpActivity.kt index d855910c4..3e767e898 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/HelpActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/HelpActivity.kt @@ -1,10 +1,6 @@ package com.github.libretube.ui.activities import android.os.Bundle -import com.github.libretube.constants.FAQ_URL -import com.github.libretube.constants.LEMMY_URL -import com.github.libretube.constants.MASTODON_URL -import com.github.libretube.constants.MATRIX_URL import com.github.libretube.databinding.ActivityHelpBinding import com.github.libretube.helpers.IntentHelper import com.github.libretube.ui.base.BaseActivity @@ -34,4 +30,11 @@ class HelpActivity : BaseActivity() { IntentHelper.openLinkFromHref(this, supportFragmentManager, link) } } + + companion object { + private const val FAQ_URL = "https://libre-tube.github.io/#faq" + private const val MATRIX_URL = "https://matrix.to/#/#LibreTube:matrix.org" + private const val MASTODON_URL = "https://fosstodon.org/@libretube" + private const val LEMMY_URL = "https://feddit.rocks/c/libretube" + } } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt index 564791696..412ccc5a4 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt @@ -7,9 +7,7 @@ import androidx.core.view.isVisible import androidx.fragment.app.DialogFragment import com.github.libretube.R import com.github.libretube.constants.IntentData -import com.github.libretube.constants.PIPED_FRONTEND_URL import com.github.libretube.constants.PreferenceKeys -import com.github.libretube.constants.YOUTUBE_FRONTEND_URL import com.github.libretube.databinding.DialogShareBinding import com.github.libretube.db.DatabaseHolder.Database import com.github.libretube.enums.ShareObjectType @@ -117,4 +115,9 @@ class ShareDialog : DialogFragment() { // return the custom instance frontend url if available return customInstances.firstOrNull { it.apiUrl == instancePref }?.frontendUrl.orEmpty() } + + companion object { + const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com" + private const val PIPED_FRONTEND_URL = "https://piped.video" + } } diff --git a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt index 272afd5e0..99c2529bf 100644 --- a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt +++ b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt @@ -22,10 +22,9 @@ import androidx.media3.common.MediaMetadata import androidx.media3.common.Player import androidx.media3.exoplayer.ExoPlayer import coil.request.ImageRequest +import com.github.libretube.LibreTubeApp.Companion.PLAYER_CHANNEL_NAME import com.github.libretube.R import com.github.libretube.constants.IntentData -import com.github.libretube.constants.PLAYER_CHANNEL_ID -import com.github.libretube.constants.PLAYER_NOTIFICATION_ID import com.github.libretube.extensions.seekBy import com.github.libretube.extensions.toMediaMetadataCompat import com.github.libretube.helpers.BackgroundHelper @@ -346,7 +345,7 @@ class NowPlayingNotification( * Initializes the [notificationBuilder] attached to the [player] and shows it. */ private fun createNotificationBuilder() { - notificationBuilder = NotificationCompat.Builder(context, PLAYER_CHANNEL_ID) + notificationBuilder = NotificationCompat.Builder(context, PLAYER_CHANNEL_NAME) .setSmallIcon(R.drawable.ic_launcher_lockscreen) .setContentIntent(createCurrentContentIntent()) .setDeleteIntent(createIntent(STOP)) @@ -403,6 +402,7 @@ class NowPlayingNotification( } companion object { + const val PLAYER_NOTIFICATION_ID = 1 private const val PREV = "prev" private const val NEXT = "next" private const val REWIND = "rewind" diff --git a/app/src/main/java/com/github/libretube/workers/NotificationWorker.kt b/app/src/main/java/com/github/libretube/workers/NotificationWorker.kt index 637b6713c..c62669270 100644 --- a/app/src/main/java/com/github/libretube/workers/NotificationWorker.kt +++ b/app/src/main/java/com/github/libretube/workers/NotificationWorker.kt @@ -12,11 +12,11 @@ import androidx.core.app.PendingIntentCompat import androidx.core.content.getSystemService import androidx.work.CoroutineWorker import androidx.work.WorkerParameters +import com.github.libretube.LibreTubeApp.Companion.PUSH_CHANNEL_NAME import com.github.libretube.R import com.github.libretube.api.SubscriptionHelper import com.github.libretube.api.obj.StreamItem import com.github.libretube.constants.IntentData -import com.github.libretube.constants.PUSH_CHANNEL_ID import com.github.libretube.constants.PreferenceKeys import com.github.libretube.extensions.TAG import com.github.libretube.extensions.toID @@ -205,7 +205,7 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) : } private fun createNotificationBuilder(group: String): NotificationCompat.Builder { - return NotificationCompat.Builder(applicationContext, PUSH_CHANNEL_ID) + return NotificationCompat.Builder(applicationContext, PUSH_CHANNEL_NAME) .setSmallIcon(R.drawable.ic_launcher_lockscreen) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setAutoCancel(true)