Fix some deprecations and other warnings (#750)

* Fix some deprecations and other warnings
This commit is contained in:
Luna712 2023-11-10 16:48:53 -07:00 committed by GitHub
parent c4aab5e5a8
commit 3adf036135
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 106 additions and 62 deletions

View file

@ -6,7 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <!-- unless you only use cs3 as a player for downloaded stuff, you need this --> <uses-permission android:name="android.permission.INTERNET" /> <!-- unless you only use cs3 as a player for downloaded stuff, you need this -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- Downloads --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- Downloads -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- Downloads on low api devices --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- Downloads on low api devices -->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> <!-- Plugin API --> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" /> <!-- Plugin API -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <!-- some dependency needs this --> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <!-- some dependency needs this -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <!-- Used for player vertical slide --> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <!-- Used for player vertical slide -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <!-- Used for app update --> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <!-- Used for app update -->
@ -17,7 +17,11 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" /> <!-- Required for getting arbitrary Aniyomi packages --> <!-- Required for getting arbitrary Aniyomi packages -->
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<!-- Fixes android tv fuckery --> <!-- Fixes android tv fuckery -->
<uses-feature <uses-feature
android:name="android.hardware.touchscreen" android:name="android.hardware.touchscreen"
@ -37,9 +41,11 @@
<application <application
android:name=".AcraApplication" android:name=".AcraApplication"
android:allowBackup="true" android:allowBackup="true"
android:enableOnBackInvokedCallback="true"
android:appCategory="video" android:appCategory="video"
android:banner="@mipmap/ic_banner" android:banner="@mipmap/ic_banner"
android:fullBackupContent="@xml/backup_descriptor" android:fullBackupContent="@xml/backup_descriptor"
android:dataExtractionRules="@xml/data_extraction_rules"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:largeHeap="true" android:largeHeap="true"
@ -47,7 +53,7 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
tools:targetApi="o"> tools:targetApi="tiramisu">
<meta-data <meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
@ -182,8 +188,8 @@
<receiver <receiver
android:name=".receivers.VideoDownloadRestartReceiver" android:name=".receivers.VideoDownloadRestartReceiver"
android:enabled="false" android:enabled="false"
android:exported="true"> android:exported="false">
<intent-filter android:exported="true"> <intent-filter android:exported="false">
<action android:name="restart_service" /> <action android:name="restart_service" />
</intent-filter> </intent-filter>
</receiver> </receiver>

View file

@ -19,6 +19,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowManager import android.view.WindowManager
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.IdRes import androidx.annotation.IdRes
import androidx.annotation.MainThread import androidx.annotation.MainThread
@ -132,7 +133,6 @@ import com.lagradost.cloudstream3.utils.DataStore.setKey
import com.lagradost.cloudstream3.utils.DataStoreHelper import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.DataStoreHelper.migrateResumeWatching import com.lagradost.cloudstream3.utils.DataStoreHelper.migrateResumeWatching
import com.lagradost.cloudstream3.utils.Event import com.lagradost.cloudstream3.utils.Event
import com.lagradost.cloudstream3.utils.IOnBackPressed
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.UIHelper.changeStatusBarState import com.lagradost.cloudstream3.utils.UIHelper.changeStatusBarState
@ -650,34 +650,6 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
builder.show().setDefaultFocus() builder.show().setDefaultFocus()
} }
private fun backPressed() {
this.window?.navigationBarColor =
this.colorFromAttribute(R.attr.primaryGrayBackground)
this.updateLocale()
this.updateLocale()
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment
val navController = navHostFragment?.navController
val isAtHome =
navController?.currentDestination?.matchDestination(R.id.navigation_home) == true
if (isAtHome && isTvSettings()) {
showConfirmExitDialog()
} else {
super.onBackPressed()
}
}
override fun onBackPressed() {
((supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment?)?.childFragmentManager?.primaryNavigationFragment as? IOnBackPressed)?.onBackPressed()
?.let { runNormal ->
if (runNormal) backPressed()
} ?: run {
backPressed()
}
}
override fun onDestroy() { override fun onDestroy() {
val broadcastIntent = Intent() val broadcastIntent = Intent()
broadcastIntent.action = "restart_service" broadcastIntent.action = "restart_service"
@ -1087,6 +1059,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
} catch (_: Throwable) { } catch (_: Throwable) {
} }
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
app.initClient(this) app.initClient(this)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
@ -1384,6 +1357,12 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
this.putString(SearchFragment.SEARCH_QUERY, nextSearchQuery) this.putString(SearchFragment.SEARCH_QUERY, nextSearchQuery)
} }
} }
if (isTvSettings()) {
if (navDestination.matchDestination(R.id.navigation_home)) {
attachBackPressedCallback()
} else detachBackPressedCallback()
}
} }
//val navController = findNavController(R.id.nav_host_fragment) //val navController = findNavController(R.id.nav_host_fragment)
@ -1598,6 +1577,44 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
// } // }
// } // }
onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
window?.navigationBarColor = colorFromAttribute(R.attr.primaryGrayBackground)
updateLocale()
// If we don't disable we end up in a loop with default behavior calling
// this callback as well, so we disable it, run default behavior,
// then re-enable this callback so it can be used for next back press.
isEnabled = false
onBackPressedDispatcher.onBackPressed()
isEnabled = true
}
}
)
}
private var backPressedCallback: OnBackPressedCallback? = null
private fun attachBackPressedCallback() {
if (backPressedCallback == null) {
backPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
showConfirmExitDialog()
window?.navigationBarColor =
colorFromAttribute(R.attr.primaryGrayBackground)
updateLocale()
}
}
}
backPressedCallback?.isEnabled = true
onBackPressedDispatcher.addCallback(this, backPressedCallback ?: return)
}
private fun detachBackPressedCallback() {
backPressedCallback?.isEnabled = false
} }
suspend fun checkGithubConnectivity(): Boolean { suspend fun checkGithubConnectivity(): Boolean {

View file

@ -60,7 +60,7 @@ class DownloadChildFragment : Fragment() {
} }
}.sortedBy { it.data.episode + (it.data.season ?: 0) * 100000 } }.sortedBy { it.data.episode + (it.data.season ?: 0) * 100000 }
if (eps.isEmpty()) { if (eps.isEmpty()) {
activity?.onBackPressed() activity?.onBackPressedDispatcher?.onBackPressed()
return@main return@main
} }
@ -78,7 +78,7 @@ class DownloadChildFragment : Fragment() {
val folder = arguments?.getString("folder") val folder = arguments?.getString("folder")
val name = arguments?.getString("name") val name = arguments?.getString("name")
if (folder == null) { if (folder == null) {
activity?.onBackPressed() // TODO FIX activity?.onBackPressedDispatcher?.onBackPressed() // TODO FIX
return return
} }
fixPaddingStatusbar(binding?.downloadChildRoot) fixPaddingStatusbar(binding?.downloadChildRoot)
@ -87,7 +87,7 @@ class DownloadChildFragment : Fragment() {
title = name title = name
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24) setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener { setNavigationOnClickListener {
activity?.onBackPressed() activity?.onBackPressedDispatcher?.onBackPressed()
} }
} }

