mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
Add service start method to DownloadHelper
Move download service method to Download helper and start as foreground.
This commit is contained in:
parent
0ba1696448
commit
03a0f9e1fc
@ -10,9 +10,9 @@ object IntentData {
|
||||
const val fileName = "fileName"
|
||||
const val openQueueOnce = "openQueue"
|
||||
const val playlistType = "playlistType"
|
||||
const val videoFormate = "videoFormate"
|
||||
const val videoFormat = "videoFormate"
|
||||
const val videoQuality = "videoQuality"
|
||||
const val audioFormate = "audioFormate"
|
||||
const val audioFormat = "audioFormate"
|
||||
const val audioQuality = "audioQuality"
|
||||
const val subtitleCode = "subtitleCode"
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.github.libretube.ui.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
@ -13,11 +12,10 @@ import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.Streams
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.DialogDownloadBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.sanitize
|
||||
import com.github.libretube.services.DownloadService
|
||||
import com.github.libretube.util.DownloadHelper
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.io.IOException
|
||||
@ -133,20 +131,26 @@ class DownloadDialog(
|
||||
|
||||
val fileName = binding.fileName.text.toString().sanitize()
|
||||
|
||||
val intent = Intent(context, DownloadService::class.java)
|
||||
|
||||
intent.putExtra(IntentData.videoId, videoId)
|
||||
intent.putExtra(IntentData.fileName, fileName)
|
||||
if (videoPosition != -1) {
|
||||
intent.putExtra(IntentData.videoFormate, streams.videoStreams[videoPosition].format)
|
||||
intent.putExtra(IntentData.videoQuality, streams.videoStreams[videoPosition].quality)
|
||||
val videoStream = when (videoPosition) {
|
||||
-1 -> null
|
||||
else -> streams.videoStreams[videoPosition]
|
||||
}
|
||||
if (audioPosition != -1) {
|
||||
intent.putExtra(IntentData.audioFormate, streams.audioStreams[audioPosition].format)
|
||||
intent.putExtra(IntentData.audioQuality, streams.audioStreams[audioPosition].quality)
|
||||
val audioStream = when (audioPosition) {
|
||||
-1 -> null
|
||||
else -> streams.audioStreams[audioPosition]
|
||||
}
|
||||
|
||||
context?.startService(intent)
|
||||
DownloadHelper.startDownloadService(
|
||||
context = requireContext(),
|
||||
videoId = videoId,
|
||||
fileName = fileName,
|
||||
videoFormat = videoStream?.format,
|
||||
videoQuality = videoStream?.quality,
|
||||
audioFormat = audioStream?.format,
|
||||
audioQuality = audioStream?.quality,
|
||||
subtitleCode = null
|
||||
)
|
||||
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.obj.DownloadedFile
|
||||
import com.github.libretube.services.DownloadService
|
||||
import java.io.File
|
||||
|
||||
object DownloadHelper {
|
||||
@ -54,4 +57,31 @@ object DownloadHelper {
|
||||
|
||||
return files
|
||||
}
|
||||
|
||||
fun startDownloadService(
|
||||
context: Context,
|
||||
videoId: String? = null,
|
||||
fileName: String? = null,
|
||||
videoFormat: String? = null,
|
||||
videoQuality: String? = null,
|
||||
audioFormat: String? = null,
|
||||
audioQuality: String? = null,
|
||||
subtitleCode: String? = null
|
||||
) {
|
||||
val intent = Intent(context, DownloadService::class.java)
|
||||
|
||||
intent.putExtra(IntentData.videoId, videoId)
|
||||
intent.putExtra(IntentData.fileName, fileName)
|
||||
intent.putExtra(IntentData.videoFormat, videoFormat)
|
||||
intent.putExtra(IntentData.videoQuality, videoQuality)
|
||||
intent.putExtra(IntentData.audioFormat, audioFormat)
|
||||
intent.putExtra(IntentData.audioQuality, audioQuality)
|
||||
intent.putExtra(IntentData.subtitleCode, subtitleCode)
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(intent)
|
||||
} else {
|
||||
context.startService(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user