Update MerchantsFragment's SearchView suggestions UI so that they include the merchant or teller icon, to make it easier for users and improve UX.

This commit is contained in:
Severiano Jaramillo 2019-01-28 16:14:11 -06:00
parent f70e0434ff
commit 84a524c486
2 changed files with 31 additions and 11 deletions

View file

@ -59,6 +59,7 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
private const val SUGGEST_COLUMN_NAME = "suggest_name" private const val SUGGEST_COLUMN_NAME = "suggest_name"
private const val SUGGEST_COLUMN_ADDRESS = "suggest_address" private const val SUGGEST_COLUMN_ADDRESS = "suggest_address"
private const val SUGGEST_COLUMN_IS_MERCHANT = "suggest_is_merchant" private const val SUGGEST_COLUMN_IS_MERCHANT = "suggest_is_merchant"
private const val SUGGEST_COLUMN_IMAGE_RESOURCE = "suggest_image_resource"
} }
private lateinit var mMap: GoogleMap private lateinit var mMap: GoogleMap
@ -152,7 +153,9 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
val searchItem = menu.findItem(R.id.menu_search) val searchItem = menu.findItem(R.id.menu_search)
mSearchView = searchItem.actionView as SearchView mSearchView = searchItem.actionView as SearchView
mSearchView?.suggestionsAdapter = SimpleCursorAdapter(context, R.layout.item_merchant_suggestion, null, mSearchView?.suggestionsAdapter = SimpleCursorAdapter(context, R.layout.item_merchant_suggestion, null,
arrayOf(SUGGEST_COLUMN_NAME, SUGGEST_COLUMN_ADDRESS), intArrayOf(R.id.tvName, R.id.tvAddress)) arrayOf(SUGGEST_COLUMN_NAME, SUGGEST_COLUMN_ADDRESS, SUGGEST_COLUMN_IMAGE_RESOURCE),
intArrayOf(R.id.tvName, R.id.tvAddress, R.id.ivMarkerPin)
)
// Add listener to changes in the SearchView's text to update the suggestions // Add listener to changes in the SearchView's text to update the suggestions
mSearchView?.queryTextChangeEvents() mSearchView?.queryTextChangeEvents()
@ -174,13 +177,13 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
// Create a cursor out of an Array // Create a cursor out of an Array
val cursor = MatrixCursor(arrayOf(SUGGEST_COLUMN_ID, SUGGEST_COLUMN_NAME, val cursor = MatrixCursor(arrayOf(SUGGEST_COLUMN_ID, SUGGEST_COLUMN_NAME,
SUGGEST_COLUMN_ADDRESS, SUGGEST_COLUMN_IS_MERCHANT)) SUGGEST_COLUMN_ADDRESS, SUGGEST_COLUMN_IS_MERCHANT, SUGGEST_COLUMN_IMAGE_RESOURCE))
for (i in 1..3) { for (i in 1..3) {
if (i%2 == 1) if (i%2 == 1)
cursor.addRow(arrayOf(i.toString(), "Merchant $i", "Address $i", 1)) cursor.addRow(arrayOf(i.toString(), "Merchant $i", "Address $i", 1, R.drawable.ic_merchant_pin))
else else
cursor.addRow(arrayOf(i.toString(), "Teller $i", "Address $i", 0)) cursor.addRow(arrayOf(i.toString(), "Teller $i", "Address $i", 0, R.drawable.ic_teller_pin))
} }
mSearchView?.suggestionsAdapter?.changeCursor(cursor) mSearchView?.suggestionsAdapter?.changeCursor(cursor)

View file

@ -1,30 +1,47 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="8dp" android:padding="8dp"
android:background="?android:colorBackground"> android:background="?android:colorBackground">
<ImageView
android:id="@+id/ivMarkerPin"
android:layout_width="0dp"
android:layout_height="0dp"
tools:src="@drawable/ic_merchant_pin"
app:layout_constraintDimensionRatio="h1,1"
app:layout_constraintTop_toTopOf="@id/tvName"
app:layout_constraintBottom_toBottomOf="@id/tvAddress"
app:layout_constraintStart_toStartOf="parent"/>
<TextView <TextView
android:id="@+id/tvName" android:id="@+id/tvName"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp"
tools:text="Bambuddha Holistic Center" tools:text="Bambuddha Holistic Center"
android:textAppearance="@style/TextAppearance.Bitsy.Body1" android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end"/> android:ellipsize="end"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/ivMarkerPin"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView <TextView
android:id="@+id/tvAddress" android:id="@+id/tvAddress"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:layout_marginStart="4dp"
tools:text="Carretera, Barra Vieja Km 37, 39936 Acapulco, Gro." tools:text="Carretera, Barra Vieja Km 37, 39936 Acapulco, Gro."
android:textAppearance="@style/TextAppearance.Bitsy.Body2" android:textAppearance="@style/TextAppearance.Bitsy.Body2"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end"/> android:ellipsize="end"
app:layout_constraintTop_toBottomOf="@id/tvName"
app:layout_constraintStart_toEndOf="@id/ivMarkerPin"/>
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>