This commit is contained in:
LagradOst 2021-09-12 17:57:07 +02:00
parent fa1e2f7eeb
commit 2acae76c5e
6 changed files with 96 additions and 80 deletions

View file

@ -31,8 +31,8 @@ android {
applicationId "com.lagradost.cloudstream3" applicationId "com.lagradost.cloudstream3"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 30
versionCode 23 versionCode 24
versionName "1.8.8" versionName "1.9.8"
resValue "string", "app_version", resValue "string", "app_version",
"${defaultConfig.versionName}${versionNameSuffix ?: ""}" "${defaultConfig.versionName}${versionNameSuffix ?: ""}"

View file

@ -25,6 +25,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
import com.lagradost.cloudstream3.APIHolder.apis import com.lagradost.cloudstream3.APIHolder.apis
import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings
import com.lagradost.cloudstream3.APIHolder.restrictedApis import com.lagradost.cloudstream3.APIHolder.restrictedApis
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
import com.lagradost.cloudstream3.ui.APIRepository import com.lagradost.cloudstream3.ui.APIRepository
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
@ -146,16 +147,20 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
private fun enterPIPMode() { private fun enterPIPMode() {
if (!shouldShowPIPMode(canEnterPipMode) || !canShowPipMode) return if (!shouldShowPIPMode(canEnterPipMode) || !canShowPipMode) return
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { try {
try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
enterPictureInPictureMode(PictureInPictureParams.Builder().build()) try {
} catch (e: Exception) { enterPictureInPictureMode(PictureInPictureParams.Builder().build())
enterPictureInPictureMode() } catch (e: Exception) {
} enterPictureInPictureMode()
} else { }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { } else {
enterPictureInPictureMode() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
enterPictureInPictureMode()
}
} }
} catch (e : Exception) {
logError(e)
} }
} }

View file

@ -45,27 +45,25 @@ class DownloadChildFragment : Fragment() {
} }
private fun updateList(folder: String) = main { private fun updateList(folder: String) = main {
val data = withContext(Dispatchers.IO) { context?.getKeys(folder) } context?.let { ctx ->
if (data == null) { val data = withContext(Dispatchers.IO) { ctx.getKeys(folder) }
activity?.onBackPressed() // TODO FIX val eps = withContext(Dispatchers.IO) {
return@main data.mapNotNull { key ->
} context?.getKey<VideoDownloadHelper.DownloadEpisodeCached>(key)
val eps = withContext(Dispatchers.IO) { }.mapNotNull {
data.mapNotNull { key -> val info = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(ctx, it.id)
context?.getKey<VideoDownloadHelper.DownloadEpisodeCached>(key) ?: return@mapNotNull null
}.mapNotNull { VisualDownloadChildCached(info.fileLength, info.totalBytes, it)
val info = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(requireContext(), it.id) }
?: return@mapNotNull null }
VisualDownloadChildCached(info.fileLength, info.totalBytes, it) if (eps.isEmpty()) {
activity?.onBackPressed()
return@main
} }
}
if (eps.isEmpty()) {
activity?.onBackPressed()
return@main
}
(download_child_list?.adapter as DownloadChildAdapter? ?: return@main).cardList = eps (download_child_list?.adapter as DownloadChildAdapter? ?: return@main).cardList = eps
download_child_list?.adapter?.notifyDataSetChanged() download_child_list?.adapter?.notifyDataSetChanged()
}
} }
var downloadDeleteEventListener: ((Int) -> Unit)? = null var downloadDeleteEventListener: ((Int) -> Unit)? = null

View file

