mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
lots of stuff
This commit is contained in:
parent
d860f8226a
commit
5b9ff65f7b
4 changed files with 63 additions and 78 deletions
|
@ -33,9 +33,10 @@ import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
|||
import com.lagradost.cloudstream3.mvvm.observe
|
||||
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
||||
import com.lagradost.cloudstream3.ui.player.BasicLink
|
||||
import com.lagradost.cloudstream3.ui.player.DownloadFileGenerator
|
||||
import com.lagradost.cloudstream3.ui.player.DownloadedPlayerActivity
|
||||
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
|
||||
import com.lagradost.cloudstream3.ui.player.LinkGenerator
|
||||
import com.lagradost.cloudstream3.ui.player.OfflinePlaybackHelper.playUri
|
||||
import com.lagradost.cloudstream3.ui.result.FOCUS_SELF
|
||||
import com.lagradost.cloudstream3.ui.result.setLinearListLayout
|
||||
import com.lagradost.cloudstream3.ui.settings.Globals.TV
|
||||
|
@ -44,14 +45,12 @@ import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
|||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
|
||||
import com.lagradost.cloudstream3.utils.DataStore
|
||||
import com.lagradost.cloudstream3.utils.ExtractorUri
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.setAppBarNoScrollFlagsOnTV
|
||||
import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
||||
import com.lagradost.safefile.SafeFile
|
||||
import java.net.URI
|
||||
|
||||
const val DOWNLOAD_NAVIGATE_TO = "downloadpage"
|
||||
|
@ -206,15 +205,13 @@ class DownloadFragment : Fragment() {
|
|||
.setType("video/*")
|
||||
.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
.addFlags(FLAG_GRANT_READ_URI_PERMISSION) // Request temporary access
|
||||
try {
|
||||
normalSafeApiCall {
|
||||
videoResultLauncher.launch(
|
||||
Intent.createChooser(
|
||||
intent,
|
||||
getString(R.string.open_local_video)
|
||||
)
|
||||
)
|
||||
} catch (t: ActivityNotFoundException) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,28 +278,8 @@ class DownloadFragment : Fragment() {
|
|||
private val videoResultLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
val intentData = result?.data?.data
|
||||
intentData.let { selectedVideoUri ->
|
||||
val name = SafeFile.fromUri(
|
||||
context ?: return@let ,
|
||||
selectedVideoUri ?: return@registerForActivityResult
|
||||
)?.name()
|
||||
|
||||
activity?.navigate(
|
||||
R.id.global_to_navigation_player,
|
||||
GeneratorPlayer.newInstance(
|
||||
DownloadFileGenerator(
|
||||
listOf(
|
||||
ExtractorUri(
|
||||
uri = selectedVideoUri,
|
||||
name = name ?: "Local video: $selectedVideoUri"
|
||||
)
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult
|
||||
val selectedVideoUri = result?.data?.data ?: return@registerForActivityResult
|
||||
playUri(context ?: return@registerForActivityResult, selectedVideoUri)
|
||||
}
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
package com.lagradost.cloudstream3.ui.player
|
||||
|
||||
import android.content.ContentUris
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
|
@ -10,13 +8,13 @@ import androidx.activity.OnBackPressedCallback
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.lagradost.cloudstream3.CommonActivity
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.utils.ExtractorUri
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||
import com.lagradost.safefile.SafeFile
|
||||
|
||||
const val DTAG = "PlayerActivity"
|
||||
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
||||
import com.lagradost.cloudstream3.ui.player.OfflinePlaybackHelper.playLink
|
||||
import com.lagradost.cloudstream3.ui.player.OfflinePlaybackHelper.playUri
|
||||
|
||||
class DownloadedPlayerActivity : AppCompatActivity() {
|
||||
private val dTAG = "DownloadedPlayerAct"
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
CommonActivity.dispatchKeyEvent(this, event)?.let {
|
||||
return it
|
||||
|
@ -35,53 +33,18 @@ class DownloadedPlayerActivity : AppCompatActivity() {
|
|||
CommonActivity.onUserLeaveHint(this)
|
||||
}
|
||||
|
||||
private fun playLink(url: String) {
|
||||
this.navigate(
|
||||
R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
|
||||
LinkGenerator(
|
||||
listOf(
|
||||
BasicLink(url)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun playUri(uri: Uri) {
|
||||
val name = SafeFile.fromUri(this, uri)?.name()
|
||||
this.navigate(
|
||||
R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
|
||||
DownloadFileGenerator(
|
||||
listOf(
|
||||
ExtractorUri(
|
||||
uri = uri,
|
||||
name = name ?: getString(R.string.downloaded_file),
|
||||
// well not the same as a normal id, but we take it as users may want to
|
||||
// play downloaded files and save the location
|
||||
id = kotlin.runCatching { ContentUris.parseId(uri) }.getOrNull()?.hashCode()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
Log.i(DTAG, "onCreate")
|
||||
|
||||
CommonActivity.loadThemes(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
CommonActivity.loadThemes(this)
|
||||
CommonActivity.init(this)
|
||||
|
||||
setContentView(R.layout.empty_layout)
|
||||
Log.i(dTAG, "onCreate")
|
||||
|
||||
val data = intent.data
|
||||
|
||||
if (intent?.action == Intent.ACTION_SEND) {
|
||||
val extraText = try { // I dont trust android
|
||||
val extraText = normalSafeApiCall { // I dont trust android
|
||||
intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
val cd = intent.clipData
|
||||
val item = if (cd != null && cd.itemCount > 0) cd.getItemAt(0) else null
|
||||
|
@ -89,11 +52,11 @@ class DownloadedPlayerActivity : AppCompatActivity() {
|
|||
|
||||
// idk what I am doing, just hope any of these work
|
||||
if (item?.uri != null)
|
||||
playUri(item.uri)
|
||||
playUri(this, item.uri)
|
||||
else if (url != null)
|
||||
playLink(url)
|
||||
else if (data != null)
|
||||
playUri(data)
|
||||
playUri(this, data)
|
||||
else if (extraText != null)
|
||||
playLink(extraText)
|
||||
else {
|
||||
|
@ -101,7 +64,7 @@ class DownloadedPlayerActivity : AppCompatActivity() {
|
|||
return
|
||||
}
|
||||
} else if (data?.scheme == "content") {
|
||||
playUri(data)
|
||||
playUri(this, data)
|
||||
} else {
|
||||
finish()
|
||||
return
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.lagradost.cloudstream3.ui.player
|
||||
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.core.content.ContextCompat.getString
|
||||
import com.lagradost.cloudstream3.CommonActivity.activity
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.utils.ExtractorUri
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||
import com.lagradost.safefile.SafeFile
|
||||
|
||||
object OfflinePlaybackHelper {
|
||||
fun playLink(url: String) {
|
||||
activity.navigate(
|
||||
R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
|
||||
LinkGenerator(
|
||||
listOf(
|
||||
BasicLink(url)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun playUri(context: Context, uri: Uri) {
|
||||
val name = SafeFile.fromUri(context, uri)?.name()
|
||||
activity.navigate(
|
||||
R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
|
||||
DownloadFileGenerator(
|
||||
listOf(
|
||||
ExtractorUri(
|
||||
uri = uri,
|
||||
name = name ?: getString(context, R.string.downloaded_file),
|
||||
// well not the same as a normal id, but we take it as users may want to
|
||||
// play downloaded files and save the location
|
||||
id = kotlin.runCatching { ContentUris.parseId(uri) }.getOrNull()?.hashCode()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
|
@ -208,8 +208,9 @@
|
|||
android:id="@+id/open_local_video_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="?attr/floatingActionButtonSmallStyle"
|
||||
android:backgroundTint="?attr/primaryGrayBackground"
|
||||
android:src="@drawable/video_play"
|
||||
android:src="@drawable/netflix_play"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:tooltipText="@string/open_local_video"
|
||||
android:layout_gravity="bottom|end"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue