Improve firebase logging (#832)

This commit is contained in:
Mikołaj Pich 2020-05-24 19:48:14 +02:00 committed by GitHub
parent 3541ab81b8
commit 428b599be0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 131 additions and 31 deletions

View File

@ -5,8 +5,6 @@ package io.github.wulkanowy.utils
import android.content.Context
import timber.log.Timber
fun initCrashlytics(context: Context, appInfo: AppInfo) {}
open class TimberTreeNoOp : Timber.Tree() {
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {}
}

View File

@ -1,13 +1,18 @@
package io.github.wulkanowy.utils
import android.app.Activity
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
@Suppress("UNUSED_PARAMETER")
class FirebaseAnalyticsHelper @Inject constructor() {
@Suppress("UNUSED_PARAMETER")
fun logEvent(name: String, vararg params: Pair<String, Any?>) {
// do nothing
}
fun setCurrentScreen(activity: Activity, name: String?) {
// do nothing
}
}

View File

@ -215,7 +215,12 @@ class AttendancePresenter @Inject constructor(
showContent(it.isNotEmpty())
showExcuseButton(it.any { item -> item.excusable })
}
analytics.logEvent("load_attendance", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "attendance",
"items" to it.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading attendance result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -99,7 +99,13 @@ class AttendanceSummaryPresenter @Inject constructor(
showContent(it.isNotEmpty())
updateDataSet(it)
}
analytics.logEvent("load_attendance_summary", "items" to it.size, "force_refresh" to forceRefresh, "item_id" to subjectId)
analytics.logEvent(
"load_data",
"type" to "attendance_summary",
"items" to it.size,
"force_refresh" to forceRefresh,
"item_id" to subjectId
)
}) {
Timber.i("Loading attendance summary result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -131,7 +131,12 @@ class ExamPresenter @Inject constructor(
showErrorView(false)
showContent(it.isNotEmpty())
}
analytics.logEvent("load_exam", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "exam",
"items" to it.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading exam result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -152,7 +152,12 @@ class GradeDetailsPresenter @Inject constructor(
gradeColorTheme = preferencesRepository.gradeColorTheme
)
}
analytics.logEvent("load_grade_details", "items" to grades.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "grade_details",
"items" to grades.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading grade details result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -174,7 +174,12 @@ class GradeStatisticsPresenter @Inject constructor(
updateData(it, preferencesRepository.gradeColorTheme, preferencesRepository.showAllSubjectsOnStatisticsList)
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
}
analytics.logEvent("load_grade_statistics", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "grade_statistics",
"items" to it.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading grade stats result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -49,7 +49,12 @@ class GradeSummaryPresenter @Inject constructor(
showErrorView(false)
updateData(it)
}
analytics.logEvent("load_grade_summary", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "grade_summary",
"items" to it.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading grade summary result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -124,7 +124,12 @@ class HomeworkPresenter @Inject constructor(
showErrorView(false)
showContent(it.isNotEmpty())
}
analytics.logEvent("load_homework", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "homework",
"items" to it.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading homework result: An exception occurred")

View File

@ -54,7 +54,12 @@ class LuckyNumberPresenter @Inject constructor(
showEmpty(false)
showErrorView(false)
}
analytics.logEvent("load_lucky_number", "lucky_number" to it.luckyNumber, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_item",
"type" to "lucky_number",
"number" to it.luckyNumber,
"force_refresh" to forceRefresh
)
}, {
Timber.i("Loading lucky number result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -31,6 +31,7 @@ import io.github.wulkanowy.ui.modules.message.MessageFragment
import io.github.wulkanowy.ui.modules.more.MoreFragment
import io.github.wulkanowy.ui.modules.note.NoteFragment
import io.github.wulkanowy.ui.modules.timetable.TimetableFragment
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
import io.github.wulkanowy.utils.dpToPx
import io.github.wulkanowy.utils.getThemeAttrColor
import io.github.wulkanowy.utils.safelyPopFragments
@ -46,6 +47,9 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
@Inject
lateinit var navController: FragNavController
@Inject
lateinit var analytics: FirebaseAnalyticsHelper
@Inject
lateinit var overlayProvider: Lazy<ElevationOverlayProvider>
@ -136,6 +140,10 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
}
}
override fun setCurrentScreen(name: String?) {
analytics.setCurrentScreen(this, name)
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
return if (item?.itemId == R.id.mainMenuAccount) presenter.onAccountManagerSelected()
else false

View File

@ -37,8 +37,9 @@ class MainPresenter @Inject constructor(
analytics.logEvent("app_open", "destination" to initMenu?.name)
}
fun onViewChange(section: MainView.Section?) {
fun onViewChange(section: MainView.Section?, name: String?) {
view?.apply {
setCurrentScreen(name)
showActionBarElevation(section != GRADE && section != MESSAGE && section != SCHOOL)
currentViewTitle?.let { setViewTitle(it) }
currentViewSubtitle?.let { setViewSubTitle(it.ifBlank { null }) }

View File

@ -24,6 +24,8 @@ interface MainView : BaseView {
fun showAccountPicker()
fun setCurrentScreen(name: String?)
fun showActionBarElevation(show: Boolean)
fun notifyMenuViewReselected()

View File

@ -60,7 +60,11 @@ class MessagePreviewPresenter @Inject constructor(
setMessageWithAttachment(message)
initOptions()
}
analytics.logEvent("load_message_preview", "length" to message.message.content.length)
analytics.logEvent(
"load_item",
"type" to "message_preview",
"length" to message.message.content.length
)
}) {
Timber.i("Loading message ${message.messageId} preview result: An exception occurred ")
retryCallback = { onMessageLoadRetry(message) }

View File

@ -97,7 +97,12 @@ class MessageTabPresenter @Inject constructor(
Timber.i("Loading $folder message result: Success")
messages = it
onSearchQueryTextChange(lastSearchQuery)
analytics.logEvent("load_messages", "items" to it.size, "folder" to folder.name)
analytics.logEvent(
"load_data",
"type" to "messages",
"items" to it.size,
"folder" to folder.name
)
}) {
Timber.i("Loading $folder message result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -70,7 +70,12 @@ class MobileDevicePresenter @Inject constructor(
showEmpty(it.isEmpty())
showErrorView(false)
}
analytics.logEvent("load_devices", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "devices",
"items" to it.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading mobile devices result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -69,7 +69,12 @@ class NotePresenter @Inject constructor(
showErrorView(false)
showContent(it.isNotEmpty())
}
analytics.logEvent("load_note", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "note",
"items" to it.size,
"force_refresh" to forceRefresh
)
}, {
Timber.i("Loading note result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -88,7 +88,11 @@ class SchoolPresenter @Inject constructor(
showEmpty(false)
showErrorView(false)
}
analytics.logEvent("load_school", "force_refresh" to forceRefresh)
analytics.logEvent(
"load_item",
"type" to "school",
"force_refresh" to forceRefresh
)
}, {
Timber.i("Loading school result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -75,7 +75,12 @@ class TeacherPresenter @Inject constructor(
showEmpty(it.isEmpty())
showErrorView(false)
}
analytics.logEvent("load_teachers", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "teachers",
"items" to it.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading teachers result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -154,7 +154,12 @@ class TimetablePresenter @Inject constructor(
showErrorView(false)
showContent(it.isNotEmpty())
}
analytics.logEvent("load_timetable", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "timetable",
"items" to it.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading timetable result: An exception occurred")
errorHandler.dispatch(it)

View File

@ -134,7 +134,12 @@ class CompletedLessonsPresenter @Inject constructor(
showErrorView(false)
showContent(it.isNotEmpty())
}
analytics.logEvent("load_completed_lessons", "items" to it.size, "force_refresh" to forceRefresh)
analytics.logEvent(
"load_data",
"type" to "completed_lessons",
"items" to it.size,
"force_refresh" to forceRefresh
)
}) {
Timber.i("Loading completed lessons result: An exception occurred")
completedLessonsErrorHandler.dispatch(it)

View File

@ -4,14 +4,14 @@ import androidx.fragment.app.Fragment
import com.ncapdevi.fragnav.FragNavController
import io.github.wulkanowy.ui.modules.main.MainView
inline fun FragNavController.setOnViewChangeListener(crossinline listener: (section: MainView.Section?) -> Unit) {
inline fun FragNavController.setOnViewChangeListener(crossinline listener: (section: MainView.Section?, name: String?) -> Unit) {
transactionListener = object : FragNavController.TransactionListener {
override fun onFragmentTransaction(fragment: Fragment?, transactionType: FragNavController.TransactionType) {
listener(fragment?.toSection())
listener(fragment?.toSection(), fragment?.let { it::class.java.simpleName })
}
override fun onTabTransaction(fragment: Fragment?, index: Int) {
listener(fragment?.toSection())
listener(fragment?.toSection(), fragment?.let { it::class.java.simpleName })
}
}
}

View File

@ -6,20 +6,14 @@ import fr.bipi.tressence.base.FormatterPriorityTree
import fr.bipi.tressence.common.StackTraceRecorder
import io.github.wulkanowy.sdk.exception.FeatureDisabledException
import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException
import java.io.InterruptedIOException
import java.net.SocketTimeoutException
import java.net.UnknownHostException
class CrashlyticsTree : FormatterPriorityTree(Log.VERBOSE) {
private val crashlytics by lazy { FirebaseCrashlytics.getInstance() }
override fun skipLog(priority: Int, tag: String?, message: String, t: Throwable?): Boolean {
if (t is FeatureDisabledException || t is FeatureNotAvailableException || t is UnknownHostException) {
return true
}
return super.skipLog(priority, tag, message, t)
}
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
if (skipLog(priority, tag, message, t)) return
@ -31,6 +25,14 @@ class CrashlyticsExceptionTree : FormatterPriorityTree(Log.ERROR) {
private val crashlytics by lazy { FirebaseCrashlytics.getInstance() }
override fun skipLog(priority: Int, tag: String?, message: String, t: Throwable?): Boolean {
if (t is FeatureDisabledException || t is FeatureNotAvailableException || t is UnknownHostException || t is SocketTimeoutException || t is InterruptedIOException) {
return true
}
return super.skipLog(priority, tag, message, t)
}
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
if (skipLog(priority, tag, message, t)) return

View File

@ -1,5 +1,6 @@
package io.github.wulkanowy.utils
import android.app.Activity
import android.content.Context
import android.os.Bundle
import com.google.firebase.analytics.FirebaseAnalytics
@ -24,4 +25,8 @@ class FirebaseAnalyticsHelper @Inject constructor(private val context: Context)
analytics.logEvent(name, this)
}
}
fun setCurrentScreen(activity: Activity, name: String?) {
analytics.setCurrentScreen(activity, name, null)
}
}