mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fix issue where DownloadedPlayerActivity interferes with MainActivity
This commit is contained in:
parent
33eb3a3b29
commit
9933b5adbe
3 changed files with 42 additions and 5 deletions
|
@ -64,6 +64,35 @@ object CommonActivity {
|
||||||
private set(value) {
|
private set(value) {
|
||||||
_activity = WeakReference(value)
|
_activity = WeakReference(value)
|
||||||
}
|
}
|
||||||
|
private val activeActivities = mutableListOf<WeakReference<Activity>>() // Keep track of active activities
|
||||||
|
|
||||||
|
@MainThread
|
||||||
|
fun registerActivity(activity: Activity) {
|
||||||
|
activeActivities.add(WeakReference(activity))
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainThread
|
||||||
|
fun unregisterActivity(activity: Activity) {
|
||||||
|
val iterator = activeActivities.iterator()
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
val weakReference = iterator.next()
|
||||||
|
val storedActivity = weakReference.get()
|
||||||
|
if (storedActivity == null || storedActivity == activity) {
|
||||||
|
iterator.remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainThread
|
||||||
|
fun getCurrentActivity(): Activity? {
|
||||||
|
for (weakReference in activeActivities) {
|
||||||
|
val activity = weakReference.get()
|
||||||
|
if (activity != null && !activity.isFinishing) {
|
||||||
|
return activity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
fun Activity?.getCastSession(): CastSession? {
|
fun Activity?.getCastSession(): CastSession? {
|
||||||
|
@ -203,8 +232,9 @@ object CommonActivity {
|
||||||
setLocale(this, localeCode)
|
setLocale(this, localeCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun init(act: ComponentActivity?) {
|
fun init() {
|
||||||
if (act == null) return
|
val act = getCurrentActivity() as? ComponentActivity ?: return
|
||||||
|
|
||||||
activity = act
|
activity = act
|
||||||
//https://stackoverflow.com/questions/52594181/how-to-know-if-user-has-disabled-picture-in-picture-feature-permission
|
//https://stackoverflow.com/questions/52594181/how-to-know-if-user-has-disabled-picture-in-picture-feature-permission
|
||||||
//https://developer.android.com/guide/topics/ui/picture-in-picture
|
//https://developer.android.com/guide/topics/ui/picture-in-picture
|
||||||
|
|
|
@ -681,6 +681,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java)
|
broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java)
|
||||||
this.sendBroadcast(broadcastIntent)
|
this.sendBroadcast(broadcastIntent)
|
||||||
afterPluginsLoadedEvent -= ::onAllPluginsLoaded
|
afterPluginsLoadedEvent -= ::onAllPluginsLoaded
|
||||||
|
CommonActivity.unregisterActivity(this)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1369,8 +1370,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
|
|
||||||
// val navView: BottomNavigationView = findViewById(R.id.nav_view)
|
// val navView: BottomNavigationView = findViewById(R.id.nav_view)
|
||||||
setUpBackup()
|
setUpBackup()
|
||||||
|
CommonActivity.registerActivity(this)
|
||||||
CommonActivity.init(this)
|
CommonActivity.init()
|
||||||
val navHostFragment =
|
val navHostFragment =
|
||||||
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
|
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
|
||||||
val navController = navHostFragment.navController
|
val navController = navHostFragment.navController
|
||||||
|
|
|
@ -74,7 +74,8 @@ class DownloadedPlayerActivity : AppCompatActivity() {
|
||||||
|
|
||||||
CommonActivity.loadThemes(this)
|
CommonActivity.loadThemes(this)
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
CommonActivity.init(this)
|
CommonActivity.registerActivity(this)
|
||||||
|
CommonActivity.init()
|
||||||
|
|
||||||
setContentView(R.layout.empty_layout)
|
setContentView(R.layout.empty_layout)
|
||||||
|
|
||||||
|
@ -110,4 +111,9 @@ class DownloadedPlayerActivity : AppCompatActivity() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
CommonActivity.unregisterActivity(this)
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue