diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java index 5a0f32b3..f950a1d3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java +++ b/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.Toast; +import com.google.firebase.analytics.FirebaseAnalytics; + import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseApplication; import timber.log.Timber; import static gr.thmmy.mthmmy.session.SessionManager.BANNED_USER; @@ -163,6 +166,7 @@ public class LoginActivity extends BaseActivity { Toast.makeText(getApplicationContext(), "Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG) .show(); + BaseApplication.getInstance().logFirebaseAnalyticsEvent(FirebaseAnalytics.Event.LOGIN, null); //Go to main Intent intent = new Intent(LoginActivity.this, MainActivity.class); startActivity(intent); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java index 33025dfa..1709db82 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java +++ b/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.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java index 0f44a511..433ba13c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java @@ -1,7 +1,6 @@ package gr.thmmy.mthmmy.activities.settings; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import gr.thmmy.mthmmy.R; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java index 83b2dfe5..e6970a80 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java @@ -1,9 +1,7 @@ package gr.thmmy.mthmmy.activities.topic; import android.graphics.Color; -import android.util.Log; -import org.jsoup.Connection; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/DeleteTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/DeleteTask.java index f3523953..0a9486b1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/DeleteTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/DeleteTask.java @@ -38,6 +38,7 @@ public class DeleteTask extends AsyncTask { //Response response = client.newCall(delete).execute(); switch (Posting.replyStatus(response)) { case SUCCESSFUL: + BaseApplication.getInstance().logFirebaseAnalyticsEvent("post_deletion", null); return true; default: Timber.e("Something went wrong. Request string: %s", delete.toString()); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java index f9fe5444..3b5b46f0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java @@ -51,6 +51,7 @@ public class EditTask extends AsyncTask { Response response = client.newCall(post).execute(); switch (replyStatus(response)) { case SUCCESSFUL: + BaseApplication.getInstance().logFirebaseAnalyticsEvent("post_editing", null); return true; case NEW_REPLY_WHILE_POSTING: //TODO this... diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java index 7259d580..5864e635 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java +++ b/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 gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditResult; import gr.thmmy.mthmmy.base.BaseApplication; import okhttp3.OkHttpClient; import okhttp3.Request; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java index 55be056d..0b527421 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java @@ -31,7 +31,7 @@ public class ReplyTask extends AsyncTask { @Override protected Boolean doInBackground(String... args) { 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() .setType(MultipartBody.FORM) @@ -54,6 +54,7 @@ public class ReplyTask extends AsyncTask { Response response = client.newCall(post).execute(); switch (replyStatus(response)) { case SUCCESSFUL: + BaseApplication.getInstance().logFirebaseAnalyticsEvent("post_creation", null); return true; case NEW_REPLY_WHILE_POSTING: //TODO this... diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java index 570160d3..c713da1f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java @@ -1,10 +1,7 @@ package gr.thmmy.mthmmy.activities.topic.tasks; -import android.util.SparseArray; - import java.util.ArrayList; -import gr.thmmy.mthmmy.activities.topic.tasks.TopicTask; import gr.thmmy.mthmmy.model.Post; public class TopicTaskResult { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java index a847d0e2..455be865 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java +++ b/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) { Toast.makeText(context, "Upload completed successfully", Toast.LENGTH_SHORT).show(); UploadsHelper.deleteTempFiles(); + BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null); progressBar.setVisibility(View.GONE); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 94521fc9..df678e29 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/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.SharedPreferences; import android.content.pm.PackageManager; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; @@ -45,12 +44,12 @@ import java.util.ArrayList; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.AboutActivity; 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.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; 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.ThmmyFile; import gr.thmmy.mthmmy.services.DownloadHelper; diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java index 95a1ab1d..34c6d2f9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.util.DisplayMetrics; import android.widget.ImageView; @@ -12,6 +13,7 @@ import android.widget.ImageView; import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.cache.SetCookieCache; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; +import com.google.firebase.analytics.FirebaseAnalytics; import com.jakewharton.picasso.OkHttp3Downloader; import com.mikepenz.fontawesome_typeface_library.FontAwesome; import com.mikepenz.iconics.IconicsDrawable; @@ -22,7 +24,6 @@ import com.squareup.picasso.Picasso; import net.gotev.uploadservice.UploadService; import net.gotev.uploadservice.okhttp.OkHttpStack; -import java.io.IOException; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -31,16 +32,17 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.utils.CrashReportingTree; import okhttp3.HttpUrl; -import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.Response; import timber.log.Timber; public class BaseApplication extends Application { private static BaseApplication baseApplication; //BaseApplication singleton - // Client & SessionManager + //FirebaseAnalytics + private FirebaseAnalytics firebaseAnalytics; + + //Client & SessionManager private OkHttpClient client; private SessionManager sessionManager; @@ -59,32 +61,31 @@ public class BaseApplication extends Application { super.onCreate(); baseApplication = this; //init singleton - if (BuildConfig.DEBUG) { + if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree()); - } else { + else Timber.plant(new CrashReportingTree()); - } + + // Analytics init + firebaseAnalytics = FirebaseAnalytics.getInstance(this); SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE); SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); client = new OkHttpClient.Builder() .cookieJar(cookieJar) - .addInterceptor(new Interceptor() { - @Override - public Response intercept(Chain chain) throws IOException { - Request request = chain.request(); - HttpUrl oldUrl = chain.request().url(); - if (Objects.equals(chain.request().url().host(), "www.thmmy.gr")) { - if (!oldUrl.toString().contains("theme=4")) { - //Probably works but needs more testing: - HttpUrl newUrl = oldUrl.newBuilder().addQueryParameter("theme", "4").build(); - request = request.newBuilder().url(newUrl).build(); - } + .addInterceptor(chain -> { + Request request = chain.request(); + HttpUrl oldUrl = chain.request().url(); + if (Objects.equals(chain.request().url().host(), "www.thmmy.gr")) { + if (!oldUrl.toString().contains("theme=4")) { + //Probably works but needs more testing: + HttpUrl newUrl = oldUrl.newBuilder().addQueryParameter("theme", "4").build(); + request = request.newBuilder().url(newUrl).build(); } - return chain.proceed(request); - } + return chain.proceed(request); + }) .connectTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) @@ -130,6 +131,12 @@ public class BaseApplication extends Application { dpWidth = displayMetrics.widthPixels / displayMetrics.density; } + public void logFirebaseAnalyticsEvent(String event, Bundle params) { + firebaseAnalytics.logEvent(event, params); + } + + //Getters + public OkHttpClient getClient() { return client; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java index 1e1a5c31..65b5a426 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java @@ -41,6 +41,7 @@ public class DownloadHelper { request.setDestinationInExternalPublicDir(SAVE_DIR.getName(), fileName); request.allowScanningByMediaScanner(); + BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_download", null); downloadManager.enqueue(request); } catch (Exception e) { Toast.makeText(applicationContext, "Download failed...", Toast.LENGTH_SHORT).show();