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"
minSdkVersion 21
targetSdkVersion 30
versionCode 23
versionName "1.8.8"
versionCode 24
versionName "1.9.8"
resValue "string", "app_version",
"${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.getApiDubstatusSettings
import com.lagradost.cloudstream3.APIHolder.restrictedApis
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
import com.lagradost.cloudstream3.ui.APIRepository
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
@ -146,6 +147,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
private fun enterPIPMode() {
if (!shouldShowPIPMode(canEnterPipMode) || !canShowPipMode) return
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
enterPictureInPictureMode(PictureInPictureParams.Builder().build())
@ -157,6 +159,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
enterPictureInPictureMode()
}
}
} catch (e : Exception) {
logError(e)
}
}
override fun onUserLeaveHint() {

View file

@ -45,16 +45,13 @@ class DownloadChildFragment : Fragment() {
}
private fun updateList(folder: String) = main {
val data = withContext(Dispatchers.IO) { context?.getKeys(folder) }
if (data == null) {
activity?.onBackPressed() // TODO FIX
return@main
}
context?.let { ctx ->
val data = withContext(Dispatchers.IO) { ctx.getKeys(folder) }
val eps = withContext(Dispatchers.IO) {
data.mapNotNull { key ->
context?.getKey<VideoDownloadHelper.DownloadEpisodeCached>(key)
}.mapNotNull {
val info = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(requireContext(), it.id)
val info = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(ctx, it.id)
?: return@mapNotNull null
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?.notifyDataSetChanged()
}
}
var downloadDeleteEventListener: ((Int) -> Unit)? = null

View file

@ -112,7 +112,9 @@ class DownloadFragment : Fragment() {
if (downloadClickEvent.data !is VideoDownloadHelper.DownloadEpisodeCached) return@DownloadHeaderAdapter
handleDownloadClick(activity, downloadClickEvent.data.name, downloadClickEvent)
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
if (list != null) {
if (list.any { it.data.id == id }) {
context?.let { ctx ->
setList(ArrayList())
downloadsViewModel.updateList(requireContext())
downloadsViewModel.updateList(ctx)
}
}
}
}

View file

@ -558,7 +558,8 @@ class ResultFragment : Fragment() {
}
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
builder.setTitle(showTitle)
val options = requireContext().resources.getStringArray(R.array.episode_long_click_options)
@ -574,7 +575,7 @@ class ResultFragment : Fragment() {
val opv = optionsValues[i]
val op = options[i]
val isConnected = requireContext().isConnectedToChromecast()
val isConnected = ctx.isConnectedToChromecast()
val add = when (opv) {
ACTION_CHROME_CAST_EPISODE -> isConnected
ACTION_CHROME_CAST_MIRROR -> isConnected
@ -599,14 +600,17 @@ class ResultFragment : Fragment() {
dialog = builder.create()
dialog.show()
}
}
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 =
(requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?)
(act.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?)
?: return@acquireSingeExtractorLink
val clip = ClipData.newPlainText(link.name, link.url)
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 subs = currentSubs
val outputDir = requireContext().cacheDir
val outputDir = act.cacheDir
val outputFile = withContext(Dispatchers.IO) {
File.createTempFile("mirrorlist", ".m3u8", outputDir)
}
@ -682,7 +686,7 @@ class ResultFragment : Fragment() {
vlcIntent.putExtra("position", position)
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)
}
}
@ -939,7 +943,8 @@ class ResultFragment : Fragment() {
}
result_descript.setOnClickListener {
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()
}
result_descript.text = syno
@ -982,7 +987,6 @@ class ResultFragment : Fragment() {
return@setOnLongClickListener true
}
// result_options.setOnClickListener {
// val card = currentEpisodes?.first() ?: return@setOnClickListener
// handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card))
@ -1072,7 +1076,7 @@ class ResultFragment : Fragment() {
val tempUrl = url
if (tempUrl != null) {
result_reload_connectionerror.setOnClickListener {
viewModel.load(requireContext(), tempUrl, apiName)
viewModel.load(it.context, tempUrl, apiName)
}
result_reload_connection_open_in_browser.setOnClickListener {
@ -1085,8 +1089,11 @@ class ResultFragment : Fragment() {
}
}
if (viewModel.resultResponse.value == null)
viewModel.load(requireContext(), tempUrl, apiName)
if (viewModel.resultResponse.value == null) {
context?.let { ctx ->
viewModel.load(ctx, tempUrl, apiName)
}
}
}
}
}

View file

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