2021-05-16 18:28:00 +00:00
|
|
|
package com.lagradost.cloudstream3.ui.result
|
|
|
|
|
2021-05-18 13:43:32 +00:00
|
|
|
import android.annotation.SuppressLint
|
2022-02-02 22:12:52 +00:00
|
|
|
import android.app.Activity
|
2021-09-03 09:13:34 +00:00
|
|
|
import android.content.ClipData
|
|
|
|
import android.content.ClipboardManager
|
2022-04-03 20:14:51 +00:00
|
|
|
import android.content.Context
|
2021-07-17 15:56:26 +00:00
|
|
|
import android.content.Context.CLIPBOARD_SERVICE
|
2021-09-03 09:13:34 +00:00
|
|
|
import android.content.Intent
|
2021-07-17 15:56:26 +00:00
|
|
|
import android.content.Intent.*
|
2021-12-10 19:48:21 +00:00
|
|
|
import android.content.res.ColorStateList
|
2021-12-13 18:41:33 +00:00
|
|
|
import android.content.res.Configuration
|
2022-02-04 20:49:35 +00:00
|
|
|
import android.graphics.Rect
|
2021-06-10 15:15:14 +00:00
|
|
|
import android.net.Uri
|
2022-04-02 01:38:55 +00:00
|
|
|
import android.os.Build
|
2021-05-16 18:28:00 +00:00
|
|
|
import android.os.Bundle
|
2022-04-02 01:38:55 +00:00
|
|
|
import android.text.Editable
|
2021-05-16 18:28:00 +00:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
2021-06-06 18:06:01 +00:00
|
|
|
import android.view.View.GONE
|
|
|
|
import android.view.View.VISIBLE
|
2021-05-16 18:28:00 +00:00
|
|
|
import android.view.ViewGroup
|
2022-04-02 01:38:55 +00:00
|
|
|
import android.widget.*
|
2021-12-13 18:41:33 +00:00
|
|
|
import androidx.annotation.StringRes
|
2021-05-18 13:43:32 +00:00
|
|
|
import androidx.appcompat.app.AlertDialog
|
2021-07-17 15:56:26 +00:00
|
|
|
import androidx.core.content.FileProvider
|
2022-03-20 23:25:25 +00:00
|
|
|
import androidx.core.graphics.drawable.toBitmap
|
2021-12-10 00:20:24 +00:00
|
|
|
import androidx.core.view.isGone
|
2021-09-19 22:36:32 +00:00
|
|
|
import androidx.core.view.isVisible
|
2021-05-18 13:43:32 +00:00
|
|
|
import androidx.core.widget.NestedScrollView
|
2022-04-02 01:38:55 +00:00
|
|
|
import androidx.core.widget.doOnTextChanged
|
2021-05-16 18:28:00 +00:00
|
|
|
import androidx.fragment.app.Fragment
|
2022-01-07 19:27:25 +00:00
|
|
|
import androidx.lifecycle.ViewModelProvider
|
2021-09-19 22:36:32 +00:00
|
|
|
import androidx.preference.PreferenceManager
|
2021-05-18 13:43:32 +00:00
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2022-02-04 20:49:35 +00:00
|
|
|
import com.discord.panels.OverlappingPanelsLayout
|
|
|
|
import com.discord.panels.PanelsChildGestureRegionObserver
|
2021-06-06 18:06:01 +00:00
|
|
|
import com.google.android.gms.cast.framework.CastButtonFactory
|
|
|
|
import com.google.android.gms.cast.framework.CastContext
|
|
|
|
import com.google.android.gms.cast.framework.CastState
|
|
|
|
import com.google.android.material.button.MaterialButton
|
2021-06-14 00:00:29 +00:00
|
|
|
import com.lagradost.cloudstream3.*
|
2022-03-27 16:45:02 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings
|
2021-06-16 22:31:41 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
2021-07-25 16:08:34 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.getId
|
2022-02-02 22:12:52 +00:00
|
|
|
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.CommonActivity.getCastSession
|
|
|
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
|
|
|
import com.lagradost.cloudstream3.mvvm.*
|
2021-06-15 23:25:58 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.WatchType
|
2021-07-24 20:50:57 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
|
2021-07-30 01:14:53 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
|
2021-07-24 20:50:57 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
2021-08-24 22:19:15 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.download.EasyDownloadButton
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
|
2022-02-02 22:12:52 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.player.RepoLinkGenerator
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.player.SubtitleData
|
2021-11-20 00:41:37 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment
|
2021-12-13 18:41:33 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.search.SearchAdapter
|
|
|
|
import com.lagradost.cloudstream3.ui.search.SearchHelper
|
2022-04-01 20:05:34 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment
|
2022-03-29 21:50:07 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
|
2021-12-10 19:48:21 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
2021-08-22 17:14:48 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getDownloadSubsLanguageISO639_1
|
2021-07-17 14:14:25 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.*
|
2021-07-30 01:14:53 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.isAppInstalled
|
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable
|
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.isConnectedToChromecast
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.loadCache
|
2021-12-16 23:45:20 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.openBrowser
|
2021-06-14 16:58:43 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.CastHelper.startCast
|
2022-04-03 20:14:51 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
2021-07-17 14:14:25 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
2021-07-18 23:57:04 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.DataStore.getFolderName
|
2021-07-17 14:14:25 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.DataStore.setKey
|
2021-06-15 16:07:20 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
|
2021-12-10 19:48:21 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
|
2021-08-24 22:19:15 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.checkWrite
|
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
2021-12-12 02:33:17 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
2021-08-24 22:19:15 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
2021-12-13 18:41:33 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount
|
2021-08-24 22:19:15 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
2021-09-20 21:11:36 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
2021-08-24 22:19:15 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage
|
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons
|
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes
|
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
|
2021-08-19 20:05:18 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
2021-12-10 00:20:24 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.setImageBlur
|
2022-04-03 20:14:51 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getFileName
|
2021-07-04 17:00:04 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.VideoDownloadManager.sanitizeFilename
|
2021-05-18 13:43:32 +00:00
|
|
|
import kotlinx.android.synthetic.main.fragment_result.*
|
2022-02-04 20:49:35 +00:00
|
|
|
import kotlinx.android.synthetic.main.fragment_result_swipe.*
|
2022-04-18 00:26:13 +00:00
|
|
|
import kotlinx.android.synthetic.main.result_recommendations.*
|
2022-04-01 20:05:34 +00:00
|
|
|
import kotlinx.android.synthetic.main.result_sync.*
|
2021-07-30 21:03:46 +00:00
|
|
|
import kotlinx.coroutines.Dispatchers
|
2021-07-17 14:14:25 +00:00
|
|
|
import kotlinx.coroutines.Job
|
2021-07-30 21:03:46 +00:00
|
|
|
import kotlinx.coroutines.withContext
|
2021-07-17 15:56:26 +00:00
|
|
|
import java.io.File
|
2021-06-14 00:00:29 +00:00
|
|
|
|
2021-12-10 00:20:24 +00:00
|
|
|
const val MAX_SYNO_LENGH = 1000
|
2021-05-18 13:43:32 +00:00
|
|
|
|
2021-07-29 15:16:08 +00:00
|
|
|
const val START_ACTION_NORMAL = 0
|
|
|
|
const val START_ACTION_RESUME_LATEST = 1
|
2021-08-25 15:28:25 +00:00
|
|
|
const val START_ACTION_LOAD_EP = 2
|
|
|
|
|
|
|
|
const val START_VALUE_NORMAL = 0
|
2021-07-29 15:16:08 +00:00
|
|
|
|
2021-05-18 13:43:32 +00:00
|
|
|
data class ResultEpisode(
|
2022-01-07 19:27:25 +00:00
|
|
|
val headerName: String,
|
2021-05-18 13:43:32 +00:00
|
|
|
val name: String?,
|
2021-06-10 15:15:14 +00:00
|
|
|
val poster: String?,
|
2021-05-18 13:43:32 +00:00
|
|
|
val episode: Int,
|
2021-05-28 13:38:06 +00:00
|
|
|
val season: Int?,
|
2021-06-14 16:58:43 +00:00
|
|
|
val data: String,
|
2021-05-18 13:43:32 +00:00
|
|
|
val apiName: String,
|
|
|
|
val id: Int,
|
2021-05-22 22:25:56 +00:00
|
|
|
val index: Int,
|
2021-06-15 16:07:20 +00:00
|
|
|
val position: Long, // time in MS
|
2021-06-10 15:15:14 +00:00
|
|
|
val duration: Long, // duration in MS
|
2021-06-26 19:32:50 +00:00
|
|
|
val rating: Int?,
|
2021-12-10 00:20:24 +00:00
|
|
|
val description: String?,
|
2021-09-19 22:36:32 +00:00
|
|
|
val isFiller: Boolean?,
|
2022-01-07 19:27:25 +00:00
|
|
|
val tvType: TvType,
|
2022-02-13 14:51:55 +00:00
|
|
|
val parentId: Int,
|
2021-05-18 13:43:32 +00:00
|
|
|
)
|
2021-05-16 18:28:00 +00:00
|
|
|
|
2021-06-15 16:07:20 +00:00
|
|
|
fun ResultEpisode.getRealPosition(): Long {
|
|
|
|
if (duration <= 0) return 0
|
|
|
|
val percentage = position * 100 / duration
|
|
|
|
if (percentage <= 5 || percentage >= 95) return 0
|
|
|
|
return position
|
|
|
|
}
|
|
|
|
|
2021-06-16 17:40:02 +00:00
|
|
|
fun ResultEpisode.getDisplayPosition(): Long {
|
|
|
|
if (duration <= 0) return 0
|
|
|
|
val percentage = position * 100 / duration
|
|
|
|
if (percentage <= 1) return 0
|
|
|
|
if (percentage <= 5) return 5 * duration / 100
|
|
|
|
if (percentage >= 95) return duration
|
|
|
|
return position
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun buildResultEpisode(
|
2022-01-07 19:27:25 +00:00
|
|
|
headerName: String,
|
2022-04-26 13:52:30 +00:00
|
|
|
name: String? = null,
|
|
|
|
poster: String? = null,
|
2021-06-15 16:07:20 +00:00
|
|
|
episode: Int,
|
2022-04-26 13:52:30 +00:00
|
|
|
season: Int? = null,
|
2021-06-15 16:07:20 +00:00
|
|
|
data: String,
|
|
|
|
apiName: String,
|
|
|
|
id: Int,
|
|
|
|
index: Int,
|
2022-04-26 13:52:30 +00:00
|
|
|
rating: Int? = null,
|
|
|
|
description: String? = null,
|
|
|
|
isFiller: Boolean? = null,
|
2022-01-07 19:27:25 +00:00
|
|
|
tvType: TvType,
|
2022-02-13 14:51:55 +00:00
|
|
|
parentId: Int,
|
2021-06-15 16:07:20 +00:00
|
|
|
): ResultEpisode {
|
|
|
|
val posDur = getViewPos(id)
|
2021-06-26 19:32:50 +00:00
|
|
|
return ResultEpisode(
|
2022-01-07 19:27:25 +00:00
|
|
|
headerName,
|
2021-06-26 19:32:50 +00:00
|
|
|
name,
|
2021-06-15 16:07:20 +00:00
|
|
|
poster,
|
|
|
|
episode,
|
|
|
|
season,
|
|
|
|
data,
|
|
|
|
apiName,
|
|
|
|
id,
|
|
|
|
index,
|
|
|
|
posDur?.position ?: 0,
|
2021-06-26 19:32:50 +00:00
|
|
|
posDur?.duration ?: 0,
|
|
|
|
rating,
|
2021-11-30 17:59:52 +00:00
|
|
|
description,
|
2022-01-07 19:27:25 +00:00
|
|
|
isFiller,
|
|
|
|
tvType,
|
|
|
|
parentId,
|
2021-06-26 19:32:50 +00:00
|
|
|
)
|
2021-06-15 16:07:20 +00:00
|
|
|
}
|
|
|
|
|
2021-07-29 15:16:08 +00:00
|
|
|
/** 0f-1f */
|
2021-06-10 15:15:14 +00:00
|
|
|
fun ResultEpisode.getWatchProgress(): Float {
|
2021-07-29 15:16:08 +00:00
|
|
|
return (getDisplayPosition() / 1000).toFloat() / (duration / 1000).toFloat()
|
2021-06-10 15:15:14 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 20:49:35 +00:00
|
|
|
class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegionsListener {
|
2021-05-22 22:25:56 +00:00
|
|
|
companion object {
|
2021-12-17 12:42:25 +00:00
|
|
|
fun newInstance(
|
|
|
|
url: String,
|
|
|
|
apiName: String,
|
|
|
|
startAction: Int = 0,
|
|
|
|
startValue: Int = 0
|
|
|
|
): Bundle {
|
2021-09-20 21:11:36 +00:00
|
|
|
return Bundle().apply {
|
|
|
|
putString("url", url)
|
|
|
|
putString("apiName", apiName)
|
|
|
|
putInt("startAction", startAction)
|
|
|
|
putInt("startValue", startValue)
|
|
|
|
putBoolean("restart", true)
|
2021-05-18 13:43:32 +00:00
|
|
|
}
|
2021-09-20 21:11:36 +00:00
|
|
|
}
|
2022-01-18 14:10:01 +00:00
|
|
|
|
|
|
|
fun updateUI() {
|
|
|
|
updateUIListener?.invoke()
|
|
|
|
}
|
|
|
|
|
2022-01-31 20:47:59 +00:00
|
|
|
private var updateUIListener: (() -> Unit)? = null
|
2022-02-02 22:12:52 +00:00
|
|
|
|
2022-04-03 20:14:51 +00:00
|
|
|
private fun downloadSubtitle(
|
|
|
|
context: Context?,
|
|
|
|
link: SubtitleData,
|
|
|
|
meta: VideoDownloadManager.DownloadEpisodeMetadata,
|
|
|
|
) {
|
|
|
|
context?.let { ctx ->
|
|
|
|
val fileName = getFileName(ctx, meta)
|
|
|
|
val folder = getFolder(meta.type ?: return, meta.mainName)
|
|
|
|
downloadSubtitle(
|
|
|
|
ctx,
|
|
|
|
ExtractorSubtitleLink(link.name, link.url, ""),
|
|
|
|
fileName,
|
|
|
|
folder
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun downloadSubtitle(
|
|
|
|
context: Context?,
|
|
|
|
link: ExtractorSubtitleLink,
|
|
|
|
fileName: String,
|
|
|
|
folder: String
|
2022-02-02 22:12:52 +00:00
|
|
|
) {
|
2022-04-03 20:14:51 +00:00
|
|
|
ioSafe {
|
|
|
|
VideoDownloadManager.downloadThing(
|
|
|
|
context ?: return@ioSafe,
|
|
|
|
link,
|
|
|
|
"$fileName ${link.name}",
|
|
|
|
folder,
|
|
|
|
if (link.url.contains(".srt")) ".srt" else "vtt",
|
|
|
|
false,
|
|
|
|
null
|
|
|
|
) {
|
|
|
|
// no notification
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-02 22:12:52 +00:00
|
|
|
|
2022-04-03 20:14:51 +00:00
|
|
|
private fun getMeta(
|
|
|
|
episode: ResultEpisode,
|
|
|
|
titleName: String,
|
|
|
|
apiName: String,
|
|
|
|
currentPoster: String,
|
|
|
|
currentIsMovie: Boolean,
|
|
|
|
tvType: TvType,
|
|
|
|
): VideoDownloadManager.DownloadEpisodeMetadata {
|
|
|
|
return VideoDownloadManager.DownloadEpisodeMetadata(
|
2022-02-02 22:12:52 +00:00
|
|
|
episode.id,
|
2022-04-03 20:14:51 +00:00
|
|
|
sanitizeFilename(titleName),
|
2022-02-02 22:12:52 +00:00
|
|
|
apiName,
|
|
|
|
episode.poster ?: currentPoster,
|
|
|
|
episode.name,
|
|
|
|
if (currentIsMovie) null else episode.season,
|
2022-04-03 20:14:51 +00:00
|
|
|
if (currentIsMovie) null else episode.episode,
|
|
|
|
tvType,
|
2022-02-02 22:12:52 +00:00
|
|
|
)
|
2022-04-03 20:14:51 +00:00
|
|
|
}
|
2022-02-02 22:12:52 +00:00
|
|
|
|
2022-04-03 20:14:51 +00:00
|
|
|
private fun getFolder(currentType: TvType, titleName: String): String {
|
2022-04-29 22:48:05 +00:00
|
|
|
val sanitizedFileName = sanitizeFilename(titleName)
|
2022-04-03 20:14:51 +00:00
|
|
|
return when (currentType) {
|
2022-04-29 22:48:05 +00:00
|
|
|
TvType.Anime -> "Anime/$sanitizedFileName"
|
2022-02-02 22:12:52 +00:00
|
|
|
TvType.Movie -> "Movies"
|
|
|
|
TvType.AnimeMovie -> "Movies"
|
2022-04-29 22:48:05 +00:00
|
|
|
TvType.TvSeries -> "TVSeries/$sanitizedFileName"
|
2022-02-02 22:12:52 +00:00
|
|
|
TvType.OVA -> "OVA"
|
2022-04-29 22:48:05 +00:00
|
|
|
TvType.Cartoon -> "Cartoons/$sanitizedFileName"
|
2022-02-02 22:12:52 +00:00
|
|
|
TvType.Torrent -> "Torrent"
|
|
|
|
TvType.Documentary -> "Documentaries"
|
2022-03-21 11:07:36 +00:00
|
|
|
TvType.AsianDrama -> "AsianDrama"
|
2022-02-02 22:12:52 +00:00
|
|
|
}
|
2022-04-03 20:14:51 +00:00
|
|
|
}
|
2022-02-02 22:12:52 +00:00
|
|
|
|
2022-04-03 20:14:51 +00:00
|
|
|
fun startDownload(
|
|
|
|
context: Context?,
|
|
|
|
episode: ResultEpisode,
|
|
|
|
currentIsMovie: Boolean,
|
|
|
|
currentHeaderName: String,
|
|
|
|
currentType: TvType,
|
|
|
|
currentPoster: String,
|
|
|
|
apiName: String,
|
|
|
|
parentId: Int,
|
|
|
|
url: String,
|
|
|
|
links: List<ExtractorLink>,
|
|
|
|
subs: List<SubtitleData>?
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
if (context == null) return
|
|
|
|
|
|
|
|
val meta =
|
|
|
|
getMeta(
|
|
|
|
episode,
|
|
|
|
currentHeaderName,
|
|
|
|
apiName,
|
|
|
|
currentPoster,
|
|
|
|
currentIsMovie,
|
|
|
|
currentType
|
|
|
|
)
|
2022-02-02 22:12:52 +00:00
|
|
|
|
2022-04-03 20:14:51 +00:00
|
|
|
val folder = getFolder(currentType, currentHeaderName)
|
|
|
|
|
|
|
|
val src = "$DOWNLOAD_NAVIGATE_TO/$parentId" // url ?: return@let
|
|
|
|
|
|
|
|
// SET VISUAL KEYS
|
|
|
|
setKey(
|
|
|
|
DOWNLOAD_HEADER_CACHE,
|
|
|
|
parentId.toString(),
|
|
|
|
VideoDownloadHelper.DownloadHeaderCached(
|
|
|
|
apiName,
|
|
|
|
url,
|
|
|
|
currentType,
|
|
|
|
currentHeaderName,
|
|
|
|
currentPoster,
|
|
|
|
parentId,
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
)
|
2022-02-02 22:12:52 +00:00
|
|
|
)
|
|
|
|
|
2022-04-03 20:14:51 +00:00
|
|
|
setKey(
|
|
|
|
getFolderName(
|
|
|
|
DOWNLOAD_EPISODE_CACHE,
|
|
|
|
parentId.toString()
|
|
|
|
), // 3 deep folder for faster acess
|
|
|
|
episode.id.toString(),
|
|
|
|
VideoDownloadHelper.DownloadEpisodeCached(
|
|
|
|
episode.name,
|
|
|
|
episode.poster,
|
|
|
|
episode.episode,
|
|
|
|
episode.season,
|
|
|
|
episode.id,
|
|
|
|
parentId,
|
|
|
|
episode.rating,
|
|
|
|
episode.description,
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
)
|
2022-02-02 22:12:52 +00:00
|
|
|
)
|
|
|
|
|
2022-04-03 20:14:51 +00:00
|
|
|
// DOWNLOAD VIDEO
|
|
|
|
VideoDownloadManager.downloadEpisodeUsingWorker(
|
|
|
|
context,
|
|
|
|
src,//url ?: return,
|
|
|
|
folder,
|
|
|
|
meta,
|
|
|
|
links
|
|
|
|
)
|
|
|
|
|
|
|
|
// 1. Checks if the lang should be downloaded
|
|
|
|
// 2. Makes it into the download format
|
|
|
|
// 3. Downloads it as a .vtt file
|
|
|
|
val downloadList = getDownloadSubsLanguageISO639_1()
|
|
|
|
subs?.let { subsList ->
|
|
|
|
subsList.filter {
|
|
|
|
downloadList.contains(
|
|
|
|
SubtitleHelper.fromLanguageToTwoLetters(
|
|
|
|
it.name,
|
|
|
|
true
|
|
|
|
)
|
2022-02-02 22:12:52 +00:00
|
|
|
)
|
|
|
|
}
|
2022-04-03 20:14:51 +00:00
|
|
|
.map { ExtractorSubtitleLink(it.name, it.url, "") }
|
|
|
|
.forEach { link ->
|
|
|
|
val fileName = getFileName(context, meta)
|
|
|
|
downloadSubtitle(context, link, fileName, folder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
2022-02-02 22:12:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
suspend fun downloadEpisode(
|
|
|
|
activity: Activity?,
|
|
|
|
episode: ResultEpisode,
|
|
|
|
currentIsMovie: Boolean,
|
|
|
|
currentHeaderName: String,
|
|
|
|
currentType: TvType,
|
|
|
|
currentPoster: String,
|
|
|
|
apiName: String,
|
|
|
|
parentId: Int,
|
|
|
|
url: String,
|
|
|
|
) {
|
|
|
|
safeApiCall {
|
|
|
|
val generator = RepoLinkGenerator(listOf(episode))
|
|
|
|
val currentLinks = mutableSetOf<ExtractorLink>()
|
|
|
|
val currentSubs = mutableSetOf<SubtitleData>()
|
|
|
|
generator.generateLinks(clearCache = false, isCasting = false, callback = {
|
|
|
|
it.first?.let { link ->
|
|
|
|
currentLinks.add(link)
|
|
|
|
}
|
|
|
|
}, subtitleCallback = { sub ->
|
|
|
|
currentSubs.add(sub)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (currentLinks.isEmpty()) {
|
|
|
|
showToast(activity, R.string.no_links_found_toast, Toast.LENGTH_SHORT)
|
|
|
|
return@safeApiCall
|
|
|
|
}
|
|
|
|
|
|
|
|
startDownload(
|
2022-04-03 20:14:51 +00:00
|
|
|
activity,
|
2022-02-02 22:12:52 +00:00
|
|
|
episode,
|
|
|
|
currentIsMovie,
|
|
|
|
currentHeaderName,
|
|
|
|
currentType,
|
|
|
|
currentPoster,
|
|
|
|
apiName,
|
|
|
|
parentId,
|
|
|
|
url,
|
|
|
|
sortUrls(currentLinks),
|
|
|
|
sortSubs(currentSubs),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2021-05-22 22:25:56 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 12:42:25 +00:00
|
|
|
private var currentLoadingCount =
|
|
|
|
0 // THIS IS USED TO PREVENT LATE EVENTS, AFTER DISMISS WAS CLICKED
|
2022-01-07 19:27:25 +00:00
|
|
|
private lateinit var viewModel: ResultViewModel //by activityViewModels()
|
2022-04-01 20:05:34 +00:00
|
|
|
private lateinit var syncModel: SyncViewModel
|
2021-06-15 16:07:20 +00:00
|
|
|
private var currentHeaderName: String? = null
|
2021-07-04 00:59:51 +00:00
|
|
|
private var currentType: TvType? = null
|
2021-06-15 16:07:20 +00:00
|
|
|
private var currentEpisodes: List<ResultEpisode>? = null
|
2022-04-08 19:38:19 +00:00
|
|
|
private var downloadButton: EasyDownloadButton? = null
|
|
|
|
private var syncdata: Map<String, String>? = null
|
2021-05-16 18:28:00 +00:00
|
|
|
|
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
2021-05-18 13:43:32 +00:00
|
|
|
savedInstanceState: Bundle?,
|
2021-05-16 18:28:00 +00:00
|
|
|
): View? {
|
2022-01-07 19:27:25 +00:00
|
|
|
viewModel =
|
|
|
|
ViewModelProvider(this)[ResultViewModel::class.java]
|
2022-04-01 20:05:34 +00:00
|
|
|
syncModel =
|
|
|
|
ViewModelProvider(this)[SyncViewModel::class.java]
|
|
|
|
|
2022-02-04 20:49:35 +00:00
|
|
|
return inflater.inflate(R.layout.fragment_result_swipe, container, false)
|
2021-05-16 18:28:00 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 19:14:45 +00:00
|
|
|
override fun onDestroyView() {
|
|
|
|
(result_episodes?.adapter as EpisodeAdapter?)?.killAdapter()
|
|
|
|
super.onDestroyView()
|
|
|
|
}
|
|
|
|
|
2021-05-22 22:25:56 +00:00
|
|
|
override fun onDestroy() {
|
|
|
|
//requireActivity().viewModelStore.clear() // REMEMBER THE CLEAR
|
2021-07-28 19:14:45 +00:00
|
|
|
downloadButton?.dispose()
|
2022-01-18 14:10:01 +00:00
|
|
|
updateUIListener = null
|
2022-02-05 22:21:45 +00:00
|
|
|
result_cast_items?.let {
|
|
|
|
PanelsChildGestureRegionObserver.Provider.get().unregister(it)
|
|
|
|
}
|
|
|
|
|
2021-05-22 22:25:56 +00:00
|
|
|
super.onDestroy()
|
2021-06-16 00:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
activity?.let {
|
|
|
|
it.window?.navigationBarColor =
|
2021-09-19 20:33:39 +00:00
|
|
|
it.colorFromAttribute(R.attr.primaryBlackBackground)
|
2021-06-16 00:15:07 +00:00
|
|
|
}
|
2021-05-22 22:25:56 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 16:54:07 +00:00
|
|
|
/// 0 = LOADING, 1 = ERROR LOADING, 2 = LOADED
|
2021-07-02 18:46:18 +00:00
|
|
|
private fun updateVisStatus(state: Int) {
|
2021-06-16 16:54:07 +00:00
|
|
|
when (state) {
|
|
|
|
0 -> {
|
2021-12-10 19:48:21 +00:00
|
|
|
result_bookmark_fab?.isGone = true
|
|
|
|
result_loading?.isVisible = true
|
|
|
|
result_finish_loading?.isVisible = false
|
|
|
|
result_loading_error?.isVisible = false
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
|
|
|
1 -> {
|
2021-12-10 19:48:21 +00:00
|
|
|
result_bookmark_fab?.isGone = true
|
|
|
|
result_loading?.isVisible = false
|
|
|
|
result_finish_loading?.isVisible = false
|
|
|
|
result_loading_error?.isVisible = true
|
|
|
|
result_reload_connection_open_in_browser?.isVisible = url != null
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
|
|
|
2 -> {
|
2021-12-10 19:48:21 +00:00
|
|
|
result_bookmark_fab?.isGone = result_bookmark_fab?.context?.isTvSettings() == true
|
|
|
|
result_bookmark_fab?.extend()
|
2022-03-29 21:50:07 +00:00
|
|
|
if (result_bookmark_button?.context?.isTrueTvSettings() == true) {
|
|
|
|
when {
|
|
|
|
result_play_movie?.isVisible == true -> {
|
|
|
|
result_play_movie?.requestFocus()
|
|
|
|
}
|
|
|
|
result_resume_series_button?.isVisible == true -> {
|
|
|
|
result_resume_series_button?.requestFocus()
|
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
result_bookmark_button?.requestFocus()
|
|
|
|
}
|
|
|
|
}
|
2021-12-10 19:48:21 +00:00
|
|
|
}
|
2021-10-09 21:59:37 +00:00
|
|
|
|
2021-12-10 19:48:21 +00:00
|
|
|
result_loading?.isVisible = false
|
|
|
|
result_finish_loading?.isVisible = true
|
|
|
|
result_loading_error?.isVisible = false
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:07:20 +00:00
|
|
|
private var currentPoster: String? = null
|
2021-07-17 14:14:25 +00:00
|
|
|
private var currentId: Int? = null
|
2021-06-16 22:31:41 +00:00
|
|
|
private var currentIsMovie: Boolean? = null
|
2021-07-25 20:50:16 +00:00
|
|
|
private var episodeRanges: List<String>? = null
|
2021-11-02 15:09:29 +00:00
|
|
|
private var dubRange: Set<DubStatus>? = null
|
2021-06-16 16:54:07 +00:00
|
|
|
var url: String? = null
|
|
|
|
|
2021-06-26 22:15:19 +00:00
|
|
|
private fun fromIndexToSeasonText(selection: Int?): String {
|
|
|
|
return when (selection) {
|
2021-09-02 13:19:50 +00:00
|
|
|
null -> getString(R.string.no_season)
|
|
|
|
-2 -> getString(R.string.no_season)
|
|
|
|
else -> "${getString(R.string.season)} $selection"
|
2021-06-26 22:15:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-29 15:16:08 +00:00
|
|
|
var startAction: Int? = null
|
2021-12-13 18:41:33 +00:00
|
|
|
private var startValue: Int? = null
|
|
|
|
|
|
|
|
private fun setFormatText(textView: TextView?, @StringRes format: Int, arg: Any?) {
|
2021-12-17 12:42:25 +00:00
|
|
|
// java.util.IllegalFormatConversionException: f != java.lang.Integer
|
|
|
|
// This can fail with malformed formatting
|
|
|
|
normalSafeApiCall {
|
|
|
|
if (arg == null) {
|
2021-12-13 18:41:33 +00:00
|
|
|
textView?.isVisible = false
|
|
|
|
} else {
|
2021-12-17 12:42:25 +00:00
|
|
|
val text = context?.getString(format)?.format(arg)
|
|
|
|
if (text == null) {
|
|
|
|
textView?.isVisible = false
|
|
|
|
} else {
|
|
|
|
textView?.isVisible = true
|
|
|
|
textView?.text = text
|
|
|
|
}
|
2021-12-13 18:41:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setDuration(duration: Int?) {
|
|
|
|
setFormatText(result_meta_duration, R.string.duration_format, duration)
|
|
|
|
}
|
|
|
|
|
2022-02-06 14:53:39 +00:00
|
|
|
private fun setShow(showStatus: ShowStatus?) {
|
2022-02-05 22:21:45 +00:00
|
|
|
val status = when (showStatus) {
|
|
|
|
null -> null
|
|
|
|
ShowStatus.Ongoing -> R.string.status_ongoing
|
|
|
|
ShowStatus.Completed -> R.string.status_completed
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == null) {
|
|
|
|
result_meta_status?.isVisible = false
|
|
|
|
} else {
|
|
|
|
context?.getString(status)?.let {
|
|
|
|
result_meta_status?.text = it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 18:41:33 +00:00
|
|
|
private fun setYear(year: Int?) {
|
|
|
|
setFormatText(result_meta_year, R.string.year_format, year)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setRating(rating: Int?) {
|
2021-12-17 12:42:25 +00:00
|
|
|
setFormatText(result_meta_rating, R.string.rating_format, rating?.div(1000f))
|
2021-12-13 18:41:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 22:21:45 +00:00
|
|
|
private fun setActors(actors: List<ActorData>?) {
|
|
|
|
if (actors.isNullOrEmpty()) {
|
|
|
|
result_cast_text?.isVisible = false
|
|
|
|
result_cast_items?.isVisible = false
|
|
|
|
} else {
|
|
|
|
val isImage = actors.first().actor.image != null
|
|
|
|
if (isImage) {
|
|
|
|
(result_cast_items?.adapter as ActorAdaptor?)?.apply {
|
|
|
|
updateList(actors)
|
|
|
|
}
|
|
|
|
result_cast_text?.isVisible = false
|
|
|
|
result_cast_items?.isVisible = true
|
|
|
|
} else {
|
|
|
|
result_cast_text?.isVisible = true
|
|
|
|
result_cast_items?.isVisible = false
|
|
|
|
setFormatText(result_cast_text, R.string.cast_format,
|
|
|
|
actors.joinToString { it.actor.name })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-18 00:26:13 +00:00
|
|
|
private fun setRecommendations(rec: List<SearchResponse>?, validApiName: String?) {
|
2022-02-04 20:49:35 +00:00
|
|
|
val isInvalid = rec.isNullOrEmpty()
|
|
|
|
result_recommendations?.isGone = isInvalid
|
|
|
|
result_recommendations_btt?.isGone = isInvalid
|
|
|
|
result_recommendations_btt?.setOnClickListener {
|
2022-04-18 00:26:13 +00:00
|
|
|
val nextFocusDown = if (result_overlapping_panels?.getSelectedPanel()?.ordinal == 1) {
|
2022-02-04 20:49:35 +00:00
|
|
|
result_overlapping_panels?.openEndPanel()
|
2022-04-18 00:26:13 +00:00
|
|
|
R.id.result_recommendations
|
2022-02-04 20:49:35 +00:00
|
|
|
} else {
|
|
|
|
result_overlapping_panels?.closePanels()
|
2022-04-18 00:26:13 +00:00
|
|
|
R.id.result_description
|
2022-02-04 20:49:35 +00:00
|
|
|
}
|
2022-04-18 00:26:13 +00:00
|
|
|
|
|
|
|
result_recommendations_btt?.nextFocusDownId = nextFocusDown
|
|
|
|
result_search?.nextFocusDownId = nextFocusDown
|
|
|
|
result_open_in_browser?.nextFocusDownId = nextFocusDown
|
|
|
|
result_share?.nextFocusDownId = nextFocusDown
|
2022-02-04 20:49:35 +00:00
|
|
|
}
|
|
|
|
result_overlapping_panels?.setEndPanelLockState(if (isInvalid) OverlappingPanelsLayout.LockState.CLOSE else OverlappingPanelsLayout.LockState.UNLOCKED)
|
2022-04-18 00:26:13 +00:00
|
|
|
|
|
|
|
val matchAgainst = validApiName ?: rec?.firstOrNull()?.apiName
|
|
|
|
rec?.map { it.apiName }?.distinct()?.let { apiNames ->
|
|
|
|
// very dirty selection
|
|
|
|
result_recommendations_filter_button?.isVisible = apiNames.size > 1
|
|
|
|
result_recommendations_filter_button?.text = matchAgainst
|
|
|
|
result_recommendations_filter_button?.setOnClickListener { _ ->
|
|
|
|
activity?.showBottomDialog(
|
|
|
|
apiNames,
|
|
|
|
apiNames.indexOf(matchAgainst),
|
|
|
|
getString(R.string.home_change_provider_img_des), false, {}
|
|
|
|
) {
|
|
|
|
setRecommendations(rec, apiNames[it])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} ?: run {
|
|
|
|
result_recommendations_filter_button?.isVisible = false
|
|
|
|
}
|
|
|
|
|
2022-04-03 21:41:28 +00:00
|
|
|
result_recommendations?.post {
|
2022-02-05 01:05:13 +00:00
|
|
|
rec?.let { list ->
|
2022-04-18 00:26:13 +00:00
|
|
|
(result_recommendations?.adapter as SearchAdapter?)?.updateList(list.filter { it.apiName == matchAgainst })
|
2021-12-13 18:41:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun fixGrid() {
|
2022-02-04 20:49:35 +00:00
|
|
|
activity?.getSpanCount()?.let { _ ->
|
|
|
|
//result_recommendations?.spanCount = count // this is due to discord not changing size with rotation
|
2021-12-13 18:41:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
|
|
super.onConfigurationChanged(newConfig)
|
|
|
|
fixGrid()
|
|
|
|
}
|
2021-07-29 15:16:08 +00:00
|
|
|
|
2021-08-11 18:26:19 +00:00
|
|
|
private fun lateFixDownloadButton(show: Boolean) {
|
2021-08-22 17:14:48 +00:00
|
|
|
if (!show || currentType?.isMovieType() == false) {
|
2021-08-11 18:26:19 +00:00
|
|
|
result_movie_parent.visibility = GONE
|
|
|
|
result_episodes_text.visibility = VISIBLE
|
|
|
|
result_episodes.visibility = VISIBLE
|
2021-08-14 17:31:27 +00:00
|
|
|
} else {
|
|
|
|
result_movie_parent.visibility = VISIBLE
|
|
|
|
result_episodes_text.visibility = GONE
|
|
|
|
result_episodes.visibility = GONE
|
2021-08-11 18:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 14:10:01 +00:00
|
|
|
private fun updateUI() {
|
2022-04-08 19:38:19 +00:00
|
|
|
syncModel.updateUserData()
|
2022-01-18 14:10:01 +00:00
|
|
|
viewModel.reloadEpisodes()
|
|
|
|
}
|
|
|
|
|
2021-05-18 13:43:32 +00:00
|
|
|
@SuppressLint("SetTextI18n")
|
2021-05-16 18:28:00 +00:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2022-02-05 22:21:45 +00:00
|
|
|
result_cast_items?.let {
|
|
|
|
PanelsChildGestureRegionObserver.Provider.get().register(it)
|
|
|
|
}
|
2022-04-27 23:25:01 +00:00
|
|
|
result_cast_items?.adapter = ActorAdaptor()
|
2021-12-13 18:41:33 +00:00
|
|
|
fixGrid()
|
2022-02-04 20:49:35 +00:00
|
|
|
result_recommendations?.spanCount = 3
|
|
|
|
result_overlapping_panels?.setStartPanelLockState(OverlappingPanelsLayout.LockState.CLOSE)
|
|
|
|
result_overlapping_panels?.setEndPanelLockState(OverlappingPanelsLayout.LockState.CLOSE)
|
2021-08-29 13:10:36 +00:00
|
|
|
|
2022-01-18 14:10:01 +00:00
|
|
|
updateUIListener = ::updateUI
|
|
|
|
|
2021-09-20 21:11:36 +00:00
|
|
|
val restart = arguments?.getBoolean("restart") ?: false
|
|
|
|
if (restart) {
|
|
|
|
arguments?.putBoolean("restart", false)
|
|
|
|
}
|
|
|
|
|
2021-07-28 01:04:32 +00:00
|
|
|
activity?.window?.decorView?.clearFocus()
|
|
|
|
hideKeyboard()
|
2022-01-07 19:27:25 +00:00
|
|
|
activity?.loadCache()
|
2021-07-28 01:04:32 +00:00
|
|
|
|
2022-02-04 20:49:35 +00:00
|
|
|
activity?.fixPaddingStatusbar(result_top_bar)
|
2021-09-19 20:33:39 +00:00
|
|
|
//activity?.fixPaddingStatusbar(result_barstatus)
|
2021-06-06 18:06:01 +00:00
|
|
|
|
2021-12-10 00:20:24 +00:00
|
|
|
/* val backParameter = result_back.layoutParams as FrameLayout.LayoutParams
|
|
|
|
backParameter.setMargins(
|
|
|
|
backParameter.leftMargin,
|
|
|
|
backParameter.topMargin + requireContext().getStatusBarHeight(),
|
|
|
|
backParameter.rightMargin,
|
|
|
|
backParameter.bottomMargin
|
|
|
|
)
|
|
|
|
result_back.layoutParams = backParameter*/
|
2021-06-16 16:54:07 +00:00
|
|
|
|
2021-05-20 15:22:28 +00:00
|
|
|
// activity?.fixPaddingStatusbar(result_toolbar)
|
2021-05-18 13:43:32 +00:00
|
|
|
|
2021-06-16 16:54:07 +00:00
|
|
|
url = arguments?.getString("url")
|
2021-07-23 23:44:54 +00:00
|
|
|
val apiName = arguments?.getString("apiName") ?: return
|
2021-07-29 15:16:08 +00:00
|
|
|
startAction = arguments?.getInt("startAction") ?: START_ACTION_NORMAL
|
2021-08-25 15:28:25 +00:00
|
|
|
startValue = arguments?.getInt("startValue") ?: START_VALUE_NORMAL
|
2022-04-02 17:58:56 +00:00
|
|
|
syncModel.addFromUrl(url)
|
2021-09-20 21:11:36 +00:00
|
|
|
|
2021-07-23 23:44:54 +00:00
|
|
|
val api = getApiFromName(apiName)
|
|
|
|
if (media_route_button != null) {
|
|
|
|
val chromecastSupport = api.hasChromecastSupport
|
|
|
|
|
|
|
|
media_route_button?.alpha = if (chromecastSupport) 1f else 0.3f
|
|
|
|
if (!chromecastSupport) {
|
2022-04-10 22:00:03 +00:00
|
|
|
media_route_button?.setOnClickListener {
|
2022-02-12 20:38:47 +00:00
|
|
|
showToast(activity, R.string.no_chromecast_support_toast, Toast.LENGTH_LONG)
|
2021-07-23 23:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-10 22:00:03 +00:00
|
|
|
activity?.let { act ->
|
|
|
|
if (act.isCastApiAvailable()) {
|
2021-09-24 22:51:08 +00:00
|
|
|
try {
|
2022-04-10 22:00:03 +00:00
|
|
|
CastButtonFactory.setUpMediaRouteButton(act, media_route_button)
|
|
|
|
val castContext = CastContext.getSharedInstance(act.applicationContext)
|
|
|
|
|
2022-04-13 17:29:30 +00:00
|
|
|
media_route_button?.isGone =
|
|
|
|
castContext.castState == CastState.NO_DEVICES_AVAILABLE
|
2021-09-24 22:51:08 +00:00
|
|
|
|
|
|
|
castContext.addCastStateListener { state ->
|
2022-04-10 22:00:03 +00:00
|
|
|
media_route_button?.isGone = state == CastState.NO_DEVICES_AVAILABLE
|
2021-07-23 23:44:54 +00:00
|
|
|
}
|
2021-10-22 13:23:48 +00:00
|
|
|
} catch (e: Exception) {
|
2021-09-24 22:51:08 +00:00
|
|
|
logError(e)
|
2021-07-23 23:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-18 13:43:32 +00:00
|
|
|
|
2021-12-10 19:48:21 +00:00
|
|
|
result_scroll.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
|
|
|
val dy = scrollY - oldScrollY
|
|
|
|
if (dy > 0) { //check for scroll down
|
|
|
|
result_bookmark_fab?.shrink()
|
|
|
|
} else if (dy < -5) {
|
|
|
|
result_bookmark_fab?.extend()
|
|
|
|
}
|
|
|
|
result_poster_blur_holder?.translationY = -scrollY.toFloat()
|
|
|
|
})
|
2021-05-18 13:43:32 +00:00
|
|
|
|
2021-06-16 16:54:07 +00:00
|
|
|
result_back.setOnClickListener {
|
2021-07-30 21:03:46 +00:00
|
|
|
activity?.popCurrentPage()
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
2021-06-10 15:15:14 +00:00
|
|
|
|
2021-07-17 14:14:25 +00:00
|
|
|
fun handleAction(episodeClick: EpisodeClickEvent): Job = main {
|
2022-02-02 22:12:52 +00:00
|
|
|
if (episodeClick.action == ACTION_DOWNLOAD_EPISODE) {
|
|
|
|
val isMovie = currentIsMovie ?: return@main
|
|
|
|
val headerName = currentHeaderName ?: return@main
|
|
|
|
val tvType = currentType ?: return@main
|
|
|
|
val poster = currentPoster ?: return@main
|
|
|
|
val id = currentId ?: return@main
|
|
|
|
val curl = url ?: return@main
|
|
|
|
showToast(activity, R.string.download_started, Toast.LENGTH_SHORT)
|
|
|
|
downloadEpisode(
|
|
|
|
activity,
|
|
|
|
episodeClick.data,
|
|
|
|
isMovie,
|
|
|
|
headerName,
|
|
|
|
tvType,
|
|
|
|
poster,
|
|
|
|
apiName,
|
|
|
|
id,
|
|
|
|
curl,
|
|
|
|
)
|
|
|
|
return@main
|
|
|
|
}
|
|
|
|
|
2022-01-07 19:27:25 +00:00
|
|
|
var currentLinks: Set<ExtractorLink>? = null
|
|
|
|
var currentSubs: Set<SubtitleData>? = null
|
|
|
|
|
2021-06-16 16:54:07 +00:00
|
|
|
//val id = episodeClick.data.id
|
|
|
|
currentLoadingCount++
|
2021-07-17 14:14:25 +00:00
|
|
|
|
2021-09-02 13:19:50 +00:00
|
|
|
val showTitle =
|
2022-01-07 19:27:25 +00:00
|
|
|
episodeClick.data.name ?: context?.getString(R.string.episode_name_format)
|
|
|
|
?.format(
|
|
|
|
getString(R.string.episode),
|
|
|
|
episodeClick.data.episode
|
|
|
|
)
|
2021-06-16 22:31:41 +00:00
|
|
|
|
2021-07-17 14:14:25 +00:00
|
|
|
|
2022-01-07 19:27:25 +00:00
|
|
|
fun acquireSingleExtractorLink(
|
2021-08-22 17:14:48 +00:00
|
|
|
links: List<ExtractorLink>,
|
|
|
|
title: String,
|
|
|
|
callback: (ExtractorLink) -> Unit
|
|
|
|
) {
|
2021-07-17 15:56:26 +00:00
|
|
|
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom)
|
|
|
|
|
|
|
|
builder.setTitle(title)
|
2022-04-22 16:52:31 +00:00
|
|
|
builder.setItems(links.map { "${it.name} ${Qualities.getStringByInt(it.quality)}" }
|
|
|
|
.toTypedArray()) { dia, which ->
|
2021-07-17 15:56:26 +00:00
|
|
|
callback.invoke(links[which])
|
|
|
|
dia?.dismiss()
|
|
|
|
}
|
|
|
|
builder.create().show()
|
|
|
|
}
|
|
|
|
|
2022-04-03 20:14:51 +00:00
|
|
|
fun acquireSingleSubtitleLink(
|
|
|
|
links: List<SubtitleData>,
|
|
|
|
title: String,
|
|
|
|
callback: (SubtitleData) -> Unit
|
|
|
|
) {
|
|
|
|
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom)
|
|
|
|
|
|
|
|
builder.setTitle(title)
|
|
|
|
builder.setItems(links.map { it.name }.toTypedArray()) { dia, which ->
|
|
|
|
callback.invoke(links[which])
|
|
|
|
dia?.dismiss()
|
|
|
|
}
|
|
|
|
builder.create().show()
|
|
|
|
}
|
|
|
|
|
2021-08-22 17:14:48 +00:00
|
|
|
fun acquireSingeExtractorLink(title: String, callback: (ExtractorLink) -> Unit) {
|
2022-01-07 19:27:25 +00:00
|
|
|
acquireSingleExtractorLink(sortUrls(currentLinks ?: return), title, callback)
|
2021-07-17 15:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fun startChromecast(startIndex: Int) {
|
|
|
|
val eps = currentEpisodes ?: return
|
2021-09-30 12:55:56 +00:00
|
|
|
activity?.getCastSession()?.startCast(
|
2021-08-19 20:05:18 +00:00
|
|
|
apiName,
|
2021-07-17 15:56:26 +00:00
|
|
|
currentIsMovie ?: return,
|
|
|
|
currentHeaderName,
|
|
|
|
currentPoster,
|
|
|
|
episodeClick.data.index,
|
|
|
|
eps,
|
|
|
|
sortUrls(currentLinks ?: return),
|
2022-01-07 19:27:25 +00:00
|
|
|
sortSubs(currentSubs ?: return),
|
2021-07-17 15:56:26 +00:00
|
|
|
startTime = episodeClick.data.getRealPosition(),
|
|
|
|
startIndex = startIndex
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-07 19:27:25 +00:00
|
|
|
suspend fun requireLinks(isCasting: Boolean, displayLoading: Boolean = true): Boolean {
|
|
|
|
val skipLoading = getApiFromName(apiName).instantLinkLoading
|
|
|
|
|
|
|
|
var loadingDialog: AlertDialog? = null
|
|
|
|
val currentLoad = currentLoadingCount
|
|
|
|
|
|
|
|
if (!skipLoading && displayLoading) {
|
|
|
|
val builder =
|
|
|
|
AlertDialog.Builder(requireContext(), R.style.AlertDialogCustomTransparent)
|
|
|
|
val customLayout = layoutInflater.inflate(R.layout.dialog_loading, null)
|
|
|
|
builder.setView(customLayout)
|
|
|
|
|
|
|
|
loadingDialog = builder.create()
|
|
|
|
|
|
|
|
loadingDialog.show()
|
|
|
|
loadingDialog.setOnDismissListener {
|
|
|
|
currentLoadingCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val data = viewModel.loadEpisode(episodeClick.data, isCasting)
|
|
|
|
if (currentLoadingCount != currentLoad) return false
|
|
|
|
loadingDialog?.dismissSafe(activity)
|
|
|
|
|
|
|
|
when (data) {
|
|
|
|
is Resource.Success -> {
|
|
|
|
currentLinks = data.value.first
|
|
|
|
currentSubs = data.value.second
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
is Resource.Failure -> {
|
|
|
|
showToast(
|
|
|
|
activity,
|
|
|
|
R.string.error_loading_links_toast,
|
|
|
|
Toast.LENGTH_SHORT
|
|
|
|
)
|
|
|
|
}
|
|
|
|
else -> Unit
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-07-17 14:14:25 +00:00
|
|
|
val isLoaded = when (episodeClick.action) {
|
|
|
|
ACTION_PLAY_EPISODE_IN_PLAYER -> true
|
2021-07-29 15:16:08 +00:00
|
|
|
ACTION_CLICK_DEFAULT -> true
|
2021-08-29 13:10:36 +00:00
|
|
|
ACTION_SHOW_TOAST -> true
|
2022-01-07 19:27:25 +00:00
|
|
|
ACTION_DOWNLOAD_EPISODE -> {
|
|
|
|
showToast(activity, R.string.download_started, Toast.LENGTH_SHORT)
|
|
|
|
requireLinks(false, false)
|
|
|
|
}
|
2021-07-17 14:14:25 +00:00
|
|
|
ACTION_CHROME_CAST_EPISODE -> requireLinks(true)
|
|
|
|
ACTION_CHROME_CAST_MIRROR -> requireLinks(true)
|
2021-07-17 15:56:26 +00:00
|
|
|
else -> requireLinks(false)
|
2021-07-17 14:14:25 +00:00
|
|
|
}
|
|
|
|
if (!isLoaded) return@main // CANT LOAD
|
|
|
|
|
|
|
|
when (episodeClick.action) {
|
2021-08-24 22:19:15 +00:00
|
|
|
ACTION_SHOW_TOAST -> {
|
|
|
|
showToast(activity, R.string.play_episode_toast, Toast.LENGTH_SHORT)
|
|
|
|
}
|
|
|
|
|
2021-07-23 23:44:54 +00:00
|
|
|
ACTION_CLICK_DEFAULT -> {
|
|
|
|
context?.let { ctx ->
|
|
|
|
if (ctx.isConnectedToChromecast()) {
|
2021-12-17 12:42:25 +00:00
|
|
|
handleAction(
|
|
|
|
EpisodeClickEvent(
|
|
|
|
ACTION_CHROME_CAST_EPISODE,
|
|
|
|
episodeClick.data
|
|
|
|
)
|
|
|
|
)
|
2021-07-23 23:44:54 +00:00
|
|
|
} else {
|
2021-12-17 12:42:25 +00:00
|
|
|
handleAction(
|
|
|
|
EpisodeClickEvent(
|
|
|
|
ACTION_PLAY_EPISODE_IN_PLAYER,
|
|
|
|
episodeClick.data
|
|
|
|
)
|
|
|
|
)
|
2021-07-23 23:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-03 20:14:51 +00:00
|
|
|
ACTION_DOWNLOAD_EPISODE_SUBTITLE -> {
|
|
|
|
acquireSingleSubtitleLink(
|
|
|
|
sortSubs(
|
|
|
|
currentSubs ?: return@main
|
|
|
|
),//(currentLinks ?: return@main).filter { !it.isM3u8 },
|
|
|
|
getString(R.string.episode_action_download_subtitle)
|
|
|
|
) { link ->
|
|
|
|
downloadSubtitle(
|
|
|
|
context,
|
|
|
|
link,
|
|
|
|
getMeta(
|
|
|
|
episodeClick.data,
|
|
|
|
currentHeaderName ?: return@acquireSingleSubtitleLink,
|
|
|
|
apiName,
|
|
|
|
currentPoster ?: return@acquireSingleSubtitleLink,
|
|
|
|
currentIsMovie ?: return@acquireSingleSubtitleLink,
|
|
|
|
currentType ?: return@acquireSingleSubtitleLink
|
|
|
|
)
|
|
|
|
)
|
|
|
|
showToast(activity, R.string.download_started, Toast.LENGTH_SHORT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-17 14:14:25 +00:00
|
|
|
ACTION_SHOW_OPTIONS -> {
|
2021-09-12 15:57:07 +00:00
|
|
|
context?.let { ctx ->
|
|
|
|
val builder = AlertDialog.Builder(ctx, R.style.AlertDialogCustom)
|
|
|
|
var dialog: AlertDialog? = null
|
|
|
|
builder.setTitle(showTitle)
|
2021-12-17 12:42:25 +00:00
|
|
|
val options =
|
|
|
|
requireContext().resources.getStringArray(R.array.episode_long_click_options)
|
2021-09-12 15:57:07 +00:00
|
|
|
val optionsValues =
|
|
|
|
requireContext().resources.getIntArray(R.array.episode_long_click_options_values)
|
|
|
|
|
|
|
|
val verifiedOptions = ArrayList<String>()
|
|
|
|
val verifiedOptionsValues = ArrayList<Int>()
|
|
|
|
|
|
|
|
val hasDownloadSupport = api.hasDownloadSupport
|
|
|
|
|
|
|
|
for (i in options.indices) {
|
|
|
|
val opv = optionsValues[i]
|
|
|
|
val op = options[i]
|
|
|
|
|
|
|
|
val isConnected = ctx.isConnectedToChromecast()
|
|
|
|
val add = when (opv) {
|
|
|
|
ACTION_CHROME_CAST_EPISODE -> isConnected
|
|
|
|
ACTION_CHROME_CAST_MIRROR -> isConnected
|
2022-04-03 20:14:51 +00:00
|
|
|
ACTION_DOWNLOAD_EPISODE_SUBTITLE -> !currentSubs.isNullOrEmpty()
|
2021-09-12 15:57:07 +00:00
|
|
|
ACTION_DOWNLOAD_EPISODE -> hasDownloadSupport
|
|
|
|
ACTION_DOWNLOAD_MIRROR -> hasDownloadSupport
|
2021-12-17 12:42:25 +00:00
|
|
|
ACTION_PLAY_EPISODE_IN_VLC_PLAYER -> context?.isAppInstalled(
|
|
|
|
VLC_PACKAGE
|
|
|
|
) ?: false
|
2021-09-12 15:57:07 +00:00
|
|
|
else -> true
|
|
|
|
}
|
|
|
|
if (add) {
|
|
|
|
verifiedOptions.add(op)
|
|
|
|
verifiedOptionsValues.add(opv)
|
|
|
|
}
|
2021-07-17 14:14:25 +00:00
|
|
|
}
|
2021-09-12 15:57:07 +00:00
|
|
|
|
|
|
|
builder.setItems(
|
|
|
|
verifiedOptions.toTypedArray()
|
|
|
|
) { _, which ->
|
2021-12-17 12:42:25 +00:00
|
|
|
handleAction(
|
|
|
|
EpisodeClickEvent(
|
|
|
|
verifiedOptionsValues[which],
|
|
|
|
episodeClick.data
|
|
|
|
)
|
|
|
|
)
|
2021-12-12 02:33:17 +00:00
|
|
|
dialog?.dismissSafe(activity)
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
2021-07-17 14:14:25 +00:00
|
|
|
|
2021-09-12 15:57:07 +00:00
|
|
|
dialog = builder.create()
|
|
|
|
dialog.show()
|
2021-07-17 14:14:25 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-17 15:56:26 +00:00
|
|
|
ACTION_COPY_LINK -> {
|
2021-09-12 15:57:07 +00:00
|
|
|
activity?.let { act ->
|
2021-12-12 02:33:17 +00:00
|
|
|
try {
|
|
|
|
acquireSingeExtractorLink(act.getString(R.string.episode_action_copy_link)) { link ->
|
|
|
|
val serviceClipboard =
|
|
|
|
(act.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?)
|
|
|
|
?: return@acquireSingeExtractorLink
|
|
|
|
val clip = ClipData.newPlainText(link.name, link.url)
|
|
|
|
serviceClipboard.setPrimaryClip(clip)
|
|
|
|
showToast(act, R.string.copy_link_toast, Toast.LENGTH_SHORT)
|
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
|
|
|
showToast(act, e.toString(), Toast.LENGTH_LONG)
|
|
|
|
logError(e)
|
2021-09-12 15:57:07 +00:00
|
|
|
}
|
2021-07-17 15:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTION_PLAY_EPISODE_IN_BROWSER -> {
|
2021-09-02 13:19:50 +00:00
|
|
|
acquireSingeExtractorLink(getString(R.string.episode_action_play_in_browser)) { link ->
|
2022-01-13 21:09:05 +00:00
|
|
|
try {
|
|
|
|
val i = Intent(ACTION_VIEW)
|
|
|
|
i.data = Uri.parse(link.url)
|
|
|
|
startActivity(i)
|
2022-01-31 20:47:59 +00:00
|
|
|
} catch (e: Exception) {
|
2022-01-13 21:09:05 +00:00
|
|
|
logError(e)
|
|
|
|
}
|
2021-07-17 15:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-17 14:14:25 +00:00
|
|
|
|
2021-07-17 15:56:26 +00:00
|
|
|
ACTION_CHROME_CAST_MIRROR -> {
|
2022-02-12 20:38:47 +00:00
|
|
|
acquireSingeExtractorLink(getString(R.string.episode_action_chromecast_mirror)) { link ->
|
2021-07-17 15:56:26 +00:00
|
|
|
val mirrorIndex = currentLinks?.indexOf(link) ?: -1
|
|
|
|
startChromecast(if (mirrorIndex == -1) 0 else mirrorIndex)
|
|
|
|
}
|
|
|
|
}
|
2021-07-17 14:14:25 +00:00
|
|
|
|
|
|
|
ACTION_CHROME_CAST_EPISODE -> {
|
2021-07-17 15:56:26 +00:00
|
|
|
startChromecast(0)
|
|
|
|
}
|
2021-07-17 14:14:25 +00:00
|
|
|
|
2021-07-17 21:36:50 +00:00
|
|
|
ACTION_PLAY_EPISODE_IN_VLC_PLAYER -> {
|
2021-07-30 21:03:46 +00:00
|
|
|
activity?.let { act ->
|
2021-12-12 02:33:17 +00:00
|
|
|
try {
|
|
|
|
if (!act.checkWrite()) {
|
|
|
|
act.requestRW()
|
|
|
|
if (act.checkWrite()) return@main
|
|
|
|
}
|
|
|
|
val data = currentLinks ?: return@main
|
2022-01-07 19:27:25 +00:00
|
|
|
val subs = currentSubs ?: return@main
|
2021-07-30 21:03:46 +00:00
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
val outputDir = act.cacheDir
|
|
|
|
val outputFile = withContext(Dispatchers.IO) {
|
|
|
|
File.createTempFile("mirrorlist", ".m3u8", outputDir)
|
2021-07-30 21:03:46 +00:00
|
|
|
}
|
2021-12-12 02:33:17 +00:00
|
|
|
var text = "#EXTM3U"
|
2022-01-07 19:27:25 +00:00
|
|
|
for (sub in sortSubs(subs)) {
|
|
|
|
text += "\n#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"subs\",NAME=\"${sub.name}\",DEFAULT=NO,AUTOSELECT=NO,FORCED=NO,LANGUAGE=\"${sub.name}\",URI=\"${sub.url}\""
|
2021-12-12 02:33:17 +00:00
|
|
|
}
|
|
|
|
for (link in data.sortedBy { -it.quality }) {
|
|
|
|
text += "\n#EXTINF:, ${link.name}\n${link.url}"
|
|
|
|
}
|
|
|
|
outputFile.writeText(text)
|
|
|
|
|
|
|
|
val vlcIntent = Intent(VLC_INTENT_ACTION_RESULT)
|
|
|
|
|
|
|
|
vlcIntent.setPackage(VLC_PACKAGE)
|
|
|
|
vlcIntent.addFlags(FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
|
|
|
|
vlcIntent.addFlags(FLAG_GRANT_PREFIX_URI_PERMISSION)
|
|
|
|
vlcIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
vlcIntent.addFlags(FLAG_GRANT_WRITE_URI_PERMISSION)
|
|
|
|
|
|
|
|
vlcIntent.setDataAndType(
|
|
|
|
FileProvider.getUriForFile(
|
|
|
|
act,
|
|
|
|
act.applicationContext.packageName + ".provider",
|
|
|
|
outputFile
|
|
|
|
), "video/*"
|
|
|
|
)
|
2021-07-17 15:56:26 +00:00
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
val startId = VLC_FROM_PROGRESS
|
2021-07-17 15:56:26 +00:00
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
var position = startId
|
|
|
|
if (startId == VLC_FROM_START) {
|
|
|
|
position = 1
|
|
|
|
} else if (startId == VLC_FROM_PROGRESS) {
|
|
|
|
position = 0
|
|
|
|
}
|
2021-07-17 15:56:26 +00:00
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
vlcIntent.putExtra("position", position)
|
2021-07-17 15:56:26 +00:00
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
vlcIntent.component = VLC_COMPONENT
|
|
|
|
act.setKey(VLC_LAST_ID_KEY, episodeClick.data.id)
|
|
|
|
act.startActivityForResult(vlcIntent, VLC_REQUEST_CODE)
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
|
|
|
showToast(act, e.toString(), Toast.LENGTH_LONG)
|
|
|
|
}
|
2021-07-30 21:03:46 +00:00
|
|
|
}
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
2021-06-10 15:15:14 +00:00
|
|
|
|
2021-06-16 16:54:07 +00:00
|
|
|
ACTION_PLAY_EPISODE_IN_PLAYER -> {
|
2022-01-08 23:59:50 +00:00
|
|
|
viewModel.getGenerator(episodeClick.data)
|
|
|
|
?.let { generator ->
|
|
|
|
activity?.navigate(
|
|
|
|
R.id.global_to_navigation_player,
|
|
|
|
GeneratorPlayer.newInstance(
|
2022-04-08 19:38:19 +00:00
|
|
|
generator, syncdata?.let { HashMap(it) }
|
2022-01-07 19:27:25 +00:00
|
|
|
)
|
2022-01-08 23:59:50 +00:00
|
|
|
)
|
|
|
|
}
|
2021-05-23 17:07:43 +00:00
|
|
|
}
|
2021-07-17 15:56:26 +00:00
|
|
|
|
2021-06-16 16:54:07 +00:00
|
|
|
ACTION_RELOAD_EPISODE -> {
|
2022-03-06 14:44:00 +00:00
|
|
|
viewModel.loadEpisode(episodeClick.data, false, clearCache = true)
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
2021-07-17 14:14:25 +00:00
|
|
|
|
2021-07-17 15:56:26 +00:00
|
|
|
ACTION_DOWNLOAD_MIRROR -> {
|
2022-01-07 19:27:25 +00:00
|
|
|
acquireSingleExtractorLink(
|
|
|
|
sortUrls(
|
|
|
|
currentLinks ?: return@main
|
|
|
|
),//(currentLinks ?: return@main).filter { !it.isM3u8 },
|
|
|
|
getString(R.string.episode_action_download_mirror)
|
|
|
|
) { link ->
|
2022-04-03 20:14:51 +00:00
|
|
|
startDownload(
|
|
|
|
context,
|
|
|
|
episodeClick.data,
|
|
|
|
currentIsMovie ?: return@acquireSingleExtractorLink,
|
|
|
|
currentHeaderName ?: return@acquireSingleExtractorLink,
|
|
|
|
currentType ?: return@acquireSingleExtractorLink,
|
|
|
|
currentPoster ?: return@acquireSingleExtractorLink,
|
|
|
|
apiName,
|
|
|
|
currentId ?: return@acquireSingleExtractorLink,
|
|
|
|
url ?: return@acquireSingleExtractorLink,
|
|
|
|
listOf(link),
|
|
|
|
sortSubs(currentSubs ?: return@acquireSingleExtractorLink),
|
|
|
|
)
|
|
|
|
showToast(activity, R.string.download_started, Toast.LENGTH_SHORT)
|
2021-06-29 23:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-17 14:14:25 +00:00
|
|
|
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> =
|
2021-06-16 16:54:07 +00:00
|
|
|
EpisodeAdapter(
|
|
|
|
ArrayList(),
|
2021-07-23 23:44:54 +00:00
|
|
|
api.hasDownloadSupport,
|
2021-07-24 20:50:57 +00:00
|
|
|
{ episodeClick ->
|
|
|
|
handleAction(episodeClick)
|
|
|
|
},
|
|
|
|
{ downloadClickEvent ->
|
|
|
|
handleDownloadClick(activity, currentHeaderName, downloadClickEvent)
|
|
|
|
}
|
|
|
|
)
|
2021-07-17 14:14:25 +00:00
|
|
|
|
2021-05-23 17:07:43 +00:00
|
|
|
result_episodes.adapter = adapter
|
|
|
|
result_episodes.layoutManager = GridLayoutManager(context, 1)
|
|
|
|
|
2021-06-15 23:25:58 +00:00
|
|
|
result_bookmark_button.setOnClickListener {
|
|
|
|
it.popupMenuNoIcons(
|
|
|
|
items = WatchType.values()
|
|
|
|
.map { watchType -> Pair(watchType.internalId, watchType.stringRes) },
|
2021-06-16 00:15:07 +00:00
|
|
|
//.map { watchType -> Triple(watchType.internalId, watchType.iconRes, watchType.stringRes) },
|
2021-06-15 23:25:58 +00:00
|
|
|
) {
|
|
|
|
context?.let { localContext ->
|
2021-12-16 23:45:20 +00:00
|
|
|
viewModel.updateWatchStatus(WatchType.fromInternalId(this.itemId))
|
2021-06-15 23:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-10 19:48:21 +00:00
|
|
|
observe(viewModel.watchStatus) { watchType ->
|
|
|
|
result_bookmark_button?.text = getString(watchType.stringRes)
|
|
|
|
result_bookmark_fab?.text = getString(watchType.stringRes)
|
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
if (watchType == WatchType.NONE) {
|
2021-12-10 19:48:21 +00:00
|
|
|
result_bookmark_fab?.context?.colorFromAttribute(R.attr.white)
|
|
|
|
} else {
|
|
|
|
result_bookmark_fab?.context?.colorFromAttribute(R.attr.colorPrimary)
|
|
|
|
}?.let {
|
|
|
|
val colorState = ColorStateList.valueOf(it)
|
|
|
|
result_bookmark_fab?.iconTint = colorState
|
|
|
|
result_bookmark_fab?.setTextColor(colorState)
|
|
|
|
}
|
|
|
|
|
|
|
|
result_bookmark_fab?.setOnClickListener { fab ->
|
2021-12-12 02:33:17 +00:00
|
|
|
activity?.showBottomDialog(
|
2021-12-10 19:48:21 +00:00
|
|
|
WatchType.values().map { fab.context.getString(it.stringRes) }.toList(),
|
|
|
|
watchType.ordinal,
|
|
|
|
fab.context.getString(R.string.action_add_to_bookmarks),
|
2021-12-10 23:57:11 +00:00
|
|
|
showApply = false,
|
2021-12-10 19:48:21 +00:00
|
|
|
{}) {
|
2021-12-16 23:45:20 +00:00
|
|
|
viewModel.updateWatchStatus(WatchType.values()[it])
|
2021-12-10 19:48:21 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-15 23:25:58 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 16:45:02 +00:00
|
|
|
/**
|
|
|
|
* Sets next focus to allow navigation up and down between 2 views
|
|
|
|
* if either of them is null nothing happens.
|
|
|
|
**/
|
|
|
|
fun setFocusUpAndDown(upper: View?, down: View?) {
|
|
|
|
if (upper == null || down == null) return
|
|
|
|
upper.nextFocusDownId = down.id
|
|
|
|
down.nextFocusUpId = upper.id
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is to band-aid FireTV navigation
|
|
|
|
result_season_button?.isFocusableInTouchMode = context?.isTvSettings() == true
|
|
|
|
result_episode_select?.isFocusableInTouchMode = context?.isTvSettings() == true
|
|
|
|
result_dub_select?.isFocusableInTouchMode = context?.isTvSettings() == true
|
|
|
|
|
|
|
|
observe(viewModel.selectedSeason) { season ->
|
|
|
|
result_season_button?.text = fromIndexToSeasonText(season)
|
|
|
|
}
|
|
|
|
|
|
|
|
observe(viewModel.seasonSelections) { seasonList ->
|
|
|
|
result_season_button?.visibility = if (seasonList.size <= 1) GONE else VISIBLE.also {
|
|
|
|
|
|
|
|
// If the season button is visible the result season button will be next focus down
|
|
|
|
if (result_series_parent?.isVisible == true)
|
|
|
|
setFocusUpAndDown(result_resume_series_button, result_season_button)
|
|
|
|
else
|
|
|
|
setFocusUpAndDown(result_bookmark_button, result_season_button)
|
|
|
|
}
|
|
|
|
|
|
|
|
result_season_button?.setOnClickListener {
|
|
|
|
result_season_button?.popupMenuNoIconsAndNoStringRes(
|
|
|
|
items = seasonList
|
|
|
|
.map { Pair(it ?: -2, fromIndexToSeasonText(it)) },
|
|
|
|
) {
|
|
|
|
val id = this.itemId
|
|
|
|
|
|
|
|
viewModel.changeSeason(if (id == -2) null else id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
observe(viewModel.selectedRange) { range ->
|
|
|
|
result_episode_select?.text = range
|
|
|
|
}
|
|
|
|
|
|
|
|
observe(viewModel.rangeOptions) { range ->
|
|
|
|
episodeRanges = range
|
|
|
|
result_episode_select?.visibility = if (range.size <= 1) GONE else VISIBLE.also {
|
|
|
|
|
|
|
|
// If Season button is invisible then the bookmark button next focus is episode select
|
|
|
|
if (result_season_button?.isVisible != true) {
|
|
|
|
if (result_series_parent?.isVisible == true)
|
|
|
|
setFocusUpAndDown(result_resume_series_button, result_episode_select)
|
|
|
|
else
|
|
|
|
setFocusUpAndDown(result_bookmark_button, result_episode_select)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 01:38:55 +00:00
|
|
|
context?.let { ctx ->
|
|
|
|
val arrayAdapter = ArrayAdapter<String>(ctx, R.layout.sort_bottom_single_choice)
|
|
|
|
/*
|
|
|
|
-1 -> None
|
|
|
|
0 -> Watching
|
|
|
|
1 -> Completed
|
|
|
|
2 -> OnHold
|
|
|
|
3 -> Dropped
|
|
|
|
4 -> PlanToWatch
|
|
|
|
5 -> ReWatching
|
|
|
|
*/
|
|
|
|
val items = listOf(
|
|
|
|
R.string.none,
|
|
|
|
R.string.type_watching,
|
|
|
|
R.string.type_completed,
|
|
|
|
R.string.type_on_hold,
|
|
|
|
R.string.type_dropped,
|
|
|
|
R.string.type_plan_to_watch,
|
|
|
|
R.string.type_re_watching
|
|
|
|
).map { ctx.getString(it) }
|
|
|
|
arrayAdapter.addAll(items)
|
|
|
|
result_sync_check?.choiceMode = AbsListView.CHOICE_MODE_SINGLE
|
|
|
|
result_sync_check?.adapter = arrayAdapter
|
|
|
|
UIHelper.setListViewHeightBasedOnItems(result_sync_check)
|
|
|
|
|
|
|
|
result_sync_check?.setOnItemClickListener { _, _, which, _ ->
|
|
|
|
syncModel.setStatus(which - 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
result_sync_rating?.addOnChangeListener { _, value, _ ->
|
|
|
|
syncModel.setScore(value.toInt())
|
|
|
|
}
|
|
|
|
|
|
|
|
result_sync_add_episode?.setOnClickListener {
|
|
|
|
syncModel.setEpisodesDelta(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
result_sync_sub_episode?.setOnClickListener {
|
|
|
|
syncModel.setEpisodesDelta(-1)
|
|
|
|
}
|
|
|
|
|
2022-04-02 22:06:35 +00:00
|
|
|
result_sync_current_episodes?.doOnTextChanged { text, _, before, count ->
|
|
|
|
if (count == before) return@doOnTextChanged
|
2022-04-02 01:38:55 +00:00
|
|
|
text?.toString()?.toIntOrNull()?.let { ep ->
|
|
|
|
syncModel.setEpisodes(ep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-22 16:52:31 +00:00
|
|
|
val imgAdapter = ImageAdapter(
|
|
|
|
R.layout.result_mini_image,
|
|
|
|
nextFocusDown = R.id.result_sync_set_score,
|
|
|
|
clickCallback = { action ->
|
|
|
|
if (action == IMAGE_CLICK || action == IMAGE_LONG_CLICK) {
|
|
|
|
if (result_overlapping_panels?.getSelectedPanel()?.ordinal == 1) {
|
|
|
|
result_overlapping_panels?.openStartPanel()
|
|
|
|
} else {
|
|
|
|
result_overlapping_panels?.closePanels()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-04-03 01:13:02 +00:00
|
|
|
result_mini_sync?.adapter = imgAdapter
|
2022-04-02 01:38:55 +00:00
|
|
|
|
2022-04-02 22:06:35 +00:00
|
|
|
observe(syncModel.synced) { list ->
|
|
|
|
result_sync_names?.text =
|
|
|
|
list.filter { it.isSynced && it.hasAccount }.joinToString { it.name }
|
2022-04-03 01:13:02 +00:00
|
|
|
|
2022-04-22 18:53:58 +00:00
|
|
|
val newList = list.filter { it.isSynced && it.hasAccount }
|
2022-04-08 19:38:19 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_mini_sync?.isVisible = newList.isNotEmpty()
|
|
|
|
(result_mini_sync?.adapter as? ImageAdapter?)?.updateList(newList.map { it.icon })
|
2022-04-02 22:06:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-08 19:38:19 +00:00
|
|
|
observe(syncModel.syncIds) {
|
|
|
|
syncdata = it
|
|
|
|
}
|
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
var currentSyncProgress = 0
|
2022-04-03 15:00:50 +00:00
|
|
|
|
|
|
|
fun setSyncMaxEpisodes(totalEpisodes: Int?) {
|
|
|
|
result_sync_episodes?.max = (totalEpisodes ?: 0) * 1000
|
|
|
|
|
|
|
|
normalSafeApiCall {
|
|
|
|
val ctx = result_sync_max_episodes?.context
|
|
|
|
result_sync_max_episodes?.text =
|
|
|
|
totalEpisodes?.let { episodes ->
|
|
|
|
ctx?.getString(R.string.sync_total_episodes_some)?.format(episodes)
|
|
|
|
} ?: run {
|
|
|
|
ctx?.getString(R.string.sync_total_episodes_none)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 01:38:55 +00:00
|
|
|
observe(syncModel.metadata) { meta ->
|
|
|
|
when (meta) {
|
|
|
|
is Resource.Success -> {
|
|
|
|
val d = meta.value
|
2022-04-03 01:13:02 +00:00
|
|
|
result_sync_episodes?.progress = currentSyncProgress * 1000
|
2022-04-03 15:00:50 +00:00
|
|
|
setSyncMaxEpisodes(d.totalEpisodes)
|
2022-04-03 01:13:02 +00:00
|
|
|
viewModel.setMeta(d)
|
2022-04-02 01:38:55 +00:00
|
|
|
}
|
|
|
|
is Resource.Loading -> {
|
|
|
|
result_sync_max_episodes?.text =
|
|
|
|
result_sync_max_episodes?.context?.getString(R.string.sync_total_episodes_none)
|
|
|
|
}
|
|
|
|
else -> {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
observe(syncModel.userData) { status ->
|
2022-04-01 20:05:34 +00:00
|
|
|
var closed = false
|
|
|
|
when (status) {
|
|
|
|
is Resource.Failure -> {
|
|
|
|
result_sync_loading_shimmer?.stopShimmer()
|
|
|
|
result_sync_loading_shimmer?.isVisible = false
|
|
|
|
result_sync_holder?.isVisible = false
|
2022-04-03 21:41:28 +00:00
|
|
|
closed = true
|
2022-04-01 20:05:34 +00:00
|
|
|
}
|
|
|
|
is Resource.Loading -> {
|
|
|
|
result_sync_loading_shimmer?.startShimmer()
|
|
|
|
result_sync_loading_shimmer?.isVisible = true
|
|
|
|
result_sync_holder?.isVisible = false
|
|
|
|
}
|
|
|
|
is Resource.Success -> {
|
|
|
|
result_sync_loading_shimmer?.stopShimmer()
|
|
|
|
result_sync_loading_shimmer?.isVisible = false
|
|
|
|
result_sync_holder?.isVisible = true
|
|
|
|
|
|
|
|
val d = status.value
|
|
|
|
result_sync_rating?.value = d.score?.toFloat() ?: 0.0f
|
2022-04-02 01:38:55 +00:00
|
|
|
result_sync_check?.setItemChecked(d.status + 1, true)
|
|
|
|
val watchedEpisodes = d.watchedEpisodes ?: 0
|
2022-04-03 01:13:02 +00:00
|
|
|
currentSyncProgress = watchedEpisodes
|
2022-04-03 15:00:50 +00:00
|
|
|
|
|
|
|
d.maxEpisodes?.let {
|
|
|
|
// don't directly call it because we don't want to override metadata observe
|
|
|
|
setSyncMaxEpisodes(it)
|
|
|
|
}
|
|
|
|
|
2022-04-02 01:38:55 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
result_sync_episodes?.setProgress(watchedEpisodes * 1000, true)
|
|
|
|
} else {
|
|
|
|
result_sync_episodes?.progress = watchedEpisodes * 1000
|
|
|
|
}
|
|
|
|
result_sync_current_episodes?.text =
|
|
|
|
Editable.Factory.getInstance()?.newEditable(watchedEpisodes.toString())
|
|
|
|
normalSafeApiCall { // format might fail
|
|
|
|
context?.getString(R.string.sync_score_format)?.format(d.score ?: 0)?.let {
|
|
|
|
result_sync_score_text?.text = it
|
|
|
|
}
|
|
|
|
}
|
2022-04-01 20:05:34 +00:00
|
|
|
}
|
|
|
|
null -> {
|
|
|
|
closed = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result_overlapping_panels?.setStartPanelLockState(if (closed) OverlappingPanelsLayout.LockState.CLOSE else OverlappingPanelsLayout.LockState.UNLOCKED)
|
|
|
|
}
|
|
|
|
|
2021-07-29 15:16:08 +00:00
|
|
|
observe(viewModel.episodes) { episodeList ->
|
2021-08-22 17:14:48 +00:00
|
|
|
lateFixDownloadButton(episodeList.size <= 1) // movies can have multible parts but still be *movies* this will fix this
|
2022-02-04 14:46:48 +00:00
|
|
|
var isSeriesVisible = false
|
2022-02-06 15:10:45 +00:00
|
|
|
var isProgressVisible = false
|
2022-02-04 14:46:48 +00:00
|
|
|
DataStoreHelper.getLastWatched(currentId)?.let { resume ->
|
2022-02-06 15:10:45 +00:00
|
|
|
if (currentIsMovie == false) {
|
2022-02-04 14:46:48 +00:00
|
|
|
isSeriesVisible = true
|
2022-02-05 23:58:56 +00:00
|
|
|
|
2022-02-04 14:46:48 +00:00
|
|
|
result_resume_series_button?.setOnClickListener {
|
|
|
|
episodeList.firstOrNull { it.id == resume.episodeId }?.let {
|
|
|
|
handleAction(EpisodeClickEvent(ACTION_PLAY_EPISODE_IN_PLAYER, it))
|
|
|
|
}
|
|
|
|
}
|
2022-02-05 23:58:56 +00:00
|
|
|
|
2022-02-04 14:46:48 +00:00
|
|
|
result_resume_series_title?.text =
|
|
|
|
if (resume.season == null)
|
|
|
|
"${getString(R.string.episode)} ${resume.episode}"
|
|
|
|
else
|
|
|
|
" \"${getString(R.string.season_short)}${resume.season}:${getString(R.string.episode_short)}${resume.episode}\""
|
2022-02-06 15:10:45 +00:00
|
|
|
}
|
2022-02-04 14:46:48 +00:00
|
|
|
|
2022-02-06 15:10:45 +00:00
|
|
|
getViewPos(resume.episodeId)?.let { viewPos ->
|
2022-02-14 21:12:06 +00:00
|
|
|
if (viewPos.position > 30_000L || currentIsMovie == false) { // first 30s will not show for movies
|
2022-02-04 14:46:48 +00:00
|
|
|
result_resume_series_progress?.apply {
|
|
|
|
max = (viewPos.duration / 1000).toInt()
|
|
|
|
progress = (viewPos.position / 1000).toInt()
|
|
|
|
}
|
2022-02-04 20:49:35 +00:00
|
|
|
result_resume_series_progress_text?.text =
|
|
|
|
getString(R.string.resume_time_left).format((viewPos.duration - viewPos.position) / (60_000))
|
2022-02-06 15:10:45 +00:00
|
|
|
isProgressVisible = true
|
|
|
|
} else {
|
|
|
|
isProgressVisible = false
|
2022-02-05 23:58:56 +00:00
|
|
|
isSeriesVisible = false
|
2022-02-04 14:46:48 +00:00
|
|
|
}
|
2022-02-06 15:10:45 +00:00
|
|
|
} ?: run {
|
|
|
|
isProgressVisible = false
|
|
|
|
isSeriesVisible = false
|
2022-02-04 14:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-06 15:10:45 +00:00
|
|
|
|
2022-02-04 14:46:48 +00:00
|
|
|
result_series_parent?.isVisible = isSeriesVisible
|
2022-04-03 21:41:28 +00:00
|
|
|
if (isSeriesVisible && activity?.currentFocus?.id == R.id.result_back && context?.isTrueTvSettings() == true) {
|
|
|
|
result_resume_series_button?.requestFocus()
|
|
|
|
}
|
|
|
|
|
2022-03-27 16:45:02 +00:00
|
|
|
if (isSeriesVisible) {
|
|
|
|
val down = when {
|
|
|
|
result_season_button?.isVisible == true -> result_season_button
|
|
|
|
result_episode_select?.isVisible == true -> result_episode_select
|
|
|
|
result_dub_select?.isVisible == true -> result_dub_select
|
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
setFocusUpAndDown(result_resume_series_button, down)
|
|
|
|
setFocusUpAndDown(result_bookmark_button, result_resume_series_button)
|
|
|
|
}
|
|
|
|
|
2022-02-06 15:10:45 +00:00
|
|
|
result_resume_progress_holder?.isVisible = isProgressVisible
|
|
|
|
context?.getString(if (isProgressVisible) R.string.resume else R.string.play_movie_button)
|
|
|
|
?.let {
|
|
|
|
result_play_movie?.text = it
|
|
|
|
}
|
2021-08-11 18:26:19 +00:00
|
|
|
|
2021-07-29 15:16:08 +00:00
|
|
|
when (startAction) {
|
|
|
|
START_ACTION_RESUME_LATEST -> {
|
|
|
|
for (ep in episodeList) {
|
2022-04-26 13:52:30 +00:00
|
|
|
println("WATCH STATUS::: S${ep.season} E ${ep.episode} - ${ep.getWatchProgress()}")
|
2021-07-29 15:16:08 +00:00
|
|
|
if (ep.getWatchProgress() > 0.90f) { // watched too much
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
handleAction(EpisodeClickEvent(ACTION_PLAY_EPISODE_IN_PLAYER, ep))
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2021-08-25 15:28:25 +00:00
|
|
|
START_ACTION_LOAD_EP -> {
|
|
|
|
for (ep in episodeList) {
|
|
|
|
if (ep.id == startValue) { // watched too much
|
2022-04-26 13:52:30 +00:00
|
|
|
println("WATCH STATUS::: START_ACTION_LOAD_EP S${ep.season} E ${ep.episode} - ${ep.getWatchProgress()}")
|
2021-08-25 15:28:25 +00:00
|
|
|
handleAction(EpisodeClickEvent(ACTION_PLAY_EPISODE_IN_PLAYER, ep))
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-07 19:27:25 +00:00
|
|
|
else -> Unit
|
2021-07-29 15:16:08 +00:00
|
|
|
}
|
2021-09-25 13:00:59 +00:00
|
|
|
arguments?.remove("startValue")
|
|
|
|
arguments?.remove("startAction")
|
2021-08-25 15:28:25 +00:00
|
|
|
startAction = null
|
2021-09-25 13:00:59 +00:00
|
|
|
startValue = null
|
2021-07-29 15:16:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 16:45:02 +00:00
|
|
|
observe(viewModel.publicEpisodes) { episodes ->
|
2021-09-19 22:36:32 +00:00
|
|
|
when (episodes) {
|
|
|
|
is Resource.Failure -> {
|
2021-09-20 21:11:36 +00:00
|
|
|
result_episode_loading?.isVisible = false
|
|
|
|
//result_episodes?.isVisible = false
|
2021-09-19 22:36:32 +00:00
|
|
|
}
|
|
|
|
is Resource.Loading -> {
|
2021-09-20 21:11:36 +00:00
|
|
|
result_episode_loading?.isVisible = true
|
2021-10-22 13:23:48 +00:00
|
|
|
// result_episodes?.isVisible = false
|
2021-09-19 22:36:32 +00:00
|
|
|
}
|
|
|
|
is Resource.Success -> {
|
2021-09-20 21:11:36 +00:00
|
|
|
//result_episodes?.isVisible = true
|
|
|
|
result_episode_loading?.isVisible = false
|
2021-09-19 22:36:32 +00:00
|
|
|
if (result_episodes == null || result_episodes.adapter == null) return@observe
|
|
|
|
currentEpisodes = episodes.value
|
2022-02-13 00:53:40 +00:00
|
|
|
(result_episodes?.adapter as? EpisodeAdapter?)?.cardList = episodes.value
|
|
|
|
(result_episodes?.adapter as? EpisodeAdapter?)?.updateLayout()
|
|
|
|
(result_episodes?.adapter as? EpisodeAdapter?)?.notifyDataSetChanged()
|
2021-09-19 22:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-22 22:25:56 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 16:45:02 +00:00
|
|
|
observe(viewModel.dubStatus) { status ->
|
2021-11-02 15:09:29 +00:00
|
|
|
result_dub_select?.text = status.toString()
|
|
|
|
}
|
|
|
|
|
2022-03-27 16:45:02 +00:00
|
|
|
val preferDub = context?.getApiDubstatusSettings()?.all { it == DubStatus.Dubbed } == true
|
|
|
|
|
|
|
|
observe(viewModel.dubSubSelections) { range ->
|
2021-11-02 15:09:29 +00:00
|
|
|
dubRange = range
|
2022-03-27 16:45:02 +00:00
|
|
|
|
2022-04-01 20:05:34 +00:00
|
|
|
if (preferDub && dubRange?.contains(DubStatus.Dubbed) == true) {
|
2022-03-27 16:45:02 +00:00
|
|
|
viewModel.changeDubStatus(DubStatus.Dubbed)
|
|
|
|
}
|
|
|
|
|
2021-11-02 15:09:29 +00:00
|
|
|
result_dub_select?.visibility = if (range.size <= 1) GONE else VISIBLE
|
2022-03-27 16:45:02 +00:00
|
|
|
|
|
|
|
if (result_season_button?.isVisible != true && result_episode_select?.isVisible != true) {
|
|
|
|
if (result_series_parent?.isVisible == true)
|
|
|
|
setFocusUpAndDown(result_resume_series_button, result_dub_select)
|
|
|
|
else
|
|
|
|
setFocusUpAndDown(result_bookmark_button, result_dub_select)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result_cast_items?.setOnFocusChangeListener { v, hasFocus ->
|
|
|
|
// Always escape focus
|
|
|
|
if (hasFocus) result_bookmark_button?.requestFocus()
|
2021-11-02 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result_dub_select.setOnClickListener {
|
|
|
|
val ranges = dubRange
|
|
|
|
if (ranges != null) {
|
2022-03-27 16:45:02 +00:00
|
|
|
it.popupMenuNoIconsAndNoStringRes(ranges
|
|
|
|
.map { status ->
|
|
|
|
Pair(
|
|
|
|
status.ordinal,
|
|
|
|
status.toString()
|
|
|
|
)
|
|
|
|
}
|
2021-11-02 15:09:29 +00:00
|
|
|
.toList()) {
|
2021-12-16 23:45:20 +00:00
|
|
|
viewModel.changeDubStatus(DubStatus.values()[itemId])
|
2021-11-02 15:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-01 20:05:34 +00:00
|
|
|
result_episode_select?.setOnClickListener {
|
2021-07-25 20:50:16 +00:00
|
|
|
val ranges = episodeRanges
|
|
|
|
if (ranges != null) {
|
2021-12-17 12:42:25 +00:00
|
|
|
it.popupMenuNoIconsAndNoStringRes(ranges.mapIndexed { index, s -> Pair(index, s) }
|
|
|
|
.toList()) {
|
2021-12-16 23:45:20 +00:00
|
|
|
viewModel.changeRange(itemId)
|
2021-07-25 20:50:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-01 20:05:34 +00:00
|
|
|
result_sync_set_score?.setOnClickListener {
|
2022-04-02 01:38:55 +00:00
|
|
|
syncModel.publishUserData()
|
2022-04-01 20:05:34 +00:00
|
|
|
}
|
|
|
|
|
2021-07-25 20:50:16 +00:00
|
|
|
observe(viewModel.publicEpisodesCount) { count ->
|
2021-09-20 21:11:36 +00:00
|
|
|
if (count < 0) {
|
|
|
|
result_episodes_text?.isVisible = false
|
|
|
|
} else {
|
2021-10-22 13:23:48 +00:00
|
|
|
// result_episodes_text?.isVisible = true
|
2021-09-20 21:11:36 +00:00
|
|
|
result_episodes_text?.text =
|
|
|
|
"$count ${if (count == 1) getString(R.string.episode) else getString(R.string.episodes)}"
|
|
|
|
}
|
2021-07-25 20:50:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-17 14:14:25 +00:00
|
|
|
observe(viewModel.id) {
|
|
|
|
currentId = it
|
|
|
|
}
|
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
observe(viewModel.result) { data ->
|
2021-05-18 13:43:32 +00:00
|
|
|
when (data) {
|
|
|
|
is Resource.Success -> {
|
|
|
|
val d = data.value
|
2022-04-03 01:13:02 +00:00
|
|
|
if (d !is AnimeLoadResponse && result_episode_loading.isVisible) { // no episode loading when not anime
|
|
|
|
result_episode_loading.isVisible = false
|
|
|
|
}
|
2021-09-19 22:36:32 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
updateVisStatus(2)
|
2021-06-16 16:54:07 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_vpn?.text = when (api.vpnStatus) {
|
|
|
|
VPNStatus.MightBeNeeded -> getString(R.string.vpn_might_be_needed)
|
|
|
|
VPNStatus.Torrent -> getString(R.string.vpn_torrent)
|
|
|
|
else -> ""
|
|
|
|
}
|
|
|
|
result_vpn?.isGone = api.vpnStatus == VPNStatus.None
|
2021-08-29 13:10:36 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_info?.text = when (api.providerType) {
|
|
|
|
ProviderType.MetaProvider -> getString(R.string.provider_info_meta)
|
|
|
|
else -> ""
|
|
|
|
}
|
|
|
|
result_info?.isVisible = api.providerType == ProviderType.MetaProvider
|
|
|
|
|
|
|
|
if (d.type.isEpisodeBased()) {
|
|
|
|
val ep = d as? TvSeriesLoadResponse
|
|
|
|
val epCount = ep?.episodes?.size ?: 1
|
|
|
|
if (epCount < 1) {
|
|
|
|
result_info?.text = getString(R.string.no_episodes_found)
|
|
|
|
result_info?.isVisible = true
|
2022-01-11 12:53:08 +00:00
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
}
|
2022-01-11 12:53:08 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
currentHeaderName = d.name
|
|
|
|
currentType = d.type
|
2021-06-14 00:00:29 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
currentPoster = d.posterUrl
|
|
|
|
currentIsMovie = !d.isEpisodeBased()
|
2021-06-10 15:15:14 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_open_in_browser?.setOnClickListener {
|
|
|
|
val i = Intent(ACTION_VIEW)
|
|
|
|
i.data = Uri.parse(d.url)
|
|
|
|
try {
|
|
|
|
startActivity(i)
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
2021-06-10 15:15:14 +00:00
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
}
|
2021-06-10 15:15:14 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_search?.setOnClickListener {
|
|
|
|
QuickSearchFragment.pushSearch(activity, d.name)
|
|
|
|
}
|
2021-11-20 00:41:37 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_share?.setOnClickListener {
|
|
|
|
try {
|
|
|
|
val i = Intent(ACTION_SEND)
|
|
|
|
i.type = "text/plain"
|
|
|
|
i.putExtra(EXTRA_SUBJECT, d.name)
|
|
|
|
i.putExtra(EXTRA_TEXT, d.url)
|
|
|
|
startActivity(createChooser(i, d.name))
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
2021-06-10 15:15:14 +00:00
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
}
|
2021-06-10 15:15:14 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
val showStatus = when (d) {
|
|
|
|
is TvSeriesLoadResponse -> d.showStatus
|
|
|
|
is AnimeLoadResponse -> d.showStatus
|
|
|
|
else -> null
|
|
|
|
}
|
2022-04-01 20:05:34 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
setShow(showStatus)
|
|
|
|
setDuration(d.duration)
|
|
|
|
setYear(d.year)
|
|
|
|
setRating(d.rating)
|
2022-04-18 00:26:13 +00:00
|
|
|
setRecommendations(d.recommendations, null)
|
2022-04-03 01:13:02 +00:00
|
|
|
setActors(d.actors)
|
|
|
|
|
2022-04-03 21:41:28 +00:00
|
|
|
if (SettingsFragment.accountEnabled) {
|
2022-04-08 19:38:19 +00:00
|
|
|
if (syncModel.addSyncs(d.syncData)) {
|
2022-04-03 21:41:28 +00:00
|
|
|
syncModel.updateMetaAndUser()
|
|
|
|
syncModel.updateSynced()
|
|
|
|
} else {
|
|
|
|
syncModel.addFromUrl(d.url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_meta_site?.text = d.apiName
|
2022-04-01 20:05:34 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
val posterImageLink = d.posterUrl
|
|
|
|
if (!posterImageLink.isNullOrEmpty()) {
|
2022-04-13 17:29:30 +00:00
|
|
|
result_poster?.setImage(posterImageLink, d.posterHeaders)
|
|
|
|
result_poster_blur?.setImageBlur(posterImageLink, 10, 3, d.posterHeaders)
|
2022-04-03 01:13:02 +00:00
|
|
|
//Full screen view of Poster image
|
2022-04-03 21:41:28 +00:00
|
|
|
if (context?.isTrueTvSettings() == false) // Poster not clickable on tv
|
|
|
|
result_poster_holder?.setOnClickListener {
|
|
|
|
try {
|
|
|
|
context?.let { ctx ->
|
|
|
|
val bitmap = result_poster.drawable.toBitmap()
|
|
|
|
val sourceBuilder = AlertDialog.Builder(ctx)
|
|
|
|
sourceBuilder.setView(R.layout.result_poster)
|
|
|
|
|
|
|
|
val sourceDialog = sourceBuilder.create()
|
|
|
|
sourceDialog.show()
|
|
|
|
|
|
|
|
sourceDialog.findViewById<ImageView?>(R.id.imgPoster)
|
|
|
|
?.apply {
|
|
|
|
setImageBitmap(bitmap)
|
|
|
|
setOnClickListener {
|
|
|
|
sourceDialog.dismissSafe()
|
|
|
|
}
|
2022-03-20 23:25:25 +00:00
|
|
|
}
|
2022-04-03 21:41:28 +00:00
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
2022-03-20 23:25:25 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-03 21:41:28 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
} else {
|
|
|
|
result_poster?.setImageResource(R.drawable.default_cover)
|
|
|
|
result_poster_blur?.setImageResource(R.drawable.default_cover)
|
|
|
|
}
|
2021-12-10 00:20:24 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_poster_holder?.visibility = VISIBLE
|
|
|
|
|
|
|
|
/*result_play_movie?.text =
|
|
|
|
if (d.type == TvType.Torrent) getString(R.string.play_torrent_button) else getString(
|
|
|
|
R.string.play_movie_button
|
|
|
|
)*/
|
|
|
|
//result_plot_header?.text =
|
|
|
|
// if (d.type == TvType.Torrent) getString(R.string.torrent_plot) else getString(R.string.result_plot)
|
|
|
|
if (!d.plot.isNullOrEmpty()) {
|
|
|
|
var syno = d.plot!!
|
|
|
|
if (syno.length > MAX_SYNO_LENGH) {
|
|
|
|
syno = syno.substring(0, MAX_SYNO_LENGH) + "..."
|
2021-05-22 22:25:56 +00:00
|
|
|
}
|
2022-04-03 21:41:28 +00:00
|
|
|
result_description.setOnClickListener {
|
2022-04-03 01:13:02 +00:00
|
|
|
val builder: AlertDialog.Builder =
|
|
|
|
AlertDialog.Builder(requireContext())
|
|
|
|
builder.setMessage(d.plot)
|
|
|
|
.setTitle(if (d.type == TvType.Torrent) R.string.torrent_plot else R.string.result_plot)
|
|
|
|
.show()
|
|
|
|
}
|
2022-04-03 21:41:28 +00:00
|
|
|
result_description.text = syno
|
2022-04-03 01:13:02 +00:00
|
|
|
} else {
|
2022-04-03 21:41:28 +00:00
|
|
|
result_description.text =
|
2022-04-03 01:13:02 +00:00
|
|
|
if (d.type == TvType.Torrent) getString(R.string.torrent_no_plot) else getString(
|
|
|
|
R.string.normal_no_plot
|
|
|
|
)
|
|
|
|
}
|
2021-05-22 22:25:56 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_tag?.removeAllViews()
|
|
|
|
//result_tag_holder?.visibility = GONE
|
|
|
|
// result_status.visibility = GONE
|
2021-06-06 18:06:01 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
d.comingSoon.let { soon ->
|
|
|
|
result_coming_soon?.isVisible = soon
|
|
|
|
result_data_holder?.isGone = soon
|
|
|
|
}
|
2022-03-20 23:59:17 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
val tags = d.tags
|
|
|
|
if (tags.isNullOrEmpty()) {
|
|
|
|
//result_tag_holder?.visibility = GONE
|
|
|
|
} else {
|
|
|
|
//result_tag_holder?.visibility = VISIBLE
|
2022-04-03 21:41:28 +00:00
|
|
|
val isOnTv = context?.isTrueTvSettings() == true
|
2022-04-03 01:13:02 +00:00
|
|
|
for ((index, tag) in tags.withIndex()) {
|
|
|
|
val viewBtt = layoutInflater.inflate(R.layout.result_tag, null)
|
|
|
|
val btt = viewBtt.findViewById<MaterialButton>(R.id.result_tag_card)
|
|
|
|
btt.text = tag
|
2022-04-03 21:41:28 +00:00
|
|
|
btt.isFocusable = !isOnTv
|
|
|
|
btt.isClickable = !isOnTv
|
2022-04-03 01:13:02 +00:00
|
|
|
result_tag?.addView(viewBtt, index)
|
2021-06-26 14:44:53 +00:00
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
}
|
2021-06-26 14:44:53 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
if (d.type.isMovieType()) {
|
|
|
|
val hasDownloadSupport = api.hasDownloadSupport
|
|
|
|
lateFixDownloadButton(true)
|
2021-07-23 23:44:54 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_play_movie?.setOnClickListener {
|
|
|
|
val card =
|
|
|
|
currentEpisodes?.firstOrNull() ?: return@setOnClickListener
|
|
|
|
handleAction(EpisodeClickEvent(ACTION_CLICK_DEFAULT, card))
|
|
|
|
}
|
2021-07-25 16:08:34 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_play_movie?.setOnLongClickListener {
|
|
|
|
val card = currentEpisodes?.firstOrNull()
|
|
|
|
?: return@setOnLongClickListener true
|
|
|
|
handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card))
|
|
|
|
return@setOnLongClickListener true
|
|
|
|
}
|
2021-09-19 20:33:39 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_download_movie?.setOnLongClickListener {
|
|
|
|
val card = currentEpisodes?.firstOrNull()
|
|
|
|
?: return@setOnLongClickListener true
|
|
|
|
handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card))
|
|
|
|
return@setOnLongClickListener true
|
|
|
|
}
|
2021-11-30 17:59:52 +00:00
|
|
|
|
2021-07-25 16:08:34 +00:00
|
|
|
// result_options.setOnClickListener {
|
|
|
|
// val card = currentEpisodes?.first() ?: return@setOnClickListener
|
|
|
|
// handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card))
|
|
|
|
// }
|
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_download_movie?.visibility =
|
|
|
|
if (hasDownloadSupport) VISIBLE else GONE
|
|
|
|
if (hasDownloadSupport) {
|
|
|
|
val localId = d.getId()
|
|
|
|
val file =
|
|
|
|
VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(
|
|
|
|
requireContext(),
|
|
|
|
localId
|
|
|
|
)
|
|
|
|
downloadButton?.dispose()
|
|
|
|
downloadButton = EasyDownloadButton()
|
|
|
|
downloadButton?.setUpMoreButton(
|
|
|
|
file?.fileLength,
|
|
|
|
file?.totalBytes,
|
|
|
|
result_movie_progress_downloaded,
|
|
|
|
result_movie_download_icon,
|
|
|
|
result_movie_download_text,
|
|
|
|
result_movie_download_text_precentage,
|
|
|
|
result_download_movie,
|
|
|
|
true,
|
|
|
|
VideoDownloadHelper.DownloadEpisodeCached(
|
|
|
|
d.name,
|
|
|
|
d.posterUrl,
|
|
|
|
0,
|
|
|
|
null,
|
|
|
|
localId,
|
|
|
|
localId,
|
|
|
|
d.rating,
|
|
|
|
d.plot,
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
)
|
|
|
|
) { downloadClickEvent ->
|
|
|
|
if (downloadClickEvent.action == DOWNLOAD_ACTION_DOWNLOAD) {
|
|
|
|
currentEpisodes?.firstOrNull()?.let { episode ->
|
|
|
|
handleAction(
|
|
|
|
EpisodeClickEvent(
|
|
|
|
ACTION_DOWNLOAD_EPISODE,
|
|
|
|
ResultEpisode(
|
|
|
|
d.name,
|
|
|
|
d.name,
|
|
|
|
null,
|
|
|
|
0,
|
|
|
|
null,
|
|
|
|
episode.data,
|
|
|
|
d.apiName,
|
|
|
|
localId,
|
|
|
|
0,
|
|
|
|
0L,
|
|
|
|
0L,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
d.type,
|
|
|
|
localId,
|
2021-07-25 20:50:16 +00:00
|
|
|
)
|
2021-07-25 16:08:34 +00:00
|
|
|
)
|
2021-12-17 12:42:25 +00:00
|
|
|
)
|
2021-07-25 20:50:16 +00:00
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
} else {
|
|
|
|
handleDownloadClick(
|
|
|
|
activity,
|
|
|
|
currentHeaderName,
|
|
|
|
downloadClickEvent
|
|
|
|
)
|
2021-07-25 16:08:34 +00:00
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
}
|
2022-02-06 14:53:39 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
result_download_movie?.setOnLongClickListener {
|
|
|
|
val card =
|
|
|
|
currentEpisodes?.firstOrNull()
|
|
|
|
?: return@setOnLongClickListener false
|
|
|
|
handleAction(EpisodeClickEvent(ACTION_DOWNLOAD_MIRROR, card))
|
|
|
|
return@setOnLongClickListener true
|
|
|
|
}
|
2022-02-06 15:16:11 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
/*downloadButton?.setUpMaterialButton(
|
|
|
|
file?.fileLength,
|
|
|
|
file?.totalBytes,
|
|
|
|
result_movie_progress_downloaded,
|
|
|
|
result_download_movie,
|
|
|
|
null, //result_movie_text_progress
|
|
|
|
VideoDownloadHelper.DownloadEpisodeCached(
|
|
|
|
d.name,
|
|
|
|
d.posterUrl,
|
|
|
|
0,
|
|
|
|
null,
|
|
|
|
localId,
|
|
|
|
localId,
|
|
|
|
d.rating,
|
|
|
|
d.plot,
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
)
|
|
|
|
) { downloadClickEvent ->
|
|
|
|
if (downloadClickEvent.action == DOWNLOAD_ACTION_DOWNLOAD) {
|
|
|
|
currentEpisodes?.firstOrNull()?.let { episode ->
|
|
|
|
handleAction(
|
|
|
|
EpisodeClickEvent(
|
|
|
|
ACTION_DOWNLOAD_EPISODE,
|
|
|
|
ResultEpisode(
|
|
|
|
d.name,
|
|
|
|
d.name,
|
|
|
|
null,
|
|
|
|
0,
|
|
|
|
null,
|
|
|
|
episode.data,
|
|
|
|
d.apiName,
|
|
|
|
localId,
|
|
|
|
0,
|
|
|
|
0L,
|
|
|
|
0L,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
d.type,
|
|
|
|
localId,
|
2022-02-06 14:53:39 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
} else {
|
|
|
|
handleDownloadClick(
|
|
|
|
activity,
|
|
|
|
currentHeaderName,
|
|
|
|
downloadClickEvent
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}*/
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
} else {
|
|
|
|
lateFixDownloadButton(false)
|
|
|
|
}
|
2021-06-16 16:54:07 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
context?.getString(
|
|
|
|
when (d.type) {
|
|
|
|
TvType.TvSeries -> R.string.tv_series_singular
|
|
|
|
TvType.Anime -> R.string.anime_singular
|
|
|
|
TvType.OVA -> R.string.ova_singular
|
|
|
|
TvType.AnimeMovie -> R.string.movies_singular
|
|
|
|
TvType.Cartoon -> R.string.cartoons_singular
|
|
|
|
TvType.Documentary -> R.string.documentaries_singular
|
|
|
|
TvType.Movie -> R.string.movies_singular
|
|
|
|
TvType.Torrent -> R.string.torrent_singular
|
|
|
|
TvType.AsianDrama -> R.string.asian_drama_singular
|
2022-01-31 20:47:59 +00:00
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
)?.let {
|
|
|
|
result_meta_type?.text = it
|
|
|
|
}
|
2022-01-31 20:47:59 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
when (d) {
|
|
|
|
is AnimeLoadResponse -> {
|
2022-01-31 20:47:59 +00:00
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
// val preferEnglish = true
|
|
|
|
//val titleName = (if (preferEnglish) d.engName else d.japName) ?: d.name
|
|
|
|
val titleName = d.name
|
|
|
|
result_title.text = titleName
|
|
|
|
//result_toolbar.title = titleName
|
2021-05-18 13:43:32 +00:00
|
|
|
}
|
2022-04-03 01:13:02 +00:00
|
|
|
else -> result_title.text = d.name
|
2021-05-18 13:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
is Resource.Failure -> {
|
2021-08-24 22:19:15 +00:00
|
|
|
result_error_text.text = url?.plus("\n") + data.errorString
|
2021-06-16 16:54:07 +00:00
|
|
|
updateVisStatus(1)
|
|
|
|
}
|
|
|
|
is Resource.Loading -> {
|
|
|
|
updateVisStatus(0)
|
2021-05-18 13:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 18:41:33 +00:00
|
|
|
val recAdapter: RecyclerView.Adapter<RecyclerView.ViewHolder>? = activity?.let {
|
|
|
|
SearchAdapter(
|
|
|
|
ArrayList(),
|
|
|
|
result_recommendations,
|
|
|
|
) { callback ->
|
|
|
|
SearchHelper.handleSearchClickCallback(activity, callback)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-18 00:26:13 +00:00
|
|
|
result_recommendations?.adapter = recAdapter
|
2021-12-13 18:41:33 +00:00
|
|
|
|
2021-09-19 22:36:32 +00:00
|
|
|
context?.let { ctx ->
|
2021-12-10 19:48:21 +00:00
|
|
|
result_bookmark_button?.isVisible = ctx.isTvSettings()
|
|
|
|
|
2021-09-19 22:36:32 +00:00
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(ctx)
|
2021-12-17 12:42:25 +00:00
|
|
|
val showFillers =
|
2022-02-05 22:21:45 +00:00
|
|
|
settingsManager.getBoolean(ctx.getString(R.string.show_fillers_key), false)
|
2021-06-16 16:54:07 +00:00
|
|
|
|
2021-09-19 22:36:32 +00:00
|
|
|
val tempUrl = url
|
|
|
|
if (tempUrl != null) {
|
|
|
|
result_reload_connectionerror.setOnClickListener {
|
2021-12-16 23:45:20 +00:00
|
|
|
viewModel.load(tempUrl, apiName, showFillers)
|
2021-08-29 17:15:09 +00:00
|
|
|
}
|
2021-06-16 16:54:07 +00:00
|
|
|
|
2021-12-10 00:20:24 +00:00
|
|
|
result_reload_connection_open_in_browser?.setOnClickListener {
|
|
|
|
val i = Intent(ACTION_VIEW)
|
2022-03-14 12:44:54 +00:00
|
|
|
i.data = Uri.parse(tempUrl)
|
|
|
|
try {
|
|
|
|
startActivity(i)
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result_open_in_browser?.setOnClickListener {
|
|
|
|
val i = Intent(ACTION_VIEW)
|
2021-12-10 00:20:24 +00:00
|
|
|
i.data = Uri.parse(tempUrl)
|
|
|
|
try {
|
|
|
|
startActivity(i)
|
|
|
|
} catch (e: Exception) {
|
2022-01-30 22:02:57 +00:00
|
|
|
logError(e)
|
2021-12-10 00:20:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-03 21:41:28 +00:00
|
|
|
// bloats the navigation on tv
|
|
|
|
if (context?.isTrueTvSettings() == false) {
|
|
|
|
result_meta_site?.setOnClickListener {
|
|
|
|
it.context?.openBrowser(tempUrl)
|
|
|
|
}
|
|
|
|
result_meta_site?.isFocusable = true
|
|
|
|
} else {
|
|
|
|
result_meta_site?.isFocusable = false
|
2021-09-19 22:36:32 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 01:13:02 +00:00
|
|
|
if (restart || viewModel.result.value == null) {
|
2022-01-07 19:27:25 +00:00
|
|
|
//viewModel.clear()
|
2021-12-16 23:45:20 +00:00
|
|
|
viewModel.load(tempUrl, apiName, showFillers)
|
2021-09-12 15:57:07 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-16 16:54:07 +00:00
|
|
|
}
|
2022-02-05 22:21:45 +00:00
|
|
|
|
|
|
|
PanelsChildGestureRegionObserver.Provider.get().addGestureRegionsUpdateListener(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPause() {
|
|
|
|
super.onPause()
|
|
|
|
PanelsChildGestureRegionObserver.Provider.get().addGestureRegionsUpdateListener(this)
|
2021-05-16 18:28:00 +00:00
|
|
|
}
|
2022-02-04 20:49:35 +00:00
|
|
|
|
|
|
|
override fun onGestureRegionsUpdate(gestureRegions: List<Rect>) {
|
|
|
|
result_overlapping_panels?.setChildGestureRegions(gestureRegions)
|
|
|
|
}
|
2022-03-20 23:25:25 +00:00
|
|
|
}
|