Skip to content

Commit

Permalink
mozilla-mobile#7700 fixed scrolling, parallax action to match both im…
Browse files Browse the repository at this point in the history
…ages and some code clean up
  • Loading branch information
MarcLeclair committed Feb 4, 2020
1 parent b498fdd commit 22a34fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
57 changes: 22 additions & 35 deletions app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class HomeFragment : Fragment() {

data class PendingSessionDeletion(val deletionJob: (suspend () -> Unit), val sessionId: String)

private lateinit var homeAppBarOffSetListener : AppBarLayout.OnOffsetChangedListener
private val onboarding by lazy { FenixOnboarding(requireContext()) }
private lateinit var homeFragmentStore: HomeFragmentStore
private lateinit var sessionControlInteractor: SessionControlInteractor
Expand Down Expand Up @@ -205,54 +206,36 @@ class HomeFragment : Fragment() {
showDeleteCollectionPrompt = ::showDeleteCollectionPrompt
)
)

view.homeAppBar.addOnOffsetChangedListener(
AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
appBarLayout.alpha =
1.0f - abs(verticalOffset / appBarLayout.totalScrollRange.toFloat())
}
)

updateLayout(view)
setOffset(view)


sessionControlView = SessionControlView(homeFragmentStore,
view.sessionControlRecyclerView, sessionControlInteractor)
updateLayout(view)
activity.themeManager.applyStatusBarTheme(activity)
return view
}

private fun updateLayout(view: View) {
val shouldUseBottomToolbar = view.context.settings().shouldUseBottomToolbar


if(!shouldUseBottomToolbar){
view.toolbarLayout.layoutParams = CoordinatorLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.WRAP_CONTENT)
.apply {
gravity = Gravity.TOP
}
}

val headingsTopMargins = if (shouldUseBottomToolbar) { HEADER_MARGIN } else { TOP_TOOLBAR_HEADER_MARGIN }
val sessionControlViewTopMargin = if (shouldUseBottomToolbar) {
SESSION_CONTROL_VIEW_TOP_MARGIN
} else {
SESSION_CONTROL_VIEW_TOP_TOOLBAR_MARGIN
}

view.wordmark.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = headingsTopMargins.dpToPx(resources.displayMetrics)
}

sessionControlView!!.view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = sessionControlViewTopMargin.dpToPx(resources.displayMetrics)
}

if (!shouldUseBottomToolbar) {
view.privateBrowsingButton.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = PRIVATE_BROWSING_BUTTON_TOP_MARGIN.dpToPx(resources.displayMetrics)
view.homeAppBar.updateLayoutParams<ViewGroup.MarginLayoutParams>{
topMargin = HEADER_MARGIN.dpToPx(resources.displayMetrics)
}

createNewAppBarListener(HEADER_MARGIN.dpToPx(resources.displayMetrics).toFloat())
view.homeAppBar.addOnOffsetChangedListener(
homeAppBarOffSetListener
)
}else {
createNewAppBarListener(0F)
view.homeAppBar.addOnOffsetChangedListener(
homeAppBarOffSetListener
)
}
}
@ExperimentalCoroutinesApi
Expand Down Expand Up @@ -342,6 +325,7 @@ class HomeFragment : Fragment() {

override fun onDestroyView() {
sessionControlView = null
view!!.homeAppBar.removeOnOffsetChangedListener(homeAppBarOffSetListener)
super.onDestroyView()
}

Expand Down Expand Up @@ -846,6 +830,13 @@ class HomeFragment : Fragment() {
}
}

private fun createNewAppBarListener(margin : Float){
homeAppBarOffSetListener = AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
val reduceScrollRanged = appBarLayout.totalScrollRange.toFloat() - margin
appBarLayout.alpha = 1.0f - abs(verticalOffset / reduceScrollRanged)
}
}

companion object {
private const val NON_TAB_ITEM_NUM = 3
private const val ANIM_SCROLL_DELAY = 100L
Expand All @@ -858,10 +849,6 @@ class HomeFragment : Fragment() {

// Layout
private const val HEADER_MARGIN = 60
private const val TOP_TOOLBAR_HEADER_MARGIN = 120
private const val SESSION_CONTROL_VIEW_TOP_MARGIN = 32
private const val SESSION_CONTROL_VIEW_TOP_TOOLBAR_MARGIN = 64
private const val PRIVATE_BROWSING_BUTTON_TOP_MARGIN = 40
}
}

Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/content_description_private_browsing_button"
app:srcCompat="@drawable/private_browsing_button"
app:layout_collapseMode="parallax"/>
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier=".8"/>

<ImageView
android:id="@+id/wordmark"
Expand All @@ -52,7 +53,8 @@
android:focusable="false"
android:importantForAccessibility="no"
app:srcCompat="?fenixLogo"
app:layout_collapseMode="pin"/>
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier=".1"/>

</com.google.android.material.appbar.CollapsingToolbarLayout>

Expand Down

0 comments on commit 22a34fe

Please sign in to comment.