From d4014084cd995cb89265e4b52644c7d4e67f9fa7 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Wed, 1 Sep 2021 15:16:49 +0200 Subject: [PATCH] small fixes --- .../cloudstream3/ui/player/PlayerFragment.kt | 1 + .../cloudstream3/ui/result/ResultFragment.kt | 8 +- .../cloudstream3/utils/InAppUpdater.kt | 98 ++++++++++--------- .../utils/VideoDownloadManager.kt | 1 + 4 files changed, 59 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt index 213140da..eab89b30 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt @@ -903,6 +903,7 @@ class PlayerFragment : Fragment() { } private fun handlePlayerEvent(event: Int) { + if(!this::exoPlayer.isInitialized) return when (event) { PlayerEventType.Play.value -> exoPlayer.play() PlayerEventType.Pause.value -> exoPlayer.pause() diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index c57ff895..c4d10e13 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -844,12 +844,12 @@ class ResultFragment : Fragment() { if (d is LoadResponse) { updateVisStatus(2) - result_vpn.text = when (api.vpnStatus) { + result_vpn?.text = when (api.vpnStatus) { VPNStatus.MightBeNeeded -> getString(R.string.vpn_might_be_needed) VPNStatus.Torrent -> getString(R.string.vpn_torrent) else -> "" } - result_vpn.visibility = if (api.vpnStatus == VPNStatus.None) GONE else VISIBLE + result_vpn?.visibility = if (api.vpnStatus == VPNStatus.None) GONE else VISIBLE result_bookmark_button.text = "Watching" @@ -859,7 +859,7 @@ class ResultFragment : Fragment() { currentPoster = d.posterUrl currentIsMovie = !d.isEpisodeBased() - result_openinbrower.setOnClickListener { + result_openinbrower?.setOnClickListener { val i = Intent(ACTION_VIEW) i.data = Uri.parse(d.url) try { @@ -869,7 +869,7 @@ class ResultFragment : Fragment() { } } - result_share.setOnClickListener { + result_share?.setOnClickListener { val i = Intent(ACTION_SEND) i.type = "text/plain" i.putExtra(EXTRA_SUBJECT, d.name) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt index 60ba7e1f..c8b5b73d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt @@ -169,25 +169,29 @@ class InAppUpdater { registerReceiver( object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { - val downloadId = intent?.getLongExtra( - DownloadManager.EXTRA_DOWNLOAD_ID, id - ) ?: id + try { + val downloadId = intent?.getLongExtra( + DownloadManager.EXTRA_DOWNLOAD_ID, id + ) ?: id - val query = DownloadManager.Query() - query.setFilterById(downloadId) - val c = downloadManager.query(query) + val query = DownloadManager.Query() + query.setFilterById(downloadId) + val c = downloadManager.query(query) - if (c.moveToFirst()) { - val columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS) - if (DownloadManager.STATUS_SUCCESSFUL == c - .getInt(columnIndex) - ) { - c.getColumnIndex(DownloadManager.COLUMN_MEDIAPROVIDER_URI) - val uri = Uri.parse( - c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)) - ) - openApk(localContext, uri) + if (c.moveToFirst()) { + val columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS) + if (DownloadManager.STATUS_SUCCESSFUL == c + .getInt(columnIndex) + ) { + c.getColumnIndex(DownloadManager.COLUMN_MEDIAPROVIDER_URI) + val uri = Uri.parse( + c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)) + ) + openApk(localContext, uri) + } } + } catch (e : Exception) { + e.printStackTrace() } } }, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE) @@ -220,45 +224,49 @@ class InAppUpdater { val update = getAppUpdate() if (update.shouldUpdate && update.updateURL != null) { runOnUiThread { - val currentVersion = packageName?.let { - packageManager.getPackageInfo( - it, - 0 - ) - } + try { + val currentVersion = packageName?.let { + packageManager.getPackageInfo( + it, + 0 + ) + } - val builder: AlertDialog.Builder = AlertDialog.Builder(this) - builder.setTitle("New update found!\n${currentVersion?.versionName} -> ${update.updateVersion}") - builder.setMessage("${update.changelog}") + val builder: AlertDialog.Builder = AlertDialog.Builder(this) + builder.setTitle("New update found!\n${currentVersion?.versionName} -> ${update.updateVersion}") + builder.setMessage("${update.changelog}") - val context = this - builder.apply { - setPositiveButton("Update") { _, _ -> - showToast(context, "Download started", Toast.LENGTH_LONG) - thread { - val downloadStatus = - normalSafeApiCall { context.downloadUpdate(update.updateURL) } ?: false - if (!downloadStatus) { - runOnUiThread { - showToast( - context, - "Download Failed", - Toast.LENGTH_LONG - ) + val context = this + builder.apply { + setPositiveButton("Update") { _, _ -> + showToast(context, "Download started", Toast.LENGTH_LONG) + thread { + val downloadStatus = + normalSafeApiCall { context.downloadUpdate(update.updateURL) } ?: false + if (!downloadStatus) { + runOnUiThread { + showToast( + context, + "Download Failed", + Toast.LENGTH_LONG + ) + } } } } - } - setNegativeButton("Cancel") { _, _ -> } + setNegativeButton("Cancel") { _, _ -> } - if (checkAutoUpdate) { - setNeutralButton("Don't show again") { _, _ -> - settingsManager.edit().putBoolean("auto_update", false).apply() + if (checkAutoUpdate) { + setNeutralButton("Don't show again") { _, _ -> + settingsManager.edit().putBoolean("auto_update", false).apply() + } } } + builder.show() + } catch (e: Exception) { + e.printStackTrace() } - builder.show() } return true } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt index 9805d981..bb8429bf 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt @@ -124,6 +124,7 @@ object VideoDownloadManager { val totalBytes: Long, val relativePath: String, val displayName: String, + val extraData : String? = null, ) data class DownloadedFileInfoResult(