Skip to content

Commit

Permalink
add firebase tracker for detail page.
Browse files Browse the repository at this point in the history
  • Loading branch information
feilongfl authored and Haleydu committed Aug 6, 2020
1 parent fbab3e4 commit ad7d2bd
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.facebook.imagepipeline.core.ImagePipelineFactory;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.hiroshi.cimoc.App;
import com.hiroshi.cimoc.R;
import com.hiroshi.cimoc.fresco.ControllerBuilderSupplierFactory;
import com.hiroshi.cimoc.fresco.ImagePipelineFactoryBuilder;
Expand Down Expand Up @@ -139,6 +143,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
case R.id.detail_search_title:
if (!StringUtils.isEmpty(mPresenter.getComic().getTitle())) {
if(App.getPreferenceManager().getBoolean(PreferenceManager.PREF_OTHER_FIREBASE_EVENT, true)) {
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT, mPresenter.getComic().getTitle());
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "byTitle");
bundle.putInt(FirebaseAnalytics.Param.SOURCE, mPresenter.getComic().getSource());
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SEARCH, bundle);
}
intent = ResultActivity.createIntent(this, mPresenter.getComic().getTitle(), null, ResultActivity.LAUNCH_MODE_SEARCH);
startActivity(intent);
} else {
Expand All @@ -160,6 +172,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
intent.putExtra(Intent.EXTRA_TEXT, url);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, url));

// firebase analytics
if(App.getPreferenceManager().getBoolean(PreferenceManager.PREF_OTHER_FIREBASE_EVENT, true)) {
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT, url);
bundle.putInt(FirebaseAnalytics.Param.SOURCE, mPresenter.getComic().getSource());
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SHARE, bundle);
}
break;
case R.id.detail_reverse_list:
mDetailAdapter.reverse();
Expand Down Expand Up @@ -299,13 +320,31 @@ public void onComicLoadSuccess(Comic comic) {
@Override
public void onChapterLoadSuccess(List<Chapter> list) {
hideProgressBar();
if(App.getPreferenceManager().getBoolean(PreferenceManager.PREF_OTHER_FIREBASE_EVENT, true)) {
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT, mPresenter.getComic().getTitle());
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Title");
bundle.putInt(FirebaseAnalytics.Param.SOURCE, mPresenter.getComic().getSource());
bundle.putBoolean(FirebaseAnalytics.Param.SUCCESS, true);
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle);
}
if (mPresenter.getComic().getTitle() != null && mPresenter.getComic().getCover() != null) {
mDetailAdapter.addAll(list);
}
}

@Override
public void onParseError() {
if(App.getPreferenceManager().getBoolean(PreferenceManager.PREF_OTHER_FIREBASE_EVENT, true)) {
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT, mPresenter.getComic().getTitle());
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Title");
bundle.putInt(FirebaseAnalytics.Param.SOURCE, mPresenter.getComic().getSource());
bundle.putBoolean(FirebaseAnalytics.Param.SUCCESS, false);
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle);
}
hideProgressBar();
showSnackbar(R.string.common_parse_error);
}
Expand Down

0 comments on commit ad7d2bd

Please sign in to comment.