diff --git a/app/src/main/java/com/github/libretube/Constants.kt b/app/src/main/java/com/github/libretube/Constants.kt index ea4486fb0..7ef5409e0 100644 --- a/app/src/main/java/com/github/libretube/Constants.kt +++ b/app/src/main/java/com/github/libretube/Constants.kt @@ -26,4 +26,9 @@ const val TWITTER_URL = "https://twitter.com/libretube" * Share Dialog */ const val PIPED_FRONTEND_URL = "https://piped.kavin.rocks" -const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com" \ No newline at end of file +const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com" + +/** + * Retrofit Instance + */ +const val PIPED_API_URL = "https://pipedapi.kavin.rocks/" diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index c616a47b5..d0a0af4c8 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -25,6 +25,7 @@ import androidx.fragment.app.Fragment import androidx.navigation.NavController import androidx.navigation.findNavController import androidx.navigation.ui.setupWithNavController +import com.github.libretube.PIPED_API_URL import com.github.libretube.R import com.github.libretube.databinding.ActivityMainBinding import com.github.libretube.fragments.PlayerFragment @@ -74,14 +75,14 @@ class MainActivity : AppCompatActivity() { CronetHelper.initCronet(this.applicationContext) RetrofitInstance.url = - PreferenceHelper.getString(this, "selectInstance", "https://pipedapi.kavin.rocks/")!! + PreferenceHelper.getString(this, "selectInstance", PIPED_API_URL)!! // set auth instance RetrofitInstance.authUrl = if (PreferenceHelper.getBoolean(this, "auth_instance_toggle", false)) { PreferenceHelper.getString( this, "selectAuthInstance", - "https://pipedapi.kavin.rocks/" + PIPED_API_URL )!! } else { RetrofitInstance.url diff --git a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt index a056fe88c..326c93ae5 100644 --- a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt @@ -28,7 +28,6 @@ class DownloadDialog : DialogFragment() { private val TAG = "DownloadDialog" private lateinit var binding: DialogDownloadBinding - private lateinit var streams: Streams private lateinit var videoId: String private var duration = 0 @@ -86,7 +85,7 @@ class DownloadDialog : DialogFragment() { private fun fetchStreams() { lifecycleScope.launchWhenCreated { val response = try { - RetrofitInstance.api.getStreams(videoId!!) + RetrofitInstance.api.getStreams(videoId) } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") @@ -102,8 +101,8 @@ class DownloadDialog : DialogFragment() { } private fun initDownloadOptions(streams: Streams) { - var vidName = arrayListOf() - var vidUrl = arrayListOf() + val vidName = arrayListOf() + val vidUrl = arrayListOf() // add empty selection vidName.add(getString(R.string.no_video)) @@ -116,8 +115,8 @@ class DownloadDialog : DialogFragment() { vidUrl.add(vid.url!!) } - var audioName = arrayListOf() - var audioUrl = arrayListOf() + val audioName = arrayListOf() + val audioUrl = arrayListOf() // add empty selection audioName.add(getString(R.string.no_audio)) diff --git a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt index ff25e2a81..ed94c30ef 100644 --- a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt @@ -59,7 +59,7 @@ class ShareDialog( val instancePref = PreferenceHelper.getString( requireContext(), "selectInstance", - "https://pipedapi.kavin.rocks" + PIPED_FRONTEND_URL ) // get the api urls of the other custom instances diff --git a/app/src/main/java/com/github/libretube/obj/DownloadType.kt b/app/src/main/java/com/github/libretube/obj/DownloadType.kt new file mode 100644 index 000000000..a94663cc7 --- /dev/null +++ b/app/src/main/java/com/github/libretube/obj/DownloadType.kt @@ -0,0 +1,11 @@ +package com.github.libretube.obj + +/** + * object for saving the download type + */ +object DownloadType { + const val AUDIO = 0 + const val VIDEO = 1 + const val MUX = 2 + const val NONE = 3 +} 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 e422a0021..63e1ffe70 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -19,6 +19,7 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import com.arthenica.ffmpegkit.FFmpegKit import com.github.libretube.R +import com.github.libretube.obj.DownloadType import com.github.libretube.preferences.PreferenceHelper import java.io.File @@ -26,17 +27,19 @@ var IS_DOWNLOAD_RUNNING = false class DownloadService : Service() { val TAG = "DownloadService" + + private lateinit var notification: NotificationCompat.Builder + private var downloadId: Long = -1 private lateinit var videoId: String private lateinit var videoUrl: String private lateinit var audioUrl: String private lateinit var extension: String private var duration: Int = 0 + private var downloadType: Int = 3 private lateinit var audioDir: File private lateinit var videoDir: File - private lateinit var notification: NotificationCompat.Builder - private lateinit var downloadType: String private lateinit var libretubeDir: File private lateinit var tempDir: File override fun onCreate() { @@ -50,11 +53,11 @@ class DownloadService : Service() { audioUrl = intent.getStringExtra("audioUrl")!! duration = intent.getIntExtra("duration", 1) extension = PreferenceHelper.getString(this, "video_format", ".mp4")!! - downloadType = if (audioUrl != "" && videoUrl != "") "mux" - else if (audioUrl != "") "audio" - else if (videoUrl != "") "video" - else "none" - if (downloadType != "none") { + downloadType = if (audioUrl != "" && videoUrl != "") DownloadType.MUX + else if (audioUrl != "") DownloadType.AUDIO + else if (videoUrl != "") DownloadType.VIDEO + else DownloadType.NONE + if (downloadType != DownloadType.NONE) { downloadNotification(intent) downloadManager() } else { @@ -108,7 +111,7 @@ class DownloadService : Service() { IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE) ) when (downloadType) { - "mux" -> { + DownloadType.MUX -> { audioDir = File(tempDir, "$videoId-audio") videoDir = File(tempDir, "$videoId-video") downloadId = downloadManagerRequest( @@ -118,7 +121,7 @@ class DownloadService : Service() { videoDir ) } - "video" -> { + DownloadType.VIDEO -> { videoDir = File(libretubeDir, "$videoId-video") downloadId = downloadManagerRequest( getString(R.string.video), @@ -127,7 +130,7 @@ class DownloadService : Service() { videoDir ) } - "audio" -> { + DownloadType.AUDIO -> { audioDir = File(libretubeDir, "$videoId-audio") downloadId = downloadManagerRequest( getString(R.string.audio), @@ -148,7 +151,7 @@ class DownloadService : Service() { val id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) // Checking if the received broadcast is for our enqueued download by matching download id if (downloadId == id) { - if (downloadType == "mux") { + if (downloadType == DownloadType.MUX) { downloadManagerRequest( getString(R.string.audio), getString(R.string.downloading),