Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyticsを追加 #106

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ dependencies {
kapt depends.lifecycle.compiler
kapt depends.room.compiler

// Firebase
implementation depends.firebase.core

// Network
implementation depends.retrofit.core
implementation depends.retrofit.converterGson
Expand Down
14 changes: 3 additions & 11 deletions app/src/debug/kotlin/com/ayatk/biblio/DebugApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ class DebugApp : App() {
Stetho.initializeWithDefaults(this)
DebotConfigurator.configureWithDefault()
Takt.stock(this).play()
Timber.plant(Timber.DebugTree())

initLeakCanary()

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
if (!LeakCanary.isInAnalyzerProcess(this)) {
LeakCanary.install(this)
}
}

Expand All @@ -50,11 +49,4 @@ class DebugApp : App() {
Takt.finish()
super.onTerminate()
}

private fun initLeakCanary() {
if (LeakCanary.isInAnalyzerProcess(this)) {
return
}
LeakCanary.install(this)
}
}
8 changes: 8 additions & 0 deletions app/src/main/kotlin/com/ayatk/biblio/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ package com.ayatk.biblio

import android.annotation.SuppressLint
import com.ayatk.biblio.di.DaggerAppComponent
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.forest.CrashlyticsTree
import com.crashlytics.android.Crashlytics
import dagger.android.AndroidInjector
import dagger.android.support.DaggerApplication
import io.fabric.sdk.android.Fabric
import timber.log.Timber

@SuppressLint("Registered")
open class App : DaggerApplication() {
Expand All @@ -30,6 +33,11 @@ open class App : DaggerApplication() {
super.onCreate()

Fabric.with(this, Crashlytics())

Analytics.init(this)

// Timber forest
Timber.plant(CrashlyticsTree())
}

override fun applicationInjector(): AndroidInjector<out DaggerApplication> =
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/kotlin/com/ayatk/biblio/ui/detail/DetailActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.ayatk.biblio.model.Novel
import com.ayatk.biblio.ui.detail.index.IndexFragment
import com.ayatk.biblio.ui.detail.info.InfoFragment
import com.ayatk.biblio.ui.util.initBackToolbar
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.ext.extraOf
import dagger.android.support.DaggerAppCompatActivity

Expand All @@ -51,7 +52,17 @@ class DetailActivity : DaggerAppCompatActivity() {
// ViewPager
val viewPager = binding.containerPager
viewPager.adapter = DetailPagerAdapter(supportFragmentManager)

Analytics.viewPagerEvent(viewPager) { position ->
when (position) {
0 -> Analytics.event(Analytics.DetailAction.VIEW_TABLE_OF_CONTENTS, novel.code)
1 -> Analytics.event(Analytics.DetailAction.VIEW_NOVEL_INFO, novel.code)
}
}

binding.tab.setupWithViewPager(viewPager)

lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.DETAIL))
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.ayatk.biblio.model.Novel
import com.ayatk.biblio.ui.detail.index.item.IndexItem
import com.ayatk.biblio.ui.util.helper.navigateToEpisode
import com.ayatk.biblio.ui.util.init
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.Result
import com.ayatk.biblio.util.ext.observe
import com.ayatk.biblio.util.ext.setVisible
Expand Down Expand Up @@ -59,6 +60,11 @@ class IndexFragment : DaggerFragment() {
context!!.navigateToEpisode(index.novel, index.page)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.INDEX))
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.os.bundleOf
import com.ayatk.biblio.databinding.FragmentInfoBinding
import com.ayatk.biblio.di.ViewModelFactory
import com.ayatk.biblio.model.Novel
import com.ayatk.biblio.util.Analytics
import dagger.android.support.DaggerFragment
import javax.inject.Inject

Expand All @@ -46,6 +47,8 @@ class InfoFragment : DaggerFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel.novel = novel

lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.INFO))
}

override fun onCreateView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class InfoViewModel @Inject constructor(
}

fun onClickNovelPage(context: Context) {
context.navigateToWebPage( "http://ncode.syosetu.com/" + novel.code.toLowerCase())
context.navigateToWebPage("http://ncode.syosetu.com/" + novel.code.toLowerCase())
}

