From 83be7390efbae23b0da034d8ed54a80f94f7b799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylwester=20Zieli=C5=84ski?= Date: Fri, 8 Apr 2022 10:47:56 +0200 Subject: [PATCH] Add Firebase gradle configuration --- .github/workflows/deploy-all.yml | 7 +++---- .github/workflows/deploy-to-play-store.yml | 3 ++- app/build.gradle | 5 +++-- .../android/nrftoolbox/view/HomeView.kt | 12 +++++++++++ .../nrftoolbox/viewmodel/HomeViewModel.kt | 9 ++++++++- build.gradle | 2 ++ gradle/wrapper/gradle-wrapper.properties | 2 +- lib_analytics/build.gradle | 11 ++++++++++ lib_analytics/src/main/AndroidManifest.xml | 7 +++++++ .../android/analytics/AppAnalytics.kt | 20 +++++++++++++++++++ .../android/analytics/ProfileOpenEvent.kt | 16 +++++++++++++++ settings.gradle | 1 + 12 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 lib_analytics/build.gradle create mode 100644 lib_analytics/src/main/AndroidManifest.xml create mode 100644 lib_analytics/src/main/java/no/nordicsemi/android/analytics/AppAnalytics.kt create mode 100644 lib_analytics/src/main/java/no/nordicsemi/android/analytics/ProfileOpenEvent.kt diff --git a/.github/workflows/deploy-all.yml b/.github/workflows/deploy-all.yml index 4dd3c667..11241991 100644 --- a/.github/workflows/deploy-all.yml +++ b/.github/workflows/deploy-all.yml @@ -8,9 +8,8 @@ jobs: generateReadme: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: - ref: main fetch-depth: 0 - shell: bash run: | @@ -26,9 +25,8 @@ jobs: needs: generateReadme runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: - ref: main fetch-depth: 0 - shell: bash env: @@ -42,6 +40,7 @@ jobs: SONATYPE_STATING_PROFILE_ID: ${{ secrets.SONATYPE_STATING_PROFILE_ID }} run: | pwd + echo "${{ secrets.GOOGLE_SERVICES }}" > lib_analytics/src/main/res/values/keys.xml echo "${{ secrets.KEYSTORE_FILE }}" > keystore.asc gpg -d --passphrase "${{ secrets.KEYSTORE_FILE_PSWD }}" --batch keystore.asc > keystore echo "${{ secrets.GPG_FILE }}" > sec.gpg.asc diff --git a/.github/workflows/deploy-to-play-store.yml b/.github/workflows/deploy-to-play-store.yml index 7dfa3728..56f2a8b0 100644 --- a/.github/workflows/deploy-to-play-store.yml +++ b/.github/workflows/deploy-to-play-store.yml @@ -5,7 +5,7 @@ jobs: restorePassword: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - shell: bash @@ -20,6 +20,7 @@ jobs: SONATYPE_STATING_PROFILE_ID: ${{ secrets.SONATYPE_STATING_PROFILE_ID }} run: | pwd + echo "${{ secrets.GOOGLE_SERVICES }}" > lib_analytics/src/main/res/values/keys.xml echo "${{ secrets.KEYSTORE_FILE }}" > keystore.asc gpg -d --passphrase "${{ secrets.KEYSTORE_FILE_PSWD }}" --batch keystore.asc > keystore echo "${{ secrets.GPG_FILE }}" > sec.gpg.asc diff --git a/app/build.gradle b/app/build.gradle index 8de01ced..40aed4a8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,6 +4,7 @@ plugins { id 'kotlin-parcelize' id 'kotlin-kapt' id 'dagger.hilt.android.plugin' + id 'com.google.firebase.crashlytics' } apply from: rootProject.file("gradle/git-tag-version.gradle") @@ -64,8 +65,6 @@ android { } dependencies { - implementation libs.nordic.theme - //Hilt requires to implement every module in the main app module //https://github.com/google/dagger/issues/2123 implementation project(':profile_bps') @@ -79,11 +78,13 @@ dependencies { implementation project(':profile_uart') + implementation project(":lib_analytics") implementation project(":lib_theme") implementation project(":lib_utils") implementation project(":lib_service") implementation project(":lib_log") + implementation libs.nordic.theme implementation libs.nordic.ble.common implementation libs.nordic.ui.scanner implementation libs.nordic.navigation diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/HomeView.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/HomeView.kt index 65381141..31e365a7 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/HomeView.kt +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/HomeView.kt @@ -14,6 +14,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel +import no.nordicsemi.android.analytics.ProfileOpenEvent import no.nordicsemi.android.logger.LoggerAppRunner import no.nordicsemi.android.nrftoolbox.BuildConfig import no.nordicsemi.android.nrftoolbox.ProfileDestination @@ -56,12 +57,14 @@ fun HomeScreen() { FeatureButton(R.drawable.ic_gls, R.string.gls_module, R.string.gls_module_full) { viewModel.openProfile(ProfileDestination.GLS) + viewModel.logEvent(ProfileOpenEvent.GLS) } Spacer(modifier = Modifier.height(16.dp)) FeatureButton(R.drawable.ic_bps, R.string.bps_module, R.string.bps_module_full) { viewModel.openProfile(ProfileDestination.BPS) + viewModel.logEvent(ProfileOpenEvent.BPS) } Spacer(modifier = Modifier.height(16.dp)) @@ -76,36 +79,42 @@ fun HomeScreen() { FeatureButton(R.drawable.ic_csc, R.string.csc_module, R.string.csc_module_full, state.isCSCModuleRunning) { viewModel.openProfile(ProfileDestination.CSC) + viewModel.logEvent(ProfileOpenEvent.CSC) } Spacer(modifier = Modifier.height(16.dp)) FeatureButton(R.drawable.ic_hrs, R.string.hrs_module, R.string.hrs_module_full, state.isHRSModuleRunning) { viewModel.openProfile(ProfileDestination.HRS) + viewModel.logEvent(ProfileOpenEvent.HRS) } Spacer(modifier = Modifier.height(16.dp)) FeatureButton(R.drawable.ic_hts, R.string.hts_module, R.string.hts_module_full, state.isHTSModuleRunning) { viewModel.openProfile(ProfileDestination.HTS) + viewModel.logEvent(ProfileOpenEvent.HTS) } Spacer(modifier = Modifier.height(16.dp)) FeatureButton(R.drawable.ic_rscs, R.string.rscs_module, R.string.rscs_module_full, state.isRSCSModuleRunning) { viewModel.openProfile(ProfileDestination.RSCS) + viewModel.logEvent(ProfileOpenEvent.RSCS) } Spacer(modifier = Modifier.height(16.dp)) FeatureButton(R.drawable.ic_cgm, R.string.cgm_module, R.string.cgm_module_full, state.isCGMModuleRunning) { viewModel.openProfile(ProfileDestination.CGMS) + viewModel.logEvent(ProfileOpenEvent.CGMS) } Spacer(modifier = Modifier.height(16.dp)) FeatureButton(R.drawable.ic_prx, R.string.prx_module, R.string.prx_module_full, state.isPRXModuleRunning) { viewModel.openProfile(ProfileDestination.PRX) + viewModel.logEvent(ProfileOpenEvent.PRX) } Spacer(modifier = Modifier.height(16.dp)) @@ -120,6 +129,7 @@ fun HomeScreen() { FeatureButton(R.drawable.ic_uart, R.string.uart_module, R.string.uart_module_full, state.isUARTModuleRunning) { viewModel.openProfile(ProfileDestination.UART) + viewModel.logEvent(ProfileOpenEvent.UART) } Spacer(modifier = Modifier.height(16.dp)) @@ -139,6 +149,7 @@ fun HomeScreen() { } else { uriHandler.openUri(DFU_LINK) } + viewModel.logEvent(ProfileOpenEvent.DFU) } Spacer(modifier = Modifier.height(16.dp)) @@ -149,6 +160,7 @@ fun HomeScreen() { FeatureButton(R.drawable.ic_logger, R.string.logger_module, R.string.logger_module_full, null, loggerDescription) { viewModel.openLogger() + viewModel.logEvent(ProfileOpenEvent.LOGGER) } Spacer(modifier = Modifier.height(16.dp)) diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/viewmodel/HomeViewModel.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/viewmodel/HomeViewModel.kt index 27adb334..e75e0c43 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/viewmodel/HomeViewModel.kt +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/viewmodel/HomeViewModel.kt @@ -8,6 +8,8 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach +import no.nordicsemi.android.analytics.AppAnalytics +import no.nordicsemi.android.analytics.ProfileOpenEvent import no.nordicsemi.android.cgms.repository.CGMRepository import no.nordicsemi.android.csc.repository.CSCRepository import no.nordicsemi.android.hrs.service.HRSRepository @@ -33,7 +35,8 @@ class HomeViewModel @Inject constructor( prxRepository: PRXRepository, rscsRepository: RSCSRepository, uartRepository: UARTRepository, - private val loggerAppRunner: LoggerAppRunner + private val loggerAppRunner: LoggerAppRunner, + private val analytics: AppAnalytics ) : ViewModel() { private val _state = MutableStateFlow(HomeViewState()) @@ -80,4 +83,8 @@ class HomeViewModel @Inject constructor( fun openLogger() { loggerAppRunner.runLogger() } + + fun logEvent(event: ProfileOpenEvent) { + analytics.logEvent(event) + } } diff --git a/build.gradle b/build.gradle index 9ffc8cb1..24bbec42 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,8 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:7.1.3' + classpath 'com.google.gms:google-services:4.3.10' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE" classpath "com.google.dagger:hilt-android-gradle-plugin:2.40.4" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4ace9944..1b289a4d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Feb 14 14:46:55 CET 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/lib_analytics/build.gradle b/lib_analytics/build.gradle new file mode 100644 index 00000000..a097513e --- /dev/null +++ b/lib_analytics/build.gradle @@ -0,0 +1,11 @@ +apply from: rootProject.file("library.gradle") + +android { + namespace 'no.nordicsemi.android.analytics' +} + +dependencies { + implementation platform('com.google.firebase:firebase-bom:29.2.1') + implementation 'com.google.firebase:firebase-analytics' + implementation 'com.google.firebase:firebase-crashlytics' +} diff --git a/lib_analytics/src/main/AndroidManifest.xml b/lib_analytics/src/main/AndroidManifest.xml new file mode 100644 index 00000000..275af865 --- /dev/null +++ b/lib_analytics/src/main/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/lib_analytics/src/main/java/no/nordicsemi/android/analytics/AppAnalytics.kt b/lib_analytics/src/main/java/no/nordicsemi/android/analytics/AppAnalytics.kt new file mode 100644 index 00000000..ab0c3f66 --- /dev/null +++ b/lib_analytics/src/main/java/no/nordicsemi/android/analytics/AppAnalytics.kt @@ -0,0 +1,20 @@ +package no.nordicsemi.android.analytics + +import android.content.Context +import com.google.firebase.analytics.FirebaseAnalytics +import dagger.hilt.android.qualifiers.ApplicationContext +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class AppAnalytics @Inject constructor( + @ApplicationContext + private val context: Context +) { + + private val firebase by lazy { FirebaseAnalytics.getInstance(context) } + + fun logEvent(event: ProfileOpenEvent) { + firebase.logEvent(event.firebaseName, null) + } +} diff --git a/lib_analytics/src/main/java/no/nordicsemi/android/analytics/ProfileOpenEvent.kt b/lib_analytics/src/main/java/no/nordicsemi/android/analytics/ProfileOpenEvent.kt new file mode 100644 index 00000000..05391cc2 --- /dev/null +++ b/lib_analytics/src/main/java/no/nordicsemi/android/analytics/ProfileOpenEvent.kt @@ -0,0 +1,16 @@ +package no.nordicsemi.android.analytics + +enum class ProfileOpenEvent(internal val firebaseName: String) { + BPS("BPS_PROFILE_OPEN"), + CGMS("CGMS_PROFILE_OPEN"), + CSC("CSC_PROFILE_OPEN"), + GLS("GLS_PROFILE_OPEN"), + HRS("HRS_PROFILE_OPEN"), + HTS("HTS_PROFILE_OPEN"), + PRX("PRX_PROFILE_OPEN"), + RSCS("RSCS_PROFILE_OPEN"), + UART("UART_PROFILE_OPEN"), + + DFU("DFU_PROFILE_OPEN"), + LOGGER("LOGGER_PROFILE_OPEN"), +} diff --git a/settings.gradle b/settings.gradle index dd1537ea..8df67ed2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -94,6 +94,7 @@ include ':profile_prx' include ':profile_rscs' include ':profile_uart' +include ':lib_analytics' include ':lib_service' include ':lib_theme' include ':lib_utils'