From aa146c7b987ac208d4e652e2bc3d7bbf55d772b1 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Sun, 6 Feb 2022 15:53:39 +0100 Subject: [PATCH] made movie download nice --- .../animeproviders/AllAnimeProvider.kt | 17 +-- .../ui/download/EasyDownloadButton.kt | 93 ++++++++++++--- .../cloudstream3/ui/result/ResultFragment.kt | 62 +++++++++- app/src/main/res/drawable/circle_shape.xml | 2 +- app/src/main/res/layout/fragment_result.xml | 110 +++++++++++++++--- 5 files changed, 242 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AllAnimeProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AllAnimeProvider.kt index 606cdc46..92190439 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AllAnimeProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AllAnimeProvider.kt @@ -177,13 +177,14 @@ class AllAnimeProvider : MainAPI() { Pair(Actor(name, img), role) } - val recommendations = soup.select("#suggesction > div > div.p > .swipercard")?.mapNotNull { - val recTitle = it?.selectFirst(".showname > a") ?: return@mapNotNull null - val recName = recTitle.text() ?: return@mapNotNull null - val href = fixUrlNull(recTitle.attr("href")) ?: return@mapNotNull null - val img = it.selectFirst(".image > img").attr("src") ?: return@mapNotNull null - AnimeSearchResponse(recName, href, this.name, TvType.Anime, img) - } + // bruh, they use graphql + //val recommendations = soup.select("#suggesction > div > div.p > .swipercard")?.mapNotNull { + // val recTitle = it?.selectFirst(".showname > a") ?: return@mapNotNull null + // val recName = recTitle.text() ?: return@mapNotNull null + // val href = fixUrlNull(recTitle.attr("href")) ?: return@mapNotNull null + // val img = it.selectFirst(".image > img").attr("src") ?: return@mapNotNull null + // AnimeSearchResponse(recName, href, this.name, TvType.Anime, img) + //} return newAnimeLoadResponse(title, url, TvType.Anime) { posterUrl = poster @@ -192,7 +193,7 @@ class AllAnimeProvider : MainAPI() { addEpisodes(DubStatus.Subbed, episodes.first) addEpisodes(DubStatus.Dubbed, episodes.second) addActors(characters) - this.recommendations = recommendations + //this.recommendations = recommendations showStatus = getStatus(showData.status.toString()) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/EasyDownloadButton.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/EasyDownloadButton.kt index 242a7ed1..b0ad8e54 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/EasyDownloadButton.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/EasyDownloadButton.kt @@ -5,6 +5,8 @@ import android.view.View import android.view.animation.DecelerateInterpolator import android.widget.ImageView import android.widget.TextView +import androidx.core.view.isGone +import androidx.core.view.isVisible import androidx.core.widget.ContentLoadingProgressBar import com.google.android.material.button.MaterialButton import com.lagradost.cloudstream3.R @@ -28,7 +30,8 @@ class EasyDownloadButton : IDisposable { } private var downloadProgressEventListener: ((Triple) -> Unit)? = null - private var downloadStatusEventListener: ((Pair) -> Unit)? = null + private var downloadStatusEventListener: ((Pair) -> Unit)? = + null fun setUpMaterialButton( setupCurrentBytes: Long?, @@ -39,10 +42,47 @@ class EasyDownloadButton : IDisposable { data: IMinimumData, clickCallback: (DownloadClickEvent) -> Unit, ) { - setUpDownloadButton(setupCurrentBytes, setupTotalBytes, progressBar, textView, data, downloadButton, { - downloadButton.setIconResource(it.first) - downloadButton.text = it.second - }, clickCallback) + setUpDownloadButton( + setupCurrentBytes, + setupTotalBytes, + progressBar, + textView, + data, + downloadButton, + { + downloadButton.setIconResource(it.first) + downloadButton.text = it.second + }, + clickCallback + ) + } + + fun setUpMoreButton( + setupCurrentBytes: Long?, + setupTotalBytes: Long?, + progressBar: ContentLoadingProgressBar, + downloadImage: ImageView, + textView: TextView?, + textViewProgress: TextView?, + clickableView: View, + isTextPercentage: Boolean, + data: IMinimumData, + clickCallback: (DownloadClickEvent) -> Unit, + ) { + setUpDownloadButton( + setupCurrentBytes, + setupTotalBytes, + progressBar, + textViewProgress, + data, + clickableView, + { (image, text) -> + downloadImage.isVisible = textViewProgress?.isGone ?: true + downloadImage.setImageResource(image) + textView?.text = text + }, + clickCallback, isTextPercentage + ) } fun setUpButton( @@ -54,9 +94,18 @@ class EasyDownloadButton : IDisposable { data: IMinimumData, clickCallback: (DownloadClickEvent) -> Unit, ) { - setUpDownloadButton(setupCurrentBytes, setupTotalBytes, progressBar, textView, data, downloadImage, { - downloadImage.setImageResource(it.first) - }, clickCallback) + setUpDownloadButton( + setupCurrentBytes, + setupTotalBytes, + progressBar, + textView, + data, + downloadImage, + { + downloadImage.setImageResource(it.first) + }, + clickCallback + ) } private fun setUpDownloadButton( @@ -68,11 +117,12 @@ class EasyDownloadButton : IDisposable { downloadView: View, downloadImageChangeCallback: (Pair) -> Unit, clickCallback: (DownloadClickEvent) -> Unit, + isTextPercentage: Boolean = false ) { var lastState: VideoDownloadManager.DownloadType? = null var currentBytes = setupCurrentBytes ?: 0 var totalBytes = setupTotalBytes ?: 0 - var needImageUpdate = false + var needImageUpdate = true fun changeDownloadImage(state: VideoDownloadManager.DownloadType) { lastState = state @@ -92,7 +142,12 @@ class EasyDownloadButton : IDisposable { } else { Pair(R.drawable.netflix_download, R.string.download) } - downloadImageChangeCallback.invoke(Pair(img.first, downloadView.context.getString(img.second))) + downloadImageChangeCallback.invoke( + Pair( + img.first, + downloadView.context.getString(img.second) + ) + ) } fun fixDownloadedBytes(setCurrentBytes: Long, setTotalBytes: Long, animate: Boolean) { @@ -113,7 +168,9 @@ class EasyDownloadButton : IDisposable { val totalMbString = "%.1f".format(setTotalBytes / 1000000f) textView?.text = - textView?.context?.getString(R.string.download_size_format)?.format(currentMbString, totalMbString) + if (isTextPercentage) "%d%%".format(setCurrentBytes * 100L / setTotalBytes) else + textView?.context?.getString(R.string.download_size_format) + ?.format(currentMbString, totalMbString) progressBar.let { bar -> bar.max = (setTotalBytes / 1000).toInt() @@ -144,20 +201,22 @@ class EasyDownloadButton : IDisposable { if (downloadData.second != currentBytes || downloadData.third != totalBytes) { // TO PREVENT WASTING UI TIME Coroutines.runOnMainThread { fixDownloadedBytes(downloadData.second, downloadData.third, true) + changeDownloadImage(VideoDownloadManager.getDownloadState(data.id)) } } } } - downloadStatusEventListener = { downloadData: Pair -> - if (data.id == downloadData.first) { - if (lastState != downloadData.second || needImageUpdate) { // TO PREVENT WASTING UI TIME - Coroutines.runOnMainThread { - changeDownloadImage(downloadData.second) + downloadStatusEventListener = + { downloadData: Pair -> + if (data.id == downloadData.first) { + if (lastState != downloadData.second || needImageUpdate) { // TO PREVENT WASTING UI TIME + Coroutines.runOnMainThread { + changeDownloadImage(downloadData.second) + } } } } - } downloadProgressEventListener?.let { VideoDownloadManager.downloadProgressEvent += it } downloadStatusEventListener?.let { VideoDownloadManager.downloadStatusEvent += it } 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 f1bd253c..15ad6afb 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 @@ -486,7 +486,7 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio setFormatText(result_meta_duration, R.string.duration_format, duration) } - private fun setShow(showStatus : ShowStatus?) { + private fun setShow(showStatus: ShowStatus?) { val status = when (showStatus) { null -> null ShowStatus.Ongoing -> R.string.status_ongoing @@ -1439,12 +1439,15 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio ) downloadButton?.dispose() downloadButton = EasyDownloadButton() - downloadButton?.setUpMaterialButton( + downloadButton?.setUpMoreButton( file?.fileLength, file?.totalBytes, result_movie_progress_downloaded, + result_movie_download_icon, + result_movie_download_text, + result_movie_download_text_precentage, result_download_movie, - result_movie_text_progress, + true, VideoDownloadHelper.DownloadEpisodeCached( d.name, d.posterUrl, @@ -1491,6 +1494,59 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio ) } } + + /*downloadButton?.setUpMaterialButton( + file?.fileLength, + file?.totalBytes, + result_movie_progress_downloaded, + result_download_movie, + null, //result_movie_text_progress + VideoDownloadHelper.DownloadEpisodeCached( + d.name, + d.posterUrl, + 0, + null, + localId, + localId, + d.rating, + d.plot, + System.currentTimeMillis(), + ) + ) { downloadClickEvent -> + if (downloadClickEvent.action == DOWNLOAD_ACTION_DOWNLOAD) { + currentEpisodes?.firstOrNull()?.let { episode -> + handleAction( + EpisodeClickEvent( + ACTION_DOWNLOAD_EPISODE, + ResultEpisode( + d.name, + d.name, + null, + 0, + null, + episode.data, + d.apiName, + localId, + 0, + 0L, + 0L, + null, + null, + null, + d.type, + localId, + ) + ) + ) + } + } else { + handleDownloadClick( + activity, + currentHeaderName, + downloadClickEvent + ) + } + }*/ } } else { lateFixDownloadButton(false) diff --git a/app/src/main/res/drawable/circle_shape.xml b/app/src/main/res/drawable/circle_shape.xml index 56b8e4ef..aa2000d4 100644 --- a/app/src/main/res/drawable/circle_shape.xml +++ b/app/src/main/res/drawable/circle_shape.xml @@ -6,6 +6,6 @@ android:thickness="2dp" android:useLevel="false"> - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_result.xml b/app/src/main/res/layout/fragment_result.xml index 8e54558f..a98643fe 100644 --- a/app/src/main/res/layout/fragment_result.xml +++ b/app/src/main/res/layout/fragment_result.xml @@ -471,7 +471,7 @@ style="@style/WhiteButton" /> - + android:layout_width="match_parent" />--> - + + + + + + + + + + + + + + + + + +