Skip to content
Permalink
Browse files

Use new header style everywhere

  • Loading branch information...
chrisbanes committed Aug 28, 2019
1 parent b363802 commit 3d96c870b7697a2388452d312b19ecca6de5bbdf
@@ -85,11 +85,11 @@ abstract class EntryGridFragment<LI : EntryWithShow<out Entry>, VM : EntryViewMo

setController(controller)
addItemDecoration(SpacingItemDecorator(paddingLeft))
addOnScrollListener(StickyHeaderScrollListener(
addOnScrollListener(
StickyHeaderScrollListener(
controller,
controller::isHeader,
binding.headerHolder,
listOf(binding.headerDivider)
binding.headerHolder
))
}

@@ -44,23 +44,14 @@
app:spanCount="@integer/grid_span_count"
tools:listitem="@layout/view_holder_poster_grid_item" />

<androidx.constraintlayout.widget.ConstraintLayout
<app.tivi.ui.widget.HeaderHolderFrameLayout
android:id="@+id/header_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
android:paddingHorizontal="4dp">

<View
android:id="@+id/header_divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
android:paddingHorizontal="4dp"
app:dividerMarginEnd="@dimen/spacing_normal"
app:dividerMarginStart="@dimen/spacing_normal" />

</FrameLayout>

@@ -18,7 +18,6 @@ package app.tivi.common.epoxy

import android.view.View
import android.view.ViewGroup
import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import app.tivi.extensions.createAndBind
@@ -31,8 +30,7 @@ import com.airbnb.epoxy.EpoxyModel
class StickyHeaderScrollListener(
private val epoxyController: EpoxyController,
private val isHeader: (EpoxyModel<*>) -> Boolean,
private val headerHolder: ViewGroup,
private val staticViews: List<View> = emptyList()
private val headerHolder: ViewGroup
) : RecyclerView.OnScrollListener() {

init {
@@ -133,16 +131,12 @@ class StickyHeaderScrollListener(
private fun syncToHeaderHolder(header: RecyclerView.ViewHolder?) {
if (header != null) {
if (headerHolder.indexOfChild(header.itemView) < 0) {
headerHolder.addView(header.itemView, 0)
headerHolder.addView(header.itemView)
}
headerHolder.isVisible = true
} else {
if (headerHolder.childCount > 0) {
for (i in (0 until headerHolder.childCount).reversed()) {
if (headerHolder[i] !in staticViews) {
headerHolder.removeViewAt(i)
}
}
headerHolder.removeAllViews()
}
headerHolder.isVisible = false
}
@@ -0,0 +1,81 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package app.tivi.ui.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import androidx.core.content.res.use
import app.tivi.common.ui.R

class HeaderHolderFrameLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0
) : FrameLayout(context, attrs, defStyle) {

var dividerDrawable: Drawable? = null
set(value) {
field?.callback = null
if (value != null) {
value.callback = this
}
field = value
}

var dividerMarginEnd: Int = 0
set(value) {
field = value
dividerDrawable?.run { invalidateSelf() }
}

var dividerMarginStart: Int = 0
set(value) {
field = value
dividerDrawable?.run { invalidateSelf() }
}

init {
context.obtainStyledAttributes(attrs, R.styleable.HeaderHolderFrameLayout, defStyle, 0).use {
dividerDrawable = it.getDrawable(R.styleable.HeaderHolderFrameLayout_dividerDrawable)
dividerMarginStart = it.getDimensionPixelSize(
R.styleable.HeaderHolderFrameLayout_dividerMarginStart, 0)
dividerMarginEnd = it.getDimensionPixelSize(
R.styleable.HeaderHolderFrameLayout_dividerMarginEnd, 0)
}
}

override fun draw(canvas: Canvas) {
super.draw(canvas)

dividerDrawable?.run {
val left = when (layoutDirection) {
View.LAYOUT_DIRECTION_RTL -> dividerMarginEnd
else -> dividerMarginStart
}
val right = when (layoutDirection) {
View.LAYOUT_DIRECTION_RTL -> dividerMarginStart
else -> dividerMarginEnd
}
setBounds(left, height - intrinsicHeight, width - right, height)
}
dividerDrawable?.draw(canvas)
}
}
@@ -35,4 +35,10 @@
<attr name="materialBackgroundTopRightRadius" format="dimension" />
<attr name="materialBackgroundColor" format="color" />
</declare-styleable>

<declare-styleable name="HeaderHolderFrameLayout">
<attr name="dividerDrawable" format="reference" />
<attr name="dividerMarginStart" format="dimension" />
<attr name="dividerMarginEnd" format="dimension" />
</declare-styleable>
</resources>
@@ -70,8 +70,7 @@ class DiscoverFragment : TiviMvRxFragment() {
StickyHeaderScrollListener(
controller,
controller::isHeader,
binding.headerHolder,
listOf(binding.headerDivider)
binding.headerHolder
)
)
}
@@ -47,23 +47,14 @@
app:paddingBottomSystemWindowInsets="@{ true }"
tools:listitem="@layout/view_holder_poster_grid_item" />

<androidx.constraintlayout.widget.ConstraintLayout
<app.tivi.ui.widget.HeaderHolderFrameLayout
android:id="@+id/header_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface">

<View
android:id="@+id/header_divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginHorizontal="@dimen/spacing_normal"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
android:background="?attr/colorSurface"
app:dividerDrawable="?android:attr/listDivider"
app:dividerMarginEnd="@dimen/spacing_normal"
app:dividerMarginStart="@dimen/spacing_normal" />

</FrameLayout>

@@ -40,13 +40,14 @@
app:paddingBottomSystemWindowInsets="@{ true }"
tools:listitem="@layout/view_holder_library_followed_item" />

<app.tivi.ui.widget.MaterialShapeConstraintLayout
<app.tivi.ui.widget.HeaderHolderFrameLayout
android:id="@+id/header_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
android:elevation="@dimen/sticky_header_elevation"
app:materialBackgroundColor="?attr/colorSurface" />
app:dividerMarginStart="@dimen/spacing_normal"
app:dividerMarginEnd="@dimen/spacing_normal"
app:dividerDrawable="?android:attr/listDivider" />

</FrameLayout>

@@ -40,13 +40,14 @@
app:paddingBottomSystemWindowInsets="@{ true }"
tools:listitem="@layout/view_holder_library_watched_item" />

<app.tivi.ui.widget.MaterialShapeConstraintLayout
<app.tivi.ui.widget.HeaderHolderFrameLayout
android:id="@+id/header_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
android:elevation="@dimen/sticky_header_elevation"
app:materialBackgroundColor="?attr/colorSurface" />
app:dividerMarginStart="@dimen/spacing_normal"
app:dividerMarginEnd="@dimen/spacing_normal"
app:dividerDrawable="?android:attr/listDivider" />

</FrameLayout>

0 comments on commit 3d96c87

Please sign in to comment.
You can’t perform that action at this time.