From 5c6466ad2e1a53237e72295b0d44a7f23a0a9abb Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 8 Oct 2018 17:03:19 +0300 Subject: [PATCH] Added privacy-related settings --- app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 7 +- .../activities/board/BoardActivity.java | 2 +- .../activities/settings/SettingsActivity.java | 2 +- .../activities/settings/SettingsFragment.java | 57 ++++++++++++--- .../activities/topic/TopicActivity.java | 3 - .../mthmmy/activities/topic/TopicAdapter.java | 2 - .../topic/tasks/TopicTaskResult.java | 1 - .../gr/thmmy/mthmmy/base/BaseActivity.java | 70 +++++++++---------- .../gr/thmmy/mthmmy/base/BaseApplication.java | 50 ++++++++----- .../mthmmy/services/NotificationService.java | 9 +++ .../mthmmy/utils/parsing/ParseHelpers.java | 2 - .../mthmmy/viewmodel/TopicViewModel.java | 4 +- app/src/main/res/values/strings.xml | 10 ++- app/src/main/res/xml/app_preferences.xml | 49 +++++++------ 15 files changed, 163 insertions(+), 109 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5baea52e..81b88eb7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,13 +4,13 @@ apply plugin: 'com.android.application' apply plugin: 'io.fabric' android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { vectorDrawables.useSupportLibrary = true applicationId "gr.thmmy.mthmmy" minSdkVersion 19 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 13 versionName "1.4.1" archivesBaseName = "mTHMMY-v$versionName" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3b37c299..72b99fbc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,9 +17,10 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - + + + + { + if (sessionManager.isLoggedIn()) { + Intent intent = new Intent(BaseActivity.this, ProfileActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_PROFILE_URL, "https://www.thmmy.gr/smf/index.php?action=profile"); + if (!sessionManager.hasAvatar()) + extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, ""); + else + extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, sessionManager.getAvatarLink()); + extras.putString(BUNDLE_PROFILE_USERNAME, sessionManager.getUsername()); + intent.putExtras(extras); + intent.setFlags(FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + return false; + } else + startLoginActivity(); + return true; - } }) .build(); @@ -360,12 +358,8 @@ public abstract class BaseActivity extends AppCompatActivity { } } else if (drawerItem.equals(LOG_ID)) { if (!sessionManager.isLoggedIn()) //When logged out or if user is guest - { - Intent intent = new Intent(BaseActivity.this, LoginActivity.class); - startActivity(intent); - finish(); - overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); - } else + startLoginActivity(); + else new LogoutTask().execute(); } else if (drawerItem.equals(ABOUT_ID)) { if (!(BaseActivity.this instanceof AboutActivity)) { @@ -533,18 +527,15 @@ public abstract class BaseActivity extends AppCompatActivity { } else { thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp); } - thisPageBookmarkImageButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (thisPageBookmark.matchExists(boardsBookmarked)) { - thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp); - Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); - } else { - thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_true_accent_24dp); - Toast.makeText(getBaseContext(), "Bookmark added", Toast.LENGTH_SHORT).show(); - } - toggleBoardToBookmarks(thisPageBookmark); + thisPageBookmarkImageButton.setOnClickListener(view -> { + if (thisPageBookmark.matchExists(boardsBookmarked)) { + thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp); + Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); + } else { + thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_true_accent_24dp); + Toast.makeText(getBaseContext(), "Bookmark added", Toast.LENGTH_SHORT).show(); } + toggleBoardToBookmarks(thisPageBookmark); }); } @@ -743,4 +734,11 @@ public abstract class BaseActivity extends AppCompatActivity { protected void setMainActivity(MainActivity mainActivity) { this.mainActivity = mainActivity; } + + private void startLoginActivity(){ + Intent intent = new Intent(BaseActivity.this, LoginActivity.class); + startActivity(intent); + finish(); + overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); + } } 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 dbd760a7..0f74807d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -39,6 +39,8 @@ 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 @@ -49,11 +51,10 @@ public class BaseApplication extends Application { private OkHttpClient client; private SessionManager sessionManager; - //Shared Preferences - private final String SHARED_PREFS_NAME = "ThmmySharedPrefs"; + private final String SHARED_PREFS = "ThmmySharedPrefs"; //Display Metrics - private static float dpHeight, dpWidth; + private static float dpWidth; public static BaseApplication getInstance() { return baseApplication; @@ -64,22 +65,35 @@ public class BaseApplication extends Application { super.onCreate(); baseApplication = this; //init singleton - // Set up Crashlytics, disabled for debug builds - 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); - // Initialize timber + // Initialize Timber if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree()); else Timber.plant(new CrashReportingTree()); - // Analytics init + //Shared Preferences + SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE); + SharedPreferences settingsSharedPrefs = getSharedPreferences(SETTINGS_SHARED_PREFS, Context.MODE_PRIVATE); + + // 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.i("Starting app with Crashlytics enabled."); + } else + Timber.i("Starting app with Crashlytics disabled."); + firebaseAnalytics = FirebaseAnalytics.getInstance(this); + boolean enableAnalytics = settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_analytics_enable_key), false); + firebaseAnalytics.setAnalyticsCollectionEnabled(enableAnalytics); + if(enableAnalytics) + Timber.i("Starting app with Analytics enabled."); + else + Timber.i("Starting app with Analytics disabled."); - SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE); SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); client = new OkHttpClient.Builder() @@ -137,7 +151,6 @@ public class BaseApplication extends Application { }); DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics(); - dpHeight = displayMetrics.heightPixels / displayMetrics.density; dpWidth = displayMetrics.widthPixels / displayMetrics.density; } @@ -145,8 +158,13 @@ public class BaseApplication extends Application { firebaseAnalytics.logEvent(event, params); } - //Getters + public void firebaseAnalyticsCollection(boolean enabled) { + firebaseAnalytics.setAnalyticsCollectionEnabled(enabled); + if(!enabled) + firebaseAnalytics.resetAnalyticsData(); + } + //Getters public OkHttpClient getClient() { return client; } @@ -155,10 +173,6 @@ public class BaseApplication extends Application { return sessionManager; } - public float getDpHeight() { - return dpHeight; - } - public float getDpWidth() { return dpWidth; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java index 8f27c963..a383e282 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java @@ -226,4 +226,13 @@ public class NotificationService extends FirebaseMessagingService { } + /** + * Called if InstanceID token is updated. Note that this is called when the InstanceID token + * is initially generated so this is where you would retrieve the token. + */ + @Override + public void onNewToken(String s) { + super.onNewToken(s); + Timber.i("InstanceID token updated (onNewToken)"); + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index 52669582..2208ff04 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -8,8 +8,6 @@ import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; -import timber.log.Timber; - /** * This class consists exclusively of static classes (enums) and methods (excluding methods of inner * classes). It can be used to resolve a page's language and state or fix embedded videos html code. diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index ec875274..530cdc9d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -10,12 +10,10 @@ import android.widget.LinearLayout; import android.widget.RadioGroup; import java.util.ArrayList; -import java.util.Arrays; -import java.util.TimerTask; import gr.thmmy.mthmmy.activities.settings.SettingsActivity; -import gr.thmmy.mthmmy.activities.topic.tasks.EditTask; import gr.thmmy.mthmmy.activities.topic.tasks.DeleteTask; +import gr.thmmy.mthmmy.activities.topic.tasks.EditTask; import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditResult; import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditTask; import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReply; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 310c407f..3c133b80 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -152,8 +152,6 @@ Default home tab Notifications - Vibration Notifications led Enables/disables the notifications led (if the device has one) @@ -168,6 +166,14 @@ App signature Appends an \"uploaded from mTHMMY\" message to the descriptions of your uploads + Privacy + pref_privacy_crashlytics_enable_key + Crash data reports + Automatically send us anonymized reports of errors and crashes + pref_privacy_analytics_enable_key + Analytics data reports + Automatically send us anonymized data for analytical purposes + Black Red diff --git a/app/src/main/res/xml/app_preferences.xml b/app/src/main/res/xml/app_preferences.xml index 806ba3a8..82127641 100644 --- a/app/src/main/res/xml/app_preferences.xml +++ b/app/src/main/res/xml/app_preferences.xml @@ -2,66 +2,65 @@ - - + android:title="@string/pref_title_app_main_default_tab" + android:summary="@string/pref_summary_app_main_default_tab" /> - - - - - + android:title="@string/pref_title_notification_led_enable" + android:summary="@string/pref_summary_notification_led_enable" /> - + android:title="@string/pref_title_notifications_sound" + android:summary="@string/pref_summary_notifications_sound" /> - - + android:title="@string/pref_title_posting_app_signature_enable" + android:summary="@string/pref_summary_posting_app_signature_enable" /> - + android:title="@string/pref_title_uploading_app_signature_enable" + android:summary="@string/pref_summary_uploading_app_signature_enable" /> + + + + \ No newline at end of file