mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-07 18:10:31 +05:30
move download action from player fragment to download dialog
This commit is contained in:
parent
73276894f0
commit
e802ea118b
@ -1,8 +1,12 @@
|
|||||||
package com.github.libretube.dialogs
|
package com.github.libretube.dialogs
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Environment
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -13,14 +17,18 @@ import android.widget.RadioButton
|
|||||||
import android.widget.RadioGroup
|
import android.widget.RadioGroup
|
||||||
import android.widget.Spinner
|
import android.widget.Spinner
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import com.github.libretube.DownloadService
|
import com.github.libretube.DownloadService
|
||||||
|
import com.github.libretube.MainActivity
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
import com.github.libretube.obj.Streams
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
class DownloadDialog : DialogFragment() {
|
class DownloadDialog : DialogFragment() {
|
||||||
private val TAG = "DownloadDialog"
|
private val TAG = "DownloadDialog"
|
||||||
|
var streams: Streams = Streams()
|
||||||
var vidName = arrayListOf<String>()
|
var vidName = arrayListOf<String>()
|
||||||
var vidUrl = arrayListOf<String>()
|
var vidUrl = arrayListOf<String>()
|
||||||
var audioName = arrayListOf<String>()
|
var audioName = arrayListOf<String>()
|
||||||
@ -32,12 +40,62 @@ class DownloadDialog : DialogFragment() {
|
|||||||
private lateinit var videoId: String
|
private lateinit var videoId: String
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
return activity?.let {
|
return activity?.let {
|
||||||
vidName = arguments?.getStringArrayList("videoName") as ArrayList<String>
|
streams = arguments?.getParcelable("streams")!!
|
||||||
vidUrl = arguments?.getStringArrayList("videoUrl") as ArrayList<String>
|
videoId = arguments?.getString("video_id")!!
|
||||||
audioName = arguments?.getStringArrayList("audioName") as ArrayList<String>
|
|
||||||
audioUrl = arguments?.getStringArrayList("audioUrl") as ArrayList<String>
|
val mainActivity = activity as MainActivity
|
||||||
duration = arguments?.getInt("duration")!!
|
Log.e(TAG, "download button clicked!")
|
||||||
videoId = arguments?.getString("videoId")!!
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
Log.d("myz", "" + Build.VERSION.SDK_INT)
|
||||||
|
if (!Environment.isExternalStorageManager()) {
|
||||||
|
ActivityCompat.requestPermissions(
|
||||||
|
mainActivity,
|
||||||
|
arrayOf(
|
||||||
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.MANAGE_EXTERNAL_STORAGE
|
||||||
|
),
|
||||||
|
1
|
||||||
|
) // permission request code is just an int
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ActivityCompat.checkSelfPermission(
|
||||||
|
requireContext(),
|
||||||
|
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||||
|
) != PackageManager.PERMISSION_GRANTED ||
|
||||||
|
ActivityCompat.checkSelfPermission(
|
||||||
|
requireContext(),
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
|
) != PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
ActivityCompat.requestPermissions(
|
||||||
|
mainActivity,
|
||||||
|
arrayOf(
|
||||||
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
|
),
|
||||||
|
1
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var vidName = arrayListOf<String>()
|
||||||
|
vidName.add("No video")
|
||||||
|
var vidUrl = arrayListOf<String>()
|
||||||
|
vidUrl.add("")
|
||||||
|
for (vid in streams?.videoStreams!!) {
|
||||||
|
val name = vid.quality + " " + vid.format
|
||||||
|
vidName.add(name)
|
||||||
|
vidUrl.add(vid.url!!)
|
||||||
|
}
|
||||||
|
var audioName = arrayListOf<String>()
|
||||||
|
audioName.add("No audio")
|
||||||
|
var audioUrl = arrayListOf<String>()
|
||||||
|
audioUrl.add("")
|
||||||
|
for (audio in streams?.audioStreams!!) {
|
||||||
|
val name = audio.quality + " " + audio.format
|
||||||
|
audioName.add(name)
|
||||||
|
audioUrl.add(audio.url!!)
|
||||||
|
}
|
||||||
|
|
||||||
val builder = MaterialAlertDialogBuilder(it)
|
val builder = MaterialAlertDialogBuilder(it)
|
||||||
// Get the layout inflater
|
// Get the layout inflater
|
||||||
val inflater = requireActivity().layoutInflater
|
val inflater = requireActivity().layoutInflater
|
||||||
@ -115,12 +173,4 @@ class DownloadDialog : DialogFragment() {
|
|||||||
builder.create()
|
builder.create()
|
||||||
} ?: throw IllegalStateException("Activity cannot be null")
|
} ?: throw IllegalStateException("Activity cannot be null")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
vidName.clear()
|
|
||||||
vidUrl.clear()
|
|
||||||
audioUrl.clear()
|
|
||||||
audioName.clear()
|
|
||||||
super.onDestroy()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
package com.github.libretube.fragments
|
package com.github.libretube.fragments
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Build.VERSION.SDK_INT
|
import android.os.Build.VERSION.SDK_INT
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Environment
|
|
||||||
import android.support.v4.media.session.MediaSessionCompat
|
import android.support.v4.media.session.MediaSessionCompat
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
@ -34,7 +31,6 @@ import android.widget.TextView
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.core.app.ActivityCompat
|
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
@ -85,11 +81,11 @@ import com.google.android.exoplayer2.util.RepeatModeUtil
|
|||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
|
import org.chromium.net.CronetEngine
|
||||||
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import org.chromium.net.CronetEngine
|
|
||||||
import retrofit2.HttpException
|
|
||||||
|
|
||||||
var isFullScreen = false
|
var isFullScreen = false
|
||||||
|
|
||||||
@ -729,66 +725,10 @@ class PlayerFragment : Fragment() {
|
|||||||
// download clicked
|
// download clicked
|
||||||
relDownloadVideo.setOnClickListener {
|
relDownloadVideo.setOnClickListener {
|
||||||
if (!IS_DOWNLOAD_RUNNING) {
|
if (!IS_DOWNLOAD_RUNNING) {
|
||||||
val mainActivity = activity as MainActivity
|
|
||||||
Log.e(TAG, "download button clicked!")
|
|
||||||
if (SDK_INT >= Build.VERSION_CODES.R) {
|
|
||||||
Log.d("myz", "" + SDK_INT)
|
|
||||||
if (!Environment.isExternalStorageManager()) {
|
|
||||||
ActivityCompat.requestPermissions(
|
|
||||||
mainActivity,
|
|
||||||
arrayOf(
|
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
||||||
Manifest.permission.MANAGE_EXTERNAL_STORAGE
|
|
||||||
),
|
|
||||||
1
|
|
||||||
) // permission request code is just an int
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (ActivityCompat.checkSelfPermission(
|
|
||||||
requireContext(),
|
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
|
||||||
) != PackageManager.PERMISSION_GRANTED ||
|
|
||||||
ActivityCompat.checkSelfPermission(
|
|
||||||
requireContext(),
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
||||||
) != PackageManager.PERMISSION_GRANTED
|
|
||||||
) {
|
|
||||||
ActivityCompat.requestPermissions(
|
|
||||||
mainActivity,
|
|
||||||
arrayOf(
|
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
||||||
),
|
|
||||||
1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var vidName = arrayListOf<String>()
|
|
||||||
vidName.add("No video")
|
|
||||||
var vidUrl = arrayListOf<String>()
|
|
||||||
vidUrl.add("")
|
|
||||||
for (vid in response.videoStreams) {
|
|
||||||
val name = vid.quality + " " + vid.format
|
|
||||||
vidName.add(name)
|
|
||||||
vidUrl.add(vid.url!!)
|
|
||||||
}
|
|
||||||
var audioName = arrayListOf<String>()
|
|
||||||
audioName.add("No audio")
|
|
||||||
var audioUrl = arrayListOf<String>()
|
|
||||||
audioUrl.add("")
|
|
||||||
for (audio in response.audioStreams!!) {
|
|
||||||
val name = audio.quality + " " + audio.format
|
|
||||||
audioName.add(name)
|
|
||||||
audioUrl.add(audio.url!!)
|
|
||||||
}
|
|
||||||
val newFragment = DownloadDialog()
|
val newFragment = DownloadDialog()
|
||||||
var bundle = Bundle()
|
var bundle = Bundle()
|
||||||
bundle.putStringArrayList("videoName", vidName)
|
bundle.putString("video_id", videoId)
|
||||||
bundle.putStringArrayList("videoUrl", vidUrl)
|
bundle.putParcelable("streams", response)
|
||||||
bundle.putStringArrayList("audioName", audioName)
|
|
||||||
bundle.putStringArrayList("audioUrl", audioUrl)
|
|
||||||
bundle.putString("videoId", videoId)
|
|
||||||
bundle.putInt("duration", response.duration)
|
|
||||||
newFragment.arguments = bundle
|
newFragment.arguments = bundle
|
||||||
newFragment.show(childFragmentManager, "Download")
|
newFragment.show(childFragmentManager, "Download")
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.github.libretube.obj
|
package com.github.libretube.obj
|
||||||
|
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
@ -26,9 +28,69 @@ data class Streams(
|
|||||||
val livestream: Boolean?,
|
val livestream: Boolean?,
|
||||||
val proxyUrl: String?,
|
val proxyUrl: String?,
|
||||||
val chapters: List<ChapterSegment>?
|
val chapters: List<ChapterSegment>?
|
||||||
) {
|
) : Parcelable {
|
||||||
|
constructor(parcel: Parcel) : this(
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readString(),
|
||||||
|
parcel.readValue(Boolean::class.java.classLoader) as? Boolean,
|
||||||
|
parcel.readValue(Int::class.java.classLoader) as? Int,
|
||||||
|
parcel.readValue(Long::class.java.classLoader) as? Long,
|
||||||
|
parcel.readValue(Long::class.java.classLoader) as? Long,
|
||||||
|
parcel.readValue(Int::class.java.classLoader) as? Int,
|
||||||
|
TODO("audioStreams"),
|
||||||
|
TODO("videoStreams"),
|
||||||
|
TODO("relatedStreams"),
|
||||||
|
TODO("subtitles"),
|
||||||
|
parcel.readValue(Boolean::class.java.classLoader) as? Boolean,
|
||||||
|
parcel.readString(),
|
||||||
|
TODO("chapters")
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
constructor() : this(
|
constructor() : this(
|
||||||
"", "", "", "", "", "", "", "", "", "", null, -1, -1, -1, -1, emptyList(), emptyList(),
|
"", "", "", "", "", "", "", "", "", "", null, -1, -1, -1, -1, emptyList(), emptyList(),
|
||||||
emptyList(), emptyList(), null, "", emptyList()
|
emptyList(), emptyList(), null, "", emptyList()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||||
|
parcel.writeString(title)
|
||||||
|
parcel.writeString(description)
|
||||||
|
parcel.writeString(uploadDate)
|
||||||
|
parcel.writeString(uploader)
|
||||||
|
parcel.writeString(uploaderUrl)
|
||||||
|
parcel.writeString(uploaderAvatar)
|
||||||
|
parcel.writeString(thumbnailUrl)
|
||||||
|
parcel.writeString(hls)
|
||||||
|
parcel.writeString(dash)
|
||||||
|
parcel.writeString(lbryId)
|
||||||
|
parcel.writeValue(uploaderVerified)
|
||||||
|
parcel.writeValue(duration)
|
||||||
|
parcel.writeValue(views)
|
||||||
|
parcel.writeValue(likes)
|
||||||
|
parcel.writeValue(dislikes)
|
||||||
|
parcel.writeValue(livestream)
|
||||||
|
parcel.writeString(proxyUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun describeContents(): Int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object CREATOR : Parcelable.Creator<Streams> {
|
||||||
|
override fun createFromParcel(parcel: Parcel): Streams {
|
||||||
|
return Streams(parcel)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<Streams?> {
|
||||||
|
return arrayOfNulls(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user