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
|
||||
|
||||
object NavBarHelper {
|
||||
|
||||
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
|
||||
fun getNavBarItems(context: Context): List<MenuItem> {
|
||||
val prefItems = try {
|
||||
PreferenceHelper.getString(
|
||||
PreferenceKeys.NAVBAR_ITEMS,
|
||||
""
|
||||
).split(SEPARATOR)
|
||||
getNavBarPrefs()
|
||||
} catch (e: Exception) {
|
||||
Log.e("fail to parse nav items", e.toString())
|
||||
return getDefaultNavBarItems(context)
|
||||
@ -126,4 +133,11 @@ object NavBarHelper {
|
||||
val index = getDefaultNavBarItems(context).indexOfFirst { it.itemId == itemId }
|
||||
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.BackgroundHelper
|
||||
import com.github.libretube.helpers.ImageHelper
|
||||
import com.github.libretube.helpers.NavBarHelper
|
||||
import com.github.libretube.helpers.NavigationHelper
|
||||
import com.github.libretube.helpers.PlayerHelper
|
||||
import com.github.libretube.helpers.ThemeHelper
|
||||
@ -216,6 +217,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
private fun initializeTransitionLayout() {
|
||||
mainActivity.binding.container.isVisible = true
|
||||
val mainMotionLayout = mainActivity.binding.mainMotionLayout
|
||||
mainMotionLayout.progress = 0F
|
||||
|
||||
val surfaceColor = SurfaceColors.getColorForElevation(requireContext(), 3f)
|
||||
binding.audioPlayerContainer.setBackgroundColor(surfaceColor)
|
||||
@ -227,7 +229,9 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
endId: Int,
|
||||
progress: Float
|
||||
) {
|
||||
if (NavBarHelper.hasTabs()) {
|
||||
mainMotionLayout.progress = abs(progress)
|
||||
}
|
||||
transitionEndId = endId
|
||||
transitionStartId = startId
|
||||
}
|
||||
@ -235,7 +239,9 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
|
||||
if (currentId == transitionEndId) {
|
||||
viewModel.isMiniPlayerVisible.value = true
|
||||
if (NavBarHelper.hasTabs()) {
|
||||
mainMotionLayout.progress = 1F
|
||||
}
|
||||
} else if (currentId == transitionStartId) {
|
||||
viewModel.isMiniPlayerVisible.value = false
|
||||
mainMotionLayout.progress = 0F
|
||||
|
@ -79,6 +79,7 @@ import com.github.libretube.extensions.togglePlayPauseState
|
||||
import com.github.libretube.extensions.updateParameters
|
||||
import com.github.libretube.helpers.BackgroundHelper
|
||||
import com.github.libretube.helpers.ImageHelper
|
||||
import com.github.libretube.helpers.NavBarHelper
|
||||
import com.github.libretube.helpers.NavigationHelper
|
||||
import com.github.libretube.helpers.PlayerHelper
|
||||
import com.github.libretube.helpers.PlayerHelper.SPONSOR_HIGHLIGHT_CATEGORY
|
||||
@ -423,6 +424,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
private fun initializeTransitionLayout() {
|
||||
mainActivity.binding.container.isVisible = true
|
||||
val mainMotionLayout = mainActivity.binding.mainMotionLayout
|
||||
mainMotionLayout.progress = 0F
|
||||
|
||||
binding.playerMotionLayout.addTransitionListener(object : TransitionAdapter() {
|
||||
override fun onTransitionChange(
|
||||
@ -433,7 +435,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
) {
|
||||
if (_binding == null) return
|
||||
|
||||
if (NavBarHelper.hasTabs()) {
|
||||
mainMotionLayout.progress = abs(progress)
|
||||
}
|
||||
disableController()
|
||||
commentsViewModel.setCommentSheetExpand(false)
|
||||
chaptersBottomSheet?.dismiss()
|
||||
@ -459,7 +463,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
disableController()
|
||||
commentsViewModel.setCommentSheetExpand(null)
|
||||
binding.sbSkipBtn.isGone = true
|
||||
if (NavBarHelper.hasTabs()) {
|
||||
mainMotionLayout.progress = 1F
|
||||
}
|
||||
(activity as MainActivity).requestOrientationChange()
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,27 @@
|
||||
android:translationY="0dp"
|
||||
motion:framePosition="0"
|
||||
motion:motionTarget="@+id/bottomNav" />
|
||||
|
||||
<KeyAttribute
|
||||
android:translationY="55dp"
|
||||
motion:framePosition="75"
|
||||
android:translationY="80dp"
|
||||
motion:framePosition="1"
|
||||
motion:motionTarget="@+id/bottomNav" />
|
||||
|
||||
<KeyAttribute
|
||||
android:translationY="0dp"
|
||||
motion:framePosition="100"
|
||||
motion:motionTarget="@+id/bottomNav" />
|
||||
|
||||
<KeyAttribute
|
||||
android:scaleY="1"
|
||||
motion:framePosition="50"
|
||||
motion:framePosition="30"
|
||||
motion:motionTarget="@+id/container" />
|
||||
|
||||
<KeyAttribute
|
||||
android:translationY="0dp"
|
||||
motion:framePosition="35"
|
||||
motion:motionTarget="@+id/container" />
|
||||
|
||||
<KeyAttribute
|
||||
android:translationY="-80dp"
|
||||
motion:framePosition="100"
|
||||
|
Loading…
x
Reference in New Issue
Block a user