Skip to content
Permalink
Browse files

Improve search visually

  • Loading branch information...
chrisbanes committed Oct 4, 2019
1 parent 90dd40b commit 3b74b49f6672ad69e1a84b70c34d7e27f4fba773
@@ -76,6 +76,30 @@ fun View.doOnAttach(f: (View) -> Unit) {
}
}

/**
* Allows easy listening to layout passing. Return [true] if you need the listener to keep being
* attached.
*/
inline fun View.doOnLayouts(crossinline action: (view: View) -> Boolean) {
addOnLayoutChangeListener(object : View.OnLayoutChangeListener {
override fun onLayoutChange(
view: View,
left: Int,
top: Int,
right: Int,
bottom: Int,
oldLeft: Int,
oldTop: Int,
oldRight: Int,
oldBottom: Int
) {
if (!action(view)) {
view.removeOnLayoutChangeListener(this)
}
}
})
}

private fun createStateForViewPadding(view: View) = ViewDimensions(
view.paddingLeft, view.paddingTop, view.paddingRight, view.paddingBottom, view.paddingStart,
view.paddingEnd
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Google, Inc.
~
~ 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.
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorSurface" android:alpha="0.70" />
</selector>
@@ -22,12 +22,15 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.SearchView
import androidx.core.view.marginBottom
import androidx.core.view.updatePadding
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupWithNavController
import app.tivi.AppNavigator
import app.tivi.DaggerMvRxFragment
import app.tivi.data.entities.TiviShow
import app.tivi.extensions.doOnLayouts
import app.tivi.extensions.hideSoftInput
import app.tivi.home.search.databinding.FragmentSearchBinding
import app.tivi.ui.ListItemSharedElementHelper
@@ -69,6 +72,11 @@ internal class SearchFragment : DaggerMvRxFragment() {
addOnScrollListener(HideImeOnScrollListener())
}

binding.searchAppbar.doOnLayouts { appBar ->
binding.searchRecyclerview.updatePadding(top = appBar.bottom + appBar.marginBottom)
true
}

binding.searchToolbar.setupWithNavController(findNavController(), appBarConfiguration)

val searchMenuItem = binding.searchToolbar.menu.findItem(R.id.menu_search)
@@ -24,53 +24,64 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/search_app_bar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.MaterialComponents.ActionBar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:paddingTopSystemWindowInsets="@{true}">

<androidx.appcompat.widget.Toolbar
android:id="@+id/search_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:menu="@menu/search_toolbar" />

</FrameLayout>

<com.airbnb.epoxy.EpoxyRecyclerView
android:id="@+id/search_recyclerview"
style="@style/Widget.Tivi.RecyclerView.FastScroll"
android:layout_width="0dp"
android:layout_height="0dp"
android:clipToPadding="false"
android:paddingBottom="@dimen/spacing_small"
android:paddingTop="@dimen/spacing_small"
android:paddingBottom="@dimen/spacing_small"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/search_app_bar"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/view_holder_search_item_show" />

<ProgressBar
android:id="@+id/search_progress"
style="?android:attr/progressBarStyleHorizontal"
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/rectangle"
android:backgroundTint="@color/color_surface_70"
app:layout_constraintBottom_toBottomOf="@id/search_appbar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/search_appbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:indeterminate="true"
app:layout_constraintTop_toTopOf="@id/search_recyclerview"
android:layout_marginHorizontal="@dimen/spacing_normal"
android:layout_marginVertical="@dimen/spacing_small"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:visible="@{state.refreshing}" />
app:layout_constraintTop_toTopOf="parent"
app:marginTopSystemWindowInsets="@{true}">

<androidx.appcompat.widget.Toolbar
android:id="@+id/search_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.MaterialComponents.ActionBar"
app:menu="@menu/search_toolbar" />

<ProgressBar
android:id="@+id/search_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:indeterminate="true"
app:visible="@{state.refreshing}" />

</com.google.android.material.card.MaterialCardView>

</androidx.constraintlayout.widget.ConstraintLayout>

<data>

<variable
name="state"
type="app.tivi.home.search.SearchViewState" />

0 comments on commit 3b74b49

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