Skip to content

Commit

Permalink
Fix many build warnings/deprecations (#1478)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna712 authored Jan 26, 2025
1 parent 642004d commit 679f365
Show file tree
Hide file tree
Showing 18 changed files with 266 additions and 139 deletions.
11 changes: 8 additions & 3 deletions app/src/main/java/com/lagradost/cloudstream3/AcraApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ class AcraApplication : Application(), SingletonImageLoader.Factory {
var exceptionHandler: ExceptionHandler? = null

/** Use to get activity from Context */
tailrec fun Context.getActivity(): Activity? = this as? Activity
?: (this as? ContextWrapper)?.baseContext?.getActivity()
tailrec fun Context.getActivity(): Activity? {
return when (this) {
is Activity -> this
is ContextWrapper -> baseContext.getActivity()
else -> null
}
}

private var _context: WeakReference<Context>? = null
var context
Expand Down Expand Up @@ -225,4 +230,4 @@ class AcraApplication : Application(), SingletonImageLoader.Factory {
)
}
}
}
}
11 changes: 8 additions & 3 deletions app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ object CommonActivity {
val toast = Toast(act)
toast.duration = duration ?: Toast.LENGTH_SHORT
toast.setGravity(Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM, 0, 5.toPx)
toast.view = binding.root //fixme Find an alternative using default Toasts since custom toasts are deprecated and won't appear with api30 set as minSDK version.
@Suppress("DEPRECATION")
toast.view = binding.root // FIXME Find an alternative using default Toasts since custom toasts are deprecated and won't appear with api30 set as minSDK version.
currentToast = toast
toast.show()

Expand Down Expand Up @@ -193,7 +194,8 @@ object CommonActivity {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
context.createConfigurationContext(config)
resources.updateConfiguration(config, resources.displayMetrics)
@Suppress("DEPRECATION")
resources.updateConfiguration(config, resources.displayMetrics) // FIXME this should be replaced
}

fun Context.updateLocale() {
Expand Down Expand Up @@ -255,10 +257,13 @@ object CommonActivity {
try {
enterPictureInPictureMode(PictureInPictureParams.Builder().build())
} catch (e: Exception) {
// Use fallback just in case
@Suppress("DEPRECATION")
enterPictureInPictureMode()
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@Suppress("DEPRECATION")
enterPictureInPictureMode()
}
}
Expand Down Expand Up @@ -626,4 +631,4 @@ object CommonActivity {
}
return null
}
}
}
4 changes: 3 additions & 1 deletion app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
if (navDestination.matchDestination(R.id.navigation_home)) {
attachBackPressedCallback("MainActivity") {
showConfirmExitDialog(settingsManager)
@Suppress("DEPRECATION")
window?.navigationBarColor =
colorFromAttribute(R.attr.primaryGrayBackground)
updateLocale()
Expand Down Expand Up @@ -1785,6 +1786,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
@Suppress("DEPRECATION")
window?.navigationBarColor = colorFromAttribute(R.attr.primaryGrayBackground)
updateLocale()

Expand Down Expand Up @@ -1819,4 +1821,4 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
false
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.net.nsd.NsdManager
import android.net.nsd.NsdManager.ResolveListener
import android.net.nsd.NsdServiceInfo
import android.os.Build
import android.os.ext.SdkExtensions
import android.util.Log
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe

Expand Down Expand Up @@ -72,23 +73,52 @@ class FcastManager {

override fun onServiceFound(serviceInfo: NsdServiceInfo?) {
if (serviceInfo == null) return
nsdManager?.resolveService(serviceInfo, object : ResolveListener {
override fun onResolveFailed(serviceInfo: NsdServiceInfo?, errorCode: Int) {
}

override fun onServiceResolved(serviceInfo: NsdServiceInfo?) {
if (serviceInfo == null) return

synchronized(_currentDevices) {
_currentDevices.add(PublicDeviceInfo(serviceInfo))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && SdkExtensions.getExtensionVersion(
Build.VERSION_CODES.TIRAMISU) >= 7) {
nsdManager?.registerServiceInfoCallback(serviceInfo,
Runnable::run,
object : NsdManager.ServiceInfoCallback {
override fun onServiceInfoCallbackRegistrationFailed(errorCode: Int) {
Log.e(tag, "Service registration failed: $errorCode")
}
override fun onServiceUpdated(serviceInfo: NsdServiceInfo) {
Log.d(tag,
"Service updated: ${serviceInfo.serviceName}," +
"Net: ${serviceInfo.hostAddresses.firstOrNull()?.hostAddress}"
)
synchronized(_currentDevices) {
_currentDevices.removeIf { it.rawName == serviceInfo.serviceName }
_currentDevices.add(PublicDeviceInfo(serviceInfo))
}
}
override fun onServiceLost() {
Log.d(tag, "Service lost: ${serviceInfo.serviceName},")
synchronized(_currentDevices) {
_currentDevices.removeIf { it.rawName == serviceInfo.serviceName }
}
}
override fun onServiceInfoCallbackUnregistered() {}
})
} else {
@Suppress("DEPRECATION")
nsdManager?.resolveService(serviceInfo, object : ResolveListener {
override fun onResolveFailed(serviceInfo: NsdServiceInfo?, errorCode: Int) {}

override fun onServiceResolved(serviceInfo: NsdServiceInfo?) {
if (serviceInfo == null) return

synchronized(_currentDevices) {
_currentDevices.add(PublicDeviceInfo(serviceInfo))
}

Log.d(
tag,
"Service found: ${serviceInfo.serviceName}, Net: ${serviceInfo.host.hostAddress}"
)
}

Log.d(
tag,
"Service found: ${serviceInfo.serviceName}, Net: ${serviceInfo.host.hostAddress}"
)
}
})
})
}
}

override fun onServiceLost(serviceInfo: NsdServiceInfo?) {
Expand Down Expand Up @@ -135,6 +165,15 @@ class FcastManager {

class PublicDeviceInfo(serviceInfo: NsdServiceInfo) {
val rawName: String = serviceInfo.serviceName
val host: String? = serviceInfo.host.hostAddress
val host: String? = if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
SdkExtensions.getExtensionVersion(
Build.VERSION_CODES.TIRAMISU) >= 7
) {
serviceInfo.hostAddresses.firstOrNull()?.hostAddress
} else {
@Suppress("DEPRECATION")
serviceInfo.host.hostAddress
}
val name = rawName.replace("-", " ") + host?.let { " $it" }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ open class TmdbProvider : MainAPI() {
}

private fun BaseTvShow.toSearchResponse(): TvSeriesSearchResponse {
@Suppress("DEPRECATION")
return TvSeriesSearchResponse(
this.name ?: this.original_name,
getUrl(id, true),
Expand All @@ -71,6 +72,7 @@ open class TmdbProvider : MainAPI() {
}

private fun BaseMovie.toSearchResponse(): MovieSearchResponse {
@Suppress("DEPRECATION")
return MovieSearchResponse(
this.title ?: this.original_title,
getUrl(id, false),
Expand Down Expand Up @@ -99,6 +101,7 @@ open class TmdbProvider : MainAPI() {
val episodes = this.seasons?.filter { !disableSeasonZero || (it.season_number ?: 0) != 0 }
?.mapNotNull { season ->
season.episodes?.map { episode ->
@Suppress("DEPRECATION")
Episode(
TmdbLink(
episode.external_ids?.imdb_id ?: this.external_ids?.imdb_id,
Expand All @@ -116,6 +119,7 @@ open class TmdbProvider : MainAPI() {
episode.air_date?.time,
)
} ?: (1..(season.episode_count ?: 1)).map { episodeNum ->
@Suppress("DEPRECATION")
Episode(
episode = episodeNum,
data = TmdbLink(
Expand Down Expand Up @@ -242,6 +246,7 @@ open class TmdbProvider : MainAPI() {
}
)

@Suppress("DEPRECATION")
return HomePageResponse(
listOf(
// HomePageList("Popular Series", popularSeries),
Expand Down Expand Up @@ -387,4 +392,4 @@ open class TmdbProvider : MainAPI() {
it.movie?.toSearchResponse() ?: it.tvShow?.toSearchResponse()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ open class TraktProvider : MainAPI() {
).toJson()

episodes.add(
@Suppress("DEPRECATION")
Episode(
data = linkData.toJson(),
name = episode.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.lagradost.cloudstream3.mvvm.safeApiCall
import com.lagradost.cloudstream3.utils.Coroutines.threadSafeListOf
import com.lagradost.cloudstream3.utils.ExtractorLink
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope.coroutineContext
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -132,6 +133,7 @@ class APIRepository(val api: MainAPI) {
delay(delta)
}

@OptIn(DelicateCoroutinesApi::class)
suspend fun getMainPage(page: Int, nameIndex: Int? = null): Resource<List<HomePageResponse?>> {
return safeApiCall {
api.lastHomepageRequest = unixTimeMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.appcompat.app.AlertDialog
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.kotlinModule
import com.google.android.gms.cast.MediaLoadOptions
import com.google.android.gms.cast.MediaQueueItem
import com.google.android.gms.cast.MediaSeekOptions
import com.google.android.gms.cast.MediaStatus.REPEAT_MODE_REPEAT_OFF
Expand Down Expand Up @@ -239,12 +240,22 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi
loadMirror(index + 1)
}
} else {
awaitLinks(remoteMediaClient?.load(mediaItem, true, startAt)) {
val mediaLoadOptions =
MediaLoadOptions.Builder()
.setPlayPosition(startAt)
.setAutoplay(true)
.build()
awaitLinks(remoteMediaClient?.load(mediaItem, mediaLoadOptions)) {
loadMirror(index + 1)
}
}
} catch (e: Exception) {
awaitLinks(remoteMediaClient?.load(mediaItem, true, startAt)) {
val mediaLoadOptions =
MediaLoadOptions.Builder()
.setPlayPosition(startAt)
.setAutoplay(true)
.build()
awaitLinks(remoteMediaClient?.load(mediaItem, mediaLoadOptions)) {
loadMirror(index + 1)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AccountSelectActivity : AppCompatActivity(), BiometricCallback {
super.onCreate(savedInstanceState)
loadThemes(this)

@Suppress("DEPRECATION")
window.navigationBarColor = colorFromAttribute(R.attr.primaryBlackBackground)

// Are we editing and coming from MainActivity?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ abstract class AbstractPlayerFragment(
}

// Necessary for multiple combined videos
@Suppress("DEPRECATION")
playerView?.setShowMultiWindowTimeBar(true)
playerView?.player = player
playerView?.performClick()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lagradost.cloudstream3.ui.player

import Torrent
import android.annotation.SuppressLint
import android.content.Context
import android.content.DialogInterface
Expand Down Expand Up @@ -47,7 +48,7 @@ import androidx.media3.exoplayer.drm.DefaultDrmSessionManager
import androidx.media3.exoplayer.drm.FrameworkMediaDrm
import androidx.media3.exoplayer.drm.LocalMediaDrmCallback
import androidx.media3.exoplayer.source.ClippingMediaSource
import androidx.media3.exoplayer.source.ConcatenatingMediaSource
import androidx.media3.exoplayer.source.ConcatenatingMediaSource2
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.exoplayer.source.MergingMediaSource
import androidx.media3.exoplayer.source.SingleSampleMediaSource
Expand Down Expand Up @@ -766,6 +767,7 @@ class CS3IPlayer : IPlayer {
).apply {
// Required to make the decoder work with old subtitles
// Upgrade CustomSubtitleDecoderFactory when media3 supports it
@Suppress("DEPRECATION")
experimentalSetLegacyDecodingEnabled(true)
}.also { renderer ->
this.currentTextRenderer = renderer
Expand Down Expand Up @@ -836,17 +838,17 @@ class CS3IPlayer : IPlayer {
factory.createMediaSource(item.mediaItem)
}
} else {
val source = ConcatenatingMediaSource()
val source = ConcatenatingMediaSource2.Builder()
mediaItemSlices.map { item ->
source.addMediaSource(
source.add(
// The duration MUST be known for it to work properly, see https://github.com/google/ExoPlayer/issues/4727
ClippingMediaSource(
factory.createMediaSource(item.mediaItem),
item.durationUs
)
)
}
source
source.build()
}

//println("PLAYBACK POS $playbackPosition")
Expand Down Expand Up @@ -1571,4 +1573,4 @@ class CS3IPlayer : IPlayer {
loadOfflinePlayer(context, it)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
override fun onResume() {
afterPluginsLoadedEvent += ::reloadViewModel
activity?.let {
@Suppress("DEPRECATION")
it.window?.navigationBarColor =
it.colorFromAttribute(R.attr.primaryBlackBackground)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class ResultFragmentTv : Fragment() {

override fun onResume() {
activity?.let {
@Suppress("DEPRECATION")
it.window?.navigationBarColor =
it.colorFromAttribute(R.attr.primaryBlackBackground)
}
Expand Down
Loading

0 comments on commit 679f365

Please sign in to comment.