View file

@ -6,6 +6,7 @@ import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.lagradost.cloudstream3.CommonActivity import com.lagradost.cloudstream3.CommonActivity
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
@ -34,10 +35,6 @@ class DownloadedPlayerActivity : AppCompatActivity() {
CommonActivity.onUserLeaveHint(this) CommonActivity.onUserLeaveHint(this)
} }
override fun onBackPressed() {
finish()
}
private fun playLink(url: String) { private fun playLink(url: String) {
this.navigate( this.navigate(
R.id.global_to_navigation_player, GeneratorPlayer.newInstance( R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
@ -109,6 +106,15 @@ class DownloadedPlayerActivity : AppCompatActivity() {
finish() finish()
return return
} }
onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
)
} }
override fun onResume() { override fun onResume() {

View file

@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.activity.OnBackPressedCallback
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.lagradost.cloudstream3.CommonActivity.screenHeight import com.lagradost.cloudstream3.CommonActivity.screenHeight
@ -15,10 +16,8 @@ import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.ui.player.CSPlayerEvent import com.lagradost.cloudstream3.ui.player.CSPlayerEvent
import com.lagradost.cloudstream3.ui.player.PlayerEventSource import com.lagradost.cloudstream3.ui.player.PlayerEventSource
import com.lagradost.cloudstream3.ui.player.SubtitleData import com.lagradost.cloudstream3.ui.player.SubtitleData
import com.lagradost.cloudstream3.utils.IOnBackPressed
open class ResultTrailerPlayer : ResultFragmentPhone() {
open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed {
override var lockRotation = false override var lockRotation = false
override var isFullScreenPlayer = false override var isFullScreenPlayer = false
@ -28,7 +27,7 @@ open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed {
const val TAG = "RESULT_TRAILER" const val TAG = "RESULT_TRAILER"
} }
var playerWidthHeight: Pair<Int, Int>? = null private var playerWidthHeight: Pair<Int, Int>? = null
override fun nextEpisode() {} override fun nextEpisode() {}
@ -154,6 +153,10 @@ open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed {
} }
fixPlayerSize() fixPlayerSize()
uiReset() uiReset()
if (isFullScreenPlayer) {
attachBackPressedCallback()
} else detachBackPressedCallback()
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -172,12 +175,26 @@ open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed {
} }
} }
override fun onBackPressed(): Boolean { private var backPressedCallback: OnBackPressedCallback? = null
return if (isFullScreenPlayer) {
updateFullscreen(false) private fun attachBackPressedCallback() {
false if (backPressedCallback == null) {
} else { backPressedCallback = object : OnBackPressedCallback(true) {
true override fun handleOnBackPressed() {
updateFullscreen(false)
}
}
} }
backPressedCallback?.isEnabled = true
activity?.onBackPressedDispatcher?.addCallback(
activity ?: return,
backPressedCallback ?: return
)
}
private fun detachBackPressedCallback() {
backPressedCallback?.isEnabled = false
} }
} }

