mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
redirected downloadbutton longclick
This commit is contained in:
parent
3ae44d5675
commit
9755bbacb9
2 changed files with 80 additions and 42 deletions
|
@ -13,6 +13,7 @@ import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.databinding.ResultEpisodeBinding
|
import com.lagradost.cloudstream3.databinding.ResultEpisodeBinding
|
||||||
import com.lagradost.cloudstream3.databinding.ResultEpisodeLargeBinding
|
import com.lagradost.cloudstream3.databinding.ResultEpisodeLargeBinding
|
||||||
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
|
||||||
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_LONG_CLICK
|
||||||
import com.lagradost.cloudstream3.ui.download.DownloadClickEvent
|
import com.lagradost.cloudstream3.ui.download.DownloadClickEvent
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||||
|
@ -93,13 +94,13 @@ class EpisodeAdapter(
|
||||||
diffResult.dispatchUpdatesTo(this)
|
diffResult.dispatchUpdatesTo(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getItem(position: Int) : ResultEpisode {
|
private fun getItem(position: Int): ResultEpisode {
|
||||||
return cardList[position]
|
return cardList[position]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
val item = getItem(position)
|
val item = getItem(position)
|
||||||
return if(item.poster.isNullOrBlank()) 0 else 1
|
return if (item.poster.isNullOrBlank()) 0 else 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,23 +111,33 @@ class EpisodeAdapter(
|
||||||
R.layout.result_episode_large
|
R.layout.result_episode_large
|
||||||
else R.layout.result_episode*/
|
else R.layout.result_episode*/
|
||||||
|
|
||||||
return when(viewType) {
|
return when (viewType) {
|
||||||
0 -> {
|
0 -> {
|
||||||
EpisodeCardViewHolderSmall(
|
EpisodeCardViewHolderSmall(
|
||||||
ResultEpisodeBinding.inflate(LayoutInflater.from(parent.context), parent, false),
|
ResultEpisodeBinding.inflate(
|
||||||
|
LayoutInflater.from(parent.context),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
),
|
||||||
hasDownloadSupport,
|
hasDownloadSupport,
|
||||||
clickCallback,
|
clickCallback,
|
||||||
downloadClickCallback
|
downloadClickCallback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
1 -> {
|
1 -> {
|
||||||
EpisodeCardViewHolderLarge(
|
EpisodeCardViewHolderLarge(
|
||||||
ResultEpisodeLargeBinding.inflate(LayoutInflater.from(parent.context), parent, false),
|
ResultEpisodeLargeBinding.inflate(
|
||||||
|
LayoutInflater.from(parent.context),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
),
|
||||||
hasDownloadSupport,
|
hasDownloadSupport,
|
||||||
clickCallback,
|
clickCallback,
|
||||||
downloadClickCallback
|
downloadClickCallback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> throw NotImplementedError()
|
else -> throw NotImplementedError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +147,7 @@ class EpisodeAdapter(
|
||||||
is EpisodeCardViewHolderLarge -> {
|
is EpisodeCardViewHolderLarge -> {
|
||||||
holder.bind(getItem(position))
|
holder.bind(getItem(position))
|
||||||
}
|
}
|
||||||
|
|
||||||
is EpisodeCardViewHolderSmall -> {
|
is EpisodeCardViewHolderSmall -> {
|
||||||
holder.bind(getItem(position))
|
holder.bind(getItem(position))
|
||||||
}
|
}
|
||||||
|
@ -148,7 +160,7 @@ class EpisodeAdapter(
|
||||||
|
|
||||||
class EpisodeCardViewHolderLarge
|
class EpisodeCardViewHolderLarge
|
||||||
constructor(
|
constructor(
|
||||||
val binding : ResultEpisodeLargeBinding,
|
val binding: ResultEpisodeLargeBinding,
|
||||||
private val hasDownloadSupport: Boolean,
|
private val hasDownloadSupport: Boolean,
|
||||||
private val clickCallback: (EpisodeClickEvent) -> Unit,
|
private val clickCallback: (EpisodeClickEvent) -> Unit,
|
||||||
private val downloadClickCallback: (DownloadClickEvent) -> Unit,
|
private val downloadClickCallback: (DownloadClickEvent) -> Unit,
|
||||||
|
@ -159,7 +171,8 @@ class EpisodeAdapter(
|
||||||
fun bind(card: ResultEpisode) {
|
fun bind(card: ResultEpisode) {
|
||||||
localCard = card
|
localCard = card
|
||||||
|
|
||||||
val setWidth = if(isTvSettings()) ViewGroup.LayoutParams.WRAP_CONTENT else ViewGroup.LayoutParams.MATCH_PARENT
|
val setWidth =
|
||||||
|
if (isTvSettings()) ViewGroup.LayoutParams.WRAP_CONTENT else ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
|
||||||
binding.episodeLinHolder.layoutParams.width = setWidth
|
binding.episodeLinHolder.layoutParams.width = setWidth
|
||||||
binding.episodeHolderLarge.layoutParams.width = setWidth
|
binding.episodeHolderLarge.layoutParams.width = setWidth
|
||||||
|
@ -169,7 +182,8 @@ class EpisodeAdapter(
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
downloadButton.isVisible = hasDownloadSupport
|
downloadButton.isVisible = hasDownloadSupport
|
||||||
downloadButton.setDefaultClickListener(VideoDownloadHelper.DownloadEpisodeCached(
|
downloadButton.setDefaultClickListener(
|
||||||
|
VideoDownloadHelper.DownloadEpisodeCached(
|
||||||
card.name,
|
card.name,
|
||||||
card.poster,
|
card.poster,
|
||||||
card.episode,
|
card.episode,
|
||||||
|
@ -179,13 +193,22 @@ class EpisodeAdapter(
|
||||||
card.rating,
|
card.rating,
|
||||||
card.description,
|
card.description,
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
), null) {
|
), null
|
||||||
if (it.action == DOWNLOAD_ACTION_DOWNLOAD) {
|
) {
|
||||||
|
when (it.action) {
|
||||||
|
DOWNLOAD_ACTION_DOWNLOAD -> {
|
||||||
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
|
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
DOWNLOAD_ACTION_LONG_CLICK -> {
|
||||||
|
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_MIRROR, card))
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
downloadClickCallback.invoke(it)
|
downloadClickCallback.invoke(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val name =
|
val name =
|
||||||
if (card.name == null) "${episodeText.context.getString(R.string.episode)} ${card.episode}" else "${card.episode}. ${card.name}"
|
if (card.name == null) "${episodeText.context.getString(R.string.episode)} ${card.episode}" else "${card.episode}. ${card.name}"
|
||||||
|
@ -259,7 +282,7 @@ class EpisodeAdapter(
|
||||||
|
|
||||||
class EpisodeCardViewHolderSmall
|
class EpisodeCardViewHolderSmall
|
||||||
constructor(
|
constructor(
|
||||||
val binding : ResultEpisodeBinding,
|
val binding: ResultEpisodeBinding,
|
||||||
private val hasDownloadSupport: Boolean,
|
private val hasDownloadSupport: Boolean,
|
||||||
private val clickCallback: (EpisodeClickEvent) -> Unit,
|
private val clickCallback: (EpisodeClickEvent) -> Unit,
|
||||||
private val downloadClickCallback: (DownloadClickEvent) -> Unit,
|
private val downloadClickCallback: (DownloadClickEvent) -> Unit,
|
||||||
|
@ -269,12 +292,14 @@ class EpisodeAdapter(
|
||||||
val isTrueTv = isTrueTvSettings()
|
val isTrueTv = isTrueTvSettings()
|
||||||
|
|
||||||
binding.episodeHolder.layoutParams.apply {
|
binding.episodeHolder.layoutParams.apply {
|
||||||
width = if(isTvSettings()) ViewGroup.LayoutParams.WRAP_CONTENT else ViewGroup.LayoutParams.MATCH_PARENT
|
width =
|
||||||
|
if (isTvSettings()) ViewGroup.LayoutParams.WRAP_CONTENT else ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
downloadButton.isVisible = hasDownloadSupport
|
downloadButton.isVisible = hasDownloadSupport
|
||||||
downloadButton.setDefaultClickListener(VideoDownloadHelper.DownloadEpisodeCached(
|
downloadButton.setDefaultClickListener(
|
||||||
|
VideoDownloadHelper.DownloadEpisodeCached(
|
||||||
card.name,
|
card.name,
|
||||||
card.poster,
|
card.poster,
|
||||||
card.episode,
|
card.episode,
|
||||||
|
@ -284,13 +309,22 @@ class EpisodeAdapter(
|
||||||
card.rating,
|
card.rating,
|
||||||
card.description,
|
card.description,
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
), null) {
|
), null
|
||||||
if (it.action == DOWNLOAD_ACTION_DOWNLOAD) {
|
) {
|
||||||
|
when (it.action) {
|
||||||
|
DOWNLOAD_ACTION_DOWNLOAD -> {
|
||||||
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
|
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
DOWNLOAD_ACTION_LONG_CLICK -> {
|
||||||
|
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_MIRROR, card))
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
downloadClickCallback.invoke(it)
|
downloadClickCallback.invoke(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val name =
|
val name =
|
||||||
if (card.name == null) "${episodeText.context.getString(R.string.episode)} ${card.episode}" else "${card.episode}. ${card.name}"
|
if (card.name == null) "${episodeText.context.getString(R.string.episode)} ${card.episode}" else "${card.episode}. ${card.name}"
|
||||||
|
|
|
@ -50,6 +50,7 @@ import com.lagradost.cloudstream3.mvvm.observeNullable
|
||||||
import com.lagradost.cloudstream3.services.SubscriptionWorkManager
|
import com.lagradost.cloudstream3.services.SubscriptionWorkManager
|
||||||
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.DOWNLOAD_ACTION_LONG_CLICK
|
||||||
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup
|
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup
|
||||||
import com.lagradost.cloudstream3.ui.player.CSPlayerEvent
|
import com.lagradost.cloudstream3.ui.player.CSPlayerEvent
|
||||||
import com.lagradost.cloudstream3.ui.player.FullScreenPlayer
|
import com.lagradost.cloudstream3.ui.player.FullScreenPlayer
|
||||||
|
@ -594,6 +595,9 @@ open class ResultFragmentPhone : FullScreenPlayer(),
|
||||||
EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, ep)
|
EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, ep)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DOWNLOAD_ACTION_LONG_CLICK -> {
|
||||||
|
viewModel.handleAction(EpisodeClickEvent(ACTION_DOWNLOAD_MIRROR, ep))
|
||||||
|
}
|
||||||
|
|
||||||
else -> DownloadButtonSetup.handleDownloadClick(click)
|
else -> DownloadButtonSetup.handleDownloadClick(click)
|
||||||
}
|
}
|
||||||
|
@ -912,11 +916,11 @@ open class ResultFragmentPhone : FullScreenPlayer(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
observe(viewModel.loadedLinks) { load ->
|
observeNullable(viewModel.loadedLinks) { load ->
|
||||||
if (load == null) {
|
if (load == null) {
|
||||||
loadingDialog?.dismissSafe(activity)
|
loadingDialog?.dismissSafe(activity)
|
||||||
loadingDialog = null
|
loadingDialog = null
|
||||||
return@observe
|
return@observeNullable
|
||||||
}
|
}
|
||||||
if (loadingDialog?.isShowing != true) {
|
if (loadingDialog?.isShowing != true) {
|
||||||
loadingDialog?.dismissSafe(activity)
|
loadingDialog?.dismissSafe(activity)
|
||||||
|
|
Loading…
Reference in a new issue