forked from recloudstream/cloudstream
load episode mirrors
This commit is contained in:
parent
c5364ecd9a
commit
eef78f8275
4 changed files with 57 additions and 15 deletions
|
@ -207,7 +207,7 @@ class ShiroProvider : MainAPI() {
|
||||||
|
|
||||||
override fun loadLinks(data: Any, isCasting: Boolean, callback: (ExtractorLink) -> Unit): Boolean {
|
override fun loadLinks(data: Any, isCasting: Boolean, callback: (ExtractorLink) -> Unit): Boolean {
|
||||||
if (data is ShiroEpisodes) {
|
if (data is ShiroEpisodes) {
|
||||||
return Vidstream().getUrl(data._id, isCasting) {
|
return Vidstream().getUrl(data.videos[0].video_id, isCasting) {
|
||||||
callback.invoke(it)
|
callback.invoke(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,16 @@ import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import kotlinx.android.synthetic.main.result_episode.view.*
|
import kotlinx.android.synthetic.main.result_episode.view.*
|
||||||
|
|
||||||
|
const val ACTION_PLAY_EPISODE = 1
|
||||||
|
const val ACTION_RELOAD_EPISODE = 2
|
||||||
|
|
||||||
|
data class EpisodeClickEvent(val action: Int, val data: ResultEpisode)
|
||||||
|
|
||||||
class EpisodeAdapter(
|
class EpisodeAdapter(
|
||||||
private var activity: Activity,
|
private var activity: Activity,
|
||||||
var cardList: ArrayList<ResultEpisode>,
|
var cardList: ArrayList<ResultEpisode>,
|
||||||
val resView: RecyclerView,
|
val resView: RecyclerView,
|
||||||
val clickCallback: (ResultEpisode) -> Unit
|
val clickCallback: (EpisodeClickEvent) -> Unit,
|
||||||
) :
|
) :
|
||||||
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
|
|
||||||
|
@ -44,7 +48,12 @@ class EpisodeAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
class CardViewHolder
|
class CardViewHolder
|
||||||
constructor(itemView: View, _activity: Activity, resView: RecyclerView, clickCallback: (ResultEpisode) -> Unit) : RecyclerView.ViewHolder(itemView) {
|
constructor(
|
||||||
|
itemView: View,
|
||||||
|
_activity: Activity,
|
||||||
|
resView: RecyclerView,
|
||||||
|
clickCallback: (EpisodeClickEvent) -> Unit,
|
||||||
|
) : RecyclerView.ViewHolder(itemView) {
|
||||||
val activity = _activity
|
val activity = _activity
|
||||||
val episode_view_procentage: View = itemView.episode_view_procentage
|
val episode_view_procentage: View = itemView.episode_view_procentage
|
||||||
val episode_view_procentage_off: View = itemView.episode_view_procentage_off
|
val episode_view_procentage_off: View = itemView.episode_view_procentage_off
|
||||||
|
@ -68,7 +77,7 @@ class EpisodeAdapter(
|
||||||
setWidth(episode_view_procentage_off, 1 - card.watchProgress)
|
setWidth(episode_view_procentage_off, 1 - card.watchProgress)
|
||||||
|
|
||||||
episode_play.setOnClickListener {
|
episode_play.setOnClickListener {
|
||||||
clickCallback.invoke(card)
|
clickCallback.invoke(EpisodeClickEvent(ACTION_PLAY_EPISODE, card))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ class ResultFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var viewModel: ResultViewModel
|
private lateinit var viewModel: ResultViewModel
|
||||||
|
private var allEpisodes: HashMap<Int, ArrayList<ExtractorLink>> = HashMap()
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
@ -91,6 +92,10 @@ class ResultFragment : Fragment() {
|
||||||
activity?.onBackPressed()
|
activity?.onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
observe(viewModel.allEpisodes) {
|
||||||
|
allEpisodes = it
|
||||||
|
}
|
||||||
|
|
||||||
observe(viewModel.resultResponse) { data ->
|
observe(viewModel.resultResponse) { data ->
|
||||||
when (data) {
|
when (data) {
|
||||||
is Resource.Success -> {
|
is Resource.Success -> {
|
||||||
|
@ -121,13 +126,39 @@ class ResultFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder>? = activity?.let {
|
fun playEpisode(data: ArrayList<ExtractorLink>?) {
|
||||||
|
if (data != null) {
|
||||||
|
for (d in data) {
|
||||||
|
println(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder>? = activity?.let { it ->
|
||||||
EpisodeAdapter(
|
EpisodeAdapter(
|
||||||
it,
|
it,
|
||||||
ArrayList(),
|
ArrayList(),
|
||||||
result_episodes,
|
result_episodes,
|
||||||
) {
|
) { episodeClick ->
|
||||||
viewModel.loadEpisode(it)
|
val id = episodeClick.data.id
|
||||||
|
when (episodeClick.action) {
|
||||||
|
ACTION_PLAY_EPISODE -> {
|
||||||
|
if (allEpisodes.containsKey(id)) {
|
||||||
|
playEpisode(allEpisodes[id])
|
||||||
|
} else {
|
||||||
|
viewModel.loadEpisode(episodeClick.data) { res ->
|
||||||
|
if (res is Resource.Success) {
|
||||||
|
playEpisode(allEpisodes[id])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ACTION_RELOAD_EPISODE -> viewModel.loadEpisode(episodeClick.data) { res ->
|
||||||
|
if (res is Resource.Success) {
|
||||||
|
playEpisode(allEpisodes[id])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,19 +24,21 @@ class ResultViewModel : ViewModel() {
|
||||||
_resultResponse.postValue(data)
|
_resultResponse.postValue(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
val allEpisodes : MutableLiveData<HashMap<Int,ArrayList<ExtractorLink>>> = MutableLiveData()
|
private val _allEpisodes: MutableLiveData<HashMap<Int, ArrayList<ExtractorLink>>> = MutableLiveData(HashMap())
|
||||||
private val _episodeResponse: MutableLiveData<Resource<Boolean>> = MutableLiveData()
|
val allEpisodes: LiveData<HashMap<Int, ArrayList<ExtractorLink>>> get() = _allEpisodes
|
||||||
val episodeResponse: LiveData<Resource<Boolean>> get() = _episodeResponse
|
|
||||||
|
|
||||||
fun loadEpisode(episode: ResultEpisode) = viewModelScope.launch {
|
fun loadEpisode(episode: ResultEpisode, callback: (Resource<Boolean>) -> Unit) = viewModelScope.launch {
|
||||||
if(allEpisodes.value?.contains(episode.id) == true) {
|
if (_allEpisodes.value?.contains(episode.id) == true) {
|
||||||
allEpisodes.value?.remove(episode.id)
|
_allEpisodes.value?.remove(episode.id)
|
||||||
}
|
}
|
||||||
|
val links = ArrayList<ExtractorLink>()
|
||||||
val data = safeApiCall {
|
val data = safeApiCall {
|
||||||
getApiFromName(episode.apiName).loadLinks(episode.data, false) { //TODO IMPLEMENT CASTING
|
getApiFromName(episode.apiName).loadLinks(episode.data, false) { //TODO IMPLEMENT CASTING
|
||||||
allEpisodes.value?.get(episode.id)?.add(it)
|
links.add(it)
|
||||||
|
_allEpisodes.value?.set(episode.id, links)
|
||||||
|
// _allEpisodes.value?.get(episode.id)?.add(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_episodeResponse.postValue(data)
|
callback.invoke(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue