Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

added no results & no query screens #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.view.View
import android.view.View.INVISIBLE
import android.view.inputmethod.EditorInfo.IME_ACTION_GO
import android.widget.EditText
import android.widget.TextView
import com.jakewharton.rxbinding2.view.keys
import com.jakewharton.rxbinding2.view.visibility
import com.jakewharton.rxbinding2.widget.editorActionEvents
Expand All @@ -28,6 +29,8 @@ import com.jakewharton.sdksearch.reference.ITEM_LIST_URL_PATHS
import com.jakewharton.sdksearch.reference.PRODUCTION_DAC
import com.jakewharton.sdksearch.reference.PRODUCTION_GIT_WEB
import com.jakewharton.sdksearch.sync.ItemSynchronizer
import com.jakewharton.sdksearch.util.plusAssign
import com.jakewharton.sdksearch.util.visible
import io.reactivex.Observable
import io.reactivex.Observable.just
import io.reactivex.Observable.merge
Expand Down Expand Up @@ -79,6 +82,9 @@ class MainActivity : Activity() {

setContentView(R.layout.main)

val noQuery = findViewById<View>(R.id.noQuery)
val noResultsText = findViewById<TextView>(R.id.noResultsText)
val noResults = findViewById<View>(R.id.noResults)
val recycler = findViewById<RecyclerView>(R.id.results)
val layoutManager = LinearLayoutManager(this)
recycler.layoutManager = layoutManager
Expand Down Expand Up @@ -129,6 +135,9 @@ class MainActivity : Activity() {
adapter.updateItems(it.query, it.data)
it.diff.dispatchUpdatesTo(adapter)
recycler.scrollToPosition(scrollPosition)
noQuery.visible = it.query.isBlank()
noResults.visible = !it.query.isBlank() && it.data.isEmpty()
noResultsText.text = getString(R.string.no_results, it.query)
}

val clear = findViewById<View>(R.id.clear_query)
Expand Down Expand Up @@ -194,15 +203,12 @@ class MainActivity : Activity() {

@Suppress("NOTHING_TO_INLINE") // Needed for correct stacktraces.
private inline fun <I> Observable<I>.crashingSubscribe(noinline onNext: (I) -> Unit) {
subscribe(onNext, { throw OnErrorNotImplementedException(it) }).addTo(disposables)
disposables += subscribe(onNext, { throw OnErrorNotImplementedException(it) })
}

@Suppress("NOTHING_TO_INLINE") // Needed for correct stacktraces.
private inline fun <I> Observable<I>.crashingSubscribe(onNext: Consumer<in I>) {
subscribe(onNext, Consumer { throw OnErrorNotImplementedException(it) }).addTo(disposables)
disposables += subscribe(onNext, Consumer { throw OnErrorNotImplementedException(it) })
}

private fun Disposable.addTo(compositeDisposable: CompositeDisposable) {
compositeDisposable.add(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.jakewharton.sdksearch.util

import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable

operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
this.add(disposable)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.jakewharton.sdksearch.util

import android.view.View

inline var View.visible: Boolean
get() = visibility == View.VISIBLE
set(visible) { visibility = if (visible) View.VISIBLE else View.GONE }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="80dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="80dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFA4C639" android:pathData="M6,18c0,0.55 0.45,1 1,1h1v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L11,19h2v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L16,19h1c0.55,0 1,-0.45 1,-1L18,8L6,8v10zM3.5,8C2.67,8 2,8.67 2,9.5v7c0,0.83 0.67,1.5 1.5,1.5S5,17.33 5,16.5v-7C5,8.67 4.33,8 3.5,8zM20.5,8c-0.83,0 -1.5,0.67 -1.5,1.5v7c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5v-7c0,-0.83 -0.67,-1.5 -1.5,-1.5zM15.53,2.16l1.3,-1.3c0.2,-0.2 0.2,-0.51 0,-0.71 -0.2,-0.2 -0.51,-0.2 -0.71,0l-1.48,1.48C13.85,1.23 12.95,1 12,1c-0.96,0 -1.86,0.23 -2.66,0.63L7.85,0.15c-0.2,-0.2 -0.51,-0.2 -0.71,0 -0.2,0.2 -0.2,0.51 0,0.71l1.31,1.31C6.97,3.26 6,5.01 6,7h12c0,-1.99 -0.97,-3.75 -2.47,-4.84zM10,5L9,5L9,4h1v1zM15,5h-1L14,4h1v1z"/>
</vector>
9 changes: 9 additions & 0 deletions frontend/android/src/main/res/drawable/ic_block_grey_24dp.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:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF333333"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM4,12c0,-4.42 3.58,-8 8,-8 1.85,0 3.55,0.63 4.9,1.69L5.69,16.9C4.63,15.55 4,13.85 4,12zM12,20c-1.85,0 -3.55,-0.63 -4.9,-1.69L18.31,7.1C19.37,8.45 20,10.15 20,12c0,4.42 -3.58,8 -8,8z"/>
</vector>
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:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF333333"
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
</vector>
16 changes: 16 additions & 0 deletions frontend/android/src/main/res/drawable/no_query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
>

<item
android:drawable="@drawable/ic_android_green_80dp"
/>

<item
android:drawable="@drawable/ic_search_grey_24dp"
android:gravity="center"
android:top="10dp"
/>

</layer-list>
16 changes: 16 additions & 0 deletions frontend/android/src/main/res/drawable/no_results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
>

<item
android:drawable="@drawable/ic_android_green_80dp"
/>

<item
android:drawable="@drawable/ic_block_grey_24dp"
android:gravity="center"
android:top="10dp"
/>

</layer-list>
14 changes: 14 additions & 0 deletions frontend/android/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
/>
<include
android:id="@+id/noQuery"
layout="@layout/main_no_query"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"/>
<include
android:id="@+id/noResults"
layout="@layout/main_no_results"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"/>
</android.support.constraint.ConstraintLayout>
30 changes: 30 additions & 0 deletions frontend/android/src/main/res/layout/main_no_query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ImageView
android:id="@+id/noQueryAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/noQueryText"
app:layout_constraintVertical_chainStyle="packed"
android:src="@drawable/no_query"/>

<TextView
android:id="@+id/noQueryText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/noQueryAndroid"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="24dp"
android:fontFamily="@font/roboto_mono_regular"
android:text="@string/no_query_instruction"/>

</android.support.constraint.ConstraintLayout>
32 changes: 32 additions & 0 deletions frontend/android/src/main/res/layout/main_no_results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<ImageView
android:id="@+id/noResultsAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/noResultsText"
app:layout_constraintVertical_chainStyle="packed"
android:src="@drawable/no_results"/>

<TextView
android:id="@+id/noResultsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/noResultsAndroid"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="24dp"
android:fontFamily="@font/roboto_mono_regular"
tools:text="No classes matching &quot;NSObject&quot;"/>

</android.support.constraint.ConstraintLayout>
2 changes: 2 additions & 0 deletions frontend/android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<string name="view_source">View source</string>
<string name="view_class_source">View %s source</string>
<string name="unknown_source">Unknown source location!</string>
<string name="no_query_instruction">What are you looking for?</string>
<string name="no_results">No classes matching \"%s\"</string>

<plurals name="updating">
<item quantity="one">Updating %d class list…</item>
Expand Down