View file

@ -82,7 +82,7 @@ class SettingsFragment : Fragment() {
setTitle(title) setTitle(title)
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24) setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener { setNavigationOnClickListener {
activity?.onBackPressed() activity?.onBackPressedDispatcher?.onBackPressed()
} }
} }
fixPaddingStatusbar(settingsToolbar) fixPaddingStatusbar(settingsToolbar)
@ -97,7 +97,7 @@ class SettingsFragment : Fragment() {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24) setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
children.firstOrNull { it is ImageView }?.tag = getString(R.string.tv_no_focus_tag) children.firstOrNull { it is ImageView }?.tag = getString(R.string.tv_no_focus_tag)
setNavigationOnClickListener { setNavigationOnClickListener {
activity?.onBackPressed() activity?.onBackPressedDispatcher?.onBackPressed()
} }
} }
fixPaddingStatusbar(settingsToolbar) fixPaddingStatusbar(settingsToolbar)

View file

@ -70,7 +70,7 @@ class PluginsFragment : Fragment() {
val isLocal = arguments?.getBoolean(PLUGINS_BUNDLE_LOCAL) == true val isLocal = arguments?.getBoolean(PLUGINS_BUNDLE_LOCAL) == true
if (url == null || name == null) { if (url == null || name == null) {
activity?.onBackPressed() activity?.onBackPressedDispatcher?.onBackPressed()
return return
} }
@ -119,7 +119,7 @@ class PluginsFragment : Fragment() {
if (searchView?.isIconified == false) { if (searchView?.isIconified == false) {
searchView.isIconified = true searchView.isIconified = true
} else { } else {
activity?.onBackPressed() activity?.onBackPressedDispatcher?.onBackPressed()
} }
} }
searchView?.setOnQueryTextFocusChangeListener { _, hasFocus -> searchView?.setOnQueryTextFocusChangeListener { _, hasFocus ->

View file

@ -1,5 +0,0 @@
package com.lagradost.cloudstream3.utils
interface IOnBackPressed {
fun onBackPressed(): Boolean
}

View file

@ -418,7 +418,7 @@ object UIHelper {
} }
fun FragmentActivity.popCurrentPage() { fun FragmentActivity.popCurrentPage() {
this.onBackPressed() this.onBackPressedDispatcher.onBackPressed()
/*val currentFragment = supportFragmentManager.fragments.lastOrNull { /*val currentFragment = supportFragmentManager.fragments.lastOrNull {
it.isVisible it.isVisible
} ?: return } ?: return
@ -438,7 +438,7 @@ object UIHelper {
val currentFragment = supportFragmentManager.fragments.lastOrNull { val currentFragment = supportFragmentManager.fragments.lastOrNull {
it.isVisible it.isVisible
} }
?: //this.onBackPressed() ?: //this.onBackPressedDispatcher.onBackPressed()
return return
/* /*

View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
</data-extraction-rules>