Skip to content

Commit

Permalink
fix: reverse geocode and direction button should not work if only dat…
Browse files Browse the repository at this point in the history
…a is pulled bug fixes

fix: Two bottom sheet opening fixes with code optimization
refactor: Auth SDK version update with related code changes

ALS-1882
  • Loading branch information
shah272728 committed Nov 8, 2024
1 parent d7b035c commit ddfc221
Show file tree
Hide file tree
Showing 17 changed files with 279 additions and 301 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ dependencies {

implementation "org.maplibre.gl:android-sdk:11.0.0"
implementation "org.maplibre.gl:android-plugin-annotation-v9:3.0.0"
implementation("software.amazon.location:auth:0.2.5")
implementation("software.amazon.location:auth:1.1.0")
implementation("com.google.android.gms:play-services-location:21.3.0")

implementation "androidx.navigation:navigation-fragment-ktx:2.7.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class RemoteDataSourceImpl(
if (mContext.isInternetAvailable()) {
val mSearchSuggestionResponse =
mPlacesProvider.searchPlaceSuggestion(lat, lng, searchText, mLocationProvider.getBaseActivity(), mLocationProvider.getGeoPlacesClient())
if (validateLatLng(searchText) != null) {
val mLatLng = validateLatLng(searchText)
if (validateLatLng(searchText.trim()) != null) {
val mLatLng = validateLatLng(searchText.trim())
if (mSearchSuggestionResponse.text == (mLatLng?.latitude.toString() + "," + mLatLng?.longitude.toString())) {
searchPlace.getSearchPlaceSuggestionResponse(mSearchSuggestionResponse)
} else {
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/java/com/aws/amazonlocation/ui/base/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import software.amazon.location.auth.AuthHelper
import javax.inject.Inject

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand Down Expand Up @@ -73,7 +72,6 @@ open class BaseActivity : AppCompatActivity() {
lateinit var mLocationProvider: LocationProvider

private var subTitle = ""
lateinit var authHelper: AuthHelper
val mSignInViewModel: SignInViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -105,7 +103,6 @@ open class BaseActivity : AppCompatActivity() {
mGeofenceBottomSheetHelper = GeofenceBottomSheetHelper(this@BaseActivity)
mGeofenceUtils = GeofenceUtils()

authHelper = AuthHelper(applicationContext)
val preference = PreferenceManager(applicationContext)
mTrackingUtils = TrackingUtils(preference, this@BaseActivity, mLocationProvider)
mSimulationUtils = SimulationUtils(preference, this@BaseActivity, mLocationProvider)
Expand All @@ -127,8 +124,8 @@ open class BaseActivity : AppCompatActivity() {
}

suspend fun initMobileClient() {
mLocationProvider.initializeLocationCredentialsProvider(authHelper, this)
mLocationProvider.initPlaceRoutesClients()
mLocationProvider.initializeLocationCredentialsProvider(this)
mLocationProvider.initPlaceRoutesClients(this)
}

private fun locationPermissionDialog() {
Expand Down Expand Up @@ -253,10 +250,10 @@ open class BaseActivity : AppCompatActivity() {

fun restartAppWithClearData() {
lifecycleScope.launch {
mLocationProvider.locationCredentialsProvider?.clear()
mLocationProvider.clearCredentials()
mPreferenceManager.setDefaultConfig()
delay(RESTART_DELAY)
restartApplication()
}
}
}
}
27 changes: 5 additions & 22 deletions app/src/main/java/com/aws/amazonlocation/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ import com.aws.amazonlocation.utils.LANGUAGE_CODE_ARABIC
import com.aws.amazonlocation.utils.LANGUAGE_CODE_HEBREW
import com.aws.amazonlocation.utils.LANGUAGE_CODE_HEBREW_1
import com.aws.amazonlocation.utils.NetworkConnectivityObserveInterface
import com.aws.amazonlocation.utils.PREFS_KEY_IDENTITY_ID
import com.aws.amazonlocation.utils.PREFS_NAME_AUTH
import com.aws.amazonlocation.utils.SETTING_FRAGMENT
import com.aws.amazonlocation.utils.SIGN_IN
import com.aws.amazonlocation.utils.SIGN_OUT
Expand All @@ -102,7 +100,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import software.amazon.location.auth.EncryptedSharedPreferences

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Expand All @@ -122,14 +119,7 @@ class MainActivity :
private var alertDialog: Dialog? = null
private var currentPage: String? = null
private var connectivityObserver: ConnectivityObserveInterface? = null
private var encryptedSharedPreferences: EncryptedSharedPreferences? = null
var analyticsUtils: AnalyticsUtils? = null
private val mServiceName = "geo"

var resultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
checkMap()
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
Expand Down Expand Up @@ -310,13 +300,6 @@ class MainActivity :
}
}
initClick()
if (encryptedSharedPreferences == null) {
encryptedSharedPreferences =
EncryptedSharedPreferences(
applicationContext,
PREFS_NAME_AUTH,
).apply { initEncryptedSharedPreferences() }
}
KeyBoardUtils.attachKeyboardListeners(
mBinding.root,
object : KeyBoardUtils.KeyBoardInterface {
Expand Down Expand Up @@ -425,14 +408,14 @@ class MainActivity :
"",
) != AuthEnum.SIGNED_IN.name
) {
mLocationProvider.locationCredentialsProvider?.clear()
mLocationProvider.clearCredentials()
}
mPreferenceManager.setValue(
KEY_CLOUD_FORMATION_STATUS,
AuthEnum.SIGNED_IN.name,
)
mBottomSheetDialog?.dismiss()
async { mLocationProvider.generateNewAuthCredentials(authHelper) }.await()
async { mLocationProvider.generateNewAuthCredentials() }.await()
val fragment = mNavHostFragment.childFragmentManager.fragments[0]
getTokenAndAttachPolicy()
val propertiesAws =
Expand Down Expand Up @@ -706,7 +689,7 @@ class MainActivity :
}

private fun setSimulationIotPolicy() {
val identityId = encryptedSharedPreferences?.get(PREFS_KEY_IDENTITY_ID)
val identityId = mLocationProvider.getIdentityId()
CoroutineScope(Dispatchers.IO).launch {
val attachPolicyRequest =
AttachPolicyRequest {
Expand Down Expand Up @@ -1252,11 +1235,11 @@ class MainActivity :
fun initClient(isAfterSignOut:Boolean = false){
if (!isAfterSignOut) {
try {
mLocationProvider.locationCredentialsProvider?.clear()
mLocationProvider.clearCredentials()
} catch (_: Exception) { }
}
CoroutineScope(Dispatchers.IO).launch {
async { initMobileClient() }.await()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import com.aws.amazonlocation.utils.DELAY_300
import com.aws.amazonlocation.utils.DELAY_500
import com.aws.amazonlocation.utils.Distance.DISTANCE_IN_METER_10
import com.aws.amazonlocation.utils.Durations
import com.aws.amazonlocation.utils.Durations.DELAY_FOR_BOTTOM_SHEET_LOAD
import com.aws.amazonlocation.utils.EventType
import com.aws.amazonlocation.utils.EventType.PLACE_SEARCH
import com.aws.amazonlocation.utils.EventType.ROUTE_OPTION_CHANGED
Expand All @@ -97,8 +98,6 @@ import com.aws.amazonlocation.utils.LANGUAGE_CODE_HEBREW_1
import com.aws.amazonlocation.utils.MAP_STYLE_ATTRIBUTION
import com.aws.amazonlocation.utils.MILES
import com.aws.amazonlocation.utils.MapHelper
import com.aws.amazonlocation.utils.PREFS_KEY_IDENTITY_ID
import com.aws.amazonlocation.utils.PREFS_NAME_AUTH
import com.aws.amazonlocation.utils.STRING_FORMAT
import com.aws.amazonlocation.utils.SignOutInterface
import com.aws.amazonlocation.utils.SimulationDialogInterface
Expand All @@ -124,6 +123,7 @@ import com.aws.amazonlocation.utils.isRunningTest3LiveLocation
import com.aws.amazonlocation.utils.isRunningTestLiveLocation
import com.aws.amazonlocation.utils.locationPermissionDialog
import com.aws.amazonlocation.utils.show
import com.aws.amazonlocation.utils.showKeyboard
import com.aws.amazonlocation.utils.showViews
import com.aws.amazonlocation.utils.simulationExit
import com.aws.amazonlocation.utils.textChanges
Expand Down Expand Up @@ -162,7 +162,6 @@ import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.OnMapReadyCallback
import org.maplibre.geojson.Point
import org.maplibre.geojson.Point.fromLngLat
import software.amazon.location.auth.EncryptedSharedPreferences

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Expand Down Expand Up @@ -211,7 +210,6 @@ class ExploreFragment :
private var mTravelMode: String = RouteTravelMode.Car.value
private var mRouteFinish: Boolean = false
private var mRedirectionType: String? = null
private var encryptedSharedPreferences: EncryptedSharedPreferences?= null

private var gpsActivityResult =
registerForActivityResult(
Expand Down Expand Up @@ -726,10 +724,7 @@ class ExploreFragment :
collectionName: String,
position1: List<Double>?,
) {
if (encryptedSharedPreferences == null) {
encryptedSharedPreferences = EncryptedSharedPreferences(requireContext(), PREFS_NAME_AUTH).apply { initEncryptedSharedPreferences() }
}
val identityId = encryptedSharedPreferences?.get(PREFS_KEY_IDENTITY_ID)
val identityId = mLocationProvider.getIdentityId()
identityId?.let {
mSimulationViewModel.evaluateGeofence(
collectionName,
Expand Down Expand Up @@ -1143,9 +1138,10 @@ class ExploreFragment :
}
} else {
bottomSheetDirectionSearch.apply {
clSearchLoaderDirectionSearch.root.show()
layoutNoDataFound.root.hide()
rvSearchPlacesSuggestionDirection.hide()
rvSearchPlacesDirection.hide()
clSearchLoaderDirectionSearch.root.show()
}
}
}.onSuccess {
Expand Down Expand Up @@ -1207,6 +1203,8 @@ class ExploreFragment :
bottomSheetDirection.apply {
groupDistanceLoad.show()
groupDistance.invisible()
btnDirection.alpha = 0.5F
btnDirection.isEnabled = false
}
}
} else {
Expand All @@ -1218,6 +1216,8 @@ class ExploreFragment :
if (!mBottomSheetHelper.isDirectionSearchSheetVisible()) {
bottomSheetDirection.apply {
groupDistanceLoad.hide()
btnDirection.alpha = 1.0F
btnDirection.isEnabled = true
groupDistance.show()
tvDirectionError.hide()
tvDirectionError2.hide()
Expand Down Expand Up @@ -1515,6 +1515,8 @@ class ExploreFragment :
if (!mBottomSheetHelper.isDirectionSearchSheetVisible()) {
bottomSheetDirection.apply {
groupDistanceLoad.hide()
btnDirection.isEnabled = true
btnDirection.alpha = 1.0F
groupDistance.show()
tvDirectionTime.hide()
tvDirectionDot.invisible()
Expand Down Expand Up @@ -2000,8 +2002,8 @@ class ExploreFragment :
val mText =
mBinding.bottomSheetSearch.edtSearchPlaces.text
.toString()
if (validateLatLng(mText) != null) {
val mLatLng = validateLatLng(mText)
if (validateLatLng(mText.trim()) != null) {
val mLatLng = validateLatLng(mText.trim())
if (it.text == (mLatLng?.latitude.toString() + "," + mLatLng?.longitude.toString())) {
setPlaceData(it, searchPlaceIndexText)
}
Expand Down Expand Up @@ -2046,7 +2048,7 @@ class ExploreFragment :
it: SearchSuggestionResponse,
searchPlaceIndexText: SearchApiEnum,
) {
val mText: String =
var mText: String =
if (!isDataSearchForDestination) {
mBinding.bottomSheetDirectionSearch.edtSearchDirection.text
.toString()
Expand All @@ -2056,6 +2058,10 @@ class ExploreFragment :
.toString()
.trim()
}
if (validateLatLng(mText) != null) {
val mLatLng = validateLatLng(mText)
mText = mLatLng?.latitude.toString() + "," + mLatLng?.longitude.toString()
}
if (!it.text.isNullOrEmpty() &&
it.text
.toString()
Expand Down Expand Up @@ -2111,7 +2117,7 @@ class ExploreFragment :
if (mPlaceList.isNotEmpty()) {
clNoInternetConnectionDirectionSearch.hide()
nsDirectionSearchPlaces.show()
layoutNoDataFound.groupNoSearchFound.hide()
layoutNoDataFound.root.hide()
layoutCardError.groupCardErrorNoSearchFound.hide()
when (searchPlaceIndexText) {
SearchApiEnum.SEARCH_PLACE_INDEX_TEXT -> {
Expand All @@ -2126,7 +2132,7 @@ class ExploreFragment :
}
} else {
hideViews(rvSearchPlacesDirection, nsDirectionSearchPlaces)
layoutNoDataFound.groupNoSearchFound.show()
layoutNoDataFound.root.show()
}
}
}
Expand Down Expand Up @@ -2211,7 +2217,17 @@ class ExploreFragment :
private fun clickListener() {
mBinding.apply {
cardGeofenceMap.setOnClickListener {
(activity as MainActivity).geofenceClick()
lifecycleScope.launch {
if (mBottomSheetHelper.isDirectionSearchSheetVisible()) {
bottomSheetDirectionSearch.ivDirectionCloseDirectionSearch.performClick()
}
if (mBottomSheetHelper.isDirectionSheetVisible()) {
bottomSheetDirection.ivDirectionCloseDirection.performClick()
}
(activity as MainActivity).geofenceClick()
delay(DELAY_FOR_BOTTOM_SHEET_LOAD)
mBottomSheetHelper.hideSearchBottomSheet(true)
}
}

cardNavigation.setOnClickListener {
Expand Down Expand Up @@ -2806,8 +2822,7 @@ class ExploreFragment :
lifecycleScope.launch {
activity?.hideKeyboard()
delay(DELAY_300)
mBinding.bottomSheetSearch.clSearchLoaderSearchSheet.root
.hide()
mBinding.bottomSheetSearch.clSearchLoaderSearchSheet.root.hide()
mMapHelper.addLiveLocationMarker(false)
mBottomSheetHelper.hideDirectionSearchBottomSheet(this@ExploreFragment)
hideDirectionBottomSheet()
Expand All @@ -2816,22 +2831,22 @@ class ExploreFragment :

mBinding.bottomSheetDirection.apply {
btnDirection.setOnClickListener {
if (checkInternetConnection()) {
if (activity?.checkLocationPermission() == true) {
if (isGPSEnabled(requireContext())) {
if (mViewModel.mCarData?.routes?.get(0)?.legs != null) {
routeOption()
} else {
openDirectionWithError()
}
} else {
mViewModel.mCarData = null
openDirectionWithError()
}
} else {
mViewModel.mCarData = null
openDirectionWithError()
}
if (!checkInternetConnection()) return@setOnClickListener
if (cardLoaderSheet1.isVisible) return@setOnClickListener
if (activity?.checkLocationPermission() != true) {
mViewModel.mCarData = null
openDirectionWithError()
return@setOnClickListener
}
if (!isGPSEnabled(requireContext())) {
mViewModel.mCarData = null
openDirectionWithError()
return@setOnClickListener
}
if (mViewModel.mCarData?.routes?.get(0)?.legs == null) {
openDirectionWithError()
} else {
routeOption()
}
}
ivInfo.setOnClickListener {
Expand Down Expand Up @@ -3104,6 +3119,7 @@ class ExploreFragment :
mIsAvoidFerries = mPreferenceManager.getValue(KEY_AVOID_FERRIES, false)
cardDirection.hide()
bottomSheetDirectionSearch.clSearchLoaderDirectionSearch.root.hide()
bottomSheetDirectionSearch.layoutNoDataFound.root.hide()
bottomSheetSearch.edtSearchPlaces.setText("")
bottomSheetSearch.edtSearchPlaces.clearFocus()
mBaseActivity?.bottomNavigationVisibility(false)
Expand Down Expand Up @@ -3136,6 +3152,10 @@ class ExploreFragment :
mPlaceList.clear()
mAdapterDirection?.notifyDataSetChanged()
mSearchPlacesDirectionSuggestionAdapter?.notifyDataSetChanged()
if (!edtSearchDest.hasFocus()) {
edtSearchDirection.requestFocus()
}
mBaseActivity?.showKeyboard()
}
mBottomSheetHelper.expandDirectionSearchSheet(this@ExploreFragment)
mIsDirectionSheetHalfExpanded = false
Expand Down Expand Up @@ -3902,7 +3922,7 @@ class ExploreFragment :
tvTruckSelected,
tvWalkSelected,
layoutCardError.root,
layoutNoDataFound.groupNoSearchFound,
layoutNoDataFound.root,
)
}
mBinding.bottomSheetDirection.apply {
Expand Down
Loading

0 comments on commit ddfc221

Please sign in to comment.