Skip to content

Commit ddfc221

Browse files
committed
fix: reverse geocode and direction button should not work if only data is pulled bug fixes
fix: Two bottom sheet opening fixes with code optimization refactor: Auth SDK version update with related code changes ALS-1882
1 parent d7b035c commit ddfc221

File tree

17 files changed

+279
-301
lines changed

17 files changed

+279
-301
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ dependencies {
145145

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

151151
implementation "androidx.navigation:navigation-fragment-ktx:2.7.7"

app/src/main/java/com/aws/amazonlocation/data/datasource/RemoteDataSourceImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class RemoteDataSourceImpl(
4848
if (mContext.isInternetAvailable()) {
4949
val mSearchSuggestionResponse =
5050
mPlacesProvider.searchPlaceSuggestion(lat, lng, searchText, mLocationProvider.getBaseActivity(), mLocationProvider.getGeoPlacesClient())
51-
if (validateLatLng(searchText) != null) {
52-
val mLatLng = validateLatLng(searchText)
51+
if (validateLatLng(searchText.trim()) != null) {
52+
val mLatLng = validateLatLng(searchText.trim())
5353
if (mSearchSuggestionResponse.text == (mLatLng?.latitude.toString() + "," + mLatLng?.longitude.toString())) {
5454
searchPlace.getSearchPlaceSuggestionResponse(mSearchSuggestionResponse)
5555
} else {

app/src/main/java/com/aws/amazonlocation/ui/base/BaseActivity.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import dagger.hilt.android.AndroidEntryPoint
4444
import kotlinx.coroutines.delay
4545
import kotlinx.coroutines.launch
4646
import kotlinx.coroutines.runBlocking
47-
import software.amazon.location.auth.AuthHelper
4847
import javax.inject.Inject
4948

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

7574
private var subTitle = ""
76-
lateinit var authHelper: AuthHelper
7775
val mSignInViewModel: SignInViewModel by viewModels()
7876

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

108-
authHelper = AuthHelper(applicationContext)
109106
val preference = PreferenceManager(applicationContext)
110107
mTrackingUtils = TrackingUtils(preference, this@BaseActivity, mLocationProvider)
111108
mSimulationUtils = SimulationUtils(preference, this@BaseActivity, mLocationProvider)
@@ -127,8 +124,8 @@ open class BaseActivity : AppCompatActivity() {
127124
}
128125

129126
suspend fun initMobileClient() {
130-
mLocationProvider.initializeLocationCredentialsProvider(authHelper, this)
131-
mLocationProvider.initPlaceRoutesClients()
127+
mLocationProvider.initializeLocationCredentialsProvider(this)
128+
mLocationProvider.initPlaceRoutesClients(this)
132129
}
133130

134131
private fun locationPermissionDialog() {
@@ -253,10 +250,10 @@ open class BaseActivity : AppCompatActivity() {
253250

254251
fun restartAppWithClearData() {
255252
lifecycleScope.launch {
256-
mLocationProvider.locationCredentialsProvider?.clear()
253+
mLocationProvider.clearCredentials()
257254
mPreferenceManager.setDefaultConfig()
258255
delay(RESTART_DELAY)
259256
restartApplication()
260257
}
261258
}
262-
}
259+
}

app/src/main/java/com/aws/amazonlocation/ui/main/MainActivity.kt

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ import com.aws.amazonlocation.utils.LANGUAGE_CODE_ARABIC
7979
import com.aws.amazonlocation.utils.LANGUAGE_CODE_HEBREW
8080
import com.aws.amazonlocation.utils.LANGUAGE_CODE_HEBREW_1
8181
import com.aws.amazonlocation.utils.NetworkConnectivityObserveInterface
82-
import com.aws.amazonlocation.utils.PREFS_KEY_IDENTITY_ID
83-
import com.aws.amazonlocation.utils.PREFS_NAME_AUTH
8482
import com.aws.amazonlocation.utils.SETTING_FRAGMENT
8583
import com.aws.amazonlocation.utils.SIGN_IN
8684
import com.aws.amazonlocation.utils.SIGN_OUT
@@ -102,7 +100,6 @@ import kotlinx.coroutines.delay
102100
import kotlinx.coroutines.flow.launchIn
103101
import kotlinx.coroutines.flow.onEach
104102
import kotlinx.coroutines.launch
105-
import software.amazon.location.auth.EncryptedSharedPreferences
106103

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

@@ -122,14 +119,7 @@ class MainActivity :
122119
private var alertDialog: Dialog? = null
123120
private var currentPage: String? = null
124121
private var connectivityObserver: ConnectivityObserveInterface? = null
125-
private var encryptedSharedPreferences: EncryptedSharedPreferences? = null
126122
var analyticsUtils: AnalyticsUtils? = null
127-
private val mServiceName = "geo"
128-
129-
var resultLauncher =
130-
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
131-
checkMap()
132-
}
133123

134124
override fun onConfigurationChanged(newConfig: Configuration) {
135125
super.onConfigurationChanged(newConfig)
@@ -310,13 +300,6 @@ class MainActivity :
310300
}
311301
}
312302
initClick()
313-
if (encryptedSharedPreferences == null) {
314-
encryptedSharedPreferences =
315-
EncryptedSharedPreferences(
316-
applicationContext,
317-
PREFS_NAME_AUTH,
318-
).apply { initEncryptedSharedPreferences() }
319-
}
320303
KeyBoardUtils.attachKeyboardListeners(
321304
mBinding.root,
322305
object : KeyBoardUtils.KeyBoardInterface {
@@ -425,14 +408,14 @@ class MainActivity :
425408
"",
426409
) != AuthEnum.SIGNED_IN.name
427410
) {
428-
mLocationProvider.locationCredentialsProvider?.clear()
411+
mLocationProvider.clearCredentials()
429412
}
430413
mPreferenceManager.setValue(
431414
KEY_CLOUD_FORMATION_STATUS,
432415
AuthEnum.SIGNED_IN.name,
433416
)
434417
mBottomSheetDialog?.dismiss()
435-
async { mLocationProvider.generateNewAuthCredentials(authHelper) }.await()
418+
async { mLocationProvider.generateNewAuthCredentials() }.await()
436419
val fragment = mNavHostFragment.childFragmentManager.fragments[0]
437420
getTokenAndAttachPolicy()
438421
val propertiesAws =
@@ -706,7 +689,7 @@ class MainActivity :
706689
}
707690

708691
private fun setSimulationIotPolicy() {
709-
val identityId = encryptedSharedPreferences?.get(PREFS_KEY_IDENTITY_ID)
692+
val identityId = mLocationProvider.getIdentityId()
710693
CoroutineScope(Dispatchers.IO).launch {
711694
val attachPolicyRequest =
712695
AttachPolicyRequest {
@@ -1252,11 +1235,11 @@ class MainActivity :
12521235
fun initClient(isAfterSignOut:Boolean = false){
12531236
if (!isAfterSignOut) {
12541237
try {
1255-
mLocationProvider.locationCredentialsProvider?.clear()
1238+
mLocationProvider.clearCredentials()
12561239
} catch (_: Exception) { }
12571240
}
12581241
CoroutineScope(Dispatchers.IO).launch {
12591242
async { initMobileClient() }.await()
12601243
}
12611244
}
1262-
}
1245+
}

app/src/main/java/com/aws/amazonlocation/ui/main/explore/ExploreFragment.kt

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import com.aws.amazonlocation.utils.DELAY_300
7878
import com.aws.amazonlocation.utils.DELAY_500
7979
import com.aws.amazonlocation.utils.Distance.DISTANCE_IN_METER_10
8080
import com.aws.amazonlocation.utils.Durations
81+
import com.aws.amazonlocation.utils.Durations.DELAY_FOR_BOTTOM_SHEET_LOAD
8182
import com.aws.amazonlocation.utils.EventType
8283
import com.aws.amazonlocation.utils.EventType.PLACE_SEARCH
8384
import com.aws.amazonlocation.utils.EventType.ROUTE_OPTION_CHANGED
@@ -97,8 +98,6 @@ import com.aws.amazonlocation.utils.LANGUAGE_CODE_HEBREW_1
9798
import com.aws.amazonlocation.utils.MAP_STYLE_ATTRIBUTION
9899
import com.aws.amazonlocation.utils.MILES
99100
import com.aws.amazonlocation.utils.MapHelper
100-
import com.aws.amazonlocation.utils.PREFS_KEY_IDENTITY_ID
101-
import com.aws.amazonlocation.utils.PREFS_NAME_AUTH
102101
import com.aws.amazonlocation.utils.STRING_FORMAT
103102
import com.aws.amazonlocation.utils.SignOutInterface
104103
import com.aws.amazonlocation.utils.SimulationDialogInterface
@@ -124,6 +123,7 @@ import com.aws.amazonlocation.utils.isRunningTest3LiveLocation
124123
import com.aws.amazonlocation.utils.isRunningTestLiveLocation
125124
import com.aws.amazonlocation.utils.locationPermissionDialog
126125
import com.aws.amazonlocation.utils.show
126+
import com.aws.amazonlocation.utils.showKeyboard
127127
import com.aws.amazonlocation.utils.showViews
128128
import com.aws.amazonlocation.utils.simulationExit
129129
import com.aws.amazonlocation.utils.textChanges
@@ -162,7 +162,6 @@ import org.maplibre.android.maps.MapLibreMap
162162
import org.maplibre.android.maps.OnMapReadyCallback
163163
import org.maplibre.geojson.Point
164164
import org.maplibre.geojson.Point.fromLngLat
165-
import software.amazon.location.auth.EncryptedSharedPreferences
166165

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

@@ -211,7 +210,6 @@ class ExploreFragment :
211210
private var mTravelMode: String = RouteTravelMode.Car.value
212211
private var mRouteFinish: Boolean = false
213212
private var mRedirectionType: String? = null
214-
private var encryptedSharedPreferences: EncryptedSharedPreferences?= null
215213

216214
private var gpsActivityResult =
217215
registerForActivityResult(
@@ -726,10 +724,7 @@ class ExploreFragment :
726724
collectionName: String,
727725
position1: List<Double>?,
728726
) {
729-
if (encryptedSharedPreferences == null) {
730-
encryptedSharedPreferences = EncryptedSharedPreferences(requireContext(), PREFS_NAME_AUTH).apply { initEncryptedSharedPreferences() }
731-
}
732-
val identityId = encryptedSharedPreferences?.get(PREFS_KEY_IDENTITY_ID)
727+
val identityId = mLocationProvider.getIdentityId()
733728
identityId?.let {
734729
mSimulationViewModel.evaluateGeofence(
735730
collectionName,
@@ -1143,9 +1138,10 @@ class ExploreFragment :
11431138
}
11441139
} else {
11451140
bottomSheetDirectionSearch.apply {
1146-
clSearchLoaderDirectionSearch.root.show()
1141+
layoutNoDataFound.root.hide()
11471142
rvSearchPlacesSuggestionDirection.hide()
11481143
rvSearchPlacesDirection.hide()
1144+
clSearchLoaderDirectionSearch.root.show()
11491145
}
11501146
}
11511147
}.onSuccess {
@@ -1207,6 +1203,8 @@ class ExploreFragment :
12071203
bottomSheetDirection.apply {
12081204
groupDistanceLoad.show()
12091205
groupDistance.invisible()
1206+
btnDirection.alpha = 0.5F
1207+
btnDirection.isEnabled = false
12101208
}
12111209
}
12121210
} else {
@@ -1218,6 +1216,8 @@ class ExploreFragment :
12181216
if (!mBottomSheetHelper.isDirectionSearchSheetVisible()) {
12191217
bottomSheetDirection.apply {
12201218
groupDistanceLoad.hide()
1219+
btnDirection.alpha = 1.0F
1220+
btnDirection.isEnabled = true
12211221
groupDistance.show()
12221222
tvDirectionError.hide()
12231223
tvDirectionError2.hide()
@@ -1515,6 +1515,8 @@ class ExploreFragment :
15151515
if (!mBottomSheetHelper.isDirectionSearchSheetVisible()) {
15161516
bottomSheetDirection.apply {
15171517
groupDistanceLoad.hide()
1518+
btnDirection.isEnabled = true
1519+
btnDirection.alpha = 1.0F
15181520
groupDistance.show()
15191521
tvDirectionTime.hide()
15201522
tvDirectionDot.invisible()
@@ -2000,8 +2002,8 @@ class ExploreFragment :
20002002
val mText =
20012003
mBinding.bottomSheetSearch.edtSearchPlaces.text
20022004
.toString()
2003-
if (validateLatLng(mText) != null) {
2004-
val mLatLng = validateLatLng(mText)
2005+
if (validateLatLng(mText.trim()) != null) {
2006+
val mLatLng = validateLatLng(mText.trim())
20052007
if (it.text == (mLatLng?.latitude.toString() + "," + mLatLng?.longitude.toString())) {
20062008
setPlaceData(it, searchPlaceIndexText)
20072009
}
@@ -2046,7 +2048,7 @@ class ExploreFragment :
20462048
it: SearchSuggestionResponse,
20472049
searchPlaceIndexText: SearchApiEnum,
20482050
) {
2049-
val mText: String =
2051+
var mText: String =
20502052
if (!isDataSearchForDestination) {
20512053
mBinding.bottomSheetDirectionSearch.edtSearchDirection.text
20522054
.toString()
@@ -2056,6 +2058,10 @@ class ExploreFragment :
20562058
.toString()
20572059
.trim()
20582060
}
2061+
if (validateLatLng(mText) != null) {
2062+
val mLatLng = validateLatLng(mText)
2063+
mText = mLatLng?.latitude.toString() + "," + mLatLng?.longitude.toString()
2064+
}
20592065
if (!it.text.isNullOrEmpty() &&
20602066
it.text
20612067
.toString()
@@ -2111,7 +2117,7 @@ class ExploreFragment :
21112117
if (mPlaceList.isNotEmpty()) {
21122118
clNoInternetConnectionDirectionSearch.hide()
21132119
nsDirectionSearchPlaces.show()
2114-
layoutNoDataFound.groupNoSearchFound.hide()
2120+
layoutNoDataFound.root.hide()
21152121
layoutCardError.groupCardErrorNoSearchFound.hide()
21162122
when (searchPlaceIndexText) {
21172123
SearchApiEnum.SEARCH_PLACE_INDEX_TEXT -> {
@@ -2126,7 +2132,7 @@ class ExploreFragment :
21262132
}
21272133
} else {
21282134
hideViews(rvSearchPlacesDirection, nsDirectionSearchPlaces)
2129-
layoutNoDataFound.groupNoSearchFound.show()
2135+
layoutNoDataFound.root.show()
21302136
}
21312137
}
21322138
}
@@ -2211,7 +2217,17 @@ class ExploreFragment :
22112217
private fun clickListener() {
22122218
mBinding.apply {
22132219
cardGeofenceMap.setOnClickListener {
2214-
(activity as MainActivity).geofenceClick()
2220+
lifecycleScope.launch {
2221+
if (mBottomSheetHelper.isDirectionSearchSheetVisible()) {
2222+
bottomSheetDirectionSearch.ivDirectionCloseDirectionSearch.performClick()
2223+
}
2224+
if (mBottomSheetHelper.isDirectionSheetVisible()) {
2225+
bottomSheetDirection.ivDirectionCloseDirection.performClick()
2226+
}
2227+
(activity as MainActivity).geofenceClick()
2228+
delay(DELAY_FOR_BOTTOM_SHEET_LOAD)
2229+
mBottomSheetHelper.hideSearchBottomSheet(true)
2230+
}
22152231
}
22162232

22172233
cardNavigation.setOnClickListener {
@@ -2806,8 +2822,7 @@ class ExploreFragment :
28062822
lifecycleScope.launch {
28072823
activity?.hideKeyboard()
28082824
delay(DELAY_300)
2809-
mBinding.bottomSheetSearch.clSearchLoaderSearchSheet.root
2810-
.hide()
2825+
mBinding.bottomSheetSearch.clSearchLoaderSearchSheet.root.hide()
28112826
mMapHelper.addLiveLocationMarker(false)
28122827
mBottomSheetHelper.hideDirectionSearchBottomSheet(this@ExploreFragment)
28132828
hideDirectionBottomSheet()
@@ -2816,22 +2831,22 @@ class ExploreFragment :
28162831

28172832
mBinding.bottomSheetDirection.apply {
28182833
btnDirection.setOnClickListener {
2819-
if (checkInternetConnection()) {
2820-
if (activity?.checkLocationPermission() == true) {
2821-
if (isGPSEnabled(requireContext())) {
2822-
if (mViewModel.mCarData?.routes?.get(0)?.legs != null) {
2823-
routeOption()
2824-
} else {
2825-
openDirectionWithError()
2826-
}
2827-
} else {
2828-
mViewModel.mCarData = null
2829-
openDirectionWithError()
2830-
}
2831-
} else {
2832-
mViewModel.mCarData = null
2833-
openDirectionWithError()
2834-
}
2834+
if (!checkInternetConnection()) return@setOnClickListener
2835+
if (cardLoaderSheet1.isVisible) return@setOnClickListener
2836+
if (activity?.checkLocationPermission() != true) {
2837+
mViewModel.mCarData = null
2838+
openDirectionWithError()
2839+
return@setOnClickListener
2840+
}
2841+
if (!isGPSEnabled(requireContext())) {
2842+
mViewModel.mCarData = null
2843+
openDirectionWithError()
2844+
return@setOnClickListener
2845+
}
2846+
if (mViewModel.mCarData?.routes?.get(0)?.legs == null) {
2847+
openDirectionWithError()
2848+
} else {
2849+
routeOption()
28352850
}
28362851
}
28372852
ivInfo.setOnClickListener {
@@ -3104,6 +3119,7 @@ class ExploreFragment :
31043119
mIsAvoidFerries = mPreferenceManager.getValue(KEY_AVOID_FERRIES, false)
31053120
cardDirection.hide()
31063121
bottomSheetDirectionSearch.clSearchLoaderDirectionSearch.root.hide()
3122+
bottomSheetDirectionSearch.layoutNoDataFound.root.hide()
31073123
bottomSheetSearch.edtSearchPlaces.setText("")
31083124
bottomSheetSearch.edtSearchPlaces.clearFocus()
31093125
mBaseActivity?.bottomNavigationVisibility(false)
@@ -3136,6 +3152,10 @@ class ExploreFragment :
31363152
mPlaceList.clear()
31373153
mAdapterDirection?.notifyDataSetChanged()
31383154
mSearchPlacesDirectionSuggestionAdapter?.notifyDataSetChanged()
3155+
if (!edtSearchDest.hasFocus()) {
3156+
edtSearchDirection.requestFocus()
3157+
}
3158+
mBaseActivity?.showKeyboard()
31393159
}
31403160
mBottomSheetHelper.expandDirectionSearchSheet(this@ExploreFragment)
31413161
mIsDirectionSheetHalfExpanded = false
@@ -3902,7 +3922,7 @@ class ExploreFragment :
39023922
tvTruckSelected,
39033923
tvWalkSelected,
39043924
layoutCardError.root,
3905-
layoutNoDataFound.groupNoSearchFound,
3925+
layoutNoDataFound.root,
39063926
)
39073927
}
39083928
mBinding.bottomSheetDirection.apply {

0 commit comments

Comments
 (0)