@ -112,7 +112,9 @@ class DownloadFragment : Fragment() {
if (downloadClickEvent.data !is VideoDownloadHelper.DownloadEpisodeCached) return@DownloadHeaderAdapter if (downloadClickEvent.data !is VideoDownloadHelper.DownloadEpisodeCached) return@DownloadHeaderAdapter
handleDownloadClick(activity, downloadClickEvent.data.name, downloadClickEvent) handleDownloadClick(activity, downloadClickEvent.data.name, downloadClickEvent)
if (downloadClickEvent.action == DOWNLOAD_ACTION_DELETE_FILE) { if (downloadClickEvent.action == DOWNLOAD_ACTION_DELETE_FILE) {
downloadsViewModel.updateList(requireContext()) context?.let { ctx ->
downloadsViewModel.updateList(ctx)
}
} }
} }
) )
@ -121,8 +123,10 @@ class DownloadFragment : Fragment() {
val list = (download_list?.adapter as DownloadHeaderAdapter?)?.cardList val list = (download_list?.adapter as DownloadHeaderAdapter?)?.cardList
if (list != null) { if (list != null) {
if (list.any { it.data.id == id }) { if (list.any { it.data.id == id }) {
setList(ArrayList()) context?.let { ctx ->
downloadsViewModel.updateList(requireContext()) setList(ArrayList())
downloadsViewModel.updateList(ctx)
}
} }
} }
} }

View file

