Browse Source

Analytics & Crashlytics fixes

pull/61/merge
Ezerous 6 years ago
parent
commit
104645c663
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 6
      app/proguard-rules.pro
  2. 34
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java
  3. 17
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  4. 56
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

6
app/proguard-rules.pro

@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Ragnar\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# in sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
@ -43,3 +43,7 @@
# JSoup
-keep class org.jsoup.**
# Markwon
-keep class com.caverock.androidsvg.** { *; }
-dontwarn com.caverock.androidsvg.**

34
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java

@ -23,7 +23,6 @@ import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.POSTING_APP_SIGNATURE_ENABLE_KEY;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.UPLOADING_APP_SIGNATURE_ENABLE_KEY;
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final String ARG_IS_LOGGED_IN = "selectedRingtoneKey";
@ -93,25 +92,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
findPreference(POSTING_CATEGORY).setVisible(isLoggedIn);
findPreference(POSTING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn);
//findPreference(UPLOADING_CATEGORY).setVisible(isLoggedIn);
//findPreference(UPLOADING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn);
if (!isLoggedIn && defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.remove("Unread");
defaultHomeTabValues.remove("2");
} else if (isLoggedIn && !defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.add("Unread");
defaultHomeTabValues.add("2");
}
CharSequence[] tmpCs = defaultHomeTabEntries.toArray(new CharSequence[defaultHomeTabEntries.size()]);
((ListPreference) findPreference(DEFAULT_HOME_TAB)).setEntries(tmpCs);
tmpCs = defaultHomeTabValues.toArray(new CharSequence[defaultHomeTabValues.size()]);
((ListPreference) findPreference(DEFAULT_HOME_TAB)).setEntryValues(tmpCs);
updatePreferenceVisibility();
}
@Override
@ -167,10 +148,12 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
public void updateUserLoginState(boolean isLoggedIn) {
this.isLoggedIn = isLoggedIn;
updatePreferenceVisibility();
}
private void updatePreferenceVisibility(){
findPreference(POSTING_CATEGORY).setVisible(isLoggedIn);
findPreference(POSTING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn);
//findPreference(UPLOADING_CATEGORY).setVisible(isLoggedIn);
//findPreference(UPLOADING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn);
@ -195,13 +178,14 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
if (key.equals(getString(R.string.pref_privacy_crashlytics_enable_key))) {
enabled = sharedPreferences.getBoolean(key, false);
if(enabled)
Timber.i("Crashlytics collection will be enabled after restarting.");
else
BaseApplication.getInstance().startFirebaseCrashlyticsCollection();
else {
Timber.i("Crashlytics collection will be disabled after restarting.");
Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "This change will take effect once you restart the app.", Toast.LENGTH_SHORT).show();
Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "This change will take effect once you restart the app.", Toast.LENGTH_SHORT).show();
}
} else if (key.equals(getString(R.string.pref_privacy_analytics_enable_key))) {
enabled = sharedPreferences.getBoolean(key, false);
BaseApplication.getInstance().firebaseAnalyticsCollection(enabled);
BaseApplication.getInstance().setFirebaseAnalyticsCollection(enabled);
if(enabled)
Timber.i("Analytics collection enabled.");
else

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

@ -51,7 +51,6 @@ 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;
@ -352,11 +351,11 @@ public abstract class BaseActivity extends AppCompatActivity {
intent.putExtras(extras);
startActivity(intent);
}
} else if (drawerItem.equals(UPLOAD_ID)) {
if (!(BaseActivity.this instanceof UploadActivity)) {
Intent intent = new Intent(BaseActivity.this, UploadActivity.class);
startActivity(intent);
}
// } else if (drawerItem.equals(UPLOAD_ID)) {
// if (!(BaseActivity.this instanceof UploadActivity)) {
// Intent intent = new Intent(BaseActivity.this, UploadActivity.class);
// startActivity(intent);
// }
} else if (drawerItem.equals(BOOKMARKS_ID)) {
if (!(BaseActivity.this instanceof BookmarkActivity)) {
Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class);
@ -742,7 +741,11 @@ public abstract class BaseActivity extends AppCompatActivity {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
builder.setTitle("User Agreement");
builder.setMessage(R.string.user_agreement_dialog_text);
builder.setPositiveButton("Yes, I want to help", (dialogInterface, i) -> FirebaseMessaging.getInstance().setAutoInitEnabled(true));
builder.setPositiveButton("Yes, I want to help", (dialogInterface, i) -> {
FirebaseMessaging.getInstance().setAutoInitEnabled(true);
BaseApplication.getInstance().startFirebaseCrashlyticsCollection();
BaseApplication.getInstance().setFirebaseAnalyticsCollection(true);
});
builder.setNegativeButton("Nope, leave me alone", (dialogInterface, i) -> FirebaseMessaging.getInstance().setAutoInitEnabled(true));
builder.setNeutralButton("Privacy Policy", (dialog, which) -> {/*Will be overridden below*/});
builder.setCancelable(false);

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

@ -6,6 +6,7 @@ import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.util.DisplayMetrics;
import android.widget.ImageView;
@ -39,8 +40,6 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SETTINGS_SHARED_PREFS;
public class BaseApplication extends Application {
private static BaseApplication baseApplication; //BaseApplication singleton
@ -71,18 +70,11 @@ public class BaseApplication extends Application {
//Shared Preferences
SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
SharedPreferences settingsSharedPrefs = getSharedPreferences(SETTINGS_SHARED_PREFS, Context.MODE_PRIVATE);
SharedPreferences settingsSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
// Set up Crashlytics, disabled for debug builds
if (settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_crashlytics_enable_key), false)) {
Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
.build();
// Initialize Fabric with the debug-disabled Crashlytics.
Fabric.with(this, crashlyticsKit);
Timber.plant(new CrashReportingTree());
Timber.i("Starting app with Crashlytics enabled.");
} else
if (settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_crashlytics_enable_key), false))
startFirebaseCrashlyticsCollection();
else
Timber.i("Starting app with Crashlytics disabled.");
firebaseAnalytics = FirebaseAnalytics.getInstance(this);
@ -153,16 +145,6 @@ public class BaseApplication extends Application {
dpWidth = displayMetrics.widthPixels / displayMetrics.density;
}
public void logFirebaseAnalyticsEvent(String event, Bundle params) {
firebaseAnalytics.logEvent(event, params);
}
public void firebaseAnalyticsCollection(boolean enabled) {
firebaseAnalytics.setAnalyticsCollectionEnabled(enabled);
if(!enabled)
firebaseAnalytics.resetAnalyticsData();
}
//Getters
public Context getContext() {
return getApplicationContext();
@ -179,4 +161,32 @@ public class BaseApplication extends Application {
public float getDpWidth() {
return dpWidth;
}
//--------------------Firebase--------------------
public void logFirebaseAnalyticsEvent(String event, Bundle params) {
firebaseAnalytics.logEvent(event, params);
}
public void setFirebaseAnalyticsCollection(boolean enabled) {
firebaseAnalytics.setAnalyticsCollectionEnabled(enabled);
if(!enabled)
firebaseAnalytics.resetAnalyticsData();
}
// Set up Crashlytics, disabled for debug builds
public void startFirebaseCrashlyticsCollection() {
if(!Fabric.isInitialized()){
Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
.build();
// Initialize Fabric with the debug-disabled Crashlytics.
Fabric.with(this, crashlyticsKit);
Timber.plant(new CrashReportingTree());
Timber.i("Crashlytics enabled.");
}
else
Timber.i("Crashlytics were already initialized for this app session.");
}
}

Loading…
Cancel
Save