Skip to content

Commit

Permalink
V2 bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shah272728 committed Oct 16, 2023
1 parent 1be41f6 commit 0d6bc18
Show file tree
Hide file tree
Showing 23 changed files with 133 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.aws.amazonlocation.utils.KEY_USER_DETAILS
import com.aws.amazonlocation.utils.LatencyChecker
import com.aws.amazonlocation.utils.PreferenceManager
import com.aws.amazonlocation.utils.RESTART_DELAY
import com.aws.amazonlocation.utils.Units
import com.aws.amazonlocation.utils.regionList
import com.aws.amazonlocation.utils.restartApplication
import com.google.android.material.snackbar.Snackbar
Expand Down Expand Up @@ -106,7 +107,9 @@ open class BaseActivity : AppCompatActivity() {
mGeofenceUtils = GeofenceUtils()

val preference = PreferenceManager(this)
mAWSLocationHelper.initAWSMobileClient(this@BaseActivity)
if (Units.checkInternetConnection(applicationContext)) {
initMobileClient()
}
mTrackingUtils = TrackingUtils(preference, this@BaseActivity, mAWSLocationHelper)
mSimulationUtils = SimulationUtils(preference, this@BaseActivity, mAWSLocationHelper)
locationPermissionDialog()
Expand All @@ -123,6 +126,11 @@ open class BaseActivity : AppCompatActivity() {
snackBar.show()
}

fun initMobileClient() {
if (!mAWSLocationHelper.checkClientInitialize()) {
mAWSLocationHelper.initAWSMobileClient(this@BaseActivity)
}
}
private fun locationPermissionDialog() {
val dialogBuilder = AlertDialog.Builder(this, R.style.MyDialogTheme)
dialogBuilder.setMessage(resources.getString(R.string.location_permission_is_required))
Expand Down
31 changes: 28 additions & 3 deletions app/src/main/java/com/aws/amazonlocation/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ import com.aws.amazonlocation.ui.main.simulation.SimulationUtils
import com.aws.amazonlocation.ui.main.welcome.WelcomeBottomSheetFragment
import com.aws.amazonlocation.utils.*
import com.aws.amazonlocation.utils.Durations.DELAY_FOR_FRAGMENT_LOAD
import com.aws.amazonlocation.utils.Units.checkInternetConnection
import java.util.Date
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand All @@ -72,6 +77,7 @@ class MainActivity : BaseActivity(), CrashListener {
private var mBottomSheetDialog: Dialog? = null
private var alertDialog: Dialog? = null
private var currentPage: String? = null
private var connectivityObserver: ConnectivityObserveInterface? = null
var resultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
checkMap()
Expand Down Expand Up @@ -230,8 +236,25 @@ class MainActivity : BaseActivity(), CrashListener {
val languageCode = getLanguageCode()
languageCode?.let { setLocale(it, applicationContext) }
}
checkInternetObserver()
}

private fun checkInternetObserver() {
connectivityObserver = NetworkConnectivityObserveInterface(applicationContext)
connectivityObserver?.observer()?.onEach {
when (it) {
ConnectivityObserveInterface.ConnectionStatus.Available -> {
initMobileClient()
}
ConnectivityObserveInterface.ConnectionStatus.Lost -> {
}
ConnectivityObserveInterface.ConnectionStatus.Unavailable -> {
}
else -> {
}
}
}?.launchIn(CoroutineScope(Dispatchers.Main))
}
// check rtl layout
private fun checkRtl() {
if (isTablet) {
Expand Down Expand Up @@ -657,9 +680,11 @@ class MainActivity : BaseActivity(), CrashListener {
mBottomSheetHelper.hideMapStyleSheet()
}
showSimulationTop()
if (!isSimulationPolicyAttached) {
lifecycleScope.launch {
setSimulationIotPolicy()
if (checkInternetConnection(applicationContext)) {
if (!isSimulationPolicyAttached) {
lifecycleScope.launch {
setSimulationIotPolicy()
}
}
}
mGeofenceUtils?.hideAllGeofenceBottomSheet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,10 @@ class ExploreFragment :
}

cardMap.setOnClickListener {
if (SystemClock.elapsedRealtime() - mLastClickTime < CLICK_TIME_DIFFERENCE) {
return@setOnClickListener
}
mLastClickTime = SystemClock.elapsedRealtime()
mBaseActivity?.isTablet?.let { it1 ->
if (it1) {
mapStyleBottomSheetFragment =
Expand Down Expand Up @@ -2578,7 +2582,7 @@ class ExploreFragment :
}
activity?.hideKeyboard()
lifecycleScope.launch {
delay(DELAY_500)
delay(CLICK_DEBOUNCE)
mIsSwapClicked = false
}
}
Expand Down Expand Up @@ -2631,7 +2635,12 @@ class ExploreFragment :
if (text?.trim().toString().lowercase() == getString(R.string.label_my_location).trim().lowercase()) {
return@onEach
}
if (mBottomSheetHelper.isDirectionSearchSheetVisible() && !mIsDirectionDataSet && !mIsSwapClicked && mViewModel.mIsPlaceSuggestion && !text.isNullOrEmpty()) {
if (text.isNullOrEmpty()) {
mViewModel.mSearchDirectionDestinationData = null
hideViews(cardRoutingOption, cardMapOption, cardListRoutesOption, layoutCardError.root, clDriveLoader, clWalkLoader, clTruckLoader)
return@onEach
}
if (mBottomSheetHelper.isDirectionSearchSheetVisible() && !mIsDirectionDataSet && !mIsSwapClicked && mViewModel.mIsPlaceSuggestion) {
cardRouteOptionHide()
clearMapLineMarker()
mViewModel.mSearchDirectionDestinationData = null
Expand All @@ -2652,7 +2661,12 @@ class ExploreFragment :
if (text?.trim().toString().lowercase() == getString(R.string.label_my_location).trim().lowercase()) {
return@onEach
}
if (mBottomSheetHelper.isDirectionSearchSheetVisible() && !mIsDirectionDataSetNew && !mIsSwapClicked && !mIsDirectionDataSet && mViewModel.mIsPlaceSuggestion && !text.isNullOrEmpty()) {
if (text.isNullOrEmpty()) {
mViewModel.mSearchDirectionOriginData = null
hideViews(cardRoutingOption, cardMapOption, cardListRoutesOption, layoutCardError.root, clDriveLoader, clWalkLoader, clTruckLoader)
return@onEach
}
if (mBottomSheetHelper.isDirectionSearchSheetVisible() && !mIsDirectionDataSetNew && !mIsSwapClicked && !mIsDirectionDataSet && mViewModel.mIsPlaceSuggestion) {
cardRouteOptionHide()
clearMapLineMarker()
mViewModel.mSearchDirectionOriginData = null
Expand Down Expand Up @@ -2788,8 +2802,13 @@ class ExploreFragment :

bottomSheetDirectionSearch.edtSearchDest.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
notifyAdapters()
mViewModel.searchPlaceIndexForText(bottomSheetDirectionSearch.edtSearchDest.text.toString())
if (checkInternetConnection() && bottomSheetDirectionSearch.edtSearchDest.text.toString().trim().isNotEmpty()) {
mBinding.bottomSheetDirectionSearch.apply {
clNoInternetConnectionDirectionSearch.hide()
}
notifyAdapters()
mViewModel.searchPlaceIndexForText(bottomSheetDirectionSearch.edtSearchDest.text.toString())
}
true
} else {
false
Expand Down Expand Up @@ -3614,7 +3633,7 @@ class ExploreFragment :
if (isMetric) {
showError(getString(R.string.error_distance_400))
} else {
showError(String.format(getString(R.string.error_distance_248_miles), getFormatter()?.format(248.5)))
showError(String.format(getString(R.string.error_distance_248_miles), getFormatter()?.format(248.5), getFormatter()?.format(24.85)))
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.aws.amazonlocation.utils.SOURCE
import com.aws.amazonlocation.utils.SOURCE_SIMULATION_ICON
import com.aws.amazonlocation.utils.TRACKER
import com.aws.amazonlocation.utils.Units
import com.aws.amazonlocation.utils.Units.checkInternetConnection
import com.aws.amazonlocation.utils.Units.getSimulationWebSocketUrl
import com.aws.amazonlocation.utils.Units.readRouteData
import com.aws.amazonlocation.utils.geofence_helper.turf.TurfConstants
Expand Down Expand Up @@ -158,7 +159,11 @@ class SimulationUtils(
mBottomSheetSimulationBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED
}
}
simulationInterface?.getGeofenceList()
mActivity?.let {
if (checkInternetConnection(it.applicationContext)) {
simulationInterface?.getGeofenceList()
}
}
setBounds()
mFragmentActivity?.applicationContext?.let { context ->
notificationHelper = NotificationHelper(context)
Expand Down Expand Up @@ -405,7 +410,11 @@ class SimulationUtils(
val position = arrayListOf<Double>()
position.add(latLng.longitude)
position.add(latLng.latitude)
simulationInterface?.evaluateGeofence(simulationCollectionName[busIndex], position)
mActivity?.let {
if (checkInternetConnection(it.applicationContext)) {
simulationInterface?.evaluateGeofence(simulationCollectionName[busIndex], position)
}
}

mMapHelper?.startAnimation(latLng, busIndex)
delay(DELAY_1000)
Expand Down Expand Up @@ -708,7 +717,14 @@ class SimulationUtils(
viewLoader.show()
tvStopTracking.hide()
cardStartTracking.isEnabled = false
startMqttManager()
mActivity?.let {
if (checkInternetConnection(it.applicationContext)) {
startMqttManager()
} else {
mIsLocationUpdateEnable = true
startTracking()
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class AWSLocationHelper(
mBaseActivity = baseActivity
}

fun checkClientInitialize() :Boolean {
return mClient != null
}

fun initCognitoCachingCredentialsProvider(): CognitoCredentialsProvider? {
val idToken = mPreferenceManager.getValue(KEY_ID_TOKEN, "")
var identityPoolId = mPreferenceManager.getValue(KEY_POOL_ID, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class BottomSheetHelper {
view.ivAmazonInfoSearchSheet.alpha = 0f
isSearchSheetOpen = true
view.tvSearchCancel?.show()
view.edtSearchPlaces.requestFocus()
activity.showKeyboard()
}
BottomSheetBehavior.STATE_DRAGGING -> {
}
Expand Down Expand Up @@ -252,6 +254,10 @@ class BottomSheetHelper {
mBaseActivity?.bottomNavigationVisibility(false)
view.imgAmazonLogoDirectionSearchSheet.alpha = 0f
view.ivAmazonInfoDirectionSearchSheet.alpha = 0f
if (!view.edtSearchDest.hasFocus()) {
view.edtSearchDirection.requestFocus()
}
mBaseActivity?.showKeyboard()
}
BottomSheetBehavior.STATE_DRAGGING -> {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const val DELAY_300 = 300L
const val DELAY_1000 = 1000L
const val DELAY_SIMULATION_2000 = 2000L
const val DELAY_LANGUAGE_3000 = 3000L
const val CLICK_TIME_DIFFERENCE = 1500
const val KEY_AVOID_TOLLS = "Avoid Tolls"
const val KEY_AVOID_FERRIES = "Avoid Ferries"
const val AWS_CLOUD_INFORMATION_FRAGMENT = "AwsCloudInformationFragment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ fun EditText.textChanges(): Flow<CharSequence?> {
}.onStart { emit(text) }
}

fun Activity.showKeyboard() {
val imm: InputMethodManager =
getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
var view = currentFocus
if (view == null) view = View(this)
imm.showSoftInput(view, 0)
}

// hide the keyboard
fun Activity.hideKeyboard() {
val imm: InputMethodManager =
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/aws/amazonlocation/utils/Units.kt
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,8 @@ object Units {

return sanitizedUrl
}

fun checkInternetConnection(context: Context): Boolean {
return context.isInternetAvailable()
}
}
6 changes: 3 additions & 3 deletions app/src/main/res/layout/bottom_sheet_direction_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_swap_location"
android:layout_width="@dimen/dp_22"
android:layout_height="@dimen/dp_22"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:src="@drawable/ic_switch"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down Expand Up @@ -301,7 +301,7 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

<com.google.android.material.card.MaterialCardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_list_routes_option"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-ar/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
<string name="no_route_found">لا طريق وجد</string>
<string name="error_switch_to_here">مسافة هو أعظم من 400 كم، لا أستطيع حساب بواسطة إسري، يرجى مفتاح كهربائي إلى هنا مزود</string>
<string name="error_switch_to_here_miles">مسافة هو أعظم من %s مي، لا أستطيع حساب بواسطة إسري، يرجى مفتاح كهربائي إلى هنا مزود</string>
<string name="error_distance_400">في مصدر البيانات إسري، جميع نقاط الطريق ضرورة هو داخل 400 كم.</string>
<string name="error_distance_248_miles">في مصدر البيانات إسري، جميع نقاط الطريق ضرورة هو داخل %sim.</string>
<string name="error_distance_400">في مصدر البيانات إسري، نقاط الطريق من أجل سيارة و شاحنة ضرورة هو داخل 400 كم، و نقاط الطريق من أجل مشي ضرورة هو داخل 40 كم.</string>
<string name="error_distance_248_miles">في مصدر البيانات إسري، نقاط الطريق من أجل سيارة و شاحنة ضرورة هو داخل %sim، و نقاط الطريق من أجل مشي ضرورة هو داخل %sim.</string>
<string name="connect_to_aws_account">قم بالاتصال الخدمات اللاسلكية المتقدمة الحساب</string>
<string name="label_preview">استطلاع</string>
<string name="label_location_permission_denied">الموقع تصريح تم رفضه</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-de/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
<string name="no_route_found">Nein Route gefunden</string>
<string name="error_switch_to_here">Entfernung ist größer als 400 km, kann\nicht berechnen über Esri, freundlich Schalter zu HIER Anbieter</string>
<string name="error_switch_to_here_miles">Entfernung ist größer als %s mi, kann\nicht berechnen über Esri, freundlich Schalter zu HIER Anbieter</string>
<string name="error_distance_400">In Datenquelle Esri, alles Wegpunkte Muss Sein innerhalb 400 km.</string>
<string name="error_distance_248_miles">In Datenquelle Esri, alles Wegpunkte Muss Sein innerhalb %smi.</string>
<string name="error_distance_400">In Datenquelle Esri, Wegpunkte zum Auto und lkw Muss Sein innerhalb 400 km, und Wegpunkte zum gehen Muss Sein innerhalb 40 km.</string>
<string name="error_distance_248_miles">In Datenquelle Esri, Wegpunkte zum Auto und lkw Muss Sein innerhalb %smi, und Wegpunkte zum gehen Muss Sein innerhalb %smi.</string>
<string name="connect_to_aws_account">Verbinden AWS Konto</string>
<string name="label_preview">Vorschau</string>
<string name="label_location_permission_denied">Standort Genehmigung verweigert</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-es/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
<string name="no_route_found">No ruta encontrado</string>
<string name="error_switch_to_here">Distancia es mayor que 400 km, no puedo calcular vía Esri, amablemente cambiar a AQUÍ proveedora</string>
<string name="error_switch_to_here_miles">Distancia es mayor que %s mi, no puedo calcular vía Esri, amablemente cambiar a AQUÍ proveedora</string>
<string name="error_distance_400">En Fuente de datos Esri, todo puntos de referencia mosto estar dentro 400 km.</string>
<string name="error_distance_248_miles">En Fuente de datos Esri, todo puntos de referencia mosto estar dentro %smi.</string>
<string name="error_distance_400">En Fuente de datos Esri, puntos de referencia por coche y camión mosto estar dentro 400 km, y puntos de referencia por camina mosto estar dentro 40 km.</string>
<string name="error_distance_248_miles">En Fuente de datos Esri, puntos de referencia por coche y camión mosto estar dentro %smi, y puntos de referencia por camina mosto estar dentro %smi.</string>
<string name="connect_to_aws_account">Conéctate AWS Cuenta</string>
<string name="label_preview">Vista previa</string>
<string name="label_location_permission_denied">Ubicación permiso denegado</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-fr/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
<string name="no_route_found">Non route trouvé</string>
<string name="error_switch_to_here">Distance est plus grand que 400 km, ne peut pas calculer via Esri, gentiment interrupteur pour ICI fournisseur</string>
<string name="error_switch_to_here_miles">Distance est plus grand que %s mi, ne peut pas calculer via Esri, gentiment interrupteur pour ICI fournisseur</string>
<string name="error_distance_400">Dans Source de données Esri, tous points de cheminement doit être dans 400 km.</string>
<string name="error_distance_248_miles">Dans Source de données Esri, tous points de cheminement doit être dans %smi.</string>
<string name="error_distance_400">Dans Source de données Esri, points de cheminement pour voiture et un camion doit être dans 400 km, et points de cheminement pour marche doit être dans 40 km.</string>
<string name="error_distance_248_miles">Dans Source de données Esri, points de cheminement pour voiture et un camion doit être dans %smi, et points de cheminement pour marche doit être dans %smi.</string>
<string name="connect_to_aws_account">Connecter AWS Compte</string>
<string name="label_preview">Aperçu</string>
<string name="label_location_permission_denied">Emplacement autorisation nié</string>
Expand Down
Loading

0 comments on commit 0d6bc18

Please sign in to comment.