// TODO: 2017/11/26 context持ってるのでFragmentに移動させる
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.ayatk.biblio.databinding.ActivityEpisodeBinding
import com.ayatk.biblio.model.Novel
import com.ayatk.biblio.ui.UiEvent
import com.ayatk.biblio.ui.util.initBackToolbar
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.ext.extraOf
import dagger.android.support.DaggerAppCompatActivity
import org.greenrobot.eventbus.EventBus
Expand All @@ -52,6 +53,8 @@ class EpisodeActivity : DaggerAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.EPISODE))

initBackToolbar(binding.toolbar)

// ViewPager
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/kotlin/com/ayatk/biblio/ui/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.ayatk.biblio.databinding.ActivityMainBinding
import com.ayatk.biblio.ui.search.SearchActivity
import com.ayatk.biblio.ui.util.Page
import com.ayatk.biblio.ui.util.helper.disableShiftingMode
import com.ayatk.biblio.util.Analytics
import dagger.android.support.DaggerAppCompatActivity
import javax.inject.Inject

Expand Down Expand Up @@ -74,7 +75,9 @@ class HomeActivity : DaggerAppCompatActivity() {
binding.bottomNav.selectedItemId = defaultPrefs.homePageState
binding.bottomNav.setOnNavigationItemSelectedListener {
defaultPrefs.homePageState = it.itemId
changePage(Page.forMenuId(it.itemId))
val page = Page.forMenuId(it.itemId)
Analytics.event(page.action, null)
changePage(page)
invalidateOptionsMenu()
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ayatk.biblio.databinding.FragmentBookmarkBinding
import com.ayatk.biblio.util.Analytics
import dagger.android.support.DaggerFragment

class BookmarkFragment : DaggerFragment() {

lateinit var binding: FragmentBookmarkBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.BOOKMARK))
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.ayatk.biblio.model.Novel
import com.ayatk.biblio.ui.home.library.item.LibraryItem
import com.ayatk.biblio.ui.util.helper.navigateToDetail
import com.ayatk.biblio.ui.util.init
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.Result
import com.ayatk.biblio.util.ext.observe
import com.ayatk.biblio.util.ext.setVisible
Expand All @@ -57,9 +58,11 @@ class LibraryFragment : DaggerFragment() {

private val librarySection = Section()
private val onClickListener = { novel: Novel ->
Analytics.event(Analytics.DetailAction.VIEW_VIA_HOME_LIBRARY, novel.code)
context!!.navigateToDetail(novel)
}
private val onMenuClickListener = { anchor: View, novel: Novel ->
Analytics.event(Analytics.LibraryAction.TAP_CELL_MENU, novel.code)
PopupMenu(context!!, anchor).apply {
inflate(R.menu.menu_library_item)
setOnMenuItemClickListener {
Expand All @@ -76,6 +79,11 @@ class LibraryFragment : DaggerFragment() {
false
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.LIBRARY))
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -113,17 +121,20 @@ class LibraryFragment : DaggerFragment() {
})
}

private fun deleteDialog(novel: Novel) =
AlertDialog.Builder(context!!)
.setTitle(context!!.getString(R.string.delete_popup_title, novel.title))
.setMessage(R.string.delete_popup_message)
.setPositiveButton(R.string.delete_popup_positive) { _, _ ->
viewModel.delete(novel)
}
.setNegativeButton(R.string.delete_popup_negative) { _, _ ->
/* no-op */
}
.show()
private fun deleteDialog(novel: Novel) {
Analytics.event(Analytics.LibraryAction.DIALOG_NOVEL_DELETE_VIEWED, novel.code)
AlertDialog.Builder(context!!)
.setTitle(context!!.getString(R.string.delete_popup_title, novel.title))
.setMessage(R.string.delete_popup_message)
.setPositiveButton(R.string.delete_popup_positive) { _, _ ->
Analytics.event(Analytics.LibraryAction.DELETE_NOVEL, novel.code)
viewModel.delete(novel)
}
.setNegativeButton(R.string.delete_popup_negative) { _, _ ->
Analytics.event(Analytics.LibraryAction.DIALOG_NOVEL_DELETE_CANCEL, novel.code)
}
.show()
}

companion object {
fun newInstance(): LibraryFragment = LibraryFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.ayatk.biblio.databinding.FragmentRankingBinding
import com.ayatk.biblio.di.ViewModelFactory
import com.ayatk.biblio.model.Ranking
import com.ayatk.biblio.ui.util.customview.RankingTopCellView
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.Result
import com.ayatk.biblio.util.ext.observe
import dagger.android.support.DaggerFragment
Expand All @@ -43,6 +44,11 @@ class TopRankingFragment : DaggerFragment() {

lateinit var binding: FragmentRankingBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.TOP_RANKING))
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ import android.support.v7.preference.PreferenceFragmentCompat
import com.ayatk.biblio.BuildConfig
import com.ayatk.biblio.R
import com.ayatk.biblio.ui.license.LicenseActivity
import com.ayatk.biblio.util.Analytics

class SettingFragment : PreferenceFragmentCompat() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.SETTINGS))
}

