From 8a7d43237bf718bd86e96f125e093b68ad6d5dfd Mon Sep 17 00:00:00 2001 From: shah Date: Mon, 23 Oct 2023 17:39:27 +0530 Subject: [PATCH] reduced search debounce time to solve swap location issue --- .../ui/main/explore/ExploreFragment.kt | 20 +++++++++++++------ .../ui/main/explore/ExploreViewModel.kt | 1 - 2 files changed, 14 insertions(+), 7 deletions(-) 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 46ad5c28..b9c3d948 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 @@ -1866,6 +1866,7 @@ class ExploreFragment : } private fun BottomSheetDirectionSearchBinding.showAllApiFailed() { + clMyLocation.root.hide() cardMapOption.hide() layoutCardError.groupCardErrorNoSearchFound.show() layoutCardError.root.show() @@ -2528,8 +2529,8 @@ class ExploreFragment : ivSwapLocation.setOnClickListener { if (checkInternetConnection() && !mIsSwapClicked && !checkDirectionLoaderVisible()) { - mViewModel.searchDebounce = DELAY_300 mIsSwapClicked = true + mLastClickTime = SystemClock.elapsedRealtime() if (!edtSearchDest.text.isNullOrEmpty() && !edtSearchDirection.text.isNullOrEmpty()) { showDirectionSearchShimmer() } @@ -2580,13 +2581,18 @@ class ExploreFragment : mViewModel.mSearchDirectionDestinationData = originData mViewModel.mSearchDirectionDestinationData?.isDestination = true showOriginToDestinationRoute() + } else if (mViewModel.mSearchDirectionOriginData != null) { + mViewModel.mSearchDirectionDestinationData = mViewModel.mSearchDirectionOriginData + mViewModel.mSearchDirectionOriginData = null + } else if (mViewModel.mSearchDirectionDestinationData != null) { + mViewModel.mSearchDirectionOriginData = mViewModel.mSearchDirectionDestinationData + mViewModel.mSearchDirectionDestinationData = null } } activity?.hideKeyboard() lifecycleScope.launch { - delay(DELAY_300) + delay(DELAY_500) mIsSwapClicked = false - mViewModel.searchDebounce = CLICK_DEBOUNCE } } } @@ -2633,7 +2639,7 @@ class ExploreFragment : isDataSearchForDestination = false } } - edtSearchDest.textChanges().debounce(mViewModel.searchDebounce).onEach { text -> + edtSearchDest.textChanges().debounce(DELAY_500).onEach { text -> updateDirectionSearchUI(text.isNullOrEmpty()) if (text?.trim().toString().lowercase() == getString(R.string.label_my_location).trim().lowercase()) { return@onEach @@ -2659,7 +2665,7 @@ class ExploreFragment : checkMyLocationUI(text, edtSearchDirection) }.launchIn(lifecycleScope) - edtSearchDirection.textChanges().debounce(mViewModel.searchDebounce).onEach { text -> + edtSearchDirection.textChanges().debounce(DELAY_500).onEach { text -> updateDirectionSearchUI(text.isNullOrEmpty()) if (text?.trim().toString().lowercase() == getString(R.string.label_my_location).trim().lowercase()) { return@onEach @@ -4035,7 +4041,9 @@ class ExploreFragment : if (mMapHelper.isGrabSelectedAndOutsideBound) { mBinding.bottomSheetDirectionSearch.clMyLocation.root.hide() } else { - mBinding.bottomSheetDirectionSearch.clMyLocation.root.show() + if (!mBinding.bottomSheetDirectionSearch.layoutCardError.root.isVisible) { + mBinding.bottomSheetDirectionSearch.clMyLocation.root.show() + } } } } 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 b780646f..f177da3e 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 @@ -74,7 +74,6 @@ class ExploreViewModel @Inject constructor( var providerOptions = ArrayList() var attributeOptions = ArrayList() var typeOptions = ArrayList() - var searchDebounce = CLICK_DEBOUNCE private val _searchForSuggestionsResultList = Channel>(Channel.BUFFERED)