From 2e4aa328febe65a43755acdcfd6371e789bcb628 Mon Sep 17 00:00:00 2001 From: shah Date: Fri, 20 Dec 2024 16:09:55 +0530 Subject: [PATCH 1/3] fix: Remove search distance from routing and e2e test cases added ALS-1918 --- .../com/aws/amazonlocation/ConstantTest.kt | 2 + .../ui/MapLoadAndPlaceSearchFlowSuite.kt | 2 + .../main/ExploreFragmentSearchDistanceTest.kt | 85 +++++++++++++++++++ .../ui/main/explore/ExploreFragment.kt | 11 ++- .../ui/main/explore/SearchPlacesAdapter.kt | 76 +++++++++++++++-- .../explore/SearchPlacesSuggestionAdapter.kt | 81 +++++++++++++++--- .../ui/main/geofence/GeofenceUtils.kt | 2 + .../com/aws/amazonlocation/utils/Constants.kt | 2 +- .../utils/providers/PlacesProvider.kt | 54 ++++++++---- .../res/layout/item_search_directions.xml | 54 ++++++++++++ 10 files changed, 328 insertions(+), 41 deletions(-) create mode 100644 app/src/androidTest/java/com/aws/amazonlocation/ui/main/ExploreFragmentSearchDistanceTest.kt create mode 100644 app/src/main/res/layout/item_search_directions.xml diff --git a/app/src/androidTest/java/com/aws/amazonlocation/ConstantTest.kt b/app/src/androidTest/java/com/aws/amazonlocation/ConstantTest.kt index 8eeb32e6..c54267ed 100644 --- a/app/src/androidTest/java/com/aws/amazonlocation/ConstantTest.kt +++ b/app/src/androidTest/java/com/aws/amazonlocation/ConstantTest.kt @@ -32,6 +32,7 @@ const val TEST_WORD_RIO_TINTO = "Rio Tinto" const val TEST_WORD_SHYAMAL = "Shyamal Cross" const val TEST_WORD_SCHOOL = "School" const val TEST_WORD_SHYAMAL_CROSS_ROAD = "Shyamal Cross Road" +const val TEST_WORD_TALWALKERS_SHYAMAL_CROSS_ROAD = "Talwalkers Shyamal Cross Road" const val TEST_WORD_DOMINO_PIZZA_VEJALPUR = "dominos Jivraj Park Cross Road, Vejalpur Police Chowky, Vejalpur" const val TEST_WORD_DOMINO_PIZZA = "Domino's" const val TEST_WORD_AUBURN_SYDNEY = "auburn sydney" @@ -75,6 +76,7 @@ const val NESTED_SCROLL_ERROR = "Nested scroll error" const val TEST_FAILED_SEARCH_FIELD_NOT_VISIBLE = "Test failed due to search field not visible" const val TEST_FAILED_EXIT_BUTTON_NOT_VISIBLE = "Test failed due to exit button not visible" const val TEST_FAILED_DISTANCE_OR_TIME_EMPTY = "Test failed due to distance or time empty" +const val TEST_FAILED_DISTANCE_EMPTY = "Test failed due to distance is empty" const val TEST_FAILED_ZOOM_LEVEL_NOT_CHANGED = "Test failed due to zoom level not changed" const val TEST_FAILED_INVALID_IDENTITY_POOL_ID = "Test failed due to invalid identity pool id" const val TEST_FAILED_LOCATION_COMPONENT_NOT_ACTIVATED_OR_ENABLED = "Test failed due to location component not activated or enabled" diff --git a/app/src/androidTest/java/com/aws/amazonlocation/ui/MapLoadAndPlaceSearchFlowSuite.kt b/app/src/androidTest/java/com/aws/amazonlocation/ui/MapLoadAndPlaceSearchFlowSuite.kt index 93297bca..2e48bdc4 100644 --- a/app/src/androidTest/java/com/aws/amazonlocation/ui/MapLoadAndPlaceSearchFlowSuite.kt +++ b/app/src/androidTest/java/com/aws/amazonlocation/ui/MapLoadAndPlaceSearchFlowSuite.kt @@ -11,6 +11,7 @@ import com.aws.amazonlocation.ui.main.ExploreFragmentMapZoomInOutTest import com.aws.amazonlocation.ui.main.ExploreFragmentMaxZoomInOutTest import com.aws.amazonlocation.ui.main.ExploreFragmentSearchByCategoriesTest import com.aws.amazonlocation.ui.main.ExploreFragmentSearchCollapseTest +import com.aws.amazonlocation.ui.main.ExploreFragmentSearchDistanceTest import com.aws.amazonlocation.ui.main.ExploreFragmentSearchExistsTest import com.aws.amazonlocation.ui.main.ExploreFragmentSearchGeocodeReversedTest import com.aws.amazonlocation.ui.main.SearchContactInfoPOICardTest @@ -32,6 +33,7 @@ import org.junit.runners.Suite ExploreFragmentSearchCollapseTest::class, ExploreFragmentSearchExistsTest::class, ExploreFragmentSearchGeocodeReversedTest::class, + ExploreFragmentSearchDistanceTest::class, SearchContactInfoPOICardTest::class ) class MapLoadAndPlaceSearchFlowSuite diff --git a/app/src/androidTest/java/com/aws/amazonlocation/ui/main/ExploreFragmentSearchDistanceTest.kt b/app/src/androidTest/java/com/aws/amazonlocation/ui/main/ExploreFragmentSearchDistanceTest.kt new file mode 100644 index 00000000..fe4e0002 --- /dev/null +++ b/app/src/androidTest/java/com/aws/amazonlocation/ui/main/ExploreFragmentSearchDistanceTest.kt @@ -0,0 +1,85 @@ +package com.aws.amazonlocation.ui.main + +import androidx.test.core.app.ApplicationProvider +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.replaceText +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.hasMinimumChildCount +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation +import androidx.test.uiautomator.By +import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.UiSelector +import androidx.test.uiautomator.Until +import com.aws.amazonlocation.ALLOW +import com.aws.amazonlocation.AMAZON_MAP_READY +import com.aws.amazonlocation.BaseTestMainActivity +import com.aws.amazonlocation.BuildConfig +import com.aws.amazonlocation.DELAY_15000 +import com.aws.amazonlocation.R +import com.aws.amazonlocation.TEST_FAILED +import com.aws.amazonlocation.TEST_FAILED_DISTANCE_EMPTY +import com.aws.amazonlocation.TEST_WORD_TALWALKERS_SHYAMAL_CROSS_ROAD +import com.aws.amazonlocation.WHILE_USING_THE_APP +import com.aws.amazonlocation.WHILE_USING_THE_APP_ALLOW +import com.aws.amazonlocation.WHILE_USING_THE_APP_CAPS +import com.aws.amazonlocation.actions.swipeLeft +import com.aws.amazonlocation.di.AppModule +import com.aws.amazonlocation.enableGPS +import com.aws.amazonlocation.failTest +import dagger.hilt.android.testing.HiltAndroidTest +import dagger.hilt.android.testing.UninstallModules +import org.junit.Assert +import org.junit.Test + +@UninstallModules(AppModule::class) +@HiltAndroidTest +class ExploreFragmentSearchDistanceTest : BaseTestMainActivity() { + private val uiDevice = UiDevice.getInstance(getInstrumentation()) + + @Test + fun testSearchDistanceTest() { + try { + val btnContinueToApp = + uiDevice.findObject(UiSelector().resourceId("${BuildConfig.APPLICATION_ID}:id/btn_continue_to_app")) + if (btnContinueToApp.exists()) { + btnContinueToApp.click() + } + uiDevice.findObject(By.text(WHILE_USING_THE_APP))?.click() + uiDevice.findObject(By.text(WHILE_USING_THE_APP_CAPS))?.click() + uiDevice.findObject(By.text(WHILE_USING_THE_APP_ALLOW))?.click() + uiDevice.findObject(By.text(ALLOW))?.click() + enableGPS(ApplicationProvider.getApplicationContext()) + uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000) + + onView(withId(R.id.mapView)).perform(swipeLeft()) + + val edtSearch = + onView(withId(R.id.edt_search_places)).check(matches(isDisplayed())) + + edtSearch.perform(click()) + onView(withId(R.id.edt_search_places)).perform( + replaceText( + TEST_WORD_TALWALKERS_SHYAMAL_CROSS_ROAD, + ), + ) + Thread.sleep(DELAY_15000) + onView(withId(R.id.rv_search_places_suggestion)).check( + matches( + hasMinimumChildCount(1), + ), + ) + val tvDistance = uiDevice.findObject(UiSelector().resourceId("${BuildConfig.APPLICATION_ID}:id/tv_distance")) + val distanceValue = tvDistance.text.split(" ")[0].toDouble() + Assert.assertTrue( + TEST_FAILED_DISTANCE_EMPTY, + distanceValue > 0.0 + ) + } catch (e: Exception) { + failTest(71, e) + Assert.fail(TEST_FAILED) + } + } +} diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/ExploreFragment.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/ExploreFragment.kt index da296348..b14e921d 100644 --- a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/ExploreFragment.kt @@ -1969,8 +1969,7 @@ class ExploreFragment : cardView: MaterialCardView, cl: ConstraintLayout, ) { - if (source == resources.getString(R.string.label_my_location) - ) { + if (source == resources.getString(R.string.label_my_location)) { mBinding.bottomSheetDirectionSearch.apply { when (cardView) { cardWalkGo -> { @@ -4078,6 +4077,7 @@ class ExploreFragment : SearchPlacesAdapter( mPlaceList, mPreferenceManager, + true, object : SearchPlacesAdapter.SearchPlaceInterface { override fun placeClick(position: Int) { if (checkInternetConnection()) { @@ -4103,6 +4103,7 @@ class ExploreFragment : SearchPlacesSuggestionAdapter( mPlaceList, mPreferenceManager, + true, object : SearchPlacesSuggestionAdapter.SearchPlaceSuggestionInterface { override fun suggestedPlaceClick(position: Int) { if (checkInternetConnection()) { @@ -4124,9 +4125,9 @@ class ExploreFragment : mIsDirectionDataSet = false } if (mPlaceList[position].placeId.isNullOrEmpty() && !mPlaceList[position].queryId.isNullOrEmpty()) { - mPlaceList[position].text?.let { + mPlaceList[position].queryId?.let { mViewModel.searchPlaceIndexForText( - it, + queryId = it ) } } else { @@ -4408,6 +4409,7 @@ class ExploreFragment : SearchPlacesAdapter( mPlaceList, mPreferenceManager, + false, object : SearchPlacesAdapter.SearchPlaceInterface { override fun placeClick(position: Int) { if (checkInternetConnection()) { @@ -4431,6 +4433,7 @@ class ExploreFragment : SearchPlacesSuggestionAdapter( mPlaceList, mPreferenceManager, + false, object : SearchPlacesSuggestionAdapter.SearchPlaceSuggestionInterface { override fun suggestedPlaceClick(position: Int) { if (checkInternetConnection()) { diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesAdapter.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesAdapter.kt index a102487b..782bbf79 100644 --- a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesAdapter.kt +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesAdapter.kt @@ -5,6 +5,7 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.aws.amazonlocation.R import com.aws.amazonlocation.data.response.SearchSuggestionData +import com.aws.amazonlocation.databinding.ItemSearchDirectionsBinding import com.aws.amazonlocation.databinding.ItemSearchPlacesBinding import com.aws.amazonlocation.utils.KEY_UNIT_SYSTEM import com.aws.amazonlocation.utils.PreferenceManager @@ -19,9 +20,15 @@ import com.aws.amazonlocation.utils.show class SearchPlacesAdapter( private val mSearchPlaceList: ArrayList, private val preferenceManager: PreferenceManager?, + private var isForDirections: Boolean, var mSearchPlaceInterface: SearchPlaceInterface, ) : - RecyclerView.Adapter() { + RecyclerView.Adapter() { + + companion object { + private const val TYPE_PLACE = 0 + private const val TYPE_DIRECTIONS = 1 + } inner class SearchPlaceVH(private val binding: ItemSearchPlacesBinding) : RecyclerView.ViewHolder(binding.root) { @@ -64,14 +71,69 @@ class SearchPlacesAdapter( } } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchPlaceVH { - return SearchPlaceVH( - ItemSearchPlacesBinding.inflate(LayoutInflater.from(parent.context), parent, false), - ) + inner class SearchDirectionsVH(private val binding: ItemSearchDirectionsBinding) : + RecyclerView.ViewHolder(binding.root) { + fun bind(data: SearchSuggestionData) { + binding.apply { + tvPlaceName.text = data.text + binding.apply { + if (data.isPlaceIndexForPosition) { + tvPlaceName.text = data.text + } else { + if (data.amazonLocationAddress?.label.isNullOrEmpty()) { + tvPlaceName.text = data.text + tvDescription.hide() + } else { + tvDescription.show() + } + data.amazonLocationAddress?.label?.split(",")?.let { parts -> + tvPlaceName.text = parts.getOrNull(0) ?: data.text + tvDescription.text = parts.drop(1).joinToString(",").trim() + } + } + + when { + data.placeId.isNullOrEmpty() -> ivSearchLocation.setImageResource(R.drawable.icon_search) + !data.placeId.isNullOrEmpty() -> ivSearchLocation.setImageResource(R.drawable.ic_map_pin) + } + clMain.setOnClickListener { + mSearchPlaceInterface.placeClick(adapterPosition) + } + } + } + } + } + + override fun getItemViewType(position: Int): Int { + return if (isForDirections) TYPE_DIRECTIONS else TYPE_PLACE } - override fun onBindViewHolder(holder: SearchPlaceVH, position: Int) { - holder.bind(mSearchPlaceList[position]) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + return when (viewType) { + TYPE_PLACE -> SearchPlaceVH( + ItemSearchPlacesBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false + ) + ) + TYPE_DIRECTIONS -> SearchDirectionsVH( + ItemSearchDirectionsBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false + ) + ) + else -> throw IllegalArgumentException("Invalid view type") + } + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + val data = mSearchPlaceList[position] + when (holder) { + is SearchPlaceVH -> holder.bind(data) + is SearchDirectionsVH -> holder.bind(data) + } } override fun getItemCount() = mSearchPlaceList.size diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesSuggestionAdapter.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesSuggestionAdapter.kt index aa11481a..4008a133 100644 --- a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesSuggestionAdapter.kt +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesSuggestionAdapter.kt @@ -5,6 +5,7 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.aws.amazonlocation.R import com.aws.amazonlocation.data.response.SearchSuggestionData +import com.aws.amazonlocation.databinding.ItemSearchDirectionsBinding import com.aws.amazonlocation.databinding.ItemSearchPlacesSuggestionBinding import com.aws.amazonlocation.utils.KEY_UNIT_SYSTEM import com.aws.amazonlocation.utils.PreferenceManager @@ -18,9 +19,14 @@ import com.aws.amazonlocation.utils.show class SearchPlacesSuggestionAdapter( private val mSearchPlaceList: ArrayList, private val preferenceManager: PreferenceManager?, + private var isForDirections: Boolean, var mSearchPlaceSuggestionInterface: SearchPlaceSuggestionInterface, -) : - RecyclerView.Adapter() { +) : RecyclerView.Adapter() { + + companion object { + private const val TYPE_PLACE = 0 + private const val TYPE_DIRECTIONS = 1 + } inner class SearchPlaceVH(private val binding: ItemSearchPlacesSuggestionBinding) : RecyclerView.ViewHolder(binding.root) { @@ -69,18 +75,69 @@ class SearchPlacesSuggestionAdapter( } } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchPlaceVH { - return SearchPlaceVH( - ItemSearchPlacesSuggestionBinding.inflate( - LayoutInflater.from(parent.context), - parent, - false, - ), - ) + inner class SearchDirectionsVH(private val binding: ItemSearchDirectionsBinding) : + RecyclerView.ViewHolder(binding.root) { + fun bind(data: SearchSuggestionData) { + binding.apply { + tvPlaceName.text = data.text + binding.apply { + if (data.isPlaceIndexForPosition) { + tvPlaceName.text = data.text + } else { + if (data.amazonLocationAddress?.label.isNullOrEmpty()) { + tvPlaceName.text = data.text + tvDescription.hide() + } else { + tvDescription.show() + } + data.amazonLocationAddress?.label?.split(",")?.let { parts -> + tvPlaceName.text = parts.getOrNull(0) ?: data.text + tvDescription.text = parts.drop(1).joinToString(",").trim() + } + } + + when { + data.placeId.isNullOrEmpty() -> ivSearchLocation.setImageResource(R.drawable.icon_search) + !data.placeId.isNullOrEmpty() -> ivSearchLocation.setImageResource(R.drawable.ic_map_pin) + } + clMain.setOnClickListener { + mSearchPlaceSuggestionInterface.suggestedPlaceClick(adapterPosition) + } + } + } + } + } + + override fun getItemViewType(position: Int): Int { + return if (isForDirections) TYPE_DIRECTIONS else TYPE_PLACE } - override fun onBindViewHolder(holder: SearchPlaceVH, position: Int) { - holder.bind(mSearchPlaceList[position]) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + return when (viewType) { + TYPE_PLACE -> SearchPlaceVH( + ItemSearchPlacesSuggestionBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false + ) + ) + TYPE_DIRECTIONS -> SearchDirectionsVH( + ItemSearchDirectionsBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false + ) + ) + else -> throw IllegalArgumentException("Invalid view type") + } + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + val data = mSearchPlaceList[position] + when (holder) { + is SearchPlaceVH -> holder.bind(data) + is SearchDirectionsVH -> holder.bind(data) + } } override fun getItemCount() = mSearchPlaceList.size diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/geofence/GeofenceUtils.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/geofence/GeofenceUtils.kt index 3e132b23..718cf1df 100644 --- a/app/src/main/java/com/aws/amazonlocation/ui/main/geofence/GeofenceUtils.kt +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/geofence/GeofenceUtils.kt @@ -807,6 +807,7 @@ class GeofenceUtils { mGeofenceSearchSuggestionAdapter = SearchPlacesSuggestionAdapter( mPlaceList, preferenceManager, + true, object : SearchPlacesSuggestionAdapter.SearchPlaceSuggestionInterface { override fun suggestedPlaceClick(position: Int) { if (checkInternetConnection()) { @@ -881,6 +882,7 @@ class GeofenceUtils { mSearchPlacesAdapter = SearchPlacesAdapter( mPlaceList, preferenceManager, + true, object : SearchPlacesAdapter.SearchPlaceInterface { override fun placeClick(position: Int) { if (checkInternetConnection()) { diff --git a/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt b/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt index 73ed95d9..e6cb4878 100644 --- a/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt +++ b/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt @@ -12,7 +12,7 @@ const val KEY_BOARD_HEIGHT = 500 const val KEY_USER_DETAILS = "user_details" const val KEY_LOCATION_PERMISSION = "location_permission" const val SEARCH_MAX_RESULT = 15 -const val SEARCH_MAX_SUGGESTION_RESULT = 5 +const val SEARCH_MAX_SUGGESTION_RESULT = 10 const val KEY_CODE = "code" const val SIGN_OUT = "signout" const val SIGN_IN = "signin" diff --git a/app/src/main/java/com/aws/amazonlocation/utils/providers/PlacesProvider.kt b/app/src/main/java/com/aws/amazonlocation/utils/providers/PlacesProvider.kt index 06160367..9574ba01 100644 --- a/app/src/main/java/com/aws/amazonlocation/utils/providers/PlacesProvider.kt +++ b/app/src/main/java/com/aws/amazonlocation/utils/providers/PlacesProvider.kt @@ -21,11 +21,14 @@ import com.aws.amazonlocation.utils.SEARCH_MAX_SUGGESTION_RESULT import com.aws.amazonlocation.utils.Units.getApiKey import com.aws.amazonlocation.utils.Units.isMetric import com.aws.amazonlocation.utils.Units.meterToFeet +import com.aws.amazonlocation.utils.geofence_helper.turf.TurfConstants +import com.aws.amazonlocation.utils.geofence_helper.turf.TurfMeasurement import com.aws.amazonlocation.utils.getLanguageCode import com.aws.amazonlocation.utils.validateLatLng import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.maplibre.android.geometry.LatLng +import org.maplibre.geojson.Point class PlacesProvider( private var mMapHelper: MapHelper, @@ -129,26 +132,43 @@ class PlacesProvider( mList.add(mSearchSuggestionData) } suggestResponse?.resultItems?.forEach { - val mSearchSuggestionData: SearchSuggestionData = - if (!it.place?.placeId.isNullOrEmpty()) { - SearchSuggestionData( - placeId = it.place!!.placeId, - searchText = searchText, - text = it.place?.address?.label, - amazonLocationAddress = it.place?.address, - distance = it.place?.distance?.toDouble(), - position = - it.place?.position?.let { doubles -> - listOf( - doubles[0], - doubles[1], + liveLocation?.let { liveLocation -> + if (!it.place?.position.isNullOrEmpty()) { + it.place?.position?.let { position -> + val distance = TurfMeasurement.distance( + Point.fromLngLat(liveLocation.longitude, liveLocation.latitude), + Point.fromLngLat(position[0], position[1]), + TurfConstants.UNIT_METRES + ) + + if (!it.place?.placeId.isNullOrEmpty()) { + mList.add( + SearchSuggestionData( + placeId = it.place!!.placeId, + searchText = searchText, + text = it.place?.address?.label, + amazonLocationAddress = it.place?.address, + distance = distance, + position = listOf(position[0], position[1]), + ), ) - }, - ) + } else { + it.query?.let { query -> + mList.add( + SearchSuggestionData(text = it.title, queryId = query.queryId), + ) + } + } + } } else { - SearchSuggestionData(text = it.title, queryId = it.query?.queryId) + it.query?.let { query -> + mList.add( + SearchSuggestionData(text = it.title, queryId = query.queryId), + ) + } } - mList.add(mSearchSuggestionData) + } + } response.data = mList return response diff --git a/app/src/main/res/layout/item_search_directions.xml b/app/src/main/res/layout/item_search_directions.xml new file mode 100644 index 00000000..bda7b48a --- /dev/null +++ b/app/src/main/res/layout/item_search_directions.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + \ No newline at end of file From fd23073c8b4adb0415f83bea2229882d5c08fada Mon Sep 17 00:00:00 2001 From: shah Date: Tue, 21 Jan 2025 10:52:20 +0530 Subject: [PATCH 2/3] fix: removed unnecessary thread.sleep ALS-1918 --- .../ui/main/ExploreFragmentSearchDistanceTest.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/androidTest/java/com/aws/amazonlocation/ui/main/ExploreFragmentSearchDistanceTest.kt b/app/src/androidTest/java/com/aws/amazonlocation/ui/main/ExploreFragmentSearchDistanceTest.kt index fe4e0002..d7475156 100644 --- a/app/src/androidTest/java/com/aws/amazonlocation/ui/main/ExploreFragmentSearchDistanceTest.kt +++ b/app/src/androidTest/java/com/aws/amazonlocation/ui/main/ExploreFragmentSearchDistanceTest.kt @@ -29,8 +29,10 @@ import com.aws.amazonlocation.actions.swipeLeft import com.aws.amazonlocation.di.AppModule import com.aws.amazonlocation.enableGPS import com.aws.amazonlocation.failTest +import com.aws.amazonlocation.waitForView import dagger.hilt.android.testing.HiltAndroidTest import dagger.hilt.android.testing.UninstallModules +import org.hamcrest.CoreMatchers.allOf import org.junit.Assert import org.junit.Test @@ -65,12 +67,8 @@ class ExploreFragmentSearchDistanceTest : BaseTestMainActivity() { TEST_WORD_TALWALKERS_SHYAMAL_CROSS_ROAD, ), ) - Thread.sleep(DELAY_15000) - onView(withId(R.id.rv_search_places_suggestion)).check( - matches( - hasMinimumChildCount(1), - ), - ) + waitForView(allOf(withId(R.id.rv_search_places_suggestion), isDisplayed(), hasMinimumChildCount(1))) + val tvDistance = uiDevice.findObject(UiSelector().resourceId("${BuildConfig.APPLICATION_ID}:id/tv_distance")) val distanceValue = tvDistance.text.split(" ")[0].toDouble() Assert.assertTrue( From 1d65d8cde9549612489720689b8c65382f0364bd Mon Sep 17 00:00:00 2001 From: shah Date: Wed, 29 Jan 2025 15:16:10 +0530 Subject: [PATCH 3/3] fix: Code optimized based on PR comments ALS-1918 --- .../ui/main/explore/SearchPlacesAdapter.kt | 10 +++------- .../ui/main/explore/SearchPlacesSuggestionAdapter.kt | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesAdapter.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesAdapter.kt index 782bbf79..18a7ee35 100644 --- a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesAdapter.kt +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesAdapter.kt @@ -77,18 +77,14 @@ class SearchPlacesAdapter( binding.apply { tvPlaceName.text = data.text binding.apply { - if (data.isPlaceIndexForPosition) { + if (data.isPlaceIndexForPosition || data.amazonLocationAddress?.label.isNullOrEmpty()) { tvPlaceName.text = data.text + tvDescription.hide() } else { - if (data.amazonLocationAddress?.label.isNullOrEmpty()) { - tvPlaceName.text = data.text - tvDescription.hide() - } else { - tvDescription.show() - } data.amazonLocationAddress?.label?.split(",")?.let { parts -> tvPlaceName.text = parts.getOrNull(0) ?: data.text tvDescription.text = parts.drop(1).joinToString(",").trim() + tvDescription.show() } } diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesSuggestionAdapter.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesSuggestionAdapter.kt index 4008a133..ae29a7ff 100644 --- a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesSuggestionAdapter.kt +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/SearchPlacesSuggestionAdapter.kt @@ -81,18 +81,14 @@ class SearchPlacesSuggestionAdapter( binding.apply { tvPlaceName.text = data.text binding.apply { - if (data.isPlaceIndexForPosition) { + if (data.isPlaceIndexForPosition || data.amazonLocationAddress?.label.isNullOrEmpty()) { tvPlaceName.text = data.text + tvDescription.hide() } else { - if (data.amazonLocationAddress?.label.isNullOrEmpty()) { - tvPlaceName.text = data.text - tvDescription.hide() - } else { - tvDescription.show() - } data.amazonLocationAddress?.label?.split(",")?.let { parts -> tvPlaceName.text = parts.getOrNull(0) ?: data.text tvDescription.text = parts.drop(1).joinToString(",").trim() + tvDescription.show() } }