diff --git a/app/src/androidTest/java/com/aws/amazonlocation/ui/main/SettingsFragmentDefaultRouteTest.kt b/app/src/androidTest/java/com/aws/amazonlocation/ui/main/SettingsFragmentDefaultRouteTest.kt index b27c86d3..384bdb62 100644 --- a/app/src/androidTest/java/com/aws/amazonlocation/ui/main/SettingsFragmentDefaultRouteTest.kt +++ b/app/src/androidTest/java/com/aws/amazonlocation/ui/main/SettingsFragmentDefaultRouteTest.kt @@ -27,7 +27,6 @@ import org.junit.* @UninstallModules(AppModule::class) @HiltAndroidTest class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() { - private val uiDevice = UiDevice.getInstance(getInstrumentation()) @Throws(java.lang.Exception::class) @@ -38,6 +37,9 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() { preferenceManager.setValue(IS_APP_FIRST_TIME_OPENED, true) preferenceManager.removeValue(KEY_AVOID_TOLLS) preferenceManager.removeValue(KEY_AVOID_FERRIES) + preferenceManager.removeValue(KEY_AVOID_DIRT_ROADS) + preferenceManager.removeValue(KEY_AVOID_U_TURN) + preferenceManager.removeValue(KEY_AVOID_TUNNEL) super.before() } @@ -52,8 +54,17 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() { toggleSwitch(R.id.switch_avoid_tools) toggleSwitch(R.id.switch_avoid_ferries) - - checkDefaultRouteOptions(avoidTollsShouldBe = true, avoidFerriesShouldBe = true) + toggleSwitch(R.id.switch_avoid_dirt_roads) + toggleSwitch(R.id.switch_avoid_u_turn) + toggleSwitch(R.id.switch_avoid_tunnels) + + checkDefaultRouteOptions( + avoidTollsShouldBe = true, + avoidFerriesShouldBe = true, + avoidDirtRoadShouldBe = true, + avoidUTurnShouldBe = true, + avoidTunnelsShouldBe = true, + ) } catch (_: Exception) { Assert.fail(TEST_FAILED) } @@ -71,16 +82,19 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() { uiDevice.findObject(By.text(mActivityRule.activity.getString(R.string.menu_setting))) explorer.click() - val routeOptions = waitForView( - allOf( - withId(R.id.cl_route_option), - isDisplayed(), - ), - ) + val routeOptions = + waitForView( + allOf( + withId(R.id.cl_route_option), + isDisplayed(), + ), + ) routeOptions?.perform(click()) } - private fun toggleSwitch(@IdRes switchId: Int) { + private fun toggleSwitch( + @IdRes switchId: Int, + ) { waitForView( allOf( withId(switchId), @@ -89,7 +103,13 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() { )?.perform(click()) } - private fun checkDefaultRouteOptions(avoidTollsShouldBe: Boolean, avoidFerriesShouldBe: Boolean) { + private fun checkDefaultRouteOptions( + avoidTollsShouldBe: Boolean, + avoidFerriesShouldBe: Boolean, + avoidDirtRoadShouldBe: Boolean, + avoidUTurnShouldBe: Boolean, + avoidTunnelsShouldBe: Boolean, + ) { val explorer = uiDevice.findObject(By.text(mActivityRule.activity.getString(R.string.menu_explore))) explorer.click() @@ -103,18 +123,20 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() { Thread.sleep(DELAY_2000) - val sourceEdt = waitForView(CoreMatchers.allOf(withId(R.id.edt_search_direction), isDisplayed())) + val sourceEdt = + waitForView(CoreMatchers.allOf(withId(R.id.edt_search_direction), isDisplayed())) sourceEdt?.perform(replaceText(SEARCH_TEST_WORD_1)) Thread.sleep(DELAY_2000) - val suggestionListSrcRv = waitForView( - CoreMatchers.allOf( - withId(R.id.rv_search_places_suggestion_direction), - isDisplayed(), - hasMinimumChildCount(1), - ), - ) + val suggestionListSrcRv = + waitForView( + CoreMatchers.allOf( + withId(R.id.rv_search_places_suggestion_direction), + isDisplayed(), + hasMinimumChildCount(1), + ), + ) suggestionListSrcRv?.perform( RecyclerViewActions.actionOnItemAtPosition( 0, @@ -124,24 +146,26 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() { Thread.sleep(DELAY_2000) - val destinationEdt = waitForView( - CoreMatchers.allOf( - withId(R.id.edt_search_dest), - isDisplayed(), - ), - ) + val destinationEdt = + waitForView( + CoreMatchers.allOf( + withId(R.id.edt_search_dest), + isDisplayed(), + ), + ) destinationEdt?.perform(click()) destinationEdt?.perform(typeText(SEARCH_TEST_WORD_2)) Thread.sleep(DELAY_2000) - val suggestionListDestRv = waitForView( - CoreMatchers.allOf( - withId(R.id.rv_search_places_suggestion_direction), - isDisplayed(), - hasMinimumChildCount(1), - ), - ) + val suggestionListDestRv = + waitForView( + CoreMatchers.allOf( + withId(R.id.rv_search_places_suggestion_direction), + isDisplayed(), + hasMinimumChildCount(1), + ), + ) suggestionListDestRv?.perform( RecyclerViewActions.actionOnItemAtPosition( 0, @@ -156,22 +180,36 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() { ), ) - val cardRoutingOption = waitForView( - CoreMatchers.allOf( - withId(R.id.card_routing_option), - withEffectiveVisibility(Visibility.VISIBLE), - ), - ) + val cardRoutingOption = + waitForView( + CoreMatchers.allOf( + withId(R.id.card_routing_option), + withEffectiveVisibility(Visibility.VISIBLE), + ), + ) cardRoutingOption?.perform(click()) Thread.sleep(DELAY_2000) getInstrumentation().waitForIdleSync() getInstrumentation().runOnMainSync { - val switchAvoidToll = mActivityRule.activity.findViewById(R.id.switch_avoid_tools) - val switchAvoidFerry = mActivityRule.activity.findViewById(R.id.switch_avoid_ferries) - - if (switchAvoidToll.isChecked != avoidTollsShouldBe || switchAvoidFerry.isChecked != avoidFerriesShouldBe) { + val switchAvoidToll = + mActivityRule.activity.findViewById(R.id.switch_avoid_tools) + val switchAvoidFerry = + mActivityRule.activity.findViewById(R.id.switch_avoid_ferries) + val switchAvoidDirtRoads = + mActivityRule.activity.findViewById(R.id.switch_avoid_dirt_roads) + val switchAvoidUTurn = + mActivityRule.activity.findViewById(R.id.switch_avoid_u_turn) + val switchAvoidTunnels = + mActivityRule.activity.findViewById(R.id.switch_avoid_tunnels) + + if (switchAvoidToll.isChecked != avoidTollsShouldBe || + switchAvoidFerry.isChecked != avoidFerriesShouldBe || + switchAvoidDirtRoads.isChecked != avoidDirtRoadShouldBe || + switchAvoidUTurn.isChecked != avoidUTurnShouldBe || + switchAvoidTunnels.isChecked != avoidTunnelsShouldBe + ) { Assert.fail(TEST_FAILED_DEFAULT_ROUTE_OPTIONS_NOT_LOADED) } } diff --git a/app/src/main/java/com/aws/amazonlocation/data/datasource/RemoteDataSource.kt b/app/src/main/java/com/aws/amazonlocation/data/datasource/RemoteDataSource.kt index 7e4df911..a32ced58 100644 --- a/app/src/main/java/com/aws/amazonlocation/data/datasource/RemoteDataSource.kt +++ b/app/src/main/java/com/aws/amazonlocation/data/datasource/RemoteDataSource.kt @@ -1,6 +1,7 @@ package com.aws.amazonlocation.data.datasource import aws.sdk.kotlin.services.location.model.ListGeofenceResponseEntry +import com.aws.amazonlocation.ui.main.explore.AvoidanceOption import com.aws.amazonlocation.domain.`interface`.BatchLocationUpdateInterface import com.aws.amazonlocation.domain.`interface`.DistanceInterface import com.aws.amazonlocation.domain.`interface`.GeofenceAPIInterface @@ -38,8 +39,7 @@ interface RemoteDataSource { lngDeparture: Double?, latDestination: Double?, lngDestination: Double?, - isAvoidFerries: Boolean?, - isAvoidTolls: Boolean?, + avoidanceOptions: ArrayList, travelMode: String?, distanceInterface: DistanceInterface ) diff --git a/app/src/main/java/com/aws/amazonlocation/data/datasource/RemoteDataSourceImpl.kt b/app/src/main/java/com/aws/amazonlocation/data/datasource/RemoteDataSourceImpl.kt index b1b590e5..0b3c1024 100644 --- a/app/src/main/java/com/aws/amazonlocation/data/datasource/RemoteDataSourceImpl.kt +++ b/app/src/main/java/com/aws/amazonlocation/data/datasource/RemoteDataSourceImpl.kt @@ -4,6 +4,7 @@ import android.content.Context import aws.sdk.kotlin.services.location.model.ListGeofenceResponseEntry import com.aws.amazonlocation.R import com.aws.amazonlocation.data.common.DataSourceException +import com.aws.amazonlocation.ui.main.explore.AvoidanceOption import com.aws.amazonlocation.domain.`interface`.BatchLocationUpdateInterface import com.aws.amazonlocation.domain.`interface`.DistanceInterface import com.aws.amazonlocation.domain.`interface`.GeofenceAPIInterface @@ -107,8 +108,7 @@ class RemoteDataSourceImpl( lngDeparture: Double?, latDestination: Double?, lngDestination: Double?, - isAvoidFerries: Boolean?, - isAvoidTolls: Boolean?, + avoidanceOptions: ArrayList, travelMode: String?, distanceInterface: DistanceInterface, ) { @@ -117,8 +117,7 @@ class RemoteDataSourceImpl( lngDeparture, latDestination, lngDestination, - isAvoidFerries, - isAvoidTolls, + avoidanceOptions, travelMode, mLocationProvider.getBaseActivity(), mLocationProvider.getGeoRoutesClient() diff --git a/app/src/main/java/com/aws/amazonlocation/data/repository/LocationSearchImp.kt b/app/src/main/java/com/aws/amazonlocation/data/repository/LocationSearchImp.kt index e1a93fe7..f269f55e 100644 --- a/app/src/main/java/com/aws/amazonlocation/data/repository/LocationSearchImp.kt +++ b/app/src/main/java/com/aws/amazonlocation/data/repository/LocationSearchImp.kt @@ -1,13 +1,12 @@ package com.aws.amazonlocation.data.repository -import aws.sdk.kotlin.services.geoplaces.GeoPlacesClient import com.aws.amazonlocation.data.datasource.RemoteDataSourceImpl +import com.aws.amazonlocation.ui.main.explore.AvoidanceOption import com.aws.amazonlocation.domain.`interface`.DistanceInterface import com.aws.amazonlocation.domain.`interface`.PlaceInterface import com.aws.amazonlocation.domain.`interface`.SearchDataInterface import com.aws.amazonlocation.domain.`interface`.SearchPlaceInterface import com.aws.amazonlocation.domain.repository.LocationSearchRepository -import com.aws.amazonlocation.ui.base.BaseActivity // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -39,8 +38,7 @@ class LocationSearchImp(private val mRemoteDataSource: RemoteDataSourceImpl) : lngDeparture: Double?, latDestination: Double?, lngDestination: Double?, - isAvoidFerries: Boolean?, - isAvoidTolls: Boolean?, + avoidanceOptions: ArrayList, travelMode: String?, distanceInterface: DistanceInterface ) { @@ -49,8 +47,7 @@ class LocationSearchImp(private val mRemoteDataSource: RemoteDataSourceImpl) : lngDeparture, latDestination, lngDestination, - isAvoidFerries, - isAvoidTolls, + avoidanceOptions, travelMode, distanceInterface ) diff --git a/app/src/main/java/com/aws/amazonlocation/domain/repository/LocationSearchRepository.kt b/app/src/main/java/com/aws/amazonlocation/domain/repository/LocationSearchRepository.kt index 60860d55..fbdb74e7 100644 --- a/app/src/main/java/com/aws/amazonlocation/domain/repository/LocationSearchRepository.kt +++ b/app/src/main/java/com/aws/amazonlocation/domain/repository/LocationSearchRepository.kt @@ -1,9 +1,7 @@ package com.aws.amazonlocation.domain.repository -import aws.sdk.kotlin.services.georoutes.model.CalculateRoutesResponse -import aws.sdk.kotlin.services.location.model.Step +import com.aws.amazonlocation.ui.main.explore.AvoidanceOption import com.aws.amazonlocation.domain.`interface`.DistanceInterface -import com.aws.amazonlocation.domain.`interface`.NavigationDataInterface import com.aws.amazonlocation.domain.`interface`.PlaceInterface import com.aws.amazonlocation.domain.`interface`.SearchDataInterface import com.aws.amazonlocation.domain.`interface`.SearchPlaceInterface @@ -33,8 +31,7 @@ interface LocationSearchRepository { lngDeparture: Double?, latDestination: Double?, lngDestination: Double?, - isAvoidFerries: Boolean?, - isAvoidTolls: Boolean?, + avoidanceOptions: ArrayList, travelMode: String?, distanceInterface: DistanceInterface ) diff --git a/app/src/main/java/com/aws/amazonlocation/domain/usecase/LocationSearchUseCase.kt b/app/src/main/java/com/aws/amazonlocation/domain/usecase/LocationSearchUseCase.kt index c71c6ae4..bbe45e16 100644 --- a/app/src/main/java/com/aws/amazonlocation/domain/usecase/LocationSearchUseCase.kt +++ b/app/src/main/java/com/aws/amazonlocation/domain/usecase/LocationSearchUseCase.kt @@ -1,9 +1,7 @@ package com.aws.amazonlocation.domain.usecase -import aws.sdk.kotlin.services.georoutes.model.CalculateRoutesResponse -import aws.sdk.kotlin.services.location.model.Step +import com.aws.amazonlocation.ui.main.explore.AvoidanceOption import com.aws.amazonlocation.domain.`interface`.DistanceInterface -import com.aws.amazonlocation.domain.`interface`.NavigationDataInterface import com.aws.amazonlocation.domain.`interface`.PlaceInterface import com.aws.amazonlocation.domain.`interface`.SearchDataInterface import com.aws.amazonlocation.domain.`interface`.SearchPlaceInterface @@ -36,8 +34,7 @@ class LocationSearchUseCase @Inject constructor(private val mLocationSearchRepos lngDeparture: Double?, latDestination: Double?, lngDestination: Double?, - isAvoidFerries: Boolean?, - isAvoidTolls: Boolean?, + avoidanceOptions: ArrayList, travelMode: String?, distanceInterface: DistanceInterface ) = mLocationSearchRepository.calculateDistance( @@ -45,8 +42,7 @@ class LocationSearchUseCase @Inject constructor(private val mLocationSearchRepos lngDeparture, latDestination, lngDestination, - isAvoidFerries, - isAvoidTolls, + avoidanceOptions, travelMode, distanceInterface ) diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/MainActivity.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/MainActivity.kt index 16698f51..02487303 100644 --- a/app/src/main/java/com/aws/amazonlocation/ui/main/MainActivity.kt +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/MainActivity.kt @@ -60,8 +60,11 @@ import com.aws.amazonlocation.utils.KEY_ACCESS_KEY import com.aws.amazonlocation.utils.KEY_ACCESS_TOKEN import com.aws.amazonlocation.utils.KEY_AUTH_EXPIRES_IN import com.aws.amazonlocation.utils.KEY_AUTH_FETCH_TIME +import com.aws.amazonlocation.utils.KEY_AVOID_DIRT_ROADS import com.aws.amazonlocation.utils.KEY_AVOID_FERRIES import com.aws.amazonlocation.utils.KEY_AVOID_TOLLS +import com.aws.amazonlocation.utils.KEY_AVOID_TUNNEL +import com.aws.amazonlocation.utils.KEY_AVOID_U_TURN import com.aws.amazonlocation.utils.KEY_CLOUD_FORMATION_STATUS import com.aws.amazonlocation.utils.KEY_CODE import com.aws.amazonlocation.utils.KEY_EXPIRATION @@ -282,6 +285,9 @@ class MainActivity : if (!isAppNotFirstOpened) { mPreferenceManager.setValue(KEY_AVOID_TOLLS, true) mPreferenceManager.setValue(KEY_AVOID_FERRIES, true) + mPreferenceManager.setValue(KEY_AVOID_TUNNEL, true) + mPreferenceManager.setValue(KEY_AVOID_DIRT_ROADS, true) + mPreferenceManager.setValue(KEY_AVOID_U_TURN, true) } val inflater = mNavHostFragment.navController.navInflater val graph = inflater.inflate(R.navigation.nav_graph) diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/AvoidanceOption.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/AvoidanceOption.kt new file mode 100644 index 00000000..598e759d --- /dev/null +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/AvoidanceOption.kt @@ -0,0 +1,5 @@ +package com.aws.amazonlocation.ui.main.explore + +enum class AvoidanceOption { + FERRIES, TOLL_ROADS, DIRT_ROADS, TUNNELS, U_TURNS +} \ No newline at end of file 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 32b30d2b..085936ae 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 @@ -32,6 +32,7 @@ import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.core.view.isVisible +import androidx.core.view.updateLayoutParams import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope import androidx.lifecycle.withStarted @@ -90,7 +91,10 @@ import com.aws.amazonlocation.utils.EventType.ROUTE_OPTION_CHANGED import com.aws.amazonlocation.utils.EventType.ROUTE_SEARCH import com.aws.amazonlocation.utils.IS_LOCATION_TRACKING_ENABLE import com.aws.amazonlocation.utils.KEY_AVOID_FERRIES +import com.aws.amazonlocation.utils.KEY_AVOID_DIRT_ROADS import com.aws.amazonlocation.utils.KEY_AVOID_TOLLS +import com.aws.amazonlocation.utils.KEY_AVOID_TUNNEL +import com.aws.amazonlocation.utils.KEY_AVOID_U_TURN import com.aws.amazonlocation.utils.KEY_CLOUD_FORMATION_STATUS import com.aws.amazonlocation.utils.KEY_COLOR_SCHEMES import com.aws.amazonlocation.utils.KEY_MAP_STYLE_NAME @@ -118,6 +122,7 @@ import com.aws.amazonlocation.utils.Units.isMetric import com.aws.amazonlocation.utils.attributionPattern import com.aws.amazonlocation.utils.checkLocationPermission import com.aws.amazonlocation.utils.copyTextToClipboard +import com.aws.amazonlocation.utils.getKeyboardHeight import com.aws.amazonlocation.utils.getLanguageCode import com.aws.amazonlocation.utils.getRegion import com.aws.amazonlocation.utils.getUserName @@ -214,6 +219,9 @@ class ExploreFragment : private val mSimulationViewModel: SimulationViewModel by viewModels() private var mIsAvoidTolls: Boolean = false private var mIsAvoidFerries: Boolean = false + private var mIsAvoidDirtRoads: Boolean = false + private var mIsAvoidUTurn: Boolean = false + private var mIsAvoidTunnel: Boolean = false private var mIsRouteOptionsOpened = false private var mTravelMode: String = RouteTravelMode.Car.value private var mRouteFinish: Boolean = false @@ -292,6 +300,10 @@ class ExploreFragment : mBaseActivity?.mGeofenceUtils?.let { if (mBottomSheetHelper.isDirectionSearchSheetVisible()) { mBottomSheetHelper.expandDirectionSearchSheet(this@ExploreFragment) + getKeyboardHeight(requireActivity()) { keyboardHeight -> + mBinding.bottomSheetDirectionSearch.viewKeyboardScroll.updateLayoutParams { height = keyboardHeight } + mBinding.bottomSheetDirectionSearch.viewKeyboardScroll.show() + } } else if (it.geofenceBottomSheetVisibility()) { mBaseActivity?.mGeofenceUtils?.expandAddGeofenceBottomSheet() } else if (mapStyleBottomSheetFragment?.isMapStyleExpandedOrHalfExpand() == true) { @@ -314,6 +326,9 @@ class ExploreFragment : } else if (mBottomSheetHelper.isDirectionSearchSheetVisible()) { mBinding.apply { bottomSheetDirectionSearch.apply { + if (!cardListRoutesOption.isVisible) { + viewKeyboardScroll.hide() + } edtSearchDest.clearFocus() edtSearchDirection.clearFocus() } @@ -352,8 +367,14 @@ class ExploreFragment : ) mIsAvoidTolls = mPreferenceManager.getValue(KEY_AVOID_TOLLS, false) mIsAvoidFerries = mPreferenceManager.getValue(KEY_AVOID_FERRIES, false) + mIsAvoidDirtRoads = mPreferenceManager.getValue(KEY_AVOID_DIRT_ROADS, false) + mIsAvoidUTurn = mPreferenceManager.getValue(KEY_AVOID_U_TURN, false) + mIsAvoidTunnel = mPreferenceManager.getValue(KEY_AVOID_TUNNEL, false) mBinding.bottomSheetDirectionSearch.switchAvoidTools.isChecked = mIsAvoidTolls mBinding.bottomSheetDirectionSearch.switchAvoidFerries.isChecked = mIsAvoidFerries + mBinding.bottomSheetDirectionSearch.switchAvoidDirtRoads.isChecked = mIsAvoidDirtRoads + mBinding.bottomSheetDirectionSearch.switchAvoidUTurn.isChecked = mIsAvoidUTurn + mBinding.bottomSheetDirectionSearch.switchAvoidTunnels.isChecked = mIsAvoidTunnel mBottomSheetHelper.setNavigationBottomSheet(mBinding.bottomSheetNavigation) mBottomSheetHelper.setNavigationCompleteBottomSheet( @@ -947,8 +968,13 @@ class ExploreFragment : latLng.longitude, mViewModel.mDestinationLatLng?.latitude, mViewModel.mDestinationLatLng?.longitude, - mIsAvoidFerries, - mIsAvoidTolls, + arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, mTravelMode, ) val isMetric = isMetric(mPreferenceManager.getValue(KEY_UNIT_SYSTEM, "")) @@ -957,7 +983,10 @@ class ExploreFragment : Pair(AnalyticsAttribute.DISTANCE_UNIT, if (isMetric) KILOMETERS else MILES), Pair(AnalyticsAttribute.TRIGGERED_BY, AnalyticsAttributeValue.ROUTE_MODULE), Pair(AnalyticsAttribute.AVOID_FERRIES, mIsAvoidFerries.toString()), - Pair(AnalyticsAttribute.AVOID_TOLLS, mIsAvoidTolls.toString()) + Pair(AnalyticsAttribute.AVOID_TOLLS, mIsAvoidTolls.toString()), + Pair(AnalyticsAttribute.AVOID_DIRT_ROADS, mIsAvoidDirtRoads.toString()), + Pair(AnalyticsAttribute.AVOID_U_TURN, mIsAvoidUTurn.toString()), + Pair(AnalyticsAttribute.AVOID_TUNNEL, mIsAvoidTunnel.toString()) ) (activity as MainActivity).analyticsUtils?.recordEvent( ROUTE_SEARCH, properties) @@ -2200,7 +2229,7 @@ class ExploreFragment : mBinding.bottomSheetDirectionSearch.apply { if (mPlaceList.isNotEmpty()) { clNoInternetConnectionDirectionSearch.hide() - nsDirectionSearchPlaces.show() + clMyLocationParent.show() layoutNoDataFound.root.hide() layoutCardError.groupCardErrorNoSearchFound.hide() when (searchPlaceIndexText) { @@ -2215,7 +2244,7 @@ class ExploreFragment : } } } else { - hideViews(rvSearchPlacesDirection, nsDirectionSearchPlaces) + hideViews(rvSearchPlacesDirection, clMyLocationParent) layoutNoDataFound.root.show() } } @@ -2490,9 +2519,13 @@ class ExploreFragment : return@setOnClickListener } mTravelMode = RouteTravelMode.Scooter.value + if (mIsRouteOptionsOpened) { + mIsRouteOptionsOpened = false + changeRouteListUI() + } + cardRoutingOption.hide() mViewModel.mScooterData?.let { tvScooterSelected.show() - showViews(cardRoutingOption) hideViews( tvDriveSelected, tvWalkSelected, @@ -2685,6 +2718,69 @@ class ExploreFragment : } } } + + switchAvoidDirtRoads.setOnCheckedChangeListener { _, isChecked -> + if (checkInternetConnection()) { + mMapHelper.removeMarkerAndLine() + clearDirectionData() + mIsAvoidDirtRoads = isChecked + if (edtSearchDirection.text.toString() == resources.getString(R.string.label_my_location)) { + mViewModel.mSearchDirectionDestinationData?.let { + showCurrentLocationDestinationRoute(it) + } + } else if (edtSearchDest.text.toString() == resources.getString(R.string.label_my_location)) { + mViewModel.mSearchDirectionOriginData?.let { + showCurrentLocationOriginRoute(it) + } + } else if (!edtSearchDirection.text.isNullOrEmpty() && + !edtSearchDest.text.isNullOrEmpty() + ) { + showOriginToDestinationRoute() + } + } + } + + switchAvoidUTurn.setOnCheckedChangeListener { _, isChecked -> + if (checkInternetConnection()) { + mMapHelper.removeMarkerAndLine() + clearDirectionData() + mIsAvoidUTurn = isChecked + if (edtSearchDirection.text.toString() == resources.getString(R.string.label_my_location)) { + mViewModel.mSearchDirectionDestinationData?.let { + showCurrentLocationDestinationRoute(it) + } + } else if (edtSearchDest.text.toString() == resources.getString(R.string.label_my_location)) { + mViewModel.mSearchDirectionOriginData?.let { + showCurrentLocationOriginRoute(it) + } + } else if (!edtSearchDirection.text.isNullOrEmpty() && + !edtSearchDest.text.isNullOrEmpty() + ) { + showOriginToDestinationRoute() + } + } + } + + switchAvoidTunnels.setOnCheckedChangeListener { _, isChecked -> + if (checkInternetConnection()) { + mMapHelper.removeMarkerAndLine() + clearDirectionData() + mIsAvoidTunnel = isChecked + if (edtSearchDirection.text.toString() == resources.getString(R.string.label_my_location)) { + mViewModel.mSearchDirectionDestinationData?.let { + showCurrentLocationDestinationRoute(it) + } + } else if (edtSearchDest.text.toString() == resources.getString(R.string.label_my_location)) { + mViewModel.mSearchDirectionOriginData?.let { + showCurrentLocationOriginRoute(it) + } + } else if (!edtSearchDirection.text.isNullOrEmpty() && + !edtSearchDest.text.isNullOrEmpty() + ) { + showOriginToDestinationRoute() + } + } + } edtSearchDest.setOnFocusChangeListener { _, hasFocus -> if (hasFocus) { isDataSearchForDestination = true @@ -3072,10 +3168,16 @@ class ExploreFragment : private fun openDirectionWithError() { mIsAvoidTolls = mPreferenceManager.getValue(KEY_AVOID_TOLLS, false) mIsAvoidFerries = mPreferenceManager.getValue(KEY_AVOID_FERRIES, false) + mIsAvoidDirtRoads = mPreferenceManager.getValue(KEY_AVOID_DIRT_ROADS, false) + mIsAvoidUTurn = mPreferenceManager.getValue(KEY_AVOID_U_TURN, false) + mIsAvoidTunnel = mPreferenceManager.getValue(KEY_AVOID_TUNNEL, false) mBinding.bottomSheetDirectionSearch.apply { clearDirectionData() switchAvoidTools.isChecked = mIsAvoidTolls switchAvoidFerries.isChecked = mIsAvoidFerries + switchAvoidDirtRoads.isChecked = mIsAvoidDirtRoads + switchAvoidUTurn.isChecked = mIsAvoidUTurn + switchAvoidTunnels.isChecked = mIsAvoidTunnel tvDriveGo.text = getString(R.string.btn_go) mIsDirectionDataSet = true if (mViewModel.mCarData?.routes?.get(0)?.legs == null) { @@ -3205,6 +3307,9 @@ class ExploreFragment : notifyAdapters() mIsAvoidTolls = mPreferenceManager.getValue(KEY_AVOID_TOLLS, false) mIsAvoidFerries = mPreferenceManager.getValue(KEY_AVOID_FERRIES, false) + mIsAvoidDirtRoads = mPreferenceManager.getValue(KEY_AVOID_DIRT_ROADS, false) + mIsAvoidUTurn = mPreferenceManager.getValue(KEY_AVOID_U_TURN, false) + mIsAvoidTunnel = mPreferenceManager.getValue(KEY_AVOID_TUNNEL, false) cardDirection.hide() bottomSheetDirectionSearch.clSearchLoaderDirectionSearch.root.hide() bottomSheetDirectionSearch.layoutNoDataFound.root.hide() @@ -3237,6 +3342,9 @@ class ExploreFragment : } switchAvoidTools.isChecked = mIsAvoidTolls switchAvoidFerries.isChecked = mIsAvoidFerries + switchAvoidDirtRoads.isChecked = mIsAvoidDirtRoads + switchAvoidUTurn.isChecked = mIsAvoidUTurn + switchAvoidTunnels.isChecked = mIsAvoidTunnel mPlaceList.clear() mAdapterDirection?.notifyDataSetChanged() mSearchPlacesDirectionSuggestionAdapter?.notifyDataSetChanged() @@ -3253,6 +3361,9 @@ class ExploreFragment : private fun routeOption() { mIsAvoidTolls = mPreferenceManager.getValue(KEY_AVOID_TOLLS, false) mIsAvoidFerries = mPreferenceManager.getValue(KEY_AVOID_FERRIES, false) + mIsAvoidDirtRoads = mPreferenceManager.getValue(KEY_AVOID_DIRT_ROADS, false) + mIsAvoidUTurn = mPreferenceManager.getValue(KEY_AVOID_U_TURN, false) + mIsAvoidTunnel = mPreferenceManager.getValue(KEY_AVOID_TUNNEL, false) if (mViewModel.mCarData?.routes?.get(0)?.legs != null) { mIsDirectionDataSetNew = true mViewModel.mCarData?.routes?.get(0)?.legs?.let { legs -> @@ -3268,6 +3379,9 @@ class ExploreFragment : tvDriveGo.text = getString(R.string.btn_go) switchAvoidTools.isChecked = mIsAvoidTolls switchAvoidFerries.isChecked = mIsAvoidFerries + switchAvoidDirtRoads.isChecked = mIsAvoidDirtRoads + switchAvoidUTurn.isChecked = mIsAvoidUTurn + switchAvoidTunnels.isChecked = mIsAvoidTunnel edtSearchDirection.setText(getString(R.string.label_my_location)) showViews( cardRoutingOption, @@ -3308,8 +3422,13 @@ class ExploreFragment : position?.get(1), lngDestination = position?.get(0), - isAvoidFerries = mIsAvoidFerries, - isAvoidTolls = mIsAvoidTolls, + avoidanceOptions = arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, isWalkingAndTruckCall = true, ) recordEventForAllMode(isWalkingAndTruckCall = false) @@ -3330,21 +3449,30 @@ class ExploreFragment : Pair(AnalyticsAttribute.DISTANCE_UNIT, if (isMetric) KILOMETERS else MILES), Pair(AnalyticsAttribute.TRIGGERED_BY, AnalyticsAttributeValue.ROUTE_MODULE), Pair(AnalyticsAttribute.AVOID_FERRIES, mIsAvoidFerries.toString()), - Pair(AnalyticsAttribute.AVOID_TOLLS, mIsAvoidTolls.toString()) + Pair(AnalyticsAttribute.AVOID_TOLLS, mIsAvoidTolls.toString()), + Pair(AnalyticsAttribute.AVOID_DIRT_ROADS, mIsAvoidDirtRoads.toString()), + Pair(AnalyticsAttribute.AVOID_U_TURN, mIsAvoidUTurn.toString()), + Pair(AnalyticsAttribute.AVOID_TUNNEL, mIsAvoidTunnel.toString()) ) val propertiesTruck = listOf( Pair(AnalyticsAttribute.TRAVEL_MODE, RouteTravelMode.Truck.value), Pair(AnalyticsAttribute.DISTANCE_UNIT, if (isMetric) KILOMETERS else MILES), Pair(AnalyticsAttribute.TRIGGERED_BY, AnalyticsAttributeValue.ROUTE_MODULE), Pair(AnalyticsAttribute.AVOID_FERRIES, mIsAvoidFerries.toString()), - Pair(AnalyticsAttribute.AVOID_TOLLS, mIsAvoidTolls.toString()) + Pair(AnalyticsAttribute.AVOID_TOLLS, mIsAvoidTolls.toString()), + Pair(AnalyticsAttribute.AVOID_DIRT_ROADS, mIsAvoidDirtRoads.toString()), + Pair(AnalyticsAttribute.AVOID_U_TURN, mIsAvoidUTurn.toString()), + Pair(AnalyticsAttribute.AVOID_TUNNEL, mIsAvoidTunnel.toString()) ) val propertiesWalk = listOf( Pair(AnalyticsAttribute.TRAVEL_MODE, RouteTravelMode.Pedestrian.value), Pair(AnalyticsAttribute.DISTANCE_UNIT, if (isMetric) KILOMETERS else MILES), Pair(AnalyticsAttribute.TRIGGERED_BY, AnalyticsAttributeValue.ROUTE_MODULE), Pair(AnalyticsAttribute.AVOID_FERRIES, mIsAvoidFerries.toString()), - Pair(AnalyticsAttribute.AVOID_TOLLS, mIsAvoidTolls.toString()) + Pair(AnalyticsAttribute.AVOID_TOLLS, mIsAvoidTolls.toString()), + Pair(AnalyticsAttribute.AVOID_DIRT_ROADS, mIsAvoidDirtRoads.toString()), + Pair(AnalyticsAttribute.AVOID_U_TURN, mIsAvoidUTurn.toString()), + Pair(AnalyticsAttribute.AVOID_TUNNEL, mIsAvoidTunnel.toString()) ) if (isWalkingAndTruckCall) { (activity as MainActivity).analyticsUtils?.recordEvent(ROUTE_SEARCH, propertiesTruck) @@ -4247,8 +4375,13 @@ class ExploreFragment : positionDestination?.get(1), lngDestination = positionDestination?.get(0), - isAvoidFerries = mIsAvoidFerries, - isAvoidTolls = mIsAvoidTolls, + avoidanceOptions = arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, isWalkingAndTruckCall = false, ) mViewModel.calculateDistance( @@ -4260,8 +4393,13 @@ class ExploreFragment : positionDestination?.get(1), lngDestination = positionDestination?.get(0), - isAvoidFerries = mIsAvoidFerries, - isAvoidTolls = mIsAvoidTolls, + avoidanceOptions = arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, isWalkingAndTruckCall = true, ) recordEventForAllMode(isWalkingAndTruckCall = true) @@ -4318,8 +4456,13 @@ class ExploreFragment : longitude = liveLocationLatLng?.longitude, latDestination = it.position?.get(1), lngDestination = it.position?.get(0), - isAvoidFerries = mIsAvoidFerries, - isAvoidTolls = mIsAvoidTolls, + avoidanceOptions = arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, isWalkingAndTruckCall = false, ) mViewModel.calculateDistance( @@ -4327,8 +4470,13 @@ class ExploreFragment : longitude = liveLocationLatLng?.longitude, latDestination = it.position?.get(1), lngDestination = it.position?.get(0), - isAvoidFerries = mIsAvoidFerries, - isAvoidTolls = mIsAvoidTolls, + avoidanceOptions = arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, isWalkingAndTruckCall = true, ) recordEventForAllMode(isWalkingAndTruckCall = true) @@ -4356,8 +4504,13 @@ class ExploreFragment : longitude = it.position?.get(0), latDestination = liveLocationLatLng?.latitude, lngDestination = liveLocationLatLng?.longitude, - isAvoidFerries = mIsAvoidFerries, - isAvoidTolls = mIsAvoidTolls, + avoidanceOptions = arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, isWalkingAndTruckCall = false, ) mViewModel.calculateDistance( @@ -4365,8 +4518,13 @@ class ExploreFragment : longitude = it.position?.get(0), latDestination = liveLocationLatLng?.latitude, lngDestination = liveLocationLatLng?.longitude, - isAvoidFerries = mIsAvoidFerries, - isAvoidTolls = mIsAvoidTolls, + avoidanceOptions = arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, isWalkingAndTruckCall = true, ) recordEventForAllMode(isWalkingAndTruckCall = true) @@ -4546,8 +4704,13 @@ class ExploreFragment : longitude = liveLocationLatLng?.longitude, latDestination = data.position?.get(1), lngDestination = data.position?.get(0), - isAvoidFerries = mIsAvoidFerries, - isAvoidTolls = mIsAvoidTolls, + avoidanceOptions = arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, isWalkingAndTruckCall = false, ) recordEventForAllMode(isWalkingAndTruckCall = false) @@ -4900,8 +5063,13 @@ class ExploreFragment : longitude = liveLocationLatLng?.longitude, latDestination = it?.position?.get(1), lngDestination = it?.position?.get(0), - isAvoidFerries = mIsAvoidFerries, - isAvoidTolls = mIsAvoidTolls, + avoidanceOptions = arrayListOf().apply { + if (mIsAvoidFerries) add(AvoidanceOption.FERRIES) + if (mIsAvoidTolls) add(AvoidanceOption.TOLL_ROADS) + if (mIsAvoidDirtRoads) add(AvoidanceOption.DIRT_ROADS) + if (mIsAvoidUTurn) add(AvoidanceOption.U_TURNS) + if (mIsAvoidTunnel) add(AvoidanceOption.TUNNELS) + }, isWalkingAndTruckCall = false, ) recordEventForAllMode(isWalkingAndTruckCall = false) diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/ExploreViewModel.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/ExploreViewModel.kt index 183f71c9..83a40824 100644 --- a/app/src/main/java/com/aws/amazonlocation/ui/main/explore/ExploreViewModel.kt +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/explore/ExploreViewModel.kt @@ -186,8 +186,7 @@ class ExploreViewModel longitude: Double?, latDestination: Double?, lngDestination: Double?, - isAvoidFerries: Boolean?, - isAvoidTolls: Boolean?, + avoidanceOptions: ArrayList, isWalkingAndTruckCall: Boolean, ) { viewModelScope.launch(Dispatchers.IO) { @@ -197,8 +196,7 @@ class ExploreViewModel longitude, latDestination, lngDestination, - isAvoidFerries, - isAvoidTolls, + avoidanceOptions, RouteTravelMode.Pedestrian.value, ) calculateDistanceFromMode( @@ -206,8 +204,7 @@ class ExploreViewModel longitude, latDestination, lngDestination, - isAvoidFerries, - isAvoidTolls, + avoidanceOptions, RouteTravelMode.Truck.value, ) calculateDistanceFromMode( @@ -215,8 +212,7 @@ class ExploreViewModel longitude, latDestination, lngDestination, - isAvoidFerries, - isAvoidTolls, + avoidanceOptions, RouteTravelMode.Scooter.value, ) } else { @@ -225,8 +221,7 @@ class ExploreViewModel longitude, latDestination, lngDestination, - isAvoidFerries, - isAvoidTolls, + avoidanceOptions, RouteTravelMode.Car.value, ) } @@ -238,8 +233,7 @@ class ExploreViewModel longitude: Double?, latDestination: Double?, lngDestination: Double?, - isAvoidFerries: Boolean?, - isAvoidTolls: Boolean?, + avoidanceOptions: ArrayList, travelMode: String?, ) { _calculateDistance.trySend(HandleResult.Loading) @@ -250,8 +244,7 @@ class ExploreViewModel longitude, latDestination, lngDestination, - isAvoidFerries, - isAvoidTolls, + avoidanceOptions, travelMode, object : DistanceInterface { override fun distanceSuccess(success: CalculateRoutesResponse) { @@ -302,8 +295,7 @@ class ExploreViewModel longitude: Double?, latDestination: Double?, lngDestination: Double?, - isAvoidFerries: Boolean?, - isAvoidTolls: Boolean?, + avoidanceOptions: ArrayList, travelMode: String?, ) { _updateCalculateDistance.trySend(HandleResult.Loading) @@ -313,8 +305,7 @@ class ExploreViewModel longitude, latDestination, lngDestination, - isAvoidFerries, - isAvoidTolls, + avoidanceOptions, travelMode, object : DistanceInterface { override fun distanceSuccess(success: CalculateRoutesResponse) { diff --git a/app/src/main/java/com/aws/amazonlocation/ui/main/route_option/RouteOptionFragment.kt b/app/src/main/java/com/aws/amazonlocation/ui/main/route_option/RouteOptionFragment.kt index 80bc9c17..8753b43e 100644 --- a/app/src/main/java/com/aws/amazonlocation/ui/main/route_option/RouteOptionFragment.kt +++ b/app/src/main/java/com/aws/amazonlocation/ui/main/route_option/RouteOptionFragment.kt @@ -8,8 +8,11 @@ import androidx.activity.addCallback import androidx.navigation.fragment.findNavController import com.aws.amazonlocation.databinding.FragmentRouteOptionBinding import com.aws.amazonlocation.ui.base.BaseFragment +import com.aws.amazonlocation.utils.KEY_AVOID_DIRT_ROADS import com.aws.amazonlocation.utils.KEY_AVOID_FERRIES import com.aws.amazonlocation.utils.KEY_AVOID_TOLLS +import com.aws.amazonlocation.utils.KEY_AVOID_TUNNEL +import com.aws.amazonlocation.utils.KEY_AVOID_U_TURN class RouteOptionFragment : BaseFragment() { @@ -32,8 +35,10 @@ class RouteOptionFragment : BaseFragment() { private fun clickListener() { mBinding.apply { switchAvoidTools.isChecked = mPreferenceManager.getValue(KEY_AVOID_TOLLS, false) - switchAvoidFerries.isChecked = - mPreferenceManager.getValue(KEY_AVOID_FERRIES, false) + switchAvoidFerries.isChecked = mPreferenceManager.getValue(KEY_AVOID_FERRIES, false) + switchAvoidDirtRoads.isChecked = mPreferenceManager.getValue(KEY_AVOID_DIRT_ROADS, false) + switchAvoidUTurn.isChecked = mPreferenceManager.getValue(KEY_AVOID_U_TURN, false) + switchAvoidTunnels.isChecked = mPreferenceManager.getValue(KEY_AVOID_TUNNEL, false) ivRouteOptionBack.setOnClickListener { findNavController().popBackStack() @@ -46,6 +51,18 @@ class RouteOptionFragment : BaseFragment() { switchAvoidFerries.setOnCheckedChangeListener { _, isChecked -> mPreferenceManager.setValue(KEY_AVOID_FERRIES, isChecked) } + + switchAvoidDirtRoads.setOnCheckedChangeListener { _, isChecked -> + mPreferenceManager.setValue(KEY_AVOID_DIRT_ROADS, isChecked) + } + + switchAvoidUTurn.setOnCheckedChangeListener { _, isChecked -> + mPreferenceManager.setValue(KEY_AVOID_U_TURN, isChecked) + } + + switchAvoidTunnels.setOnCheckedChangeListener { _, isChecked -> + mPreferenceManager.setValue(KEY_AVOID_TUNNEL, isChecked) + } } } 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 9ea35b22..6c5b1e53 100644 --- a/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt +++ b/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt @@ -64,8 +64,11 @@ const val DELAY_LANGUAGE_3000 = 3000L const val CLICK_TIME_DIFFERENCE = 1500 const val TIME_OUT = 20000L const val MQTT_CONNECT_TIME_OUT = 1000L -const val KEY_AVOID_TOLLS = "Avoid Tolls" -const val KEY_AVOID_FERRIES = "Avoid Ferries" +const val KEY_AVOID_TOLLS = "key_avoid_tolls" +const val KEY_AVOID_FERRIES = "key_avoid_ferries" +const val KEY_AVOID_DIRT_ROADS = "key_avoid_dirt_roads" +const val KEY_AVOID_U_TURN = "key_avoid_u_turn" +const val KEY_AVOID_TUNNEL = "key_avoid_tunnel" const val AWS_CLOUD_INFORMATION_FRAGMENT = "AwsCloudInformationFragment" const val SETTING_FRAGMENT = "SettingFragment" const val ABOUT_FRAGMENT = "AboutFragment" @@ -332,6 +335,9 @@ object AnalyticsAttribute { const val ACTION = "action" const val AVOID_FERRIES = "AvoidFerries" const val AVOID_TOLLS = "AvoidTolls" + const val AVOID_DIRT_ROADS = "AvoidDirtRoads" + const val AVOID_U_TURN = "AvoidUTurn" + const val AVOID_TUNNEL = "AvoidTunnel" const val GEOFENCE_ID = "geofenceId" const val EVENT_TYPE = "eventType" const val ERROR = "error" diff --git a/app/src/main/java/com/aws/amazonlocation/utils/ViewUtils.kt b/app/src/main/java/com/aws/amazonlocation/utils/ViewUtils.kt index 68eb9715..cd9dd537 100644 --- a/app/src/main/java/com/aws/amazonlocation/utils/ViewUtils.kt +++ b/app/src/main/java/com/aws/amazonlocation/utils/ViewUtils.kt @@ -1,7 +1,10 @@ package com.aws.amazonlocation.utils +import android.app.Activity import android.content.res.Resources +import android.graphics.Rect import android.view.View +import android.view.ViewTreeObserver // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -33,3 +36,28 @@ fun hideViews(vararg view: View?) { val Int.px: Int get() = (this * Resources.getSystem().displayMetrics.density).toInt() + +fun getKeyboardHeight(activity: Activity, callback: (Int) -> Unit) { + val rootView = activity.window.decorView.rootView + rootView.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + private var previousHeight = 0 + + override fun onGlobalLayout() { + val rect = Rect() + rootView.getWindowVisibleDisplayFrame(rect) + + val screenHeight = rootView.height + val visibleHeight = rect.height() + val keyboardHeight = screenHeight - visibleHeight + + if (keyboardHeight > 0) { + if (keyboardHeight != previousHeight) { + callback(keyboardHeight) + previousHeight = keyboardHeight + } + } else { + previousHeight = 0 + } + } + }) +} diff --git a/app/src/main/java/com/aws/amazonlocation/utils/providers/RoutesProvider.kt b/app/src/main/java/com/aws/amazonlocation/utils/providers/RoutesProvider.kt index c7f068b2..fb3027e5 100644 --- a/app/src/main/java/com/aws/amazonlocation/utils/providers/RoutesProvider.kt +++ b/app/src/main/java/com/aws/amazonlocation/utils/providers/RoutesProvider.kt @@ -10,6 +10,7 @@ import aws.sdk.kotlin.services.georoutes.model.RouteLegAdditionalFeature import aws.sdk.kotlin.services.georoutes.model.RouteTravelMode import aws.sdk.kotlin.services.georoutes.model.RouteTravelStepType import com.aws.amazonlocation.ui.base.BaseActivity +import com.aws.amazonlocation.ui.main.explore.AvoidanceOption import com.aws.amazonlocation.utils.KEY_UNIT_SYSTEM import com.aws.amazonlocation.utils.PreferenceManager import com.aws.amazonlocation.utils.Units.isMetric @@ -25,39 +26,65 @@ class RoutesProvider( lngDeparture: Double?, latDestination: Double?, lngDestination: Double?, - isAvoidFerries: Boolean?, - isAvoidTolls: Boolean?, + avoidanceOptions: ArrayList, travelMode: String?, mBaseActivity: BaseActivity?, - getRoutesClient: GeoRoutesClient? + getRoutesClient: GeoRoutesClient?, ): CalculateRoutesResponse? = try { val isMetric = isMetric(mPreferenceManager.getValue(KEY_UNIT_SYSTEM, "Automatic")) - val routeTravelMode = when (travelMode) { - RouteTravelMode.Car.value -> RouteTravelMode.Car - RouteTravelMode.Truck.value -> RouteTravelMode.Truck - RouteTravelMode.Scooter.value -> RouteTravelMode.Scooter - else -> RouteTravelMode.Pedestrian - } + val routeTravelMode = + when (travelMode) { + RouteTravelMode.Car.value -> RouteTravelMode.Car + RouteTravelMode.Truck.value -> RouteTravelMode.Truck + RouteTravelMode.Scooter.value -> RouteTravelMode.Scooter + else -> RouteTravelMode.Pedestrian + } - val request = CalculateRoutesRequest { - origin = listOfNotNull(lngDeparture, latDeparture) - destination = listOfNotNull(lngDestination, latDestination) - avoid = RouteAvoidanceOptions { - ferries = isAvoidFerries - tollRoads = isAvoidTolls + val request = + CalculateRoutesRequest { + origin = listOfNotNull(lngDeparture, latDeparture) + destination = listOfNotNull(lngDestination, latDestination) + avoid = + if (routeTravelMode != RouteTravelMode.Scooter && routeTravelMode != RouteTravelMode.Pedestrian) { + RouteAvoidanceOptions { + ferries = + AvoidanceOption.FERRIES + .takeIf { it in avoidanceOptions } + ?.let { true } + tollRoads = + AvoidanceOption.TOLL_ROADS + .takeIf { it in avoidanceOptions } + ?.let { true } + dirtRoads = + AvoidanceOption.DIRT_ROADS + .takeIf { it in avoidanceOptions } + ?.let { true } + tunnels = + AvoidanceOption.TUNNELS + .takeIf { it in avoidanceOptions } + ?.let { true } + uTurns = + AvoidanceOption.U_TURNS + .takeIf { it in avoidanceOptions } + ?.let { true } + } + } else { + null + } + legGeometryFormat = GeometryFormat.Simple + instructionsMeasurementSystem = + if (isMetric) MeasurementSystem.Metric else MeasurementSystem.Imperial + departNow = true + this.travelMode = routeTravelMode + travelStepType = RouteTravelStepType.Default + legAdditionalFeatures = + listOf( + RouteLegAdditionalFeature.TravelStepInstructions, + RouteLegAdditionalFeature.Summary, + ) } - legGeometryFormat = GeometryFormat.Simple - instructionsMeasurementSystem = if (isMetric) MeasurementSystem.Metric else MeasurementSystem.Imperial - departNow = true - this.travelMode = routeTravelMode - travelStepType = RouteTravelStepType.Default - legAdditionalFeatures = listOf( - RouteLegAdditionalFeature.TravelStepInstructions, - RouteLegAdditionalFeature.Summary - ) - } withContext(Dispatchers.IO) { getRoutesClient?.calculateRoutes(request) diff --git a/app/src/main/res/layout-sw600dp/bottom_sheet_direction_search.xml b/app/src/main/res/layout-sw600dp/bottom_sheet_direction_search.xml index 83998635..8c074960 100644 --- a/app/src/main/res/layout-sw600dp/bottom_sheet_direction_search.xml +++ b/app/src/main/res/layout-sw600dp/bottom_sheet_direction_search.xml @@ -1,6 +1,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/img_amazon_logo_direction_search_sheet"> - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toTopOf="parent"> - + - + - + + + - - - + + + - - + - + - + + + - + + + + + - - - - + - - - + app:layout_constraintTop_toBottomOf="@id/card_direction_search"> + android:layout_gravity="center"> - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + + + - - - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> - - - - - - - - - + + - + + - - - + - - - - - + - + - + app:layout_constraintTop_toBottomOf="@id/cl_item_route_options_2" /> - + app:layout_constraintTop_toBottomOf="@+id/cl_item_route_options_2"> + + - - - - - + + + + + + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/cl_item_route_options_3"> - - - - - - + + - + - + + - - + + + - - + - - - - + app:layout_constraintTop_toBottomOf="@id/card_list_routes_option"> - + app:layout_constraintTop_toTopOf="parent"> - + + + + + + + + + app:layout_constraintTop_toTopOf="parent"> + + - - - - - + + + + + + + + + + + + + + + + + + + + + + android:layout_marginStart="@dimen/dp_18" + android:layout_marginTop="@dimen/dp_12" + android:layout_marginEnd="@dimen/dp_16" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/view_divider_option"> + + + + + + + + + + + - - - + + + - + + + + + + + + + + + + + + + + + + - + - + - + - + - - - - - + - + - + + - + app:layout_constraintTop_toBottomOf="@id/view_divider_option_truck"> + + - - - - - + + + + + + + + + + + + + + + + + + + + + + android:layout_marginStart="@dimen/dp_18" + android:layout_marginTop="@dimen/dp_16" + android:layout_marginEnd="@dimen/dp_16" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/view_divider_option_scooter"> + + + + + + - - - - - + - + + - + + + - + + + + + + + + + + + + + + + + + + + + + - - - - - + app:layout_constraintTop_toBottomOf="@id/card_map_option" /> - - + + + app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toBottomOf="@+id/cl_my_location" /> + + + + - + app:layout_constraintTop_toBottomOf="@id/cl_my_location"> + + + + + + + + + + + - - - - diff --git a/app/src/main/res/layout-sw600dp/fragment_route_option.xml b/app/src/main/res/layout-sw600dp/fragment_route_option.xml index b0b6e790..1a77118c 100644 --- a/app/src/main/res/layout-sw600dp/fragment_route_option.xml +++ b/app/src/main/res/layout-sw600dp/fragment_route_option.xml @@ -109,4 +109,135 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/view_trolls" /> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-sw720dp/bottom_sheet_direction_search.xml b/app/src/main/res/layout-sw720dp/bottom_sheet_direction_search.xml index 914b6220..8c074960 100644 --- a/app/src/main/res/layout-sw720dp/bottom_sheet_direction_search.xml +++ b/app/src/main/res/layout-sw720dp/bottom_sheet_direction_search.xml @@ -1,6 +1,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/img_amazon_logo_direction_search_sheet"> - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toTopOf="parent"> - + - + - + + + - - - + + + - - + - + - + + + - + + + + + - - - - + - - - + app:layout_constraintTop_toBottomOf="@id/card_direction_search"> + android:layout_gravity="center"> - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + + + - - - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> - - - - - - - - - + + - + + - - - + - - - - - + - + - + app:layout_constraintTop_toBottomOf="@id/cl_item_route_options_2" /> - + app:layout_constraintTop_toBottomOf="@+id/cl_item_route_options_2"> + + - - - - - + + + + + + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/cl_item_route_options_3"> - - - - - - + + - + - + + - - + + + - - + - - - - + app:layout_constraintTop_toBottomOf="@id/card_list_routes_option"> - + app:layout_constraintTop_toTopOf="parent"> - + + + + + + + + + app:layout_constraintTop_toTopOf="parent"> + + - - - - - + + + + + + + + + + + + + + + + + + + + + + android:layout_marginStart="@dimen/dp_18" + android:layout_marginTop="@dimen/dp_12" + android:layout_marginEnd="@dimen/dp_16" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/view_divider_option"> + + + + + + + + + + + - - - + + + - + + + + + + + + + + + + + + + + + + - + - + - + - + - - - - - + - + - + + - + app:layout_constraintTop_toBottomOf="@id/view_divider_option_truck"> + + - - + + + + + + + + - - - + + + + + + + + + + + + + android:layout_marginStart="@dimen/dp_18" + android:layout_marginTop="@dimen/dp_16" + android:layout_marginEnd="@dimen/dp_16" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/view_divider_option_scooter"> + + + + + + - - - - - + - + + - + + + - + + + + + + + + + + + + + + + + + + + + + - - - - - + app:layout_constraintTop_toBottomOf="@id/card_map_option" /> - - + + + app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toBottomOf="@+id/cl_my_location" /> + + + + - + app:layout_constraintTop_toBottomOf="@id/cl_my_location"> + + + + + + + + + + + - - - - diff --git a/app/src/main/res/layout-sw720dp/fragment_route_option.xml b/app/src/main/res/layout-sw720dp/fragment_route_option.xml index b0b6e790..ee205226 100644 --- a/app/src/main/res/layout-sw720dp/fragment_route_option.xml +++ b/app/src/main/res/layout-sw720dp/fragment_route_option.xml @@ -108,5 +108,136 @@ app:trackTint="@drawable/route_options_switch_track" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/view_trolls" /> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet_direction_search.xml b/app/src/main/res/layout/bottom_sheet_direction_search.xml index f545766e..7c3f802d 100644 --- a/app/src/main/res/layout/bottom_sheet_direction_search.xml +++ b/app/src/main/res/layout/bottom_sheet_direction_search.xml @@ -1,6 +1,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/img_amazon_logo_direction_search_sheet"> - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toTopOf="parent"> - + - + - + + + - - - + + + - - + - + - + + + - + + + + + - - - - + - - - + app:layout_constraintTop_toBottomOf="@id/card_direction_search"> + android:layout_gravity="center"> - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + + + - - - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> - - - - - - - - - + + - + + - - - + - - - - - + - + - + app:layout_constraintTop_toBottomOf="@id/cl_item_route_options_2" /> - + app:layout_constraintTop_toBottomOf="@+id/cl_item_route_options_2"> + + - - - - - + + + + + + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/cl_item_route_options_3"> - - - - - - + + - + - + + - - + + + - - + - - - + app:layout_constraintTop_toBottomOf="@id/card_list_routes_option"> - + app:layout_constraintTop_toTopOf="parent"> - + + + + + + + + + app:layout_constraintTop_toTopOf="parent"> + + - - - - - + + + + + + + + + + + + + + + + + + + + + + android:layout_marginStart="@dimen/dp_18" + android:layout_marginTop="@dimen/dp_12" + android:layout_marginEnd="@dimen/dp_16" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/view_divider_option"> + + + + + + + + + + + - - - + + + - + + + + + + + + + + + + + + + + + + - + - + - + - + - - - - - + - + - + + - + app:layout_constraintTop_toBottomOf="@id/view_divider_option_truck"> + + - - - - - + + + + + + + + + + + + + + + + + + + + + + android:layout_marginStart="@dimen/dp_18" + android:layout_marginTop="@dimen/dp_16" + android:layout_marginEnd="@dimen/dp_16" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/view_divider_option_scooter"> + + + + + + - - - - - + - + + - + + + - + + + + + + + + + + + + + + + + + + + + + - - - - - + app:layout_constraintTop_toBottomOf="@id/card_map_option" /> - - + + + app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toBottomOf="@+id/cl_my_location" /> - + + + + + app:layout_constraintTop_toBottomOf="@id/cl_my_location"> + + + + + + + + + + + - - - - diff --git a/app/src/main/res/layout/fragment_route_option.xml b/app/src/main/res/layout/fragment_route_option.xml index 35c152a6..d18ed08b 100644 --- a/app/src/main/res/layout/fragment_route_option.xml +++ b/app/src/main/res/layout/fragment_route_option.xml @@ -117,4 +117,136 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/view_trolls"/> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-ar/string.xml b/app/src/main/res/values-ar/string.xml index ff2f317b..59805907 100644 --- a/app/src/main/res/values-ar/string.xml +++ b/app/src/main/res/values-ar/string.xml @@ -59,8 +59,10 @@ يصنع بالتأكيد ك بحث هو توضيح بشكل صحيح. جرب إضافة أ المدينة، الرمز البريدي، أو بلد. ابحث مجاوز تجنب رسوم - تجنب الطرق السريعة تجنب العبارات + تجنب التراب طرق + تجنب يوتورن + تجنب الأنفاق 2 دقيقة ابحث الوجهة ملكي الموقع diff --git a/app/src/main/res/values-de/string.xml b/app/src/main/res/values-de/string.xml index 32521d5d..c4e2c79e 100644 --- a/app/src/main/res/values-de/string.xml +++ b/app/src/main/res/values-de/string.xml @@ -59,8 +59,10 @@ Machen sicher dein Suche ist buchstabiert richtig. Versuche ergänzend ein stadt, postleitzahl, oder Land. Suche in der Nähe Vermeiden Mautgebühren - Vermeiden Autobahnen Vermeiden Fähren + Vermeiden Dreck Straßen + Vermeiden Biegen Sie ab + Vermeiden Tunnel 2 Min. Suche Reiseziel Mein Standort diff --git a/app/src/main/res/values-es/string.xml b/app/src/main/res/values-es/string.xml index 40e46052..c38ec943 100644 --- a/app/src/main/res/values-es/string.xml +++ b/app/src/main/res/values-es/string.xml @@ -59,8 +59,10 @@ Hacer Sí, claro vuestro búsqueda es deletreado correctamente. Prueba sumando un ciudad, código postal, o país. Buscar cerca Evitar peajes - Evitar carreteras Evitar transbordadores + Evitar suciedad carreteras + Evitar Turno en U + Evitar túneles 2 min Buscar Destino Mi Ubicación diff --git a/app/src/main/res/values-fr/string.xml b/app/src/main/res/values-fr/string.xml index 00243451..d282b0c1 100644 --- a/app/src/main/res/values-fr/string.xml +++ b/app/src/main/res/values-fr/string.xml @@ -59,8 +59,10 @@ Fabriquer sûr votre chercher est orthographié correctement. Essayer ajout un ville, code postal, ou pays. Rechercher à proximité Éviter péages - Éviter autoroutes Éviter les ferries + Éviter poussière routes + Éviter Turn + Éviter tunnels 2 minimum Rechercher Destination Mon Emplacement diff --git a/app/src/main/res/values-hi/string.xml b/app/src/main/res/values-hi/string.xml index cbd0f136..b452b236 100644 --- a/app/src/main/res/values-hi/string.xml +++ b/app/src/main/res/values-hi/string.xml @@ -59,8 +59,10 @@ बनाओ ज़रूर तुम्हारा तलाश है वर्तनी सही ढंग से। ट्राई करें जोड़ने एक शहर, पोस्टकोड, या देश। खोजें पास ही बचें यातयात कर - बचें राजमार्गों बचें नौका + बचें कचरा सड़कों + बचें यू टर्न + बचें सुरंगें 2 मिनट खोजें डेस्टिनेशन मेरा लोकेशन diff --git a/app/src/main/res/values-it/string.xml b/app/src/main/res/values-it/string.xml index 7ffa5dc3..ff54be0b 100644 --- a/app/src/main/res/values-it/string.xml +++ b/app/src/main/res/values-it/string.xml @@ -59,7 +59,9 @@ Marca sicuro tuo ricerca è scritto correttamente. Prova aggiungendo un città, codice postale, o paese. Cerca vicino Evita pedaggi - Evita autostrade + Evitare sporco strade + Evitare Turno a U + Evitare gallerie Evita traghetti 2 min Cerca Destinazione diff --git a/app/src/main/res/values-iw/string.xml b/app/src/main/res/values-iw/string.xml index 0fe52f65..f4a4c777 100644 --- a/app/src/main/res/values-iw/string.xml +++ b/app/src/main/res/values-iw/string.xml @@ -59,7 +59,9 @@ לעשות בטח שלך חפש הווה מאוית נכון. נסה מוסיף א עיר, מיקוד, או מדינה. חיפוש בקרבת מקום הימנע אגרות - הימנע כבישים מהירים + הימנע עפר דרכים + הימנע יוטורן + הימנע מנהרות הימנע מעבורות 2 דק\' חיפוש יעד diff --git a/app/src/main/res/values-ja/string.xml b/app/src/main/res/values-ja/string.xml index f2a8b1ff..8bba7ca5 100644 --- a/app/src/main/res/values-ja/string.xml +++ b/app/src/main/res/values-ja/string.xml @@ -59,7 +59,9 @@ 作る 承知しました きみの 検索 です 綴られた 正しく。 やってみる 追加 ある 都市、 郵便番号、 または 国。 検索 近所の 避ける 通行料 - 避ける 高速道路 + 避ける 泥 道路 + 避ける Uターン + 避ける トンネル 避ける フェリー 2 最小 検索 目的地 diff --git a/app/src/main/res/values-ko/string.xml b/app/src/main/res/values-ko/string.xml index 6daa46f7..0fc0a800 100644 --- a/app/src/main/res/values-ko/string.xml +++ b/app/src/main/res/values-ko/string.xml @@ -59,7 +59,9 @@ 만들기 확실한 당신의 수색 입니다 철자 바르게. 시도해 보세요 첨가 a 도시, 우편번호, 또는 국가. 검색 근처에 피하십시오 통행료 - 피하십시오 고속도로 + 피하십시오 먼지 도로 + 피하십시오 uTurn + 피하십시오 터널 피하십시오 페리 2 분 검색 목적지 diff --git a/app/src/main/res/values-pt/string.xml b/app/src/main/res/values-pt/string.xml index 9f244544..d0d983ca 100644 --- a/app/src/main/res/values-pt/string.xml +++ b/app/src/main/res/values-pt/string.xml @@ -59,7 +59,9 @@ Faça com certeza seu procurar é soletrado corretamente. Experimente adicionando uma cidade, código postal, ou país. Pesquisar nas proximidades Evite cobra pedágio - Evite rodovias + Evite sujeira estradas + Evite TuTurn + Evite túneis Evite balsas 2 min Pesquisar Destino diff --git a/app/src/main/res/values-zh-rCN/string.xml b/app/src/main/res/values-zh-rCN/string.xml index 031fa74e..d221ddf4 100644 --- a/app/src/main/res/values-zh-rCN/string.xml +++ b/app/src/main/res/values-zh-rCN/string.xml @@ -59,7 +59,9 @@ 制作 当然 您的 搜索 是 拼出的 正确地。 试试 添加 一个 城市, 邮政编码, 要么 国家。 搜寻 附近 避免 通行费 - 避免 公路 + 避免 污垢 道路 + 避免 UTurn + 避免 隧道 避免 渡轮 2 分钟 搜寻 目的地 diff --git a/app/src/main/res/values-zh-rTW/string.xml b/app/src/main/res/values-zh-rTW/string.xml index f3a1b2d4..149b8b93 100644 --- a/app/src/main/res/values-zh-rTW/string.xml +++ b/app/src/main/res/values-zh-rTW/string.xml @@ -59,7 +59,9 @@ 製作 當然 你的 搜尋 是 拼寫 正確。 嘗試 添加 一個 城市, 郵遞區號, 或者 國家。 搜索 附近 避免 過路費 - 避免 高速公路 + 避免 污垢 道路 + 避免 烏圖恩 + 避免 隧道 避免 渡輪 2 分鐘 搜索 目的地 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a79a5c21..5bca8480 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,8 +67,10 @@ Make sure your search is spelled correctly. Try adding a city, postcode, or country. Search nearby Avoid tolls - Avoid highways Avoid ferries + Avoid dirt roads + Avoid uTurn + Avoid tunnels 2 min diff --git a/app/src/test/java/com/aws/amazonlocation/viewmodel/explore/ExploreVMCalculateDistance.kt b/app/src/test/java/com/aws/amazonlocation/viewmodel/explore/ExploreVMCalculateDistance.kt index a1c16aa9..bfa219a8 100644 --- a/app/src/test/java/com/aws/amazonlocation/viewmodel/explore/ExploreVMCalculateDistance.kt +++ b/app/src/test/java/com/aws/amazonlocation/viewmodel/explore/ExploreVMCalculateDistance.kt @@ -11,6 +11,7 @@ import com.aws.amazonlocation.data.repository.LocationSearchImp import com.aws.amazonlocation.domain.`interface`.DistanceInterface import com.aws.amazonlocation.domain.usecase.LocationSearchUseCase import com.aws.amazonlocation.mock.* +import com.aws.amazonlocation.ui.main.explore.AvoidanceOption import com.aws.amazonlocation.ui.main.explore.ExploreViewModel import kotlinx.coroutines.test.runTest import org.junit.Assert @@ -56,9 +57,9 @@ class ExploreVMCalculateDistance : BaseTest() { @Test fun calculateDistanceSuccess() = runTest { - Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull())).thenAnswer { - val mode = it.arguments[6] as String - val callback: DistanceInterface = it.arguments[7] as DistanceInterface + Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any(), anyOrNull(), anyOrNull())).thenAnswer { + val mode = it.arguments[5] as String + val callback: DistanceInterface = it.arguments[6] as DistanceInterface when (mode) { RouteTravelMode.Car.value -> callback.distanceSuccess(Responses.RESPONSE_CALCULATE_DISTANCE_CAR) @@ -73,7 +74,10 @@ class ExploreVMCalculateDistance : BaseTest() { mExploreVM.mDestinationLatLng = null val start = DISTANCE_COORDINATE_FROM val end = DISTANCE_COORDINATE_TO - mExploreVM.calculateDistance(start.latitude, start.longitude, end.latitude, end.longitude, AVOID_FERRIES, AVOID_TOLLS, false) + mExploreVM.calculateDistance(start.latitude, start.longitude, end.latitude, end.longitude, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, false) var result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, mExploreVM.mStartLatLng == start) Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, mExploreVM.mDestinationLatLng == end) @@ -81,7 +85,10 @@ class ExploreVMCalculateDistance : BaseTest() { result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_SUCCESS, result is HandleResult.Success) Assert.assertTrue(TEST_FAILED_DUE_TO_INCORRECT_DATA, (result as? HandleResult.Success)?.response?.calculateRouteResult == Responses.RESPONSE_CALCULATE_DISTANCE_CAR) - mExploreVM.calculateDistance(start.latitude, start.longitude, end.latitude, end.longitude, AVOID_FERRIES, AVOID_TOLLS, true) + mExploreVM.calculateDistance(start.latitude, start.longitude, end.latitude, end.longitude, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, true) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() @@ -103,21 +110,27 @@ class ExploreVMCalculateDistance : BaseTest() { @Test fun calculateDistanceError() = runTest { - Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any())).thenAnswer { - val distanceType = it.arguments[6] as String? - val callback: DistanceInterface = it.arguments[7] as DistanceInterface + Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any(), anyOrNull(), anyOrNull())).thenAnswer { + val distanceType = it.arguments[5] as String? + val callback: DistanceInterface = it.arguments[6] as DistanceInterface callback.distanceFailed(DataSourceException.Error(distanceType!!)) } mExploreVM.mCalculateDistance.test { - mExploreVM.calculateDistance(null, null, null, null, AVOID_FERRIES, AVOID_TOLLS, false) + mExploreVM.calculateDistance(null, null, null, null, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, false) var result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_ERROR, result is HandleResult.Error) Assert.assertTrue(TEST_FAILED_DUE_TO_INCORRECT_ERROR_MESSAGE, (result as? HandleResult.Error)?.exception?.messageResource == RouteTravelMode.Car.value) - mExploreVM.calculateDistance(null, null, null, null, AVOID_FERRIES, AVOID_TOLLS, true) + mExploreVM.calculateDistance(null, null, null, null, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, true) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() @@ -136,13 +149,16 @@ class ExploreVMCalculateDistance : BaseTest() { @Test fun calculateDistanceInternetError() = runTest { - Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any())).thenAnswer { - val callback: DistanceInterface = it.arguments[7] as DistanceInterface + Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any(), anyOrNull(), anyOrNull())).thenAnswer { + val callback: DistanceInterface = it.arguments[6] as DistanceInterface callback.internetConnectionError(NO_INTERNET_ERROR) } mExploreVM.mCalculateDistance.test { - mExploreVM.calculateDistance(null, null, null, null, AVOID_FERRIES, AVOID_TOLLS, false) + mExploreVM.calculateDistance(null, null, null, null, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, false) var result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() diff --git a/app/src/test/java/com/aws/amazonlocation/viewmodel/explore/ExploreVMUpdateCalculateDistanceFromMode.kt b/app/src/test/java/com/aws/amazonlocation/viewmodel/explore/ExploreVMUpdateCalculateDistanceFromMode.kt index c0909263..d00e4047 100644 --- a/app/src/test/java/com/aws/amazonlocation/viewmodel/explore/ExploreVMUpdateCalculateDistanceFromMode.kt +++ b/app/src/test/java/com/aws/amazonlocation/viewmodel/explore/ExploreVMUpdateCalculateDistanceFromMode.kt @@ -22,6 +22,7 @@ import com.aws.amazonlocation.mock.TEST_FAILED_DUE_TO_INCORRECT_NO_INTERNET_ERRO import com.aws.amazonlocation.mock.TEST_FAILED_DUE_TO_STATE_NOT_ERROR import com.aws.amazonlocation.mock.TEST_FAILED_DUE_TO_STATE_NOT_LOADING import com.aws.amazonlocation.mock.TEST_FAILED_DUE_TO_STATE_NOT_SUCCESS +import com.aws.amazonlocation.ui.main.explore.AvoidanceOption import com.aws.amazonlocation.ui.main.explore.ExploreViewModel import kotlinx.coroutines.test.runTest import org.junit.Assert @@ -59,9 +60,9 @@ class ExploreVMUpdateCalculateDistanceFromMode : BaseTest() { @Test fun updateCalculateDistanceFromModeSuccess() = runTest { - Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any())).thenAnswer { - val mode = it.arguments[6] as String - val callback: DistanceInterface = it.arguments[7] as DistanceInterface + Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any(), anyOrNull(), anyOrNull())).thenAnswer { + val mode = it.arguments[5] as String + val callback: DistanceInterface = it.arguments[6] as DistanceInterface when (mode) { RouteTravelMode.Pedestrian.value -> callback.distanceSuccess(Responses.RESPONSE_CALCULATE_DISTANCE_WALKING) @@ -73,19 +74,31 @@ class ExploreVMUpdateCalculateDistanceFromMode : BaseTest() { mExploreVM.mUpdateCalculateDistance.test { val start = DISTANCE_COORDINATE_FROM val end = DISTANCE_COORDINATE_TO - mExploreVM.updateCalculateDistanceFromMode(start.latitude, start.longitude, end.latitude, end.longitude, AVOID_FERRIES, AVOID_TOLLS, RouteTravelMode.Car.value) + mExploreVM.updateCalculateDistanceFromMode(start.latitude, start.longitude, end.latitude, end.longitude, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + add(AvoidanceOption.TUNNELS) + add(AvoidanceOption.DIRT_ROADS) + add(AvoidanceOption.U_TURNS) + }, RouteTravelMode.Car.value) var result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_SUCCESS, result is HandleResult.Success) Assert.assertTrue(TEST_FAILED_DUE_TO_INCORRECT_DATA, (result as? HandleResult.Success)?.response?.calculateRouteResult == Responses.RESPONSE_CALCULATE_DISTANCE_CAR) - mExploreVM.updateCalculateDistanceFromMode(start.latitude, start.longitude, end.latitude, end.longitude, AVOID_FERRIES, AVOID_TOLLS, RouteTravelMode.Pedestrian.value) + mExploreVM.updateCalculateDistanceFromMode(start.latitude, start.longitude, end.latitude, end.longitude, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, RouteTravelMode.Pedestrian.value) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_SUCCESS, result is HandleResult.Success) Assert.assertTrue(TEST_FAILED_DUE_TO_INCORRECT_DATA, (result as? HandleResult.Success)?.response?.calculateRouteResult == Responses.RESPONSE_CALCULATE_DISTANCE_WALKING) - mExploreVM.updateCalculateDistanceFromMode(start.latitude, start.longitude, end.latitude, end.longitude, AVOID_FERRIES, AVOID_TOLLS, RouteTravelMode.Truck.value) + mExploreVM.updateCalculateDistanceFromMode(start.latitude, start.longitude, end.latitude, end.longitude, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, RouteTravelMode.Truck.value) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() @@ -97,28 +110,37 @@ class ExploreVMUpdateCalculateDistanceFromMode : BaseTest() { @Test fun updateCalculateDistanceFromModeError() = runTest { - Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any())).thenAnswer { - val distanceType = it.arguments[6] as String? - val callback: DistanceInterface = it.arguments[7] as DistanceInterface + Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any(), anyOrNull(), anyOrNull())).thenAnswer { + val distanceType = it.arguments[5] as String? + val callback: DistanceInterface = it.arguments[6] as DistanceInterface callback.distanceFailed(DataSourceException.Error(distanceType!!)) } mExploreVM.mUpdateCalculateDistance.test { - mExploreVM.updateCalculateDistanceFromMode(null, null, null, null, AVOID_FERRIES, AVOID_TOLLS, RouteTravelMode.Car.value) + mExploreVM.updateCalculateDistanceFromMode(null, null, null, null, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, RouteTravelMode.Car.value) var result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_ERROR, result is HandleResult.Error) Assert.assertTrue(TEST_FAILED_DUE_TO_INCORRECT_ERROR_MESSAGE, (result as? HandleResult.Error)?.exception?.messageResource == RouteTravelMode.Car.value) - mExploreVM.updateCalculateDistanceFromMode(null, null, null, null, AVOID_FERRIES, AVOID_TOLLS, RouteTravelMode.Pedestrian.value) + mExploreVM.updateCalculateDistanceFromMode(null, null, null, null, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, RouteTravelMode.Pedestrian.value) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_ERROR, result is HandleResult.Error) Assert.assertTrue(TEST_FAILED_DUE_TO_INCORRECT_ERROR_MESSAGE, (result as? HandleResult.Error)?.exception?.messageResource == RouteTravelMode.Pedestrian.value) - mExploreVM.updateCalculateDistanceFromMode(null, null, null, null, AVOID_FERRIES, AVOID_TOLLS, RouteTravelMode.Truck.value) + mExploreVM.updateCalculateDistanceFromMode(null, null, null, null, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, RouteTravelMode.Truck.value) result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem() @@ -131,13 +153,16 @@ class ExploreVMUpdateCalculateDistanceFromMode : BaseTest() { @Test fun updateCalculateDistanceFromModeInternetError() = runTest { - Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any())).thenAnswer { - val callback: DistanceInterface = it.arguments[7] as DistanceInterface + Mockito.`when`(mRemoteDataSourceImpl.calculateRoute(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), any(), anyOrNull(), anyOrNull())).thenAnswer { + val callback: DistanceInterface = it.arguments[6] as DistanceInterface callback.internetConnectionError(NO_INTERNET_ERROR) } mExploreVM.mUpdateCalculateDistance.test { - mExploreVM.updateCalculateDistanceFromMode(null, null, null, null, AVOID_FERRIES, AVOID_TOLLS, RouteTravelMode.Car.value) + mExploreVM.updateCalculateDistanceFromMode(null, null, null, null, arrayListOf().apply { + add(AvoidanceOption.FERRIES) + add(AvoidanceOption.TOLL_ROADS) + }, RouteTravelMode.Car.value) var result = awaitItem() Assert.assertTrue(TEST_FAILED_DUE_TO_STATE_NOT_LOADING, result is HandleResult.Loading) result = awaitItem()