@ -558,55 +558,59 @@ class ResultFragment : Fragment() {
} }
ACTION_SHOW_OPTIONS -> { ACTION_SHOW_OPTIONS -> {
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom) context?.let { ctx ->
var dialog: AlertDialog? = null val builder = AlertDialog.Builder(ctx, R.style.AlertDialogCustom)
builder.setTitle(showTitle) var dialog: AlertDialog? = null
val options = requireContext().resources.getStringArray(R.array.episode_long_click_options) builder.setTitle(showTitle)
val optionsValues = val options = requireContext().resources.getStringArray(R.array.episode_long_click_options)
requireContext().resources.getIntArray(R.array.episode_long_click_options_values) val optionsValues =
requireContext().resources.getIntArray(R.array.episode_long_click_options_values)
val verifiedOptions = ArrayList<String>() val verifiedOptions = ArrayList<String>()
val verifiedOptionsValues = ArrayList<Int>() val verifiedOptionsValues = ArrayList<Int>()
val hasDownloadSupport = api.hasDownloadSupport val hasDownloadSupport = api.hasDownloadSupport
for (i in options.indices) { for (i in options.indices) {
val opv = optionsValues[i] val opv = optionsValues[i]
val op = options[i] val op = options[i]
val isConnected = requireContext().isConnectedToChromecast() val isConnected = ctx.isConnectedToChromecast()
val add = when (opv) { val add = when (opv) {
ACTION_CHROME_CAST_EPISODE -> isConnected ACTION_CHROME_CAST_EPISODE -> isConnected
ACTION_CHROME_CAST_MIRROR -> isConnected ACTION_CHROME_CAST_MIRROR -> isConnected
ACTION_DOWNLOAD_EPISODE -> hasDownloadSupport ACTION_DOWNLOAD_EPISODE -> hasDownloadSupport
ACTION_DOWNLOAD_MIRROR -> hasDownloadSupport ACTION_DOWNLOAD_MIRROR -> hasDownloadSupport
ACTION_PLAY_EPISODE_IN_VLC_PLAYER -> context?.isAppInstalled(VLC_PACKAGE) ?: false ACTION_PLAY_EPISODE_IN_VLC_PLAYER -> context?.isAppInstalled(VLC_PACKAGE) ?: false
else -> true else -> true
}
if (add) {
verifiedOptions.add(op)
verifiedOptionsValues.add(opv)
}
} }
if (add) {
verifiedOptions.add(op) builder.setItems(
verifiedOptionsValues.add(opv) verifiedOptions.toTypedArray()
) { _, which ->
handleAction(EpisodeClickEvent(verifiedOptionsValues[which], episodeClick.data))
dialog?.dismiss()
} }
}
builder.setItems( dialog = builder.create()
verifiedOptions.toTypedArray() dialog.show()
) { _, which ->
handleAction(EpisodeClickEvent(verifiedOptionsValues[which], episodeClick.data))
dialog?.dismiss()
} }
dialog = builder.create()
dialog.show()
} }
ACTION_COPY_LINK -> { ACTION_COPY_LINK -> {
acquireSingeExtractorLink(getString(R.string.episode_action_copy_link)) { link -> activity?.let { act ->
val serviceClipboard = acquireSingeExtractorLink(act.getString(R.string.episode_action_copy_link)) { link ->
(requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?) val serviceClipboard =
?: return@acquireSingeExtractorLink (act.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?)
val clip = ClipData.newPlainText(link.name, link.url) ?: return@acquireSingeExtractorLink
serviceClipboard.setPrimaryClip(clip) val clip = ClipData.newPlainText(link.name, link.url)
showToast(activity, R.string.copy_link_toast, Toast.LENGTH_SHORT) serviceClipboard.setPrimaryClip(clip)
showToast(act, R.string.copy_link_toast, Toast.LENGTH_SHORT)
}
} }
} }
@ -638,7 +642,7 @@ class ResultFragment : Fragment() {
val data = currentLinks ?: return@main val data = currentLinks ?: return@main
val subs = currentSubs val subs = currentSubs
val outputDir = requireContext().cacheDir val outputDir = act.cacheDir
val outputFile = withContext(Dispatchers.IO) { val outputFile = withContext(Dispatchers.IO) {
File.createTempFile("mirrorlist", ".m3u8", outputDir) File.createTempFile("mirrorlist", ".m3u8", outputDir)
} }
@ -682,7 +686,7 @@ class ResultFragment : Fragment() {
vlcIntent.putExtra("position", position) vlcIntent.putExtra("position", position)
vlcIntent.component = VLC_COMPONENT vlcIntent.component = VLC_COMPONENT
requireContext().setKey(VLC_LAST_ID_KEY, episodeClick.data.id) act.setKey(VLC_LAST_ID_KEY, episodeClick.data.id)
act.startActivityForResult(vlcIntent, VLC_REQUEST_CODE) act.startActivityForResult(vlcIntent, VLC_REQUEST_CODE)
} }
} }
@ -939,7 +943,8 @@ class ResultFragment : Fragment() {
} }
result_descript.setOnClickListener { result_descript.setOnClickListener {
val builder: AlertDialog.Builder = AlertDialog.Builder(requireContext()) 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) builder.setMessage(d.plot)
.setTitle(if (d.type == TvType.Torrent) R.string.torrent_plot else R.string.result_plot)
.show() .show()
} }
result_descript.text = syno result_descript.text = syno
@ -981,8 +986,7 @@ class ResultFragment : Fragment() {
handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card)) handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card))
return@setOnLongClickListener true return@setOnLongClickListener true
} }
// result_options.setOnClickListener { // result_options.setOnClickListener {
// val card = currentEpisodes?.first() ?: return@setOnClickListener // val card = currentEpisodes?.first() ?: return@setOnClickListener
// handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card)) // handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card))
@ -1072,7 +1076,7 @@ class ResultFragment : Fragment() {
val tempUrl = url val tempUrl = url
if (tempUrl != null) { if (tempUrl != null) {
result_reload_connectionerror.setOnClickListener { result_reload_connectionerror.setOnClickListener {
viewModel.load(requireContext(), tempUrl, apiName) viewModel.load(it.context, tempUrl, apiName)
} }
result_reload_connection_open_in_browser.setOnClickListener { result_reload_connection_open_in_browser.setOnClickListener {
@ -1085,8 +1089,11 @@ class ResultFragment : Fragment() {
} }
} }
if (viewModel.resultResponse.value == null) if (viewModel.resultResponse.value == null) {
viewModel.load(requireContext(), tempUrl, apiName) context?.let { ctx ->
viewModel.load(ctx, tempUrl, apiName)
}
}
} }
} }
} }

View file

@ -226,6 +226,8 @@ object VideoDownloadManager {
progress: Long, progress: Long,
total: Long, total: Long,
) { ) {
if(total <= 0) return // crash, invalid data
main { // DON'T WANT TO SLOW IT DOWN main { // DON'T WANT TO SLOW IT DOWN
val builder = NotificationCompat.Builder(context, DOWNLOAD_CHANNEL_ID) val builder = NotificationCompat.Builder(context, DOWNLOAD_CHANNEL_ID)
.setAutoCancel(true) .setAutoCancel(true)