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,6 +147,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
private fun enterPIPMode() { private fun enterPIPMode() {
if (!shouldShowPIPMode(canEnterPipMode) || !canShowPipMode) return if (!shouldShowPIPMode(canEnterPipMode) || !canShowPipMode) return
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try { try {
enterPictureInPictureMode(PictureInPictureParams.Builder().build()) enterPictureInPictureMode(PictureInPictureParams.Builder().build())
@ -157,6 +159,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
enterPictureInPictureMode() enterPictureInPictureMode()
} }
} }
} catch (e : Exception) {
logError(e)
}
} }
override fun onUserLeaveHint() { override fun onUserLeaveHint() {

View file

@ -45,16 +45,13 @@ 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
return@main
}
val eps = withContext(Dispatchers.IO) { val eps = withContext(Dispatchers.IO) {
data.mapNotNull { key -> data.mapNotNull { key ->
context?.getKey<VideoDownloadHelper.DownloadEpisodeCached>(key) context?.getKey<VideoDownloadHelper.DownloadEpisodeCached>(key)
}.mapNotNull { }.mapNotNull {
val info = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(requireContext(), it.id) val info = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(ctx, it.id)
?: return@mapNotNull null ?: return@mapNotNull null
VisualDownloadChildCached(info.fileLength, info.totalBytes, it) VisualDownloadChildCached(info.fileLength, info.totalBytes, it)
} }
@ -67,6 +64,7 @@ class DownloadChildFragment : Fragment() {
(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 }) {
context?.let { ctx ->
setList(ArrayList()) setList(ArrayList())
downloadsViewModel.updateList(requireContext()) downloadsViewModel.updateList(ctx)
}
} }
} }
} }

View file

@ -558,7 +558,8 @@ class ResultFragment : Fragment() {
} }
ACTION_SHOW_OPTIONS -> { ACTION_SHOW_OPTIONS -> {
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom) context?.let { ctx ->
val builder = AlertDialog.Builder(ctx, R.style.AlertDialogCustom)
var dialog: AlertDialog? = null var dialog: AlertDialog? = null
builder.setTitle(showTitle) builder.setTitle(showTitle)
val options = requireContext().resources.getStringArray(R.array.episode_long_click_options) val options = requireContext().resources.getStringArray(R.array.episode_long_click_options)
@ -574,7 +575,7 @@ class ResultFragment : Fragment() {
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
@ -599,14 +600,17 @@ class ResultFragment : Fragment() {
dialog = builder.create() dialog = builder.create()
dialog.show() dialog.show()
} }
}
ACTION_COPY_LINK -> { ACTION_COPY_LINK -> {
acquireSingeExtractorLink(getString(R.string.episode_action_copy_link)) { link -> activity?.let { act ->
acquireSingeExtractorLink(act.getString(R.string.episode_action_copy_link)) { link ->
val serviceClipboard = val serviceClipboard =
(requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?) (act.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?)
?: return@acquireSingeExtractorLink ?: return@acquireSingeExtractorLink
val clip = ClipData.newPlainText(link.name, link.url) val clip = ClipData.newPlainText(link.name, link.url)
serviceClipboard.setPrimaryClip(clip) serviceClipboard.setPrimaryClip(clip)
showToast(activity, R.string.copy_link_toast, Toast.LENGTH_SHORT) 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
@ -982,7 +987,6 @@ class ResultFragment : Fragment() {
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)