Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some deprecations and other warnings #750

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.READ_EXTERNAL_STORAGE" /> <!-- Downloads -->
<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.MODIFY_AUDIO_SETTINGS" /> <!-- Used for player vertical slide -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <!-- Used for app update -->
Expand All @@ -17,7 +17,11 @@

<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 -->
<uses-feature
android:name="android.hardware.touchscreen"
Expand All @@ -37,17 +41,19 @@
<application
android:name=".AcraApplication"
android:allowBackup="true"
android:enableOnBackInvokedCallback="true"
android:appCategory="video"
android:banner="@mipmap/ic_banner"
android:fullBackupContent="@xml/backup_descriptor"
android:dataExtractionRules="@xml/data_extraction_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="o">
tools:targetApi="tiramisu">

<meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
Expand Down Expand Up @@ -182,8 +188,8 @@
<receiver
android:name=".receivers.VideoDownloadRestartReceiver"
android:enabled="false"
android:exported="true">
<intent-filter android:exported="true">
android:exported="false">
<intent-filter android:exported="false">
<action android:name="restart_service" />
</intent-filter>
</receiver>
Expand Down
55 changes: 26 additions & 29 deletions app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.IdRes
import androidx.annotation.MainThread
Expand Down Expand Up @@ -132,7 +133,6 @@ import com.lagradost.cloudstream3.utils.DataStore.setKey
import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.DataStoreHelper.migrateResumeWatching
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.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.UIHelper.changeStatusBarState
Expand Down Expand Up @@ -650,34 +650,6 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
builder.show().setDefaultFocus()
}

private fun backPressed() {
this.window?.navigationBarColor =
Luna712 marked this conversation as resolved.
Show resolved Hide resolved
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() {
val broadcastIntent = Intent()
broadcastIntent.action = "restart_service"
Expand Down Expand Up @@ -1087,6 +1059,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
} catch (_: Throwable) {
}
}

override fun onCreate(savedInstanceState: Bundle?) {
app.initClient(this)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
Expand Down Expand Up @@ -1384,6 +1357,12 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
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)
Expand Down Expand Up @@ -1597,7 +1576,25 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
// showToast(this, currentFocus.toString(), Toast.LENGTH_LONG)
// }
// }
}

private var backPressedCallback: OnBackPressedCallback? = null

private fun attachBackPressedCallback() {
if (backPressedCallback == null) {
backPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
showConfirmExitDialog()
}
}
}

backPressedCallback?.isEnabled = true
onBackPressedDispatcher.addCallback(this, backPressedCallback!!)
}

private fun detachBackPressedCallback() {
backPressedCallback?.isEnabled = false
}

suspend fun checkGithubConnectivity(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DownloadChildFragment : Fragment() {
}
}.sortedBy { it.data.episode + (it.data.season ?: 0) * 100000 }
if (eps.isEmpty()) {
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
return@main
}

Expand All @@ -78,7 +78,7 @@ class DownloadChildFragment : Fragment() {
val folder = arguments?.getString("folder")
val name = arguments?.getString("name")
if (folder == null) {
activity?.onBackPressed() // TODO FIX
activity?.onBackPressedDispatcher?.onBackPressed() // TODO FIX
return
}
fixPaddingStatusbar(binding?.downloadChildRoot)
Expand All @@ -87,7 +87,7 @@ class DownloadChildFragment : Fragment() {
title = name
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener {
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import com.lagradost.cloudstream3.CommonActivity
import com.lagradost.cloudstream3.R
Expand Down Expand Up @@ -34,10 +35,6 @@ class DownloadedPlayerActivity : AppCompatActivity() {
CommonActivity.onUserLeaveHint(this)
}

override fun onBackPressed() {
finish()
}

private fun playLink(url: String) {
this.navigate(
R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
Expand Down Expand Up @@ -109,6 +106,15 @@ class DownloadedPlayerActivity : AppCompatActivity() {
finish()
return
}

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
)
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.activity.OnBackPressedCallback
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.lagradost.cloudstream3.CommonActivity.screenHeight
Expand All @@ -15,10 +16,8 @@ import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.ui.player.CSPlayerEvent
import com.lagradost.cloudstream3.ui.player.PlayerEventSource
import com.lagradost.cloudstream3.ui.player.SubtitleData
import com.lagradost.cloudstream3.utils.IOnBackPressed


open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed {
open class ResultTrailerPlayer : ResultFragmentPhone() {

override var lockRotation = false
override var isFullScreenPlayer = false
Expand All @@ -28,7 +27,7 @@ open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed {
const val TAG = "RESULT_TRAILER"
}

var playerWidthHeight: Pair<Int, Int>? = null
private var playerWidthHeight: Pair<Int, Int>? = null

override fun nextEpisode() {}

Expand Down Expand Up @@ -154,6 +153,10 @@ open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed {
}
fixPlayerSize()
uiReset()

if (isFullScreenPlayer) {
attachBackPressedCallback()
} else detachBackPressedCallback()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -172,12 +175,22 @@ open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed {
}
}

override fun onBackPressed(): Boolean {
return if (isFullScreenPlayer) {
updateFullscreen(false)
false
} else {
true
private var backPressedCallback: OnBackPressedCallback? = null

private fun attachBackPressedCallback() {
if (backPressedCallback == null) {
backPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
updateFullscreen(false)
}
}
}

backPressedCallback?.isEnabled = true
requireActivity().onBackPressedDispatcher.addCallback(requireActivity(), backPressedCallback!!)
Luna712 marked this conversation as resolved.
Show resolved Hide resolved
}

private fun detachBackPressedCallback() {
backPressedCallback?.isEnabled = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SettingsFragment : Fragment() {
setTitle(title)
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener {
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
}
}
fixPaddingStatusbar(settingsToolbar)
Expand All @@ -78,7 +78,7 @@ class SettingsFragment : Fragment() {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
children.firstOrNull { it is ImageView }?.tag = getString(R.string.tv_no_focus_tag)
setNavigationOnClickListener {
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
}
}
fixPaddingStatusbar(settingsToolbar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PluginsFragment : Fragment() {
val isLocal = arguments?.getBoolean(PLUGINS_BUNDLE_LOCAL) == true

if (url == null || name == null) {
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
return
}

Expand Down Expand Up @@ -117,7 +117,7 @@ class PluginsFragment : Fragment() {
if (searchView?.isIconified == false) {
searchView.isIconified = true
} else {
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
}
}
searchView?.setOnQueryTextFocusChangeListener { _, hasFocus ->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ object UIHelper {
}

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

/*
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/xml/data_extraction_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
</data-extraction-rules>