Add operation records analytics
This commit is contained in:
1 parent
dd700a0f2d
commit
169f4c3eb8
10 files changed
+131
-2
No files matched your search
@@ -20,17 +20,24 @@ import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
||||
public final class Analytics {
|
||||
|
||||
private static FirebaseAnalytics analytics;
|
||||
private static String userId;
|
||||
private static OkHttpClient client;
|
||||
|
||||
private Analytics() {}
|
||||
|
||||
public static void start(Context context) {
|
||||
analytics = FirebaseAnalytics.getInstance(context);
|
||||
analytics.setUserId(Settings.getUserID());
|
||||
userId = Settings.getUserID();
|
||||
analytics.setUserId(userId);
|
||||
client = EhApplication.getOkHttpClient(context);
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
@@ -45,4 +52,89 @@ public final class Analytics {
|
||||
analytics.logEvent("scene_view", bundle);
|
||||
}
|
||||
}
|
||||
|
||||
public static void signIn() {
|
||||
addRecord("sign_in", null, null, null);
|
||||
}
|
||||
|
||||
public static void viewGalleryList() {
|
||||
addRecord("view_gallery_list", null, null, null);
|
||||
}
|
||||
|
||||
public static void imageSearch() {
|
||||
addRecord("image_search", null, null, null);
|
||||
}
|
||||
|
||||
public static void viewWhatsHot() {
|
||||
addRecord("view_whats_hot", null, null, null);
|
||||
}
|
||||
|
||||
public static void viewHistory() {
|
||||
addRecord("view_history", null, null, null);
|
||||
}
|
||||
|
||||
public static void viewFavourite() {
|
||||
addRecord("view_favourite", null, null, null);
|
||||
}
|
||||
|
||||
public static void viewGallery(long gid, String token) {
|
||||
addRecord("view_gallery", gid, token, null);
|
||||
}
|
||||
|
||||
public static void readGallery(long gid, String token) {
|
||||
addRecord("read_gallery", gid, token, null);
|
||||
}
|
||||
|
||||
public static void downloadGallery(long gid, String token) {
|
||||
addRecord("download_gallery", gid, token, null);
|
||||
}
|
||||
|
||||
public static void rateGallery(long gid, String token) {
|
||||
addRecord("rate_gallery", gid, token, null);
|
||||
}
|
||||
|
||||
public static void commentGallery(long gid, String token) {
|
||||
addRecord("comment_gallery", gid, token, null);
|
||||
}
|
||||
|
||||
public static void voteComment(long gid, String token) {
|
||||
addRecord("vote_comment", gid, token, null);
|
||||
}
|
||||
|
||||
public static void addGalleryToFavourite(long gid, String token) {
|
||||
addRecord("add_gallery_to_favourite", gid, token, null);
|
||||
}
|
||||
|
||||
public static void downloadArchive(long gid, String token) {
|
||||
addRecord("download_archive", gid, token, null);
|
||||
}
|
||||
|
||||
private static void addRecord(String action, Long gid, String token, Integer page) {
|
||||
if (isEnabled()) {
|
||||
IoThreadPoolExecutor.getInstance().execute(() -> {
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder(150)
|
||||
.append("http://155.138.199.206:8080/addRecord?userId=")
|
||||
.append(userId)
|
||||
.append("&action=")
|
||||
.append(action);
|
||||
if (gid != null) {
|
||||
sb.append("&gid=").append(gid);
|
||||
}
|
||||
if (token != null) {
|
||||
sb.append("&token=").append(token);
|
||||
}
|
||||
if (page != null) {
|
||||
sb.append("&page=").append(page);
|
||||
}
|
||||
String url = sb.toString();
|
||||
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
client.newCall(request).execute().close();
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.dao.DownloadInfo;
|
||||
@@ -447,6 +448,8 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
for (DownloadInfoListener l: mDownloadInfoListeners) {
|
||||
l.onAdd(info, list, list.size() - 1);
|
||||
}
|
||||
|
||||
Analytics.downloadGallery(galleryInfo.gid, galleryInfo.token);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.hippo.app.ListCheckBoxDialogBuilder;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -195,6 +196,7 @@ public final class CommonOperations {
|
||||
if (slot == -1) {
|
||||
EhDB.putLocalFavorites(galleryInfo);
|
||||
listener.onSuccess(null);
|
||||
Analytics.addGalleryToFavourite(galleryInfo.gid, galleryInfo.token);
|
||||
} else if (slot >= 0 && slot <= 9) {
|
||||
EhClient client = EhApplication.getEhClient(activity);
|
||||
EhRequest request = new EhRequest();
|
||||
@@ -202,6 +204,7 @@ public final class CommonOperations {
|
||||
request.setArgs(galleryInfo.gid, galleryInfo.token, slot, "");
|
||||
request.setCallback(listener);
|
||||
client.execute(request);
|
||||
Analytics.addGalleryToFavourite(galleryInfo.gid, galleryInfo.token);
|
||||
} else {
|
||||
listener.onFailure(new Exception()); // TODO Add text
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.BuildConfig;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -206,6 +207,7 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
} else if (ACTION_EH.equals(mAction)) {
|
||||
if (mGalleryInfo != null) {
|
||||
mGalleryProvider = new EhGalleryProvider(this, mGalleryInfo);
|
||||
Analytics.readGallery(mGalleryInfo.gid, mGalleryInfo.token);
|
||||
}
|
||||
} else if (Intent.ACTION_VIEW.equals(mAction)) {
|
||||
if (mUri != null) {
|
||||
|
||||
@@ -53,6 +53,7 @@ import com.hippo.annotation.Implemented;
|
||||
import com.hippo.drawable.DrawerArrowDrawable;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.FastScroller;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -300,6 +301,8 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
guideCollections();
|
||||
|
||||
Analytics.viewFavourite();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.UrlOpener;
|
||||
@@ -281,6 +282,8 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
.setCallback(new VoteCommentListener(context,
|
||||
activity.getStageId(), getTag()));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
|
||||
Analytics.voteComment(mGid, mToken);
|
||||
}
|
||||
|
||||
private class InfoHolder extends RecyclerView.ViewHolder {
|
||||
@@ -589,6 +592,8 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
hideSoftInput();
|
||||
hideEditPanel(true);
|
||||
|
||||
Analytics.commentGallery(mGid, mToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.beerbelly.BeerBelly;
|
||||
import com.hippo.drawable.RoundSideRectDrawable;
|
||||
import com.hippo.drawerlayout.DrawerLayout;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
@@ -678,6 +679,14 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
.setCallback(callback);
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
|
||||
if (mGalleryDetail != null) {
|
||||
Analytics.viewGallery(mGalleryDetail.gid, mGalleryDetail.token);
|
||||
} else if (mGalleryInfo != null) {
|
||||
Analytics.viewGallery(mGalleryInfo.gid, mGalleryInfo.token);
|
||||
} else {
|
||||
Analytics.viewGallery(mGid, mToken);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1746,6 +1755,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
request.setArgs(mGalleryDetail.gid, mGalleryDetail.token, mArchiveFormParamOr, res);
|
||||
request.setCallback(new DownloadArchiveListener(context, activity.getStageId(), getTag()));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
Analytics.downloadArchive(mGalleryDetail.gid, mGalleryDetail.token);
|
||||
}
|
||||
|
||||
if (mDialog != null) {
|
||||
@@ -1999,6 +2009,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
.setCallback(new RateGalleryListener(context,
|
||||
activity.getStageId(), getTag(), mGalleryDetail.gid));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
|
||||
Analytics.rateGallery(mGalleryDetail.gid, mGalleryDetail.token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ import com.hippo.drawable.DrawerArrowDrawable;
|
||||
import com.hippo.drawerlayout.DrawerLayout;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.FastScroller;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -1369,6 +1370,7 @@ public final class GalleryListScene extends BaseScene
|
||||
activity.getStageId(), getTag(), taskId));
|
||||
request.setArgs();
|
||||
mClient.execute(request);
|
||||
Analytics.viewWhatsHot();
|
||||
} else if (ListUrlBuilder.MODE_IMAGE_SEARCH == mUrlBuilder.getMode()) {
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_IMAGE_SEARCH);
|
||||
@@ -1378,6 +1380,7 @@ public final class GalleryListScene extends BaseScene
|
||||
mUrlBuilder.isUseSimilarityScan(),
|
||||
mUrlBuilder.isOnlySearchCovers(), mUrlBuilder.isShowExpunged());
|
||||
mClient.execute(request);
|
||||
Analytics.imageSearch();
|
||||
} else {
|
||||
String url = mUrlBuilder.build();
|
||||
EhRequest request = new EhRequest();
|
||||
@@ -1386,6 +1389,7 @@ public final class GalleryListScene extends BaseScene
|
||||
activity.getStageId(), getTag(), taskId));
|
||||
request.setArgs(url);
|
||||
mClient.execute(request);
|
||||
Analytics.viewGalleryList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.FastScroller;
|
||||
import com.hippo.easyrecyclerview.HandlerDrawable;
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -147,6 +148,8 @@ public class HistoryScene extends ToolbarScene
|
||||
updateLazyList();
|
||||
updateView(false);
|
||||
|
||||
Analytics.viewHistory();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.widget.TextView;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -295,6 +296,7 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
.setArgs(username, password, challenge, response)
|
||||
.setCallback(callback);
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
Analytics.signIn();
|
||||
|
||||
mSigningIn = true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user