[Android] Make Toolbar snap and expand when changing fragment
Nicolas Pomepuy
git at videolan.org
Thu Jul 23 13:15:37 CEST 2020
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jul 23 07:10:19 2020 +0200| [88569c0ed1eabd9cbd0154f68d21bd1811e82e5e] | committer: Nicolas Pomepuy
Make Toolbar snap and expand when changing fragment
Fixes #1310
> https://code.videolan.org/videolan/vlc-android/commit/88569c0ed1eabd9cbd0154f68d21bd1811e82e5e
---
application/vlc-android/res/layout/toolbar.xml | 2 +-
.../vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/application/vlc-android/res/layout/toolbar.xml b/application/vlc-android/res/layout/toolbar.xml
index a505bf283..a880a28dd 100644
--- a/application/vlc-android/res/layout/toolbar.xml
+++ b/application/vlc-android/res/layout/toolbar.xml
@@ -14,7 +14,7 @@
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:keyboardNavigationCluster="true"
- app:layout_scrollFlags="scroll|enterAlways"
+ app:layout_scrollFlags="scroll|enterAlways|snap"
app:navigationContentDescription="@string/abc_action_bar_up_description"
app:navigationIcon="?attr/homeAsUpIndicator"
app:popupTheme="?attr/toolbar_popup_style"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
index e109ec7f0..98f6399bb 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
@@ -27,6 +27,7 @@ import android.content.*
import android.os.Bundle
import android.os.IBinder
import android.view.MenuItem
+import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.edit
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
@@ -34,6 +35,7 @@ import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
+import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.bottomnavigation.BottomNavigationView
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
@@ -67,6 +69,7 @@ class Navigator : BottomNavigationView.OnNavigationItemSelectedListener, Lifecyc
private lateinit var settings: SharedPreferences
private var extensionsService: ExtensionManagerService? = null
override lateinit var navigationView: BottomNavigationView
+ override lateinit var appbarLayout: AppBarLayout
override lateinit var extensionsManager: ExtensionsManager
override var extensionServiceConnection: ServiceConnection? = null
@@ -83,6 +86,7 @@ class Navigator : BottomNavigationView.OnNavigationItemSelectedListener, Lifecyc
}
lifecycle.addObserver(this at Navigator)
navigationView = findViewById(R.id.navigation)
+ appbarLayout = findViewById(R.id.appbar)
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)
@@ -174,6 +178,8 @@ class Navigator : BottomNavigationView.OnNavigationItemSelectedListener, Lifecyc
override fun onNavigationItemSelected(item: MenuItem): Boolean {
val id = item.itemId
val current = currentFragment
+
+ appbarLayout.setExpanded(true, true)
if (item.groupId == R.id.extensions_group) {
if (currentFragmentId == id) {
clearBackstackFromClass(ExtensionBrowser::class.java)
@@ -300,6 +306,7 @@ class Navigator : BottomNavigationView.OnNavigationItemSelectedListener, Lifecyc
interface INavigator {
var navigationView: BottomNavigationView
+ var appbarLayout: AppBarLayout
var currentFragmentId : Int
More information about the Android
mailing list