From 2acae76c5ef8f38e2d4a44156e43aedf5cdea182 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Sun, 12 Sep 2021 17:57:07 +0200 Subject: [PATCH] bump --- app/build.gradle | 4 +- .../lagradost/cloudstream3/MainActivity.kt | 23 ++-- .../ui/download/DownloadChildFragment.kt | 36 +++---- .../ui/download/DownloadFragment.kt | 10 +- .../cloudstream3/ui/result/ResultFragment.kt | 101 ++++++++++-------- .../utils/VideoDownloadManager.kt | 2 + 6 files changed, 96 insertions(+), 80 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d29c97fe..c8875a2d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { applicationId "com.lagradost.cloudstream3" minSdkVersion 21 targetSdkVersion 30 - versionCode 23 - versionName "1.8.8" + versionCode 24 + versionName "1.9.8" resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix ?: ""}" diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index e105bb54..82a2786e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -25,6 +25,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import com.lagradost.cloudstream3.APIHolder.apis import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings import com.lagradost.cloudstream3.APIHolder.restrictedApis +import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver import com.lagradost.cloudstream3.ui.APIRepository import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO @@ -146,16 +147,20 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { private fun enterPIPMode() { if (!shouldShowPIPMode(canEnterPipMode) || !canShowPipMode) return - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - try { - enterPictureInPictureMode(PictureInPictureParams.Builder().build()) - } catch (e: Exception) { - enterPictureInPictureMode() - } - } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - enterPictureInPictureMode() + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + try { + enterPictureInPictureMode(PictureInPictureParams.Builder().build()) + } catch (e: Exception) { + enterPictureInPictureMode() + } + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + enterPictureInPictureMode() + } } + } catch (e : Exception) { + logError(e) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt index fbb5d05a..8f972314 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt @@ -45,27 +45,25 @@ class DownloadChildFragment : Fragment() { } private fun updateList(folder: String) = main { - val data = withContext(Dispatchers.IO) { context?.getKeys(folder) } - if (data == null) { - activity?.onBackPressed() // TODO FIX - return@main - } - val eps = withContext(Dispatchers.IO) { - data.mapNotNull { key -> - context?.getKey(key) - }.mapNotNull { - val info = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(requireContext(), it.id) - ?: return@mapNotNull null - VisualDownloadChildCached(info.fileLength, info.totalBytes, it) + context?.let { ctx -> + val data = withContext(Dispatchers.IO) { ctx.getKeys(folder) } + val eps = withContext(Dispatchers.IO) { + data.mapNotNull { key -> + context?.getKey(key) + }.mapNotNull { + val info = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(ctx, it.id) + ?: return@mapNotNull null + VisualDownloadChildCached(info.fileLength, info.totalBytes, it) + } + } + if (eps.isEmpty()) { + activity?.onBackPressed() + return@main } - } - if (eps.isEmpty()) { - activity?.onBackPressed() - return@main - } - (download_child_list?.adapter as DownloadChildAdapter? ?: return@main).cardList = eps - download_child_list?.adapter?.notifyDataSetChanged() + (download_child_list?.adapter as DownloadChildAdapter? ?: return@main).cardList = eps + download_child_list?.adapter?.notifyDataSetChanged() + } } var downloadDeleteEventListener: ((Int) -> Unit)? = null diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt index 3cd7e04d..2f6c9400 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt @@ -112,7 +112,9 @@ class DownloadFragment : Fragment() { if (downloadClickEvent.data !is VideoDownloadHelper.DownloadEpisodeCached) return@DownloadHeaderAdapter handleDownloadClick(activity, downloadClickEvent.data.name, downloadClickEvent) if (downloadClickEvent.action == DOWNLOAD_ACTION_DELETE_FILE) { - downloadsViewModel.updateList(requireContext()) + context?.let { ctx -> + downloadsViewModel.updateList(ctx) + } } } ) @@ -121,8 +123,10 @@ class DownloadFragment : Fragment() { val list = (download_list?.adapter as DownloadHeaderAdapter?)?.cardList if (list != null) { if (list.any { it.data.id == id }) { - setList(ArrayList()) - downloadsViewModel.updateList(requireContext()) + context?.let { ctx -> + setList(ArrayList()) + downloadsViewModel.updateList(ctx) + } } } } 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 b52c6630..8ac1adff 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 @@ -558,55 +558,59 @@ class ResultFragment : Fragment() { } ACTION_SHOW_OPTIONS -> { - val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom) - var dialog: AlertDialog? = null - builder.setTitle(showTitle) - val options = requireContext().resources.getStringArray(R.array.episode_long_click_options) - val optionsValues = - requireContext().resources.getIntArray(R.array.episode_long_click_options_values) + context?.let { ctx -> + val builder = AlertDialog.Builder(ctx, R.style.AlertDialogCustom) + var dialog: AlertDialog? = null + builder.setTitle(showTitle) + val options = requireContext().resources.getStringArray(R.array.episode_long_click_options) + val optionsValues = + requireContext().resources.getIntArray(R.array.episode_long_click_options_values) - val verifiedOptions = ArrayList() - val verifiedOptionsValues = ArrayList() + val verifiedOptions = ArrayList() + val verifiedOptionsValues = ArrayList() - val hasDownloadSupport = api.hasDownloadSupport + val hasDownloadSupport = api.hasDownloadSupport - for (i in options.indices) { - val opv = optionsValues[i] - val op = options[i] + for (i in options.indices) { + val opv = optionsValues[i] + val op = options[i] - val isConnected = requireContext().isConnectedToChromecast() - val add = when (opv) { - ACTION_CHROME_CAST_EPISODE -> isConnected - ACTION_CHROME_CAST_MIRROR -> isConnected - ACTION_DOWNLOAD_EPISODE -> hasDownloadSupport - ACTION_DOWNLOAD_MIRROR -> hasDownloadSupport - ACTION_PLAY_EPISODE_IN_VLC_PLAYER -> context?.isAppInstalled(VLC_PACKAGE) ?: false - else -> true + val isConnected = ctx.isConnectedToChromecast() + val add = when (opv) { + ACTION_CHROME_CAST_EPISODE -> isConnected + ACTION_CHROME_CAST_MIRROR -> isConnected + ACTION_DOWNLOAD_EPISODE -> hasDownloadSupport + ACTION_DOWNLOAD_MIRROR -> hasDownloadSupport + ACTION_PLAY_EPISODE_IN_VLC_PLAYER -> context?.isAppInstalled(VLC_PACKAGE) ?: false + else -> true + } + if (add) { + verifiedOptions.add(op) + verifiedOptionsValues.add(opv) + } } - if (add) { - verifiedOptions.add(op) - verifiedOptionsValues.add(opv) + + builder.setItems( + verifiedOptions.toTypedArray() + ) { _, which -> + handleAction(EpisodeClickEvent(verifiedOptionsValues[which], episodeClick.data)) + dialog?.dismiss() } - } - builder.setItems( - verifiedOptions.toTypedArray() - ) { _, which -> - handleAction(EpisodeClickEvent(verifiedOptionsValues[which], episodeClick.data)) - dialog?.dismiss() + dialog = builder.create() + dialog.show() } - - dialog = builder.create() - dialog.show() } ACTION_COPY_LINK -> { - acquireSingeExtractorLink(getString(R.string.episode_action_copy_link)) { link -> - val serviceClipboard = - (requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?) - ?: return@acquireSingeExtractorLink - val clip = ClipData.newPlainText(link.name, link.url) - serviceClipboard.setPrimaryClip(clip) - showToast(activity, R.string.copy_link_toast, Toast.LENGTH_SHORT) + activity?.let { act -> + acquireSingeExtractorLink(act.getString(R.string.episode_action_copy_link)) { link -> + val serviceClipboard = + (act.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?) + ?: return@acquireSingeExtractorLink + val clip = ClipData.newPlainText(link.name, link.url) + serviceClipboard.setPrimaryClip(clip) + showToast(act, R.string.copy_link_toast, Toast.LENGTH_SHORT) + } } } @@ -638,7 +642,7 @@ class ResultFragment : Fragment() { val data = currentLinks ?: return@main val subs = currentSubs - val outputDir = requireContext().cacheDir + val outputDir = act.cacheDir val outputFile = withContext(Dispatchers.IO) { File.createTempFile("mirrorlist", ".m3u8", outputDir) } @@ -682,7 +686,7 @@ class ResultFragment : Fragment() { vlcIntent.putExtra("position", position) vlcIntent.component = VLC_COMPONENT - requireContext().setKey(VLC_LAST_ID_KEY, episodeClick.data.id) + act.setKey(VLC_LAST_ID_KEY, episodeClick.data.id) act.startActivityForResult(vlcIntent, VLC_REQUEST_CODE) } } @@ -939,7 +943,8 @@ class ResultFragment : Fragment() { } result_descript.setOnClickListener { val builder: AlertDialog.Builder = AlertDialog.Builder(requireContext()) - builder.setMessage(d.plot).setTitle( if (d.type == TvType.Torrent) R.string.torrent_plot else R.string.result_plot) + builder.setMessage(d.plot) + .setTitle(if (d.type == TvType.Torrent) R.string.torrent_plot else R.string.result_plot) .show() } result_descript.text = syno @@ -981,8 +986,7 @@ class ResultFragment : Fragment() { handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card)) return@setOnLongClickListener true } - - + // result_options.setOnClickListener { // val card = currentEpisodes?.first() ?: return@setOnClickListener // handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card)) @@ -1072,7 +1076,7 @@ class ResultFragment : Fragment() { val tempUrl = url if (tempUrl != null) { result_reload_connectionerror.setOnClickListener { - viewModel.load(requireContext(), tempUrl, apiName) + viewModel.load(it.context, tempUrl, apiName) } result_reload_connection_open_in_browser.setOnClickListener { @@ -1085,8 +1089,11 @@ class ResultFragment : Fragment() { } } - if (viewModel.resultResponse.value == null) - viewModel.load(requireContext(), tempUrl, apiName) + if (viewModel.resultResponse.value == null) { + context?.let { ctx -> + viewModel.load(ctx, tempUrl, apiName) + } + } } } } \ No newline at end of file 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 b415fa87..12c4c4f0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt @@ -226,6 +226,8 @@ object VideoDownloadManager { progress: Long, total: Long, ) { + if(total <= 0) return // crash, invalid data + main { // DON'T WANT TO SLOW IT DOWN val builder = NotificationCompat.Builder(context, DOWNLOAD_CHANNEL_ID) .setAutoCancel(true)