Browse Source

Added Firebase Analytics custom events

pull/50/head
Ezerous 6 years ago
parent
commit
c3b16db395
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  2. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java
  3. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java
  4. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  5. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/DeleteTask.java
  6. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java
  7. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java
  8. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java
  9. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java
  10. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  11. 3
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  12. 29
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  13. 1
      app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java

4
app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

@ -12,9 +12,12 @@ import android.widget.LinearLayout;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.Toast; import android.widget.Toast;
import com.google.firebase.analytics.FirebaseAnalytics;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.main.MainActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.session.SessionManager.BANNED_USER; import static gr.thmmy.mthmmy.session.SessionManager.BANNED_USER;
@ -163,6 +166,7 @@ public class LoginActivity extends BaseActivity {
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
"Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG) "Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG)
.show(); .show();
BaseApplication.getInstance().logFirebaseAnalyticsEvent(FirebaseAnalytics.Event.LOGIN, null);
//Go to main //Go to main
Intent intent = new Intent(LoginActivity.this, MainActivity.class); Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent); startActivity(intent);

1
app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java

@ -6,7 +6,6 @@ import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;

1
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java

@ -1,7 +1,6 @@
package gr.thmmy.mthmmy.activities.settings; package gr.thmmy.mthmmy.activities.settings;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;

2
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java

@ -1,9 +1,7 @@
package gr.thmmy.mthmmy.activities.topic; package gr.thmmy.mthmmy.activities.topic;
import android.graphics.Color; import android.graphics.Color;
import android.util.Log;
import org.jsoup.Connection;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;

1
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/DeleteTask.java

