forked from recloudstream/cloudstream
made movie download nice
This commit is contained in:
parent
765aa7c5af
commit
aa146c7b98
5 changed files with 242 additions and 42 deletions
|
@ -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())
|
||||
|
||||
|
|
|
@ -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<Int, Long, Long>) -> Unit)? = null
|
||||
private var downloadStatusEventListener: ((Pair<Int, VideoDownloadManager.DownloadType>) -> Unit)? = null
|
||||
private var downloadStatusEventListener: ((Pair<Int, VideoDownloadManager.DownloadType>) -> 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<Int, String>) -> 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<Int, VideoDownloadManager.DownloadType> ->
|
||||
if (data.id == downloadData.first) {
|
||||
if (lastState != downloadData.second || needImageUpdate) { // TO PREVENT WASTING UI TIME
|
||||
Coroutines.runOnMainThread {
|
||||
changeDownloadImage(downloadData.second)
|
||||
downloadStatusEventListener =
|
||||
{ downloadData: Pair<Int, VideoDownloadManager.DownloadType> ->
|
||||
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 }
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
android:thickness="2dp"
|
||||
android:useLevel="false">
|
||||
|
||||
<solid android:color="#CCC" />
|
||||
<solid android:color="?attr/white" />
|
||||
|
||||
</shape>
|
|
@ -471,7 +471,7 @@
|
|||
style="@style/WhiteButton" />
|
||||
|
||||
<LinearLayout
|
||||
tools:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
android:layout_marginTop="5dp"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/result_movie_parent"
|
||||
|
@ -493,7 +493,8 @@
|
|||
app:icon="@drawable/ic_baseline_play_arrow_24"
|
||||
android:layout_width="match_parent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
|
||||
<!--<com.google.android.material.button.MaterialButton
|
||||
android:nextFocusUp="@id/result_play_movie"
|
||||
android:nextFocusDown="@id/result_season_button"
|
||||
android:layout_marginBottom="10dp"
|
||||
|
@ -509,9 +510,92 @@
|
|||
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_width="match_parent" />
|
||||
android:layout_width="match_parent" />-->
|
||||
|
||||
<androidx.core.widget.ContentLoadingProgressBar
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:nextFocusUp="@id/result_play_movie"
|
||||
android:nextFocusDown="@id/result_season_button"
|
||||
|
||||
android:id="@+id/result_download_movie"
|
||||
style="@style/BlackButton"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:visibility="visible"
|
||||
android:layout_gravity="center_vertical"
|
||||
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_width="match_parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.core.widget.ContentLoadingProgressBar
|
||||
android:id="@+id/result_movie_progress_downloaded"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:indeterminate="false"
|
||||
android:progressDrawable="@drawable/circular_progress_bar_filled"
|
||||
android:background="@drawable/circle_shape"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:max="100"
|
||||
android:layout_margin="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingStart="5dp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:progress="30"
|
||||
android:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/result_movie_download_icon"
|
||||
app:tint="?attr/white"
|
||||
android:visibility="visible"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="30dp"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_baseline_play_arrow_24"
|
||||
android:contentDescription="@string/download" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/result_movie_download_text"
|
||||
android:letterSpacing="0.09"
|
||||
android:textColor="?attr/textColor"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:textAllCaps="false"
|
||||
tools:text="Downloading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:visibility="gone"
|
||||
android:id="@+id/result_movie_download_text_precentage"
|
||||
android:letterSpacing="0.09"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:textColor="?attr/textColor"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:textAllCaps="false"
|
||||
tools:text="68%"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
<!--<androidx.core.widget.ContentLoadingProgressBar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp"
|
||||
tools:progress="50"
|
||||
|
@ -524,15 +608,15 @@
|
|||
android:progress="0"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/result_movie_text_progress"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_vertical"
|
||||
tools:text="128MB / 237MB"
|
||||
android:textColor="?attr/grayTextColor"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />
|
||||
-->
|
||||
<!-- <TextView
|
||||
android:id="@+id/result_movie_text_progress"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_vertical"
|
||||
tools:text="128MB / 237MB"
|
||||
android:textColor="?attr/grayTextColor"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />-->
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
Loading…
Reference in a new issue