mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #5436 from RafaelsRamos/fix/2548
fix: Improve player to mini-player transition + bottom space when there are no navigation tabs
This commit is contained in:
commit
c63cd09c83
@ -16,15 +16,22 @@ import com.google.android.material.bottomnavigation.BottomNavigationView
|
|||||||
import com.google.android.material.navigation.NavigationBarView
|
import com.google.android.material.navigation.NavigationBarView
|
||||||
|
|
||||||
object NavBarHelper {
|
object NavBarHelper {
|
||||||
|
|
||||||
private const val SEPARATOR = ","
|
private const val SEPARATOR = ","
|
||||||
|
|
||||||
|
fun hasTabs(): Boolean {
|
||||||
|
val prefsItems = getNavBarPrefs()
|
||||||
|
|
||||||
|
val tabsUnchanged = prefsItems.isEmpty()
|
||||||
|
val allTabsHidden = prefsItems.all { it.contains("-") }
|
||||||
|
|
||||||
|
return tabsUnchanged || !allTabsHidden
|
||||||
|
}
|
||||||
|
|
||||||
// contains "-" -> invisible menu item, else -> visible menu item
|
// contains "-" -> invisible menu item, else -> visible menu item
|
||||||
fun getNavBarItems(context: Context): List<MenuItem> {
|
fun getNavBarItems(context: Context): List<MenuItem> {
|
||||||
val prefItems = try {
|
val prefItems = try {
|
||||||
PreferenceHelper.getString(
|
getNavBarPrefs()
|
||||||
PreferenceKeys.NAVBAR_ITEMS,
|
|
||||||
""
|
|
||||||
).split(SEPARATOR)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("fail to parse nav items", e.toString())
|
Log.e("fail to parse nav items", e.toString())
|
||||||
return getDefaultNavBarItems(context)
|
return getDefaultNavBarItems(context)
|
||||||
@ -126,4 +133,11 @@ object NavBarHelper {
|
|||||||
val index = getDefaultNavBarItems(context).indexOfFirst { it.itemId == itemId }
|
val index = getDefaultNavBarItems(context).indexOfFirst { it.itemId == itemId }
|
||||||
PreferenceHelper.putInt(PreferenceKeys.START_FRAGMENT, index)
|
PreferenceHelper.putInt(PreferenceKeys.START_FRAGMENT, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getNavBarPrefs(): List<String> {
|
||||||
|
return PreferenceHelper
|
||||||
|
.getString(PreferenceKeys.NAVBAR_ITEMS, "")
|
||||||
|
.split(SEPARATOR)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import com.github.libretube.extensions.toID
|
|||||||
import com.github.libretube.helpers.AudioHelper
|
import com.github.libretube.helpers.AudioHelper
|
||||||
import com.github.libretube.helpers.BackgroundHelper
|
import com.github.libretube.helpers.BackgroundHelper
|
||||||
import com.github.libretube.helpers.ImageHelper
|
import com.github.libretube.helpers.ImageHelper
|
||||||
|
import com.github.libretube.helpers.NavBarHelper
|
||||||
import com.github.libretube.helpers.NavigationHelper
|
import com.github.libretube.helpers.NavigationHelper
|
||||||
import com.github.libretube.helpers.PlayerHelper
|
import com.github.libretube.helpers.PlayerHelper
|
||||||
import com.github.libretube.helpers.ThemeHelper
|
import com.github.libretube.helpers.ThemeHelper
|
||||||
@ -216,6 +217,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
|||||||
private fun initializeTransitionLayout() {
|
private fun initializeTransitionLayout() {
|
||||||
mainActivity.binding.container.isVisible = true
|
mainActivity.binding.container.isVisible = true
|
||||||
val mainMotionLayout = mainActivity.binding.mainMotionLayout
|
val mainMotionLayout = mainActivity.binding.mainMotionLayout
|
||||||
|
mainMotionLayout.progress = 0F
|
||||||
|
|
||||||
val surfaceColor = SurfaceColors.getColorForElevation(requireContext(), 3f)
|
val surfaceColor = SurfaceColors.getColorForElevation(requireContext(), 3f)
|
||||||
binding.audioPlayerContainer.setBackgroundColor(surfaceColor)
|
binding.audioPlayerContainer.setBackgroundColor(surfaceColor)
|
||||||
@ -227,7 +229,9 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
|||||||
endId: Int,
|
endId: Int,
|
||||||
progress: Float
|
progress: Float
|
||||||
) {
|
) {
|
||||||
|
if (NavBarHelper.hasTabs()) {
|
||||||
mainMotionLayout.progress = abs(progress)
|
mainMotionLayout.progress = abs(progress)
|
||||||
|
}
|
||||||
transitionEndId = endId
|
transitionEndId = endId
|
||||||
transitionStartId = startId
|
transitionStartId = startId
|
||||||
}
|
}
|
||||||
@ -235,7 +239,9 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
|||||||
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
|
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
|
||||||
if (currentId == transitionEndId) {
|
if (currentId == transitionEndId) {
|
||||||
viewModel.isMiniPlayerVisible.value = true
|
viewModel.isMiniPlayerVisible.value = true
|
||||||
|
if (NavBarHelper.hasTabs()) {
|
||||||
mainMotionLayout.progress = 1F
|
mainMotionLayout.progress = 1F
|
||||||
|
}
|
||||||
} else if (currentId == transitionStartId) {
|
} else if (currentId == transitionStartId) {
|
||||||
viewModel.isMiniPlayerVisible.value = false
|
viewModel.isMiniPlayerVisible.value = false
|
||||||
mainMotionLayout.progress = 0F
|
mainMotionLayout.progress = 0F
|
||||||
|
@ -79,6 +79,7 @@ import com.github.libretube.extensions.togglePlayPauseState
|
|||||||
import com.github.libretube.extensions.updateParameters
|
import com.github.libretube.extensions.updateParameters
|
||||||
import com.github.libretube.helpers.BackgroundHelper
|
import com.github.libretube.helpers.BackgroundHelper
|
||||||
import com.github.libretube.helpers.ImageHelper
|
import com.github.libretube.helpers.ImageHelper
|
||||||
|
import com.github.libretube.helpers.NavBarHelper
|
||||||
import com.github.libretube.helpers.NavigationHelper
|
import com.github.libretube.helpers.NavigationHelper
|
||||||
import com.github.libretube.helpers.PlayerHelper
|
import com.github.libretube.helpers.PlayerHelper
|
||||||
import com.github.libretube.helpers.PlayerHelper.SPONSOR_HIGHLIGHT_CATEGORY
|
import com.github.libretube.helpers.PlayerHelper.SPONSOR_HIGHLIGHT_CATEGORY
|
||||||
@ -423,6 +424,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
private fun initializeTransitionLayout() {
|
private fun initializeTransitionLayout() {
|
||||||
mainActivity.binding.container.isVisible = true
|
mainActivity.binding.container.isVisible = true
|
||||||
val mainMotionLayout = mainActivity.binding.mainMotionLayout
|
val mainMotionLayout = mainActivity.binding.mainMotionLayout
|
||||||
|
mainMotionLayout.progress = 0F
|
||||||
|
|
||||||
binding.playerMotionLayout.addTransitionListener(object : TransitionAdapter() {
|
binding.playerMotionLayout.addTransitionListener(object : TransitionAdapter() {
|
||||||
override fun onTransitionChange(
|
override fun onTransitionChange(
|
||||||
@ -433,7 +435,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
) {
|
) {
|
||||||
if (_binding == null) return
|
if (_binding == null) return
|
||||||
|
|
||||||
|
if (NavBarHelper.hasTabs()) {
|
||||||
mainMotionLayout.progress = abs(progress)
|
mainMotionLayout.progress = abs(progress)
|
||||||
|
}
|
||||||
disableController()
|
disableController()
|
||||||
commentsViewModel.setCommentSheetExpand(false)
|
commentsViewModel.setCommentSheetExpand(false)
|
||||||
chaptersBottomSheet?.dismiss()
|
chaptersBottomSheet?.dismiss()
|
||||||
@ -459,7 +463,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
disableController()
|
disableController()
|
||||||
commentsViewModel.setCommentSheetExpand(null)
|
commentsViewModel.setCommentSheetExpand(null)
|
||||||
binding.sbSkipBtn.isGone = true
|
binding.sbSkipBtn.isGone = true
|
||||||
|
if (NavBarHelper.hasTabs()) {
|
||||||
mainMotionLayout.progress = 1F
|
mainMotionLayout.progress = 1F
|
||||||
|
}
|
||||||
(activity as MainActivity).requestOrientationChange()
|
(activity as MainActivity).requestOrientationChange()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,14 +12,27 @@
|
|||||||
android:translationY="0dp"
|
android:translationY="0dp"
|
||||||
motion:framePosition="0"
|
motion:framePosition="0"
|
||||||
motion:motionTarget="@+id/bottomNav" />
|
motion:motionTarget="@+id/bottomNav" />
|
||||||
|
|
||||||
<KeyAttribute
|
<KeyAttribute
|
||||||
android:translationY="55dp"
|
android:translationY="80dp"
|
||||||
motion:framePosition="75"
|
motion:framePosition="1"
|
||||||
motion:motionTarget="@+id/bottomNav" />
|
motion:motionTarget="@+id/bottomNav" />
|
||||||
|
|
||||||
|
<KeyAttribute
|
||||||
|
android:translationY="0dp"
|
||||||
|
motion:framePosition="100"
|
||||||
|
motion:motionTarget="@+id/bottomNav" />
|
||||||
|
|
||||||
<KeyAttribute
|
<KeyAttribute
|
||||||
android:scaleY="1"
|
android:scaleY="1"
|
||||||
motion:framePosition="50"
|
motion:framePosition="30"
|
||||||
motion:motionTarget="@+id/container" />
|
motion:motionTarget="@+id/container" />
|
||||||
|
|
||||||
|
<KeyAttribute
|
||||||
|
android:translationY="0dp"
|
||||||
|
motion:framePosition="35"
|
||||||
|
motion:motionTarget="@+id/container" />
|
||||||
|
|
||||||
<KeyAttribute
|
<KeyAttribute
|
||||||
android:translationY="-80dp"
|
android:translationY="-80dp"
|
||||||
motion:framePosition="100"
|
motion:framePosition="100"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user