Add Firebase gradle configuration

This commit is contained in:
Sylwester Zieliński
2022-04-08 10:47:56 +02:00
parent e618d4c949
commit 83be7390ef
12 changed files with 86 additions and 9 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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))

View File

@@ -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)
}
}

View File

@@ -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"

View File

@@ -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

View File

@@ -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'
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>

View File

@@ -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)
}
}

View File

@@ -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"),
}

View File

@@ -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'