Skip to content

Commit

Permalink
Add current location icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
Przemyslaw committed Jun 2, 2016
1 parent c742c00 commit 180d98a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.util.AttributeSet
import android.view.View
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.Toast
import com.codefactory.przemyslawdabrowski.nearinpost.R
import com.codefactory.przemyslawdabrowski.nearinpost.app.App
import com.codefactory.przemyslawdabrowski.nearinpost.injection.component.DaggerFragmentComponent
Expand All @@ -29,6 +30,11 @@ class LocationSearchView(context: Context, attrs: AttributeSet?, defStyle: Int)
*/
lateinit var search: EditText

/**
* Current location image view button.
*/
lateinit var currentLocation: View

/**
* List of search query results.
*/
Expand Down Expand Up @@ -77,6 +83,7 @@ class LocationSearchView(context: Context, attrs: AttributeSet?, defStyle: Int)
search = findViewById(R.id.customLocationSearch) as EditText
searchResult = findViewById(R.id.customLocationSearchResult) as RecyclerView
searchDivider = findViewById(R.id.customLocationDivider)
currentLocation = findViewById(R.id.customLocationCurrent)

adapter = LocationSearchAdapter(object : LocationSearchHolder.LocationSearchHolderListener {
override fun onResultClick(postalCodeUi: PostalCodeUi) {
Expand All @@ -103,6 +110,9 @@ class LocationSearchView(context: Context, attrs: AttributeSet?, defStyle: Int)
//Empty
}
})

//TODO: Search for current location.
currentLocation.setOnClickListener { view -> Toast.makeText(context, "Not implemented yet", Toast.LENGTH_SHORT).show() }
}

override fun onDetachedFromWindow() {
Expand Down Expand Up @@ -146,7 +156,7 @@ class LocationSearchView(context: Context, attrs: AttributeSet?, defStyle: Int)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
var resultWitPostalOnly = getAddressesWithPostalOnly(it)
val resultWitPostalOnly = getAddressesWithPostalOnly(it)
adapter.addSearchResult(resultWitPostalOnly)
setSearchLayoutHeight(resultWitPostalOnly.size)
searchDivider.visibility = if (resultWitPostalOnly.size > 0) VISIBLE else GONE
Expand All @@ -171,7 +181,7 @@ class LocationSearchView(context: Context, attrs: AttributeSet?, defStyle: Int)
* @param itemCount Number of items.
*/
private fun setSearchLayoutHeight(itemCount: Int = 0) {
var recyclerLayoutParams = searchResult.layoutParams
val recyclerLayoutParams = searchResult.layoutParams
recyclerLayoutParams.height = (itemCount * resources.getDimension(R.dimen.main_search_view_height)).toInt()
searchResult.layoutParams = recyclerLayoutParams
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="@color/colorAccent"
android:pathData="M12,11.5A2.5,2.5 0 0,1 9.5,9A2.5,2.5 0 0,1 12,6.5A2.5,2.5 0 0,1 14.5,9A2.5,2.5 0 0,1 12,11.5M12,2A7,7 0 0,0 5,9C5,14.25 12,22 12,22C12,22 19,14.25 19,9A7,7 0 0,0 12,2Z" />
</vector>
22 changes: 19 additions & 3 deletions app/src/main/res/layout/custom_location_search_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,25 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<EditText
android:id="@+id/customLocationSearch"
style="@style/MainSearchViewStyle" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Location input edit text-->
<EditText
android:id="@+id/customLocationSearch"
style="@style/MainSearchViewStyle"
android:layout_toStartOf="@+id/customLocationCurrent" />
<!--Image button for searching current location-->
<ImageView
android:id="@+id/customLocationCurrent"
android:layout_width="@dimen/main_search_view_current_width_height"
android:layout_height="@dimen/main_search_view_current_width_height"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/common_default_margin"
android:contentDescription="@string/app_name"
app:srcCompat="@drawable/custom_location_search_view_current_icon" />
</RelativeLayout>

<!--Divider between search view and results-->
<View
Expand Down
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 @@ -11,4 +11,5 @@
<dimen name="common_standard_text_size">16sp</dimen>
<dimen name="common_secondary_text_size">14sp</dimen>
<dimen name="machine_details_drag_distance">112dp</dimen>
<dimen name="main_search_view_current_width_height">25dp</dimen>
</resources>

0 comments on commit 180d98a

Please sign in to comment.