redirected downloadbutton longclick

This commit is contained in:
LagradOst 2023-07-19 17:58:40 +02:00
parent 3ae44d5675
commit 9755bbacb9
2 changed files with 80 additions and 42 deletions

View file

@ -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,40 +94,50 @@ 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
} }
// private val layout = R.layout.result_episode_both // private val layout = R.layout.result_episode_both
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
/*val layout = if (cardList.filter { it.poster != null }.size >= cardList.size / 2) /*val layout = if (cardList.filter { it.poster != null }.size >= cardList.size / 2)
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,21 +182,31 @@ class EpisodeAdapter(
binding.apply { binding.apply {
downloadButton.isVisible = hasDownloadSupport downloadButton.isVisible = hasDownloadSupport
downloadButton.setDefaultClickListener(VideoDownloadHelper.DownloadEpisodeCached( downloadButton.setDefaultClickListener(
card.name, VideoDownloadHelper.DownloadEpisodeCached(
card.poster, card.name,
card.episode, card.poster,
card.season, card.episode,
card.id, card.season,
card.parentId, card.id,
card.rating, card.parentId,
card.description, card.rating,
System.currentTimeMillis(), card.description,
), null) { System.currentTimeMillis(),
if (it.action == DOWNLOAD_ACTION_DOWNLOAD) { ), null
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card)) ) {
} else { when (it.action) {
downloadClickCallback.invoke(it) DOWNLOAD_ACTION_DOWNLOAD -> {
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
}
DOWNLOAD_ACTION_LONG_CLICK -> {
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_MIRROR, card))
}
else -> {
downloadClickCallback.invoke(it)
}
} }
} }
@ -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,26 +292,37 @@ 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(
card.name, VideoDownloadHelper.DownloadEpisodeCached(
card.poster, card.name,
card.episode, card.poster,
card.season, card.episode,
card.id, card.season,
card.parentId, card.id,
card.rating, card.parentId,
card.description, card.rating,
System.currentTimeMillis(), card.description,
), null) { System.currentTimeMillis(),
if (it.action == DOWNLOAD_ACTION_DOWNLOAD) { ), null
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card)) ) {
} else { when (it.action) {
downloadClickCallback.invoke(it) DOWNLOAD_ACTION_DOWNLOAD -> {
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
}
DOWNLOAD_ACTION_LONG_CLICK -> {
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_MIRROR, card))
}
else -> {
downloadClickCallback.invoke(it)
}
} }
} }

View file

@ -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)