Skip to content

Commit

Permalink
Merge pull request #594 from pennlabs/firebase-analytics
Browse files Browse the repository at this point in the history
Firebase analytics
  • Loading branch information
JSnipes29 authored Jan 21, 2024
2 parents 298bbab + 8e67913 commit ad05889
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 96 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/android-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ jobs:
env:
PLATFORM_REDIRECT_URI: ${{ secrets.PLATFORM_REDIRECT_URI }}
run: echo PLATFORM_REDIRECT_URI=\"$PLATFORM_REDIRECT_URI\" >> ./local.properties

# Create google-services.json
- name: Create google-services.json
run: |
cat << EOF > PennMobile/google-services.json
${{ secrets.GOOGLE_SERVICES_JSON }}
EOF
# Run unit tests
- name: Run Unit Tests
run: ./gradlew testDebugUnitTest
Expand Down Expand Up @@ -60,7 +68,14 @@ jobs:
env:
PLATFORM_REDIRECT_URI: ${{ secrets.PLATFORM_REDIRECT_URI }}
run: echo PLATFORM_REDIRECT_URI=\"$PLATFORM_REDIRECT_URI\" >> ./local.properties


# Create google-services.json
- name: Create google-services.json
run: |
cat << EOF > PennMobile/google-services.json
${{ secrets.GOOGLE_SERVICES_JSON }}
EOF
# Generate Signed APK
- name: Generate Release APK
run: ./gradlew assembleRelease
Expand Down Expand Up @@ -108,6 +123,13 @@ jobs:
PLATFORM_REDIRECT_URI: ${{ secrets.PLATFORM_REDIRECT_URI }}
run: echo PLATFORM_REDIRECT_URI=\"$PLATFORM_REDIRECT_URI\" >> ./local.properties

# Create google-services.json
- name: Create google-services.json
run: |
cat << EOF > PennMobile/google-services.json
${{ secrets.GOOGLE_SERVICES_JSON }}
EOF
# Run JaCoCo, generate Test Report
- name: Check Code Coverage
run: ./gradlew jacocoTestReport --stacktrace
Expand All @@ -120,6 +142,7 @@ jobs:
path: PennMobile/build/reports

# Publish to Firebase App Distribution
# https://github.com/wzieba/Firebase-Distribution-Github-Action
deploy-firebase:
needs: generate-apk
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -132,7 +155,7 @@ jobs:
uses: wzieba/Firebase-Distribution-Github-Action@v1
with:
appId: ${{secrets.FIREBASE_APP_ID}}
token: ${{secrets.FIREBASE_TOKEN}}
serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }}
groups: tester
file: PennMobile-release-unsigned-signed.apk

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gradle/wrapper/

# Local configuration file (sdk path, etc)
local.properties
google-services.json

# Proguard folder generated by Eclipse
proguard/
Expand Down
4 changes: 4 additions & 0 deletions PennMobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
id("com.google.firebase.crashlytics")
id 'jacoco'
}

Expand Down Expand Up @@ -42,6 +43,8 @@ dependencies {
implementation(platform("com.google.firebase:firebase-bom:31.5.0"))

implementation 'com.google.firebase:firebase-analytics'
implementation("com.google.firebase:firebase-crashlytics")

implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.maps:google-maps-services:2.2.0'
implementation 'org.jsoup:jsoup:1.16.2'
Expand All @@ -68,6 +71,7 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.daimajia.swipelayout:library:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.6.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'org.testng:testng:7.8.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
Expand Down
40 changes: 0 additions & 40 deletions PennMobile/google-services.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ class DiningFragment : Fragment() {
mActivity = activity as MainActivity
mActivity.closeKeyboard()
setHasOptionsMenu(true)

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "1")
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "Dining")
bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "App Feature")
FirebaseAnalytics.getInstance(mActivity).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ class FlingFragment : Fragment() {
setHasOptionsMenu(true)
mActivity = activity as MainActivity
mActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "7")
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "Spring Fling")
bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "App Feature")
FirebaseAnalytics.getInstance(mActivity).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle)
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ class GsrFragment : Fragment() {

// set default GSR selection date + time to the current date and time
selectedDateTime = DateTime.now()

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "0")
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "GSR")
bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "App Feature")
FirebaseAnalytics.getInstance(mActivity).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ class GsrReservationsFragment : Fragment() {
mActivity = activity as MainActivity

LocalBroadcastManager.getInstance(mActivity).registerReceiver(broadcastReceiver, IntentFilter("refresh"))

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "10")
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "GsrReservations")
bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "App Feature")
FirebaseAnalytics.getInstance(mActivity).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.fragment.app.Fragment
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.firebase.analytics.FirebaseAnalytics
import com.pennapps.labs.pennmobile.adapters.HomeAdapter
import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager
import com.pennapps.labs.pennmobile.classes.HomeCell
Expand All @@ -32,7 +31,6 @@ import kotlinx.android.synthetic.main.loading_panel.*
import java.util.*
import kotlin.collections.ArrayList


class HomeFragment : Fragment() {

private lateinit var mActivity: MainActivity
Expand All @@ -51,11 +49,6 @@ class HomeFragment : Fragment() {
.getInstance(mActivity)
.registerReceiver(broadcastReceiver, IntentFilter("refresh"))

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "11")
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "Home")
bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "App Feature")
FirebaseAnalytics.getInstance(mActivity).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle)
}