@ -38,6 +38,7 @@ public class DeleteTask extends AsyncTask<String, Void, Boolean> {
//Response response = client.newCall(delete).execute(); //Response response = client.newCall(delete).execute();
switch (Posting.replyStatus(response)) { switch (Posting.replyStatus(response)) {
case SUCCESSFUL: case SUCCESSFUL:
BaseApplication.getInstance().logFirebaseAnalyticsEvent("post_deletion", null);
return true; return true;
default: default:
Timber.e("Something went wrong. Request string: %s", delete.toString()); Timber.e("Something went wrong. Request string: %s", delete.toString());

1
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java

@ -51,6 +51,7 @@ public class EditTask extends AsyncTask<String, Void, Boolean> {
Response response = client.newCall(post).execute(); Response response = client.newCall(post).execute();
switch (replyStatus(response)) { switch (replyStatus(response)) {
case SUCCESSFUL: case SUCCESSFUL:
BaseApplication.getInstance().logFirebaseAnalyticsEvent("post_editing", null);
return true; return true;
case NEW_REPLY_WHILE_POSTING: case NEW_REPLY_WHILE_POSTING:
//TODO this... //TODO this...

1
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java

@ -9,7 +9,6 @@ import org.jsoup.select.Selector;
import java.io.IOException; import java.io.IOException;
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditResult;
import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseApplication;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;

3
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java

@ -31,7 +31,7 @@ public class ReplyTask extends AsyncTask<String, Void, Boolean> {
@Override @Override
protected Boolean doInBackground(String... args) { protected Boolean doInBackground(String... args) {
final String sentFrommTHMMY = includeAppSignature final String sentFrommTHMMY = includeAppSignature
? "\n[right][size=7pt][i]sent from [url=https://play.google.com/store/apps/details?id=gr.thmmy.mthmmy]mTHMMY[/url][/i] [/size][/right]" ? "\n[right][size=7pt][i]sent from [url=https://play.google.com/store/apps/details?id=gr.thmmy.mthmmy]mTHMMY [/url][/i][/size][/right]"
: ""; : "";
RequestBody postBody = new MultipartBody.Builder() RequestBody postBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM) .setType(MultipartBody.FORM)
@ -54,6 +54,7 @@ public class ReplyTask extends AsyncTask<String, Void, Boolean> {
Response response = client.newCall(post).execute(); Response response = client.newCall(post).execute();
switch (replyStatus(response)) { switch (replyStatus(response)) {
case SUCCESSFUL: case SUCCESSFUL:
BaseApplication.getInstance().logFirebaseAnalyticsEvent("post_creation", null);
return true; return true;
case NEW_REPLY_WHILE_POSTING: case NEW_REPLY_WHILE_POSTING:
//TODO this... //TODO this...

3
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java

@ -1,10 +1,7 @@
package gr.thmmy.mthmmy.activities.topic.tasks; package gr.thmmy.mthmmy.activities.topic.tasks;
import android.util.SparseArray;
import java.util.ArrayList; import java.util.ArrayList;
import gr.thmmy.mthmmy.activities.topic.tasks.TopicTask;
import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.model.Post;
public class TopicTaskResult { public class TopicTaskResult {

1
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java

@ -295,6 +295,7 @@ public class UploadActivity extends BaseActivity {
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
Toast.makeText(context, "Upload completed successfully", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Upload completed successfully", Toast.LENGTH_SHORT).show();
UploadsHelper.deleteTempFiles(); UploadsHelper.deleteTempFiles();
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }

3
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -7,7 +7,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
@ -45,12 +44,12 @@ import java.util.ArrayList;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.AboutActivity; import gr.thmmy.mthmmy.activities.AboutActivity;
import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.upload.UploadActivity;
import gr.thmmy.mthmmy.activities.bookmarks.BookmarkActivity; import gr.thmmy.mthmmy.activities.bookmarks.BookmarkActivity;
import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity;
import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.main.MainActivity;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
import gr.thmmy.mthmmy.activities.upload.UploadActivity;
import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.Bookmark;
import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyFile;
import gr.thmmy.mthmmy.services.DownloadHelper; import gr.thmmy.mthmmy.services.DownloadHelper;

29
app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.widget.ImageView; import android.widget.ImageView;
@ -12,6 +13,7 @@ import android.widget.ImageView;
import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.PersistentCookieJar;
import com.franmontiel.persistentcookiejar.cache.SetCookieCache; import com.franmontiel.persistentcookiejar.cache.SetCookieCache;
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.jakewharton.picasso.OkHttp3Downloader; import com.jakewharton.picasso.OkHttp3Downloader;
import com.mikepenz.fontawesome_typeface_library.FontAwesome; import com.mikepenz.fontawesome_typeface_library.FontAwesome;
import com.mikepenz.iconics.IconicsDrawable; import com.mikepenz.iconics.IconicsDrawable;
@ -22,7 +24,6 @@ import com.squareup.picasso.Picasso;
import net.gotev.uploadservice.UploadService; import net.gotev.uploadservice.UploadService;
import net.gotev.uploadservice.okhttp.OkHttpStack; import net.gotev.uploadservice.okhttp.OkHttpStack;
import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -31,16 +32,17 @@ import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CrashReportingTree; import gr.thmmy.mthmmy.utils.CrashReportingTree;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response;
import timber.log.Timber; import timber.log.Timber;
public class BaseApplication extends Application { public class BaseApplication extends Application {
private static BaseApplication baseApplication; //BaseApplication singleton private static BaseApplication baseApplication; //BaseApplication singleton
// Client & SessionManager //FirebaseAnalytics
private FirebaseAnalytics firebaseAnalytics;
//Client & SessionManager
private OkHttpClient client; private OkHttpClient client;
private SessionManager sessionManager; private SessionManager sessionManager;
@ -59,20 +61,20 @@ public class BaseApplication extends Application {
super.onCreate(); super.onCreate();
baseApplication = this; //init singleton baseApplication = this; //init singleton
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG)
Timber.plant(new Timber.DebugTree()); Timber.plant(new Timber.DebugTree());
} else { else
Timber.plant(new CrashReportingTree()); Timber.plant(new CrashReportingTree());
}
// Analytics init
firebaseAnalytics = FirebaseAnalytics.getInstance(this);
SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE); SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE);
SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext());
PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor);
client = new OkHttpClient.Builder() client = new OkHttpClient.Builder()
.cookieJar(cookieJar) .cookieJar(cookieJar)
.addInterceptor(new Interceptor() { .addInterceptor(chain -> {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request(); Request request = chain.request();
HttpUrl oldUrl = chain.request().url(); HttpUrl oldUrl = chain.request().url();
if (Objects.equals(chain.request().url().host(), "www.thmmy.gr")) { if (Objects.equals(chain.request().url().host(), "www.thmmy.gr")) {
@ -84,7 +86,6 @@ public class BaseApplication extends Application {
} }
return chain.proceed(request); return chain.proceed(request);
}
}) })
.connectTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS)
@ -130,6 +131,12 @@ public class BaseApplication extends Application {
dpWidth = displayMetrics.widthPixels / displayMetrics.density; dpWidth = displayMetrics.widthPixels / displayMetrics.density;
} }
public void logFirebaseAnalyticsEvent(String event, Bundle params) {
firebaseAnalytics.logEvent(event, params);
}
//Getters
public OkHttpClient getClient() { public OkHttpClient getClient() {
return client; return client;
} }

1
app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java

@ -41,6 +41,7 @@ public class DownloadHelper {
request.setDestinationInExternalPublicDir(SAVE_DIR.getName(), fileName); request.setDestinationInExternalPublicDir(SAVE_DIR.getName(), fileName);
request.allowScanningByMediaScanner(); request.allowScanningByMediaScanner();
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_download", null);
downloadManager.enqueue(request); downloadManager.enqueue(request);
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(applicationContext, "Download failed...", Toast.LENGTH_SHORT).show(); Toast.makeText(applicationContext, "Download failed...", Toast.LENGTH_SHORT).show();

Loading…
Cancel
Save