use activity instead of context

This commit is contained in:
IndusAryan 2024-06-27 21:34:12 +05:30
parent 5b9ff65f7b
commit 8f65f99b29
3 changed files with 8 additions and 11 deletions

View file

@ -2,7 +2,6 @@ package com.lagradost.cloudstream3.ui.download
import android.app.Activity import android.app.Activity
import android.app.Dialog import android.app.Dialog
import android.content.ActivityNotFoundException
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -33,7 +32,6 @@ import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
import com.lagradost.cloudstream3.ui.player.BasicLink import com.lagradost.cloudstream3.ui.player.BasicLink
import com.lagradost.cloudstream3.ui.player.DownloadedPlayerActivity
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
import com.lagradost.cloudstream3.ui.player.LinkGenerator import com.lagradost.cloudstream3.ui.player.LinkGenerator
import com.lagradost.cloudstream3.ui.player.OfflinePlaybackHelper.playUri import com.lagradost.cloudstream3.ui.player.OfflinePlaybackHelper.playUri
@ -280,6 +278,6 @@ class DownloadFragment : Fragment() {
) { result -> ) { result ->
if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult
val selectedVideoUri = result?.data?.data ?: return@registerForActivityResult val selectedVideoUri = result?.data?.data ?: return@registerForActivityResult
playUri(context ?: return@registerForActivityResult, selectedVideoUri) playUri(activity ?: return@registerForActivityResult, selectedVideoUri)
} }
} }

View file

@ -54,11 +54,11 @@ class DownloadedPlayerActivity : AppCompatActivity() {
if (item?.uri != null) if (item?.uri != null)
playUri(this, item.uri) playUri(this, item.uri)
else if (url != null) else if (url != null)
playLink(url) playLink(this, url)
else if (data != null) else if (data != null)
playUri(this, data) playUri(this, data)
else if (extraText != null) else if (extraText != null)
playLink(extraText) playLink(this, extraText)
else { else {
finish() finish()
return return

View file

@ -1,17 +1,16 @@
package com.lagradost.cloudstream3.ui.player package com.lagradost.cloudstream3.ui.player
import android.app.Activity
import android.content.ContentUris import android.content.ContentUris
import android.content.Context
import android.net.Uri import android.net.Uri
import androidx.core.content.ContextCompat.getString import androidx.core.content.ContextCompat.getString
import com.lagradost.cloudstream3.CommonActivity.activity
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.utils.ExtractorUri import com.lagradost.cloudstream3.utils.ExtractorUri
import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.navigate
import com.lagradost.safefile.SafeFile import com.lagradost.safefile.SafeFile
object OfflinePlaybackHelper { object OfflinePlaybackHelper {
fun playLink(url: String) { fun playLink(activity: Activity, url: String) {
activity.navigate( activity.navigate(
R.id.global_to_navigation_player, GeneratorPlayer.newInstance( R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
LinkGenerator( LinkGenerator(
@ -23,15 +22,15 @@ object OfflinePlaybackHelper {
) )
} }
fun playUri(context: Context, uri: Uri) { fun playUri(activity: Activity, uri: Uri) {
val name = SafeFile.fromUri(context, uri)?.name() val name = SafeFile.fromUri(activity, uri)?.name()
activity.navigate( activity.navigate(
R.id.global_to_navigation_player, GeneratorPlayer.newInstance( R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
DownloadFileGenerator( DownloadFileGenerator(
listOf( listOf(
ExtractorUri( ExtractorUri(
uri = uri, uri = uri,
name = name ?: getString(context, R.string.downloaded_file), name = name ?: getString(activity, R.string.downloaded_file),
// well not the same as a normal id, but we take it as users may want to // well not the same as a normal id, but we take it as users may want to
// play downloaded files and save the location // play downloaded files and save the location
id = kotlin.runCatching { ContentUris.parseId(uri) }.getOrNull()?.hashCode() id = kotlin.runCatching { ContentUris.parseId(uri) }.getOrNull()?.hashCode()