diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index c010ec12..30c037bd 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -47,6 +47,11 @@ object APIHolder { return apis[defProvider] } + + fun LoadResponse.getId(): Int { + return url.replace(getApiFromName(apiName).mainUrl, "").hashCode() + } + fun Activity.getApiSettings(): HashSet { val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) @@ -150,7 +155,7 @@ enum class TvType { } // IN CASE OF FUTURE ANIME MOVIE OR SMTH -fun TvType.isMovieType() : Boolean { +fun TvType.isMovieType(): Boolean { return this == TvType.Movie } diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/DubbedAnimeProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/DubbedAnimeProvider.kt index a9a8a91d..3cd5d2f5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/DubbedAnimeProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/DubbedAnimeProvider.kt @@ -55,7 +55,8 @@ class DubbedAnimeProvider : MainAPI() { val url = mainUrl + (if (isMovie) "/movies/jsonMovie" else "/xz/v3/jsonEpi") + ".php?slug=$slug&_=$unixTime" val response = khttp.get(url) - val mapped = response.let { mapper.readValue(it.text) } + println(response.text) + val mapped = mapper.readValue(response.text) return mapped.result.anime.first() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt index af35652a..42024a9c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt @@ -11,6 +11,7 @@ import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.core.widget.ContentLoadingProgressBar import androidx.fragment.app.FragmentActivity +import com.google.android.material.button.MaterialButton import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.UIHelper.popupMenuNoIcons import com.lagradost.cloudstream3.ui.player.PlayerFragment @@ -95,13 +96,14 @@ object DownloadButtonSetup { } } - fun setUpButton( + fun setUpDownloadButton( setupCurrentBytes: Long?, setupTotalBytes: Long?, progressBar: ContentLoadingProgressBar, - downloadImage: ImageView, textView: TextView?, data: VideoDownloadHelper.DownloadEpisodeCached, + downloadView: View, + downloadImageChangeCallback: (Pair) -> Unit, clickCallback: (DownloadClickEvent) -> Unit, ) { var lastState: VideoDownloadManager.DownloadType? = null @@ -112,12 +114,19 @@ object DownloadButtonSetup { fun changeDownloadImage(state: VideoDownloadManager.DownloadType) { lastState = state if (currentBytes <= 0) needImageUpdate = true - val img = if (currentBytes > 0) when (state) { - VideoDownloadManager.DownloadType.IsPaused -> R.drawable.ic_baseline_play_arrow_24 - VideoDownloadManager.DownloadType.IsDownloading -> R.drawable.netflix_pause - else -> R.drawable.ic_baseline_delete_outline_24 - } else R.drawable.netflix_download - downloadImage?.setImageResource(img) + val img = if (currentBytes > 0) { + when (state) { + VideoDownloadManager.DownloadType.IsPaused -> Pair( + R.drawable.ic_baseline_play_arrow_24, + "Download Paused" + ) + VideoDownloadManager.DownloadType.IsDownloading -> Pair(R.drawable.netflix_pause, "Downloading") + else -> Pair(R.drawable.ic_baseline_delete_outline_24, "Downloaded") + } + } else { + Pair(R.drawable.netflix_download, "Download") + } + downloadImageChangeCallback.invoke(img) } @SuppressLint("SetTextI18n") @@ -185,7 +194,7 @@ object DownloadButtonSetup { } } - downloadImage.setOnClickListener { + downloadView.setOnClickListener { if (currentBytes <= 0) { clickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_DOWNLOAD, data)) } else { @@ -212,4 +221,33 @@ object DownloadButtonSetup { } } } + + fun setUpMaterialButton( + setupCurrentBytes: Long?, + setupTotalBytes: Long?, + progressBar: ContentLoadingProgressBar, + downloadButton: MaterialButton, + textView: TextView?, + data: VideoDownloadHelper.DownloadEpisodeCached, + clickCallback: (DownloadClickEvent) -> Unit, + ) { + setUpDownloadButton(setupCurrentBytes, setupTotalBytes, progressBar, textView, data, downloadButton, { + downloadButton?.setIconResource(it.first) + downloadButton?.text = it.second + }, clickCallback) + } + + fun setUpButton( + setupCurrentBytes: Long?, + setupTotalBytes: Long?, + progressBar: ContentLoadingProgressBar, + downloadImage: ImageView, + textView: TextView?, + data: VideoDownloadHelper.DownloadEpisodeCached, + clickCallback: (DownloadClickEvent) -> Unit, + ) { + setUpDownloadButton(setupCurrentBytes, setupTotalBytes, progressBar, textView, data, downloadImage, { + downloadImage?.setImageResource(it.first) + }, clickCallback) + } } \ No newline at end of file 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 68311fe3..bcdfc411 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 @@ -33,6 +33,7 @@ import com.google.android.gms.cast.framework.CastState import com.google.android.material.button.MaterialButton import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.APIHolder.getApiFromName +import com.lagradost.cloudstream3.APIHolder.getId import com.lagradost.cloudstream3.UIHelper.checkWrite import com.lagradost.cloudstream3.UIHelper.colorFromAttribute import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar @@ -49,6 +50,8 @@ import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.ui.WatchType import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick +import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.setUpButton +import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.setUpMaterialButton import com.lagradost.cloudstream3.ui.player.PlayerData import com.lagradost.cloudstream3.ui.player.PlayerFragment import com.lagradost.cloudstream3.utils.* @@ -825,9 +828,62 @@ class ResultFragment : Fragment() { val card = currentEpisodes?.first() ?: return@setOnClickListener handleAction(EpisodeClickEvent(ACTION_CLICK_DEFAULT, card)) } - result_options.setOnClickListener { - val card = currentEpisodes?.first() ?: return@setOnClickListener + + result_play_movie.setOnLongClickListener { + val card = currentEpisodes?.first() ?: return@setOnLongClickListener true handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card)) + return@setOnLongClickListener true + } + +// result_options.setOnClickListener { +// val card = currentEpisodes?.first() ?: return@setOnClickListener +// handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card)) +// } + + val localId = d.getId() + val file = + VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(requireContext(), localId) + + setUpMaterialButton( + file?.fileLength, + file?.totalBytes, + result_movie_progress_downloaded, + result_download_movie, + result_movie_text_progress, + VideoDownloadHelper.DownloadEpisodeCached( + d.name, + d.posterUrl, + 0, + null, + localId, + localId, + d.rating, + d.plot + ) + ) { downloadClickEvent -> + if (downloadClickEvent.action == DOWNLOAD_ACTION_DOWNLOAD) { + handleAction( + EpisodeClickEvent( + ACTION_DOWNLOAD_EPISODE, + ResultEpisode( + d.name, + null, + 0, + null, + d.dataUrl, + d.apiName, + localId, + 0, + 0L, + 0L, + null, + null + ) + ) + ) + } else { + handleDownloadClick(activity, currentHeaderName, downloadClickEvent) + } } } else { result_movie_parent.visibility = GONE diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt index 0a222b5c..ba1d07b5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt @@ -4,6 +4,7 @@ import android.content.Context import androidx.lifecycle.* import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.APIHolder.getApiFromName +import com.lagradost.cloudstream3.APIHolder.getId import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.safeApiCall import com.lagradost.cloudstream3.ui.WatchType @@ -107,7 +108,7 @@ class ResultViewModel : ViewModel() { val d = data.value if (d is LoadResponse) { page.postValue(d) - val mainId = getId(d.url, api) + val mainId = d.getId() id.postValue(mainId) loadWatchStatus(context, mainId) diff --git a/app/src/main/res/layout/fragment_result.xml b/app/src/main/res/layout/fragment_result.xml index ae7b7c27..dff6a855 100644 --- a/app/src/main/res/layout/fragment_result.xml +++ b/app/src/main/res/layout/fragment_result.xml @@ -287,6 +287,7 @@ + android:layout_height="50dp"> + android:layout_height="50dp"> + + + + - +