Skip to content

Commit

Permalink
Merge pull request #118 from HLCaptain/mapbox-upgrade
Browse files Browse the repository at this point in the history
Mapbox upgrade
  • Loading branch information
HLCaptain authored Jul 31, 2024
2 parents 2e8317f + 42b349d commit ea67d9e
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 206 deletions.
113 changes: 59 additions & 54 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Balázs Püspök-Kiss (Illyan)
* Copyright (c) 2022-2024 Balázs Püspök-Kiss (Illyan)
*
* Jay is a driver behaviour analytics app.
*
Expand All @@ -16,25 +16,7 @@
* If not, see <https://www.gnu.org/licenses/>.
*/

import com.google.android.libraries.mapsplatform.secrets_gradle_plugin.loadPropertiesFile

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

plugins {
alias(libs.plugins.android.application)
Expand All @@ -52,6 +34,8 @@ plugins {
alias(libs.plugins.compose.compiler)
}

val localProperties = loadProperties("$projectDir/../local.properties")

android {
compileSdk = 35

Expand All @@ -61,54 +45,30 @@ android {
applicationId = "illyan.jay"
minSdk = 23
targetSdk = 35
versionCode = 18
versionName = "0.4.0-alpha"
versionCode = 19
versionName = "0.4.1-alpha"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
val mapboxAccessToken = properties["MAPBOX_ACCESS_TOKEN"].toString()
val mapboxDownloadsToken = properties["MAPBOX_DOWNLOADS_TOKEN"].toString()
val mapboxSdkRegistryToken = properties["SDK_REGISTRY_TOKEN"].toString()
getByName("debug") {
isDebuggable = true
buildConfigField("String", "MapboxAccessToken", "\"$mapboxAccessToken\"")
buildConfigField("String", "MapboxDownloadsToken", "\"$mapboxDownloadsToken\"")
buildConfigField("String", "MapboxSdkRegistryToken", "\"$mapboxSdkRegistryToken\"")
}
getByName("release") {
initWith(getByName("debug"))
isDebuggable = false
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

signingConfigs {
val properties = loadPropertiesFile("../local.properties").toMap()

val debugStorePath = properties["DEBUG_KEY_PATH"].toString()
val debugKeyAlias = properties["DEBUG_KEY_ALIAS"].toString()
val debugStorePassword = properties["DEBUG_KEYSTORE_PASSWORD"].toString()
val debugKeyPassword = properties["DEBUG_KEY_PASSWORD"].toString()
val debugStorePath = localProperties["DEBUG_KEY_PATH"].toString()
val debugKeyAlias = localProperties["DEBUG_KEY_ALIAS"].toString()
val debugStorePassword = localProperties["DEBUG_KEYSTORE_PASSWORD"].toString()
val debugKeyPassword = localProperties["DEBUG_KEY_PASSWORD"].toString()
getByName("debug") {
storeFile = file(debugStorePath)
keyAlias = debugKeyAlias
storePassword = debugStorePassword
keyPassword = debugKeyPassword
}
val releaseStorePath = properties["RELEASE_KEY_PATH"].toString()
val releaseKeyAlias = properties["RELEASE_KEY_ALIAS"].toString()
val releaseStorePassword = properties["RELEASE_KEYSTORE_PASSWORD"].toString()
val releaseKeyPassword = properties["RELEASE_KEY_PASSWORD"].toString()
val releaseStorePath = localProperties["RELEASE_KEY_PATH"].toString()
val releaseKeyAlias = localProperties["RELEASE_KEY_ALIAS"].toString()
val releaseStorePassword = localProperties["RELEASE_KEYSTORE_PASSWORD"].toString()
val releaseKeyPassword = localProperties["RELEASE_KEY_PASSWORD"].toString()
create("release") {
storeFile = file(releaseStorePath)
keyAlias = releaseKeyAlias
Expand All @@ -117,6 +77,32 @@ android {
}
}

buildTypes {
val mapboxAccessToken = localProperties["MAPBOX_ACCESS_TOKEN"].toString()
val mapboxDownloadsToken = localProperties["MAPBOX_DOWNLOADS_TOKEN"].toString()
val mapboxSdkRegistryToken = localProperties["SDK_REGISTRY_TOKEN"].toString()
val admobAppId = localProperties["ADMOB_APPLICATION_ID"].toString()
getByName("debug") {
isDebuggable = true
buildConfigField("String", "MAPBOX_ACCESS_TOKEN", "\"$mapboxAccessToken\"")
buildConfigField("String", "MAPBOX_DOWNLOADS_TOKEN", "\"$mapboxDownloadsToken\"")
buildConfigField("String", "SDK_REGISTRY_TOKEN", "\"$mapboxSdkRegistryToken\"")
buildConfigField("String", "ADMOB_APPLICATION_ID", "\"$admobAppId\"")
}
getByName("release") {
isDebuggable = false
isMinifyEnabled = true
isShrinkResources = true
buildConfigField("String", "MAPBOX_ACCESS_TOKEN", "\"$mapboxAccessToken\"")
buildConfigField("String", "ADMOB_APPLICATION_ID", "\"$admobAppId\"")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -291,3 +277,22 @@ hilt {
room {
schemaDirectory("$projectDir/schemas")
}

secrets {
// Ignore everything, except ADMOB_APPLICATION_ID for AndroidManifest.xml
ignoreList.addAll(
listOf(
"RELEASE_KEYSTORE_PASSWORD*",
"RELEASE_KEY_PASSWORD*",
"RELEASE_KEY_ALIAS*",
"RELEASE_KEY_PATH*",
"DEBUG_KEYSTORE_PASSWORD*",
"DEBUG_KEY_PASSWORD*",
"DEBUG_KEY_ALIAS*",
"DEBUG_KEY_PATH*",
"MAPBOX_DOWNLOADS_TOKEN*",
"SDK_REGISTRY_TOKEN*",
"MAPBOX_ACCESS_TOKEN*"
)
)
}
50 changes: 46 additions & 4 deletions app/src/main/java/illyan/jay/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Balázs Püspök-Kiss (Illyan)
* Copyright (c) 2022-2024 Balázs Püspök-Kiss (Illyan)
*
* Jay is a driver behaviour analytics app.
*
Expand All @@ -26,16 +26,28 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.tasks.Task
import com.mapbox.navigation.base.options.NavigationOptions
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
import com.ramcosta.composedestinations.DestinationsNavHost
import dagger.hilt.android.AndroidEntryPoint
import illyan.jay.domain.interactor.AuthInteractor
import illyan.jay.ui.NavGraphs
import illyan.jay.ui.components.PreviewAccessibility
import illyan.jay.ui.theme.JayThemeWithViewModel
import illyan.jay.util.MapboxExceptionHandler
import javax.inject.Inject

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

lateinit var googleSignInLauncher: ActivityResultLauncher<Intent>

init {
lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onResume(owner: LifecycleOwner) {
MapboxNavigationApp.attach(owner)
}

override fun onPause(owner: LifecycleOwner) {
MapboxNavigationApp.detach(owner)
}
})
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

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

if (!MapboxNavigationApp.isSetup()) {
MapboxNavigationApp.setup {
NavigationOptions.Builder(applicationContext).build()
}
}

val mapboxExceptionHandler = MapboxExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler(mapboxExceptionHandler)

setContent {
var mapboxMapViewNotSupported by rememberSaveable { mutableStateOf(false) }
LaunchedEffect(Unit) {
mapboxExceptionHandler.openGlNotSupportedCallback = {
mapboxMapViewNotSupported = true
}
}
JayThemeWithViewModel {
MainScreen(
modifier = Modifier.fillMaxSize()
)
CompositionLocalProvider(LocalMapboxNotSupported provides mapboxMapViewNotSupported) {
MainScreen(modifier = Modifier.fillMaxSize())
}
}
}
}
}

val LocalMapboxNotSupported = compositionLocalOf { false }

@PreviewAccessibility
@Composable
fun MainScreen(
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/illyan/jay/MainApplication.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Balázs Püspök-Kiss (Illyan)
* Copyright (c) 2023-2024 Balázs Püspök-Kiss (Illyan)
*
* Jay is a driver behaviour analytics app.
*
Expand All @@ -23,6 +23,7 @@ import com.google.android.gms.ads.MobileAds
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.perf.FirebasePerformance
import com.mapbox.common.MapboxOptions
import dagger.hilt.android.HiltAndroidApp
import illyan.jay.di.CoroutineScopeIO
import illyan.jay.domain.interactor.AuthInteractor
Expand Down Expand Up @@ -52,6 +53,7 @@ class MainApplication : Application() {
override fun onCreate() {
super.onCreate()

MapboxOptions.accessToken = BuildConfig.MAPBOX_ACCESS_TOKEN
initLogging()
initAds()
}
Expand Down
23 changes: 10 additions & 13 deletions app/src/main/java/illyan/jay/data/sensor/MapboxDataSource.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Balázs Püspök-Kiss (Illyan)
* Copyright (c) 2022-2024 Balázs Püspök-Kiss (Illyan)
*
* Jay is a driver behaviour analytics app.
*
Expand All @@ -20,28 +20,25 @@ package illyan.jay.data.sensor

import android.annotation.SuppressLint
import android.os.Looper
import com.mapbox.android.core.location.LocationEngine
import com.mapbox.android.core.location.LocationEngineCallback
import com.mapbox.android.core.location.LocationEngineRequest
import com.mapbox.android.core.location.LocationEngineResult
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationCallback
import com.google.android.gms.location.LocationRequest
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class MapboxDataSource @Inject constructor(
private val locationEngine: LocationEngine
private val fusedLocationProviderClient: FusedLocationProviderClient
) {
@SuppressLint("MissingPermission")
fun requestLocationUpdates(
request: LocationEngineRequest,
callback: LocationEngineCallback<LocationEngineResult>
request: LocationRequest,
callback: LocationCallback
) {
locationEngine.requestLocationUpdates(request, callback, Looper.getMainLooper())
fusedLocationProviderClient.requestLocationUpdates(request, callback, Looper.getMainLooper())
}

fun removeLocationUpdates(
callback: LocationEngineCallback<LocationEngineResult>
) {
locationEngine.removeLocationUpdates(callback)
fun removeLocationUpdates(callback: LocationCallback) {
fusedLocationProviderClient.removeLocationUpdates(callback)
}
}
8 changes: 2 additions & 6 deletions app/src/main/java/illyan/jay/di/MapboxModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Balázs Püspök-Kiss (Illyan)
* Copyright (c) 2023-2024 Balázs Püspök-Kiss (Illyan)
*
* Jay is a driver behaviour analytics app.
*
Expand All @@ -25,7 +25,6 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import illyan.jay.BuildConfig
import javax.inject.Singleton

@Module
Expand All @@ -34,10 +33,7 @@ object MapboxModule {

@Provides
@Singleton
fun provideSearchEngine() =
SearchEngine.createSearchEngineWithBuiltInDataProviders(
SearchEngineSettings(accessToken = BuildConfig.MapboxSdkRegistryToken)
)
fun provideSearchEngine() = SearchEngine.createSearchEngineWithBuiltInDataProviders(SearchEngineSettings())

@Provides
@Singleton
Expand Down
Loading

0 comments on commit ea67d9e

Please sign in to comment.