2021-07-30 23:41:54 +00:00
|
|
|
package com.lagradost.cloudstream3.ui.search
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
import android.widget.Toast
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
2022-05-26 22:34:09 +00:00
|
|
|
import com.lagradost.cloudstream3.R
|
2021-08-25 15:28:25 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_PLAY_FILE
|
|
|
|
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
|
|
|
import com.lagradost.cloudstream3.ui.download.DownloadClickEvent
|
|
|
|
import com.lagradost.cloudstream3.ui.result.START_ACTION_LOAD_EP
|
2021-07-30 23:41:54 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult
|
2021-08-25 15:28:25 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
|
|
|
import com.lagradost.cloudstream3.utils.VideoDownloadHelper
|
2021-07-30 23:41:54 +00:00
|
|
|
|
|
|
|
object SearchHelper {
|
|
|
|
fun handleSearchClickCallback(activity: Activity?, callback: SearchClickCallback) {
|
|
|
|
val card = callback.card
|
|
|
|
when (callback.action) {
|
|
|
|
SEARCH_ACTION_LOAD -> {
|
|
|
|
activity.loadSearchResult(card)
|
|
|
|
}
|
2021-08-25 15:28:25 +00:00
|
|
|
SEARCH_ACTION_PLAY_FILE -> {
|
2022-05-02 21:32:28 +00:00
|
|
|
if (card is DataStoreHelper.ResumeWatchingResult) {
|
2022-05-26 22:34:09 +00:00
|
|
|
val id = card.id
|
|
|
|
if(id == null) {
|
|
|
|
showToast(activity, R.string.error_invalid_id, Toast.LENGTH_SHORT)
|
|
|
|
} else {
|
|
|
|
if (card.isFromDownload) {
|
|
|
|
handleDownloadClick(
|
|
|
|
activity, card.name, DownloadClickEvent(
|
|
|
|
DOWNLOAD_ACTION_PLAY_FILE,
|
|
|
|
VideoDownloadHelper.DownloadEpisodeCached(
|
|
|
|
card.name,
|
|
|
|
card.posterUrl,
|
|
|
|
card.episode ?: 0,
|
|
|
|
card.season,
|
|
|
|
id,
|
|
|
|
card.parentId ?: return,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
System.currentTimeMillis()
|
|
|
|
)
|
2021-08-25 15:28:25 +00:00
|
|
|
)
|
|
|
|
)
|
2022-05-26 22:34:09 +00:00
|
|
|
} else {
|
|
|
|
activity.loadSearchResult(card, START_ACTION_LOAD_EP, id)
|
|
|
|
}
|
2021-08-25 15:28:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-11-30 17:59:52 +00:00
|
|
|
handleSearchClickCallback(
|
|
|
|
activity,
|
2021-12-11 21:23:36 +00:00
|
|
|
SearchClickCallback(SEARCH_ACTION_LOAD, callback.view, -1, callback.card)
|
2021-11-30 17:59:52 +00:00
|
|
|
)
|
2021-08-25 15:28:25 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-30 23:41:54 +00:00
|
|
|
SEARCH_ACTION_SHOW_METADATA -> {
|
2021-08-24 22:19:15 +00:00
|
|
|
showToast(activity, callback.card.name, Toast.LENGTH_SHORT)
|
2021-07-30 23:41:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|