forked from recloudstream/cloudstream
download movie UI
This commit is contained in:
parent
77778bdbb6
commit
de149172bc
6 changed files with 190 additions and 29 deletions
|
@ -47,6 +47,11 @@ object APIHolder {
|
||||||
return apis[defProvider]
|
return apis[defProvider]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun LoadResponse.getId(): Int {
|
||||||
|
return url.replace(getApiFromName(apiName).mainUrl, "").hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
fun Activity.getApiSettings(): HashSet<String> {
|
fun Activity.getApiSettings(): HashSet<String> {
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
|
||||||
|
@ -150,7 +155,7 @@ enum class TvType {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IN CASE OF FUTURE ANIME MOVIE OR SMTH
|
// IN CASE OF FUTURE ANIME MOVIE OR SMTH
|
||||||
fun TvType.isMovieType() : Boolean {
|
fun TvType.isMovieType(): Boolean {
|
||||||
return this == TvType.Movie
|
return this == TvType.Movie
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,8 @@ class DubbedAnimeProvider : MainAPI() {
|
||||||
val url =
|
val url =
|
||||||
mainUrl + (if (isMovie) "/movies/jsonMovie" else "/xz/v3/jsonEpi") + ".php?slug=$slug&_=$unixTime"
|
mainUrl + (if (isMovie) "/movies/jsonMovie" else "/xz/v3/jsonEpi") + ".php?slug=$slug&_=$unixTime"
|
||||||
val response = khttp.get(url)
|
val response = khttp.get(url)
|
||||||
val mapped = response.let { mapper.readValue<QueryEpisodeResultRoot>(it.text) }
|
println(response.text)
|
||||||
|
val mapped = mapper.readValue<QueryEpisodeResultRoot>(response.text)
|
||||||
|
|
||||||
return mapped.result.anime.first()
|
return mapped.result.anime.first()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.widget.TextView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.widget.ContentLoadingProgressBar
|
import androidx.core.widget.ContentLoadingProgressBar
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.UIHelper.popupMenuNoIcons
|
import com.lagradost.cloudstream3.UIHelper.popupMenuNoIcons
|
||||||
import com.lagradost.cloudstream3.ui.player.PlayerFragment
|
import com.lagradost.cloudstream3.ui.player.PlayerFragment
|
||||||
|
@ -95,13 +96,14 @@ object DownloadButtonSetup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setUpButton(
|
fun setUpDownloadButton(
|
||||||
setupCurrentBytes: Long?,
|
setupCurrentBytes: Long?,
|
||||||
setupTotalBytes: Long?,
|
setupTotalBytes: Long?,
|
||||||
progressBar: ContentLoadingProgressBar,
|
progressBar: ContentLoadingProgressBar,
|
||||||
downloadImage: ImageView,
|
|
||||||
textView: TextView?,
|
textView: TextView?,
|
||||||
data: VideoDownloadHelper.DownloadEpisodeCached,
|
data: VideoDownloadHelper.DownloadEpisodeCached,
|
||||||
|
downloadView: View,
|
||||||
|
downloadImageChangeCallback: (Pair<Int, String>) -> Unit,
|
||||||
clickCallback: (DownloadClickEvent) -> Unit,
|
clickCallback: (DownloadClickEvent) -> Unit,
|
||||||
) {
|
) {
|
||||||
var lastState: VideoDownloadManager.DownloadType? = null
|
var lastState: VideoDownloadManager.DownloadType? = null
|
||||||
|
@ -112,12 +114,19 @@ object DownloadButtonSetup {
|
||||||
fun changeDownloadImage(state: VideoDownloadManager.DownloadType) {
|
fun changeDownloadImage(state: VideoDownloadManager.DownloadType) {
|
||||||
lastState = state
|
lastState = state
|
||||||
if (currentBytes <= 0) needImageUpdate = true
|
if (currentBytes <= 0) needImageUpdate = true
|
||||||
val img = if (currentBytes > 0) when (state) {
|
val img = if (currentBytes > 0) {
|
||||||
VideoDownloadManager.DownloadType.IsPaused -> R.drawable.ic_baseline_play_arrow_24
|
when (state) {
|
||||||
VideoDownloadManager.DownloadType.IsDownloading -> R.drawable.netflix_pause
|
VideoDownloadManager.DownloadType.IsPaused -> Pair(
|
||||||
else -> R.drawable.ic_baseline_delete_outline_24
|
R.drawable.ic_baseline_play_arrow_24,
|
||||||
} else R.drawable.netflix_download
|
"Download Paused"
|
||||||
downloadImage?.setImageResource(img)
|
)
|
||||||
|
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")
|
@SuppressLint("SetTextI18n")
|
||||||
|
@ -185,7 +194,7 @@ object DownloadButtonSetup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadImage.setOnClickListener {
|
downloadView.setOnClickListener {
|
||||||
if (currentBytes <= 0) {
|
if (currentBytes <= 0) {
|
||||||
clickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_DOWNLOAD, data))
|
clickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_DOWNLOAD, data))
|
||||||
} else {
|
} 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)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ import com.google.android.gms.cast.framework.CastState
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.lagradost.cloudstream3.*
|
import com.lagradost.cloudstream3.*
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
||||||
|
import com.lagradost.cloudstream3.APIHolder.getId
|
||||||
import com.lagradost.cloudstream3.UIHelper.checkWrite
|
import com.lagradost.cloudstream3.UIHelper.checkWrite
|
||||||
import com.lagradost.cloudstream3.UIHelper.colorFromAttribute
|
import com.lagradost.cloudstream3.UIHelper.colorFromAttribute
|
||||||
import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar
|
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.WatchType
|
||||||
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
|
||||||
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
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.PlayerData
|
||||||
import com.lagradost.cloudstream3.ui.player.PlayerFragment
|
import com.lagradost.cloudstream3.ui.player.PlayerFragment
|
||||||
import com.lagradost.cloudstream3.utils.*
|
import com.lagradost.cloudstream3.utils.*
|
||||||
|
@ -825,9 +828,62 @@ class ResultFragment : Fragment() {
|
||||||
val card = currentEpisodes?.first() ?: return@setOnClickListener
|
val card = currentEpisodes?.first() ?: return@setOnClickListener
|
||||||
handleAction(EpisodeClickEvent(ACTION_CLICK_DEFAULT, card))
|
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))
|
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 {
|
} else {
|
||||||
result_movie_parent.visibility = GONE
|
result_movie_parent.visibility = GONE
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||||
import androidx.lifecycle.*
|
import androidx.lifecycle.*
|
||||||
import com.lagradost.cloudstream3.*
|
import com.lagradost.cloudstream3.*
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
||||||
|
import com.lagradost.cloudstream3.APIHolder.getId
|
||||||
import com.lagradost.cloudstream3.mvvm.Resource
|
import com.lagradost.cloudstream3.mvvm.Resource
|
||||||
import com.lagradost.cloudstream3.mvvm.safeApiCall
|
import com.lagradost.cloudstream3.mvvm.safeApiCall
|
||||||
import com.lagradost.cloudstream3.ui.WatchType
|
import com.lagradost.cloudstream3.ui.WatchType
|
||||||
|
@ -107,7 +108,7 @@ class ResultViewModel : ViewModel() {
|
||||||
val d = data.value
|
val d = data.value
|
||||||
if (d is LoadResponse) {
|
if (d is LoadResponse) {
|
||||||
page.postValue(d)
|
page.postValue(d)
|
||||||
val mainId = getId(d.url, api)
|
val mainId = d.getId()
|
||||||
id.postValue(mainId)
|
id.postValue(mainId)
|
||||||
loadWatchStatus(context, mainId)
|
loadWatchStatus(context, mainId)
|
||||||
|
|
||||||
|
|
|
@ -287,6 +287,7 @@
|
||||||
|
|
||||||
</com.lagradost.cloudstream3.widget.FlowLayout>
|
</com.lagradost.cloudstream3.widget.FlowLayout>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:id="@+id/result_movie_parent"
|
android:id="@+id/result_movie_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -297,47 +298,106 @@
|
||||||
app:cornerRadius="4dp"
|
app:cornerRadius="4dp"
|
||||||
android:id="@+id/result_play_movie"
|
android:id="@+id/result_play_movie"
|
||||||
android:text="@string/play_movie_button"
|
android:text="@string/play_movie_button"
|
||||||
|
android:textStyle="bold"
|
||||||
|
|
||||||
app:rippleColor="?attr/textColor"
|
app:rippleColor="?attr/grayBackground"
|
||||||
android:textColor="?attr/textColor"
|
android:textColor="?attr/grayBackground"
|
||||||
app:iconTint="?attr/textColor"
|
app:iconTint="?attr/grayBackground"
|
||||||
android:textAllCaps="false"
|
android:textAllCaps="false"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
|
|
||||||
app:iconGravity="textStart"
|
app:iconGravity="textStart"
|
||||||
app:strokeColor="?attr/textColor"
|
app:strokeColor="?attr/grayBackground"
|
||||||
|
app:backgroundTint="?attr/textColor"
|
||||||
app:icon="@drawable/ic_baseline_play_arrow_24"
|
app:icon="@drawable/ic_baseline_play_arrow_24"
|
||||||
android:backgroundTint="@color/transparent"
|
|
||||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="45dp">
|
android:layout_height="50dp">
|
||||||
</com.google.android.material.button.MaterialButton>
|
</com.google.android.material.button.MaterialButton>
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
app:cornerRadius="4dp"
|
app:cornerRadius="4dp"
|
||||||
android:id="@+id/result_options"
|
tools:text="Downloading"
|
||||||
android:text="@string/options"
|
tools:icon="@drawable/netflix_download"
|
||||||
|
android:textStyle="bold"
|
||||||
|
|
||||||
|
android:id="@+id/result_download_movie"
|
||||||
app:rippleColor="?attr/textColor"
|
app:rippleColor="?attr/textColor"
|
||||||
android:textColor="?attr/textColor"
|
android:textColor="?attr/textColor"
|
||||||
app:iconTint="?attr/textColor"
|
app:iconTint="?attr/textColor"
|
||||||
android:textAllCaps="false"
|
android:textAllCaps="false"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
|
android:backgroundTint="?attr/grayBackground"
|
||||||
app:iconGravity="textStart"
|
app:iconGravity="textStart"
|
||||||
app:strokeColor="?attr/textColor"
|
app:strokeColor="?attr/textColor"
|
||||||
app:icon="@drawable/ic_baseline_play_arrow_24"
|
|
||||||
android:backgroundTint="@color/transparent"
|
|
||||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="45dp">
|
android:layout_height="50dp">
|
||||||
</com.google.android.material.button.MaterialButton>
|
</com.google.android.material.button.MaterialButton>
|
||||||
|
|
||||||
|
<androidx.core.widget.ContentLoadingProgressBar
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
tools:progress="50"
|
||||||
|
android:id="@+id/result_movie_progress_downloaded"
|
||||||
|
android:indeterminate="false"
|
||||||
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
|
android:max="100"
|
||||||
|
android:layout_gravity="end|center_vertical"
|
||||||
|
android:progress="0"
|
||||||
|
android:visibility="visible"
|
||||||
|
tools:visibility="visible"/>
|
||||||
|
<!--
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="40dp">
|
||||||
|
<androidx.core.widget.ContentLoadingProgressBar
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/result_movie_download"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:paddingEnd="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
tools:progress="50"
|
||||||
|
android:id="@+id/result_movie_progress_downloaded"
|
||||||
|
android:indeterminate="false"
|
||||||
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
|
android:max="100"
|
||||||
|
android:layout_gravity="end|center_vertical"
|
||||||
|
android:progress="0"
|
||||||
|
android:visibility="visible"
|
||||||
|
tools:visibility="gone"
|
||||||
|
tools:ignore="RtlSymmetry"/>
|
||||||
|
<ImageView
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
android:visibility="visible"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_columnWeight="1"
|
||||||
|
android:layout_gravity="end|center_vertical"
|
||||||
|
android:padding="2dp"
|
||||||
|
android:id="@+id/result_movie_download"
|
||||||
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
|
android:src="@drawable/ic_baseline_play_arrow_24"
|
||||||
|
android:contentDescription="@string/download_descript"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"/>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
-->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/result_movie_text_progress"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
tools:text="128MB / 237MB"
|
||||||
|
android:textColor="@color/grayTextColor"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
</TextView>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout android:orientation="horizontal" android:gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content">
|
<LinearLayout android:orientation="horizontal" android:gravity="center_vertical"
|
||||||
|
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
|
Loading…
Reference in a new issue