1
1
package com.aws.amazonlocation.ui.main
2
2
3
3
import android.annotation.SuppressLint
4
+ import android.app.AlertDialog
4
5
import android.app.Dialog
5
6
import android.content.pm.ActivityInfo
6
7
import android.content.res.Configuration
@@ -14,7 +15,6 @@ import android.webkit.WebResourceRequest
14
15
import android.webkit.WebView
15
16
import android.webkit.WebViewClient
16
17
import androidx.activity.OnBackPressedCallback
17
- import androidx.activity.result.contract.ActivityResultContracts
18
18
import androidx.constraintlayout.widget.ConstraintSet
19
19
import androidx.core.content.ContextCompat
20
20
import androidx.fragment.app.Fragment
@@ -85,14 +85,17 @@ import com.aws.amazonlocation.utils.SIGN_OUT
85
85
import com.aws.amazonlocation.utils.Units.checkInternetConnection
86
86
import com.aws.amazonlocation.utils.VERSION_FRAGMENT
87
87
import com.aws.amazonlocation.utils.analytics.AnalyticsUtils
88
+ import com.aws.amazonlocation.utils.analyticsFields
88
89
import com.aws.amazonlocation.utils.getLanguageCode
89
90
import com.aws.amazonlocation.utils.hide
90
91
import com.aws.amazonlocation.utils.hideViews
91
92
import com.aws.amazonlocation.utils.invisible
92
93
import com.aws.amazonlocation.utils.makeTransparentStatusBar
94
+ import com.aws.amazonlocation.utils.requiredFields
93
95
import com.aws.amazonlocation.utils.setLocale
94
96
import com.aws.amazonlocation.utils.show
95
97
import com.aws.amazonlocation.utils.showViews
98
+ import com.aws.amazonlocation.utils.simulationFields
96
99
import kotlinx.coroutines.CoroutineScope
97
100
import kotlinx.coroutines.Dispatchers
98
101
import kotlinx.coroutines.async
@@ -642,6 +645,7 @@ class MainActivity :
642
645
var mRegion = mPreferenceManager.getValue(KEY_USER_REGION , " " )
643
646
644
647
if (mRegion.isNullOrEmpty()) {
648
+ if (BuildConfig .DEFAULT_REGION == " null" ) return @launch
645
649
mRegion = BuildConfig .DEFAULT_REGION
646
650
}
647
651
val iotClient =
@@ -690,6 +694,7 @@ class MainActivity :
690
694
691
695
private fun setSimulationIotPolicy () {
692
696
val identityId = mLocationProvider.getIdentityId()
697
+ if (identityId.isNullOrEmpty()) return
693
698
CoroutineScope (Dispatchers .IO ).launch {
694
699
val attachPolicyRequest =
695
700
AttachPolicyRequest {
@@ -699,7 +704,7 @@ class MainActivity :
699
704
700
705
val iotClient =
701
706
IotClient {
702
- region = identityId? .split(" :" )?.get( 0 )
707
+ region = identityId.split(" :" )[ 0 ]
703
708
credentialsProvider =
704
709
createCredentialsProviderForPolicy(
705
710
mLocationProvider.getCredentials(),
@@ -934,7 +939,7 @@ class MainActivity :
934
939
mBinding.imgAmazonLogo?.setImageResource(logoResId)
935
940
}
936
941
937
- fun setExplorer () {
942
+ private fun setExplorer () {
938
943
val fragment = mNavHostFragment.childFragmentManager.fragments[0 ]
939
944
if (fragment !is ExploreFragment ) {
940
945
mNavController.navigate(R .id.explore_fragment)
@@ -998,7 +1003,6 @@ class MainActivity :
998
1003
mTrackingUtils?.hideTrackingBottomSheet()
999
1004
mSimulationUtils?.showSimulationBottomSheet()
1000
1005
if (mNavHostFragment.childFragmentManager.fragments.isNotEmpty()) {
1001
- val fragment = mNavHostFragment.childFragmentManager.fragments[0 ]
1002
1006
if (fragment is ExploreFragment ) {
1003
1007
if (isTablet) {
1004
1008
fragment.hideDirectionAndCurrentLocationIcon()
@@ -1200,7 +1204,64 @@ class MainActivity :
1200
1204
}
1201
1205
}
1202
1206
1203
- fun setWelcomeToExplorer () {
1207
+ fun checkPropertiesData () {
1208
+ val missingRequiredFields = requiredFields.filter { it.value == " null" }.keys
1209
+ val simulationMissingFields = simulationFields.filter { it.value == " null" }.keys
1210
+ val analyticsMissingFields = analyticsFields.filter { it.value == " null" }.keys
1211
+
1212
+ if (missingRequiredFields.isNotEmpty() || simulationMissingFields.isNotEmpty() || analyticsMissingFields.isNotEmpty()) {
1213
+ val dialogMessage = buildString {
1214
+ when {
1215
+ missingRequiredFields.isNotEmpty() -> {
1216
+ append(getString(R .string.label_required_fields_missing))
1217
+ append(" \n " )
1218
+ missingRequiredFields.forEach { append(" • $it \n " ) }
1219
+ simulationMissingFields.forEach { append(" • $it \n " ) }
1220
+ analyticsMissingFields.forEach { append(" • $it \n " ) }
1221
+ }
1222
+ simulationMissingFields.isNotEmpty() && analyticsMissingFields.isNotEmpty() -> {
1223
+ append(getString(R .string.label_some_fields_missing))
1224
+ append(" \n " )
1225
+ simulationMissingFields.forEach { append(" • $it \n " ) }
1226
+ analyticsMissingFields.forEach { append(" • $it \n " ) }
1227
+ }
1228
+ simulationMissingFields.isNotEmpty() -> {
1229
+ append(getString(R .string.label_simulation_fields_missing))
1230
+ append(" \n " )
1231
+ simulationMissingFields.forEach { append(" • $it \n " ) }
1232
+ }
1233
+ analyticsMissingFields.isNotEmpty() -> {
1234
+ append(getString(R .string.label_analytics_fields_missing))
1235
+ append(" \n " )
1236
+ analyticsMissingFields.forEach { append(" • $it \n " ) }
1237
+ }
1238
+ }
1239
+ }
1240
+
1241
+ val dialogTitle = getString(R .string.title_configuration_incomplete)
1242
+ val positiveButtonText = if (missingRequiredFields.isNotEmpty()) {
1243
+ getString(R .string.ok)
1244
+ } else {
1245
+ getString(R .string.label_continue)
1246
+ }
1247
+
1248
+ AlertDialog
1249
+ .Builder (this )
1250
+ .setTitle(dialogTitle)
1251
+ .setMessage(dialogMessage)
1252
+ .setPositiveButton(positiveButtonText) { _, _ ->
1253
+ if (missingRequiredFields.isNotEmpty()) {
1254
+ finish()
1255
+ } else {
1256
+ setWelcomeToExplorer()
1257
+ }
1258
+ }.setCancelable(false ).show()
1259
+ } else {
1260
+ setWelcomeToExplorer()
1261
+ }
1262
+ }
1263
+
1264
+ private fun setWelcomeToExplorer () {
1204
1265
mPreferenceManager.setValue(IS_APP_FIRST_TIME_OPENED , true )
1205
1266
isAppNotFirstOpened = true
1206
1267
val fragment =
@@ -1232,11 +1293,12 @@ class MainActivity :
1232
1293
}
1233
1294
}
1234
1295
1235
- fun initClient (isAfterSignOut : Boolean = false){
1296
+ fun initClient (isAfterSignOut : Boolean = false) {
1236
1297
if (! isAfterSignOut) {
1237
1298
try {
1238
1299
mLocationProvider.clearCredentials()
1239
- } catch (_: Exception ) { }
1300
+ } catch (_: Exception ) {
1301
+ }
1240
1302
}
1241
1303
CoroutineScope (Dispatchers .IO ).launch {
1242
1304
async { initMobileClient() }.await()
0 commit comments