override fun onCreatePreferences(bundle: Bundle?, s: String?) {
addPreferencesFromResource(R.xml.pref)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.support.v7.app.AppCompatActivity
import com.ayatk.biblio.R
import com.ayatk.biblio.databinding.ActivityWebBinding
import com.ayatk.biblio.ui.util.initBackToolbar
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.ext.extraOf

class LicenseActivity : AppCompatActivity() {
Expand All @@ -34,6 +35,7 @@ class LicenseActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.LICENSE))

val title = intent.getStringExtra(EXTRA_TITLE)
val url = intent.getStringExtra(EXTRA_URL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.ayatk.biblio.R
import com.ayatk.biblio.databinding.ActivityRankingBinding
import com.ayatk.biblio.model.enums.RankingType
import com.ayatk.biblio.ui.util.initBackToolbar
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.ext.extraOf
import com.ayatk.biblio.util.ext.integer
import dagger.android.support.DaggerAppCompatActivity
Expand All @@ -44,6 +45,8 @@ class RankingActivity : DaggerAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.RANKING))

initBackToolbar(binding.toolbar)

binding.rankingViewPager.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.ayatk.biblio.model.enums.RankingType
import com.ayatk.biblio.ui.ranking.item.RankingItem
import com.ayatk.biblio.ui.util.helper.navigateToDetail
import com.ayatk.biblio.ui.util.init
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.Result
import com.ayatk.biblio.util.ext.observe
import com.ayatk.biblio.util.ext.setVisible
Expand Down Expand Up @@ -57,9 +58,15 @@ class RankingListFragment : DaggerFragment() {

private val rankingSection = Section()
private val onClickListener = { novel: Novel ->
Analytics.event(Analytics.DetailAction.VIEW_VIA_RANKING_LIST, novel.code)
context!!.navigateToDetail(novel)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.RANKING_LIST))
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.ayatk.biblio.ui.search.item.SearchResultItem
import com.ayatk.biblio.ui.util.helper.navigateToDetail
import com.ayatk.biblio.ui.util.init
import com.ayatk.biblio.ui.util.initBackToolbar
import com.ayatk.biblio.util.Analytics
import com.ayatk.biblio.util.Result
import com.ayatk.biblio.util.ext.observe
import com.ayatk.biblio.util.ext.setVisible
Expand Down Expand Up @@ -64,6 +65,7 @@ class SearchActivity : DaggerAppCompatActivity() {

private val searchSection = Section()
private val onItemClickListener = { novel: Novel ->
Analytics.event(Analytics.DetailAction.VIEW_VIA_SEARCH_RESULT, novel.code)
navigateToDetail(novel)
}
private val onDownloadClickListener: (Novel) -> Unit = { novel: Novel ->
Expand All @@ -76,6 +78,8 @@ class SearchActivity : DaggerAppCompatActivity() {
binding.setLifecycleOwner(this)
binding.viewModel = viewModel

lifecycle.addObserver(Analytics.ScreenLog(Analytics.Screen.SEARCH))

initBackToolbar(binding.toolbar)

val scrollListener = object : OnScrollListener() {
Expand Down
Loading