Skip to content

Commit

Permalink
Analytics and Crashlytics (#142)
Browse files Browse the repository at this point in the history
* adds firebase deps for analytics

* adds firebase crash and anal

* google-services file as env var on ci
  • Loading branch information
niehusst authored Mar 10, 2021
1 parent 1f02113 commit d20e382
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ aliases:
command: |
echo "SPOTIFY_CLIENT_ID="$SPOTIFY_CLIENT_ID > apikey.properties
echo $PARTYQ_KEYSTORE_FILE | base64 --decode > partyq_release.jks
echo $GOOGLE_SERVICES_FILE | base64 --decode > app/google-services.json
defaults: &defaults
working_directory: *root_dir
Expand Down
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

android {
compileSdkVersion rootProject.compileSdkVersion
Expand Down Expand Up @@ -87,6 +89,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':spotify-developer-sdk')
implementation platform('com.google.firebase:firebase-bom:26.6.0')

implementation "androidx.annotation:annotation:$androidXAnnotations"
implementation 'androidx.appcompat:appcompat:1.2.0'
Expand All @@ -99,6 +102,8 @@ dependencies {
implementation "com.google.android.gms:play-services-nearby:17.0.0"
implementation "com.google.android.material:material:$materialVersion"
implementation "com.google.code.gson:gson:2.8.5"
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation "com.jakewharton.timber:timber:$timberVersion"
implementation 'com.spotify.android:auth:1.1.0'
implementation "com.squareup.retrofit2:converter-moshi:2.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.NavigationUI
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.niehusst.partyq.BundleNames
import com.niehusst.partyq.R
import com.niehusst.partyq.SharedPrefNames.AGREED_TO_EULA
Expand Down Expand Up @@ -54,6 +55,9 @@ class MainActivity : AppCompatActivity() {
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navController = navHostFragment.navController
NavigationUI.setupActionBarWithNavController(this, navController)

// set Firebase key to indicate a user's host status
FirebaseCrashlytics.getInstance().setCustomKey("isHost", false)
}

override fun onStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.niehusst.partyq.BundleNames
import com.niehusst.partyq.R
import com.niehusst.partyq.databinding.SpotifyLoginFragmentBinding
Expand Down Expand Up @@ -108,6 +109,9 @@ class SpotifyLoginFragment : Fragment() {

when (response.type) {
AuthenticationResponse.Type.CODE -> {
// tell crashlytics this user is now a host
FirebaseCrashlytics.getInstance().setCustomKey("isHost", true)

viewModel.swapCodeForTokenAsync(response.code)
// result handled in `setObservers` from observing `tokenResponse` live data
}
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"

classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down

0 comments on commit d20e382

Please sign in to comment.