Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
add the empty views
Browse files Browse the repository at this point in the history
  • Loading branch information
quiro91 committed Apr 3, 2018
1 parent 11ee2d9 commit 32cae4b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 6 deletions.
12 changes: 12 additions & 0 deletions app/src/main/java/net/squanchy/search/SearchActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.os.Bundle
import android.os.Handler
import android.os.ResultReceiver
import android.speech.RecognizerIntent
import android.support.annotation.DrawableRes
import android.support.v4.content.res.ResourcesCompat
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.text.Editable
Expand All @@ -17,6 +19,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
Expand Down Expand Up @@ -97,6 +100,9 @@ class SearchActivity : AppCompatActivity(), SearchRecyclerView.OnSearchResultCli

private fun onSearchSuccessful(searchResult: SearchResult.Success) {
if (searchResult.isEmpty) {
emptyViewMessage.loadCompoundDrawableTop(R.drawable.ic_error_outline
)

searchRecyclerView.visibility = View.INVISIBLE
emptyView.visibility = View.VISIBLE

Expand All @@ -111,6 +117,7 @@ class SearchActivity : AppCompatActivity(), SearchRecyclerView.OnSearchResultCli
}

private fun onSearchError() {
emptyViewMessage.loadCompoundDrawableTop(R.drawable.ic_cloud_off)
emptyViewMessage.setText(R.string.search_error_message)
searchRecyclerView.visibility = View.INVISIBLE
emptyView.visibility = View.VISIBLE
Expand All @@ -130,6 +137,11 @@ class SearchActivity : AppCompatActivity(), SearchRecyclerView.OnSearchResultCli
imm.showSoftInput(view, 0, ResultReceiver(Handler()))
}

private fun TextView.loadCompoundDrawableTop(@DrawableRes drawableRes: Int) {
val drawable = ResourcesCompat.getDrawable(resources, drawableRes, theme)
setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null)
}

override fun onStop() {
super.onStop()

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_cloud_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="120dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="120dp">
<path
android:fillColor="@color/empty_view_text_color"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4c-1.48,0 -2.85,0.43 -4.01,1.17l1.46,1.46C10.21,6.23 11.08,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3 0,1.13 -0.64,2.11 -1.56,2.62l1.45,1.45C23.16,18.16 24,16.68 24,15c0,-2.64 -2.05,-4.78 -4.65,-4.96zM3,5.27l2.75,2.74C2.56,8.15 0,10.77 0,14c0,3.31 2.69,6 6,6h11.73l2,2L21,20.73 4.27,4 3,5.27zM7.73,10l8,8H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h1.73z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_error_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="120dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="120dp">
<path
android:fillColor="@color/empty_view_text_color"
android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z" />
</vector>
7 changes: 4 additions & 3 deletions app/src/main/res/layout/activity_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
<TextView
android:id="@+id/emptyViewMessage"
style="@style/Search.EmptyMessage"
android:padding="@dimen/search_empty_state_padding"
android:textAlignment="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
android:layout_gravity="center"
android:padding="@dimen/search_empty_state_padding"
android:drawablePadding="@dimen/search_compound_drawable_padding"
android:textAlignment="center" />
</FrameLayout>

</android.support.design.widget.CoordinatorLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<color name="dialog_dim">#4D000000</color>
<color name="track_filters_close_button_tint">#4D000000</color>

<color name="schedule_empty_view_text_color">#4d606060</color>
<color name="empty_view_text_color">#4d606060</color>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<dimen name="search_card_item_photo_margin_bottom">4dp</dimen>
<dimen name="search_header_padding">16dp</dimen>
<dimen name="search_empty_state_text">16sp</dimen>
<dimen name="search_compound_drawable_padding">24dp</dimen>
<dimen name="search_empty_state_padding">32dp</dimen>
<dimen name="search_photo">48dp</dimen>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
</style>

<style name="TextAppearance.Squanchy.Schedule.EmptyView" parent="None">
<item name="android:textColor">@color/schedule_empty_view_text_color</item>
<item name="android:textColor">@color/empty_view_text_color</item>
<item name="android:textSize">@dimen/schedule_empty_view_text_size</item>
<item name="android:fontFamily">@font/default_typeface_medium</item>
</style>
Expand Down
2 changes: 1 addition & 1 deletion app/src/test/java/net/squanchy/search/SearchServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SearchServiceTest {
}

@Test
fun `should not filter the results when the query is not long enough`() {
fun `should show only the speakers when the query is not long enough`() {
val eventList = listOf(anEvent(), anEvent(id = "qwer"))
val speakerList = listOf(aSpeaker(), aSpeaker(id = "qwer"))
`when`(algoliaSearchEngine.query(QUERY)).thenReturn(Observable.just(AlgoliaSearchResult.QueryNotLongEnough))
Expand Down

0 comments on commit 32cae4b

Please sign in to comment.