Skip to content

Commit ea67d9e

Browse files
authored
Merge pull request #118 from HLCaptain/mapbox-upgrade
Mapbox upgrade
2 parents 2e8317f + 42b349d commit ea67d9e

File tree

15 files changed

+300
-206
lines changed

15 files changed

+300
-206
lines changed

app/build.gradle.kts

+59-54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Balázs Püspök-Kiss (Illyan)
2+
* Copyright (c) 2022-2024 Balázs Püspök-Kiss (Illyan)
33
*
44
* Jay is a driver behaviour analytics app.
55
*
@@ -16,25 +16,7 @@
1616
* If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import com.google.android.libraries.mapsplatform.secrets_gradle_plugin.loadPropertiesFile
20-
21-
/*
22-
* Copyright (c) 2022-2023 Balázs Püspök-Kiss (Illyan)
23-
*
24-
* Jay is a driver behaviour analytics app.
25-
*
26-
* This file is part of Jay.
27-
*
28-
* Jay is free software: you can redistribute it and/or modify it under the
29-
* terms of the GNU General Public License as published by the Free Software
30-
* Foundation, either version 3 of the License, or (at your option) any later version.
31-
* Jay is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
32-
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
33-
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
34-
*
35-
* You should have received a copy of the GNU General Public License along with Jay.
36-
* If not, see <https://www.gnu.org/licenses/>.
37-
*/
19+
import org.jetbrains.kotlin.konan.properties.loadProperties
3820

3921
plugins {
4022
alias(libs.plugins.android.application)
@@ -52,6 +34,8 @@ plugins {
5234
alias(libs.plugins.compose.compiler)
5335
}
5436

37+
val localProperties = loadProperties("$projectDir/../local.properties")
38+
5539
android {
5640
compileSdk = 35
5741

@@ -61,54 +45,30 @@ android {
6145
applicationId = "illyan.jay"
6246
minSdk = 23
6347
targetSdk = 35
64-
versionCode = 18
65-
versionName = "0.4.0-alpha"
48+
versionCode = 19
49+
versionName = "0.4.1-alpha"
6650

6751
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
6852
vectorDrawables {
6953
useSupportLibrary = true
7054
}
7155
}
7256

73-
buildTypes {
74-
val mapboxAccessToken = properties["MAPBOX_ACCESS_TOKEN"].toString()
75-
val mapboxDownloadsToken = properties["MAPBOX_DOWNLOADS_TOKEN"].toString()
76-
val mapboxSdkRegistryToken = properties["SDK_REGISTRY_TOKEN"].toString()
77-
getByName("debug") {
78-
isDebuggable = true
79-
buildConfigField("String", "MapboxAccessToken", "\"$mapboxAccessToken\"")
80-
buildConfigField("String", "MapboxDownloadsToken", "\"$mapboxDownloadsToken\"")
81-
buildConfigField("String", "MapboxSdkRegistryToken", "\"$mapboxSdkRegistryToken\"")
82-
}
83-
getByName("release") {
84-
initWith(getByName("debug"))
85-
isDebuggable = false
86-
isMinifyEnabled = true
87-
isShrinkResources = true
88-
proguardFiles(
89-
getDefaultProguardFile("proguard-android-optimize.txt"),
90-
"proguard-rules.pro"
91-
)
92-
}
93-
}
94-
9557
signingConfigs {
96-
val properties = loadPropertiesFile("../local.properties").toMap()
97-
98-
val debugStorePath = properties["DEBUG_KEY_PATH"].toString()
99-
val debugKeyAlias = properties["DEBUG_KEY_ALIAS"].toString()
100-
val debugStorePassword = properties["DEBUG_KEYSTORE_PASSWORD"].toString()
101-
val debugKeyPassword = properties["DEBUG_KEY_PASSWORD"].toString()
58+
val debugStorePath = localProperties["DEBUG_KEY_PATH"].toString()
59+
val debugKeyAlias = localProperties["DEBUG_KEY_ALIAS"].toString()
60+
val debugStorePassword = localProperties["DEBUG_KEYSTORE_PASSWORD"].toString()
61+
val debugKeyPassword = localProperties["DEBUG_KEY_PASSWORD"].toString()
10262
getByName("debug") {
10363
storeFile = file(debugStorePath)
10464
keyAlias = debugKeyAlias
10565
storePassword = debugStorePassword
10666
keyPassword = debugKeyPassword
10767
}
108-
val releaseStorePath = properties["RELEASE_KEY_PATH"].toString()
109-
val releaseKeyAlias = properties["RELEASE_KEY_ALIAS"].toString()
110-
val releaseStorePassword = properties["RELEASE_KEYSTORE_PASSWORD"].toString()
111-
val releaseKeyPassword = properties["RELEASE_KEY_PASSWORD"].toString()
68+
val releaseStorePath = localProperties["RELEASE_KEY_PATH"].toString()
69+
val releaseKeyAlias = localProperties["RELEASE_KEY_ALIAS"].toString()
70+
val releaseStorePassword = localProperties["RELEASE_KEYSTORE_PASSWORD"].toString()
71+
val releaseKeyPassword = localProperties["RELEASE_KEY_PASSWORD"].toString()
11272
create("release") {
11373
storeFile = file(releaseStorePath)
11474
keyAlias = releaseKeyAlias
@@ -117,6 +77,32 @@ android {
11777
}
11878
}
11979

80+
buildTypes {
81+
val mapboxAccessToken = localProperties["MAPBOX_ACCESS_TOKEN"].toString()
82+
val mapboxDownloadsToken = localProperties["MAPBOX_DOWNLOADS_TOKEN"].toString()
83+
val mapboxSdkRegistryToken = localProperties["SDK_REGISTRY_TOKEN"].toString()
84+
val admobAppId = localProperties["ADMOB_APPLICATION_ID"].toString()
85+
getByName("debug") {
86+
isDebuggable = true
87+
buildConfigField("String", "MAPBOX_ACCESS_TOKEN", "\"$mapboxAccessToken\"")
88+
buildConfigField("String", "MAPBOX_DOWNLOADS_TOKEN", "\"$mapboxDownloadsToken\"")
89+
buildConfigField("String", "SDK_REGISTRY_TOKEN", "\"$mapboxSdkRegistryToken\"")
90+
buildConfigField("String", "ADMOB_APPLICATION_ID", "\"$admobAppId\"")
91+
}
92+
getByName("release") {
93+
isDebuggable = false
94+
isMinifyEnabled = true
95+
isShrinkResources = true
96+
buildConfigField("String", "MAPBOX_ACCESS_TOKEN", "\"$mapboxAccessToken\"")
97+
buildConfigField("String", "ADMOB_APPLICATION_ID", "\"$admobAppId\"")
98+
proguardFiles(
99+
getDefaultProguardFile("proguard-android-optimize.txt"),
100+
"proguard-rules.pro"
101+
)
102+
signingConfig = signingConfigs.getByName("release")
103+
}
104+
}
105+
120106
compileOptions {
121107
sourceCompatibility = JavaVersion.VERSION_17
122108
targetCompatibility = JavaVersion.VERSION_17
@@ -291,3 +277,22 @@ hilt {
291277
room {
292278
schemaDirectory("$projectDir/schemas")
293279
}
280+
281+
secrets {
282+
// Ignore everything, except ADMOB_APPLICATION_ID for AndroidManifest.xml
283+
ignoreList.addAll(
284+
listOf(
285+
"RELEASE_KEYSTORE_PASSWORD*",
286+
"RELEASE_KEY_PASSWORD*",
287+
"RELEASE_KEY_ALIAS*",
288+
"RELEASE_KEY_PATH*",
289+
"DEBUG_KEYSTORE_PASSWORD*",
290+
"DEBUG_KEY_PASSWORD*",
291+
"DEBUG_KEY_ALIAS*",
292+
"DEBUG_KEY_PATH*",
293+
"MAPBOX_DOWNLOADS_TOKEN*",
294+
"SDK_REGISTRY_TOKEN*",
295+
"MAPBOX_ACCESS_TOKEN*"
296+
)
297+
)
298+
}

app/src/main/java/illyan/jay/MainActivity.kt

+46-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022-2023 Balázs Püspök-Kiss (Illyan)
2+
* Copyright (c) 2022-2024 Balázs Püspök-Kiss (Illyan)
33
*
44
* Jay is a driver behaviour analytics app.
55
*
@@ -26,16 +26,28 @@ import androidx.activity.result.contract.ActivityResultContracts
2626
import androidx.appcompat.app.AppCompatActivity
2727
import androidx.compose.foundation.layout.fillMaxSize
2828
import androidx.compose.runtime.Composable
29+
import androidx.compose.runtime.CompositionLocalProvider
30+
import androidx.compose.runtime.LaunchedEffect
31+
import androidx.compose.runtime.compositionLocalOf
32+
import androidx.compose.runtime.getValue
33+
import androidx.compose.runtime.mutableStateOf
34+
import androidx.compose.runtime.saveable.rememberSaveable
35+
import androidx.compose.runtime.setValue
2936
import androidx.compose.ui.Modifier
37+
import androidx.lifecycle.DefaultLifecycleObserver
38+
import androidx.lifecycle.LifecycleOwner
3039
import com.google.android.gms.auth.api.signin.GoogleSignIn
3140
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
3241
import com.google.android.gms.tasks.Task
42+
import com.mapbox.navigation.base.options.NavigationOptions
43+
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
3344
import com.ramcosta.composedestinations.DestinationsNavHost
3445
import dagger.hilt.android.AndroidEntryPoint
3546
import illyan.jay.domain.interactor.AuthInteractor
3647
import illyan.jay.ui.NavGraphs
3748
import illyan.jay.ui.components.PreviewAccessibility
3849
import illyan.jay.ui.theme.JayThemeWithViewModel
50+
import illyan.jay.util.MapboxExceptionHandler
3951
import javax.inject.Inject
4052

4153
@AndroidEntryPoint
@@ -45,6 +57,19 @@ class MainActivity : AppCompatActivity() {
4557
lateinit var authInteractor: AuthInteractor
4658

4759
lateinit var googleSignInLauncher: ActivityResultLauncher<Intent>
60+
61+
init {
62+
lifecycle.addObserver(object : DefaultLifecycleObserver {
63+
override fun onResume(owner: LifecycleOwner) {
64+
MapboxNavigationApp.attach(owner)
65+
}
66+
67+
override fun onPause(owner: LifecycleOwner) {
68+
MapboxNavigationApp.detach(owner)
69+
}
70+
})
71+
}
72+
4873
override fun onCreate(savedInstanceState: Bundle?) {
4974
super.onCreate(savedInstanceState)
5075

@@ -55,16 +80,33 @@ class MainActivity : AppCompatActivity() {
5580
authInteractor.handleGoogleSignInResult(this, task)
5681
}
5782

83+
if (!MapboxNavigationApp.isSetup()) {
84+
MapboxNavigationApp.setup {
85+
NavigationOptions.Builder(applicationContext).build()
86+
}
87+
}
88+
89+
val mapboxExceptionHandler = MapboxExceptionHandler()
90+
Thread.setDefaultUncaughtExceptionHandler(mapboxExceptionHandler)
91+
5892
setContent {
93+
var mapboxMapViewNotSupported by rememberSaveable { mutableStateOf(false) }
94+
LaunchedEffect(Unit) {
95+
mapboxExceptionHandler.openGlNotSupportedCallback = {
96+
mapboxMapViewNotSupported = true
97+
}
98+
}
5999
JayThemeWithViewModel {
60-
MainScreen(
61-
modifier = Modifier.fillMaxSize()
62-
)
100+
CompositionLocalProvider(LocalMapboxNotSupported provides mapboxMapViewNotSupported) {
101+
MainScreen(modifier = Modifier.fillMaxSize())
102+
}
63103
}
64104
}
65105
}
66106
}
67107

108+
val LocalMapboxNotSupported = compositionLocalOf { false }
109+
68110
@PreviewAccessibility
69111
@Composable
70112
fun MainScreen(

app/src/main/java/illyan/jay/MainApplication.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Balázs Püspök-Kiss (Illyan)
2+
* Copyright (c) 2023-2024 Balázs Püspök-Kiss (Illyan)
33
*
44
* Jay is a driver behaviour analytics app.
55
*
@@ -23,6 +23,7 @@ import com.google.android.gms.ads.MobileAds
2323
import com.google.firebase.analytics.FirebaseAnalytics
2424
import com.google.firebase.crashlytics.FirebaseCrashlytics
2525
import com.google.firebase.perf.FirebasePerformance
26+
import com.mapbox.common.MapboxOptions
2627
import dagger.hilt.android.HiltAndroidApp
2728
import illyan.jay.di.CoroutineScopeIO
2829
import illyan.jay.domain.interactor.AuthInteractor
@@ -52,6 +53,7 @@ class MainApplication : Application() {
5253
override fun onCreate() {
5354
super.onCreate()
5455

56+
MapboxOptions.accessToken = BuildConfig.MAPBOX_ACCESS_TOKEN
5557
initLogging()
5658
initAds()
5759
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022-2023 Balázs Püspök-Kiss (Illyan)
2+
* Copyright (c) 2022-2024 Balázs Püspök-Kiss (Illyan)
33
*
44
* Jay is a driver behaviour analytics app.
55
*
@@ -20,28 +20,25 @@ package illyan.jay.data.sensor
2020

2121
import android.annotation.SuppressLint
2222
import android.os.Looper
23-
import com.mapbox.android.core.location.LocationEngine
24-
import com.mapbox.android.core.location.LocationEngineCallback
25-
import com.mapbox.android.core.location.LocationEngineRequest
26-
import com.mapbox.android.core.location.LocationEngineResult
23+
import com.google.android.gms.location.FusedLocationProviderClient
24+
import com.google.android.gms.location.LocationCallback
25+
import com.google.android.gms.location.LocationRequest
2726
import javax.inject.Inject
2827
import javax.inject.Singleton
2928

3029
@Singleton
3130
class MapboxDataSource @Inject constructor(
32-
private val locationEngine: LocationEngine
31+
private val fusedLocationProviderClient: FusedLocationProviderClient
3332
) {
3433
@SuppressLint("MissingPermission")
3534
fun requestLocationUpdates(
36-
request: LocationEngineRequest,
37-
callback: LocationEngineCallback<LocationEngineResult>
35+
request: LocationRequest,
36+
callback: LocationCallback
3837
) {
39-
locationEngine.requestLocationUpdates(request, callback, Looper.getMainLooper())
38+
fusedLocationProviderClient.requestLocationUpdates(request, callback, Looper.getMainLooper())
4039
}
4140

42-
fun removeLocationUpdates(
43-
callback: LocationEngineCallback<LocationEngineResult>
44-
) {
45-
locationEngine.removeLocationUpdates(callback)
41+
fun removeLocationUpdates(callback: LocationCallback) {
42+
fusedLocationProviderClient.removeLocationUpdates(callback)
4643
}
4744
}

app/src/main/java/illyan/jay/di/MapboxModule.kt

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Balázs Püspök-Kiss (Illyan)
2+
* Copyright (c) 2023-2024 Balázs Püspök-Kiss (Illyan)
33
*
44
* Jay is a driver behaviour analytics app.
55
*
@@ -25,7 +25,6 @@ import dagger.Module
2525
import dagger.Provides
2626
import dagger.hilt.InstallIn
2727
import dagger.hilt.components.SingletonComponent
28-
import illyan.jay.BuildConfig
2928
import javax.inject.Singleton
3029

3130
@Module
@@ -34,10 +33,7 @@ object MapboxModule {
3433

3534
@Provides
3635
@Singleton
37-
fun provideSearchEngine() =
38-
SearchEngine.createSearchEngineWithBuiltInDataProviders(
39-
SearchEngineSettings(accessToken = BuildConfig.MapboxSdkRegistryToken)
40-
)
36+
fun provideSearchEngine() = SearchEngine.createSearchEngineWithBuiltInDataProviders(SearchEngineSettings())
4137

4238
@Provides
4339
@Singleton

0 commit comments

Comments
 (0)