From 6b82d954e8e2ee31339d11f1e8bae190a746f060 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 1 May 2024 17:35:48 +0200 Subject: [PATCH] fix: video links dont open on android 10 and below --- .../libretube/ui/activities/MainActivity.kt | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index 71fbda6bd..a91a39b39 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -3,6 +3,7 @@ package com.github.libretube.ui.activities import android.annotation.SuppressLint import android.content.Intent import android.content.res.Configuration +import android.os.Build import android.os.Bundle import android.view.KeyEvent import android.view.Menu @@ -438,20 +439,29 @@ class MainActivity : BaseActivity() { .show(supportFragmentManager, null) } intent?.getStringExtra(IntentData.videoId)?.let { - // the bottom navigation bar has to be created before opening the video - // otherwise the player layout measures aren't calculated properly - // and the miniplayer is opened at a closed state and overlapping the navigation bar - binding.bottomNav.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { - override fun onGlobalLayout() { - NavigationHelper.navigateVideo( - context = this@MainActivity, - videoUrlOrId = it, - timestamp = intent.getLongExtra(IntentData.timeStamp, 0L) - ) + // the below explained work around only seems to work on Android 11 and above + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + // the bottom navigation bar has to be created before opening the video + // otherwise the player layout measures aren't calculated properly + // and the miniplayer is opened at a closed state and overlapping the navigation bar + binding.bottomNav.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + NavigationHelper.navigateVideo( + 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 { savedSearchQuery = it