fix: video links dont open on android 10 and below

This commit is contained in:
Bnyro 2024-05-01 17:35:48 +02:00
parent d40e4eb9fa
commit 6b82d954e8

View File

@ -3,6 +3,7 @@ package com.github.libretube.ui.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.KeyEvent import android.view.KeyEvent
import android.view.Menu import android.view.Menu
@ -438,20 +439,29 @@ class MainActivity : BaseActivity() {
.show(supportFragmentManager, null) .show(supportFragmentManager, null)
} }
intent?.getStringExtra(IntentData.videoId)?.let { intent?.getStringExtra(IntentData.videoId)?.let {
// the bottom navigation bar has to be created before opening the video // the below explained work around only seems to work on Android 11 and above
// otherwise the player layout measures aren't calculated properly if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// and the miniplayer is opened at a closed state and overlapping the navigation bar // the bottom navigation bar has to be created before opening the video
binding.bottomNav.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { // otherwise the player layout measures aren't calculated properly
override fun onGlobalLayout() { // and the miniplayer is opened at a closed state and overlapping the navigation bar
NavigationHelper.navigateVideo( binding.bottomNav.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
context = this@MainActivity, override fun onGlobalLayout() {
videoUrlOrId = it, NavigationHelper.navigateVideo(
timestamp = intent.getLongExtra(IntentData.timeStamp, 0L) context = this@MainActivity,
) videoUrlOrId = it,
timestamp = intent.getLongExtra(IntentData.timeStamp, 0L)
)
binding.bottomNav.viewTreeObserver.removeOnGlobalLayoutListener(this) binding.bottomNav.viewTreeObserver.removeOnGlobalLayoutListener(this)
} }
}) })
} else {
NavigationHelper.navigateVideo(
context = this@MainActivity,
videoUrlOrId = it,
timestamp = intent.getLongExtra(IntentData.timeStamp, 0L)
)
}
} }
intent?.getStringExtra(IntentData.query)?.let { intent?.getStringExtra(IntentData.query)?.let {
savedSearchQuery = it savedSearchQuery = it