override fun onCreateView(
Expand All @@ -72,7 +65,9 @@ class HomeFragment : Fragment() {
view.home_refresh_layout
.setColorSchemeResources(R.color.color_accent, R.color.color_primary)
view.home_refresh_layout
.setOnRefreshListener { getHomePage() }
.setOnRefreshListener {
getHomePage()
}

initAppBar(view)
return view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ class LaundrySettingsFragment : Fragment() {
setHasOptionsMenu(true)
mActivity.toolbar.visibility = View.VISIBLE
mActivity.hideBottomBar()

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "12")
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "Laundry Settings")
bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "App Feature")
FirebaseAnalytics.getInstance(mContext).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
Expand All @@ -67,10 +61,8 @@ class LaundrySettingsFragment : Fragment() {
editor?.apply()

for (i in 0 until numRooms) {
editor?.remove(Integer.toString(i))?.apply()
editor?.remove(i.toString())?.apply()
}

//view.laundry_building_expandable_list?.setAdapter(mAdapter)
}

// set up back button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ class LoginFragment : Fragment() {

val fragmentManager = mActivity.supportFragmentManager
val gif = R.drawable.login_background
// if (Build.VERSION.SDK_INT > 28 && (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
// gif = R.drawable.login_background_dark
// }

Glide.with(this).asGif().load(gif).listener(object : RequestListener<GifDrawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target<GifDrawable>?, isFirstResource: Boolean): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import android.widget.LinearLayout
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.api.Platform
import com.pennapps.labs.pennmobile.api.Platform.platformBaseUrl
Expand Down Expand Up @@ -89,7 +91,6 @@ class LoginWebviewFragment : Fragment() {
cancelButton.setOnClickListener {
mActivity.startLoginFragment()
}

}

private fun encryptPassword(password: String) {
Expand Down Expand Up @@ -164,6 +165,9 @@ class LoginWebviewFragment : Fragment() {

override fun success(t: AccessTokenResponse?, response: Response?) {
if (response?.status == 200) {

FirebaseAnalytics.getInstance(mActivity).logEvent("LoginEvent", null)

val accessToken = t?.accessToken
val editor = sp.edit()
editor.putString(getString(R.string.access_token), accessToken)
Expand All @@ -180,6 +184,7 @@ class LoginWebviewFragment : Fragment() {
}

override fun failure(error: RetrofitError) {
FirebaseCrashlytics.getInstance().recordException(error)
Log.e("Accounts", "Error fetching access token $error", error)
Toast.makeText(mActivity, "Error logging in", Toast.LENGTH_SHORT).show()
mActivity.startLoginFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.preference.PreferenceManager
import androidx.viewpager.widget.ViewPager
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayout
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.pennapps.labs.pennmobile.adapters.MainPagerAdapter
Expand All @@ -52,13 +53,16 @@ import retrofit.client.OkClient
import retrofit.converter.GsonConverter
import java.util.concurrent.TimeUnit


class MainActivity : AppCompatActivity() {
private var tabShowed = false
private lateinit var fragmentManager: FragmentManager
private lateinit var mSharedPrefs: SharedPreferences

val tokenMutex = Mutex()
private lateinit var mFirebaseAnalytics: FirebaseAnalytics
val mNetworkManager by lazy { OAuth2NetworkManager(this) }

override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme)
if (Build.VERSION.SDK_INT > 28) {
Expand Down Expand Up @@ -88,6 +92,9 @@ class MainActivity : AppCompatActivity() {
showBottomBar()
supportActionBar?.setDisplayShowTitleEnabled(false)

mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.logEvent("MainActivityStart", null)

// Show HomeFragment if logged in, otherwise show LoginFragment
val pennKey = mSharedPrefs.getString(getString(R.string.pennkey), null)
val guestMode = mSharedPrefs.getBoolean(getString(R.string.guest_mode), false)
Expand Down Expand Up @@ -398,4 +405,4 @@ fun ViewGroup.showSneakerToast(message: String, doOnRetry: (() -> Unit)?, sneake
messageView.text = message

sneaker.sneakCustom(view).setCornerRadius(12, 16).setMessage(message)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,7 @@ class NewsFragment : ListFragment() {
mActivity.closeKeyboard()
setHasOptionsMenu(true)

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "5")
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "News")
bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "App Feature")
FirebaseAnalytics.getInstance(mActivity).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle)
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mActivity)

}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import androidx.preference.PreferenceManager
import android.provider.Settings
import android.util.Log
import androidx.lifecycle.lifecycleScope
import com.google.firebase.crashlytics.FirebaseCrashlytics

import com.pennapps.labs.pennmobile.BuildConfig
import com.pennapps.labs.pennmobile.MainActivity
import com.pennapps.labs.pennmobile.R
Expand Down Expand Up @@ -80,6 +82,7 @@ class OAuth2NetworkManager(private var mActivity: MainActivity) {

override fun failure(error: RetrofitError) {

FirebaseCrashlytics.getInstance().recordException(error)
Log.e("Accounts", "Error refreshing access token $error")

if (error.response != null && error.response.status == 400) {
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ plugins {
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.22' apply false
id 'com.google.gms.google-services' version "4.4.0" apply false
id("com.google.firebase.crashlytics") version "2.9.9" apply false
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Nov 01 14:54:54 EDT 2023
#Fri Dec 01 16:55:01 EST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit ad05889

Please sign in to comment.