Fix HMS analytics and crashlytics (#1042)

This commit is contained in:
Rafał Borcz 2020-12-06 19:31:35 +01:00 committed by GitHub
parent 05a597313b
commit 6ca5e11371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 16 deletions

View File

@ -15,4 +15,8 @@ class AnalyticsHelper @Inject constructor() {
fun setCurrentScreen(activity: Activity, name: String?) {
// do nothing
}
fun popCurrentScreen(name: String?) {
// do nothing
}
}

View File

@ -30,9 +30,10 @@ class AnalyticsHelper @Inject constructor(
}
fun setCurrentScreen(activity: Activity, name: String?) {
analytics.onEvent("screen_view", Bundle().apply {
putString("screen_name", name)
putString("screen_class", activity::class.simpleName)
})
analytics.pageStart(name, activity::class.simpleName)
}
fun popCurrentScreen(name: String?) {
analytics.pageEnd(name)
}
}

View File

@ -44,9 +44,9 @@ class CrashLogExceptionTree : FormatterPriorityTree(Log.ERROR) {
connectCrash.setCustomKey("message", message)
if (t != null) {
connectCrash.log(priority, t.stackTraceToString())
connectCrash.recordException(t)
} else {
connectCrash.log(priority, StackTraceRecorder(format(priority, tag, message)).stackTraceToString())
connectCrash.recordException(StackTraceRecorder(format(priority, tag, message)))
}
}
}

View File

@ -3,10 +3,15 @@ package io.github.wulkanowy.ui.base
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import androidx.viewbinding.ViewBinding
import io.github.wulkanowy.utils.AnalyticsHelper
import io.github.wulkanowy.utils.lifecycleAwareVariable
import javax.inject.Inject
abstract class BaseDialogFragment<VB : ViewBinding> : DialogFragment(), BaseView {
@Inject
lateinit var analyticsHelper: AnalyticsHelper
protected var binding: VB by lifecycleAwareVariable()
override fun showError(text: String, error: Throwable) {
@ -28,4 +33,14 @@ abstract class BaseDialogFragment<VB : ViewBinding> : DialogFragment(), BaseView
override fun showErrorDetailsDialog(error: Throwable) {
ErrorDialog.newInstance(error).show(childFragmentManager, error.toString())
}
override fun onResume() {
super.onResume()
analyticsHelper.setCurrentScreen(requireActivity(), this::class.simpleName)
}
override fun onPause() {
super.onPause()
analyticsHelper.popCurrentScreen(this::class.simpleName)
}
}

View File

@ -38,8 +38,8 @@ 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.AppInfo
import io.github.wulkanowy.utils.AnalyticsHelper
import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.UpdateHelper
import io.github.wulkanowy.utils.dpToPx
import io.github.wulkanowy.utils.getThemeAttrColor
@ -182,7 +182,10 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
}
with(navController) {
setOnViewChangeListener(presenter::onViewChange)
setOnViewChangeListener { section, name ->
analytics.setCurrentScreen(this@MainActivity, name)
presenter.onViewChange(section)
}
fragmentHideStrategy = HIDE
rootFragments = listOf(
GradeFragment.newInstance(),
@ -194,10 +197,6 @@ 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
@ -208,6 +207,7 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
}
override fun switchMenuView(position: Int) {
analytics.popCurrentScreen(navController.currentFrag!!::class.simpleName)
navController.switchTab(position)
}
@ -245,10 +245,12 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
}
fun pushView(fragment: Fragment) {
analytics.popCurrentScreen(navController.currentFrag!!::class.simpleName)
navController.pushFragment(fragment)
}
override fun popView(depth: Int) {
analytics.popCurrentScreen(navController.currentFrag!!::class.simpleName)
navController.safelyPopFragments(depth)
}

View File

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

View File

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

View File

@ -35,4 +35,8 @@ class AnalyticsHelper @Inject constructor(
putString(FirebaseAnalytics.Param.SCREEN_CLASS, activity::class.simpleName)
})
}
@Suppress("UNUSED_PARAMETER")
fun popCurrentScreen(name: String?) {
}
}