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 2341fd70..dba06d2b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -90,6 +90,7 @@ public abstract class BaseActivity extends AppCompatActivity { private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey"; protected Bookmark thisPageBookmark; private MenuItem thisPageBookmarkMenuButton; + private SharedPreferences sharedPreferences; private SharedPreferences bookmarksFile; private ArrayList topicsBookmarked; private ArrayList boardsBookmarked; @@ -99,10 +100,14 @@ public abstract class BaseActivity extends AppCompatActivity { protected Drawer drawer; private MainActivity mainActivity; + private boolean isMainActivity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + isMainActivity = this instanceof MainActivity; + if (client == null) client = BaseApplication.getInstance().getClient(); //must check every time - e.g. @@ -115,6 +120,8 @@ public abstract class BaseActivity extends AppCompatActivity { loadSavedBookmarks(); } + sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + BaseViewModel baseViewModel = ViewModelProviders.of(this).get(BaseViewModel.class); baseViewModel.getCurrentPageBookmark().observe(this, thisPageBookmark -> setTopicBookmark(thisPageBookmarkMenuButton)); } @@ -123,7 +130,7 @@ public abstract class BaseActivity extends AppCompatActivity { protected void onResume() { super.onResume(); updateDrawer(); - if(LaunchType.getLaunchType()==FIRST_LAUNCH_EVER||LaunchType.getLaunchType()== INDETERMINATE) + if(!sharedPreferences.getBoolean(getString(R.string.user_consent_shared_preference_key),false)) showUserConsentDialog(); } @@ -338,7 +345,7 @@ public abstract class BaseActivity extends AppCompatActivity { .withAccountHeader(accountHeader) .withOnDrawerItemClickListener((view, position, drawerItem) -> { if (drawerItem.equals(HOME_ID)) { - if (!(BaseActivity.this instanceof MainActivity)) { + if (!isMainActivity) { Intent intent = new Intent(BaseActivity.this, MainActivity.class); startActivity(intent); } @@ -392,7 +399,7 @@ public abstract class BaseActivity extends AppCompatActivity { drawer = drawerBuilder.build(); - if (!(BaseActivity.this instanceof MainActivity)) + if (!isMainActivity) drawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false); drawer.setOnDrawerNavigationListener(clickedView -> { @@ -742,11 +749,15 @@ public abstract class BaseActivity extends AppCompatActivity { builder.setTitle("User Agreement"); builder.setMessage(R.string.user_agreement_dialog_text); builder.setPositiveButton("Yes, I want to help", (dialogInterface, i) -> { + addUserConsent(); FirebaseMessaging.getInstance().setAutoInitEnabled(true); BaseApplication.getInstance().startFirebaseCrashlyticsCollection(); BaseApplication.getInstance().setFirebaseAnalyticsCollection(true); }); - builder.setNegativeButton("Nope, leave me alone", (dialogInterface, i) -> FirebaseMessaging.getInstance().setAutoInitEnabled(true)); + builder.setNegativeButton("Nope, leave me alone", (dialogInterface, i) -> { + addUserConsent(); + FirebaseMessaging.getInstance().setAutoInitEnabled(true); + }); builder.setNeutralButton("Privacy Policy", (dialog, which) -> {/*Will be overridden below*/}); builder.setCancelable(false); AlertDialog alertDialog = builder.create(); @@ -791,6 +802,11 @@ public abstract class BaseActivity extends AppCompatActivity { } } + private void addUserConsent (){ + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putBoolean(getString(R.string.user_consent_shared_preference_key), true).apply(); + } + //----------------------------------MISC---------------------- protected void setMainActivity(MainActivity mainActivity) { this.mainActivity = mainActivity; 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 6a01e61c..e1a33b30 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -50,7 +50,8 @@ public class BaseApplication extends Application { private OkHttpClient client; private SessionManager sessionManager; - private final String SHARED_PREFS = "ThmmySharedPrefs"; + //TODO: maybe use PreferenceManager.getDefaultSharedPreferences here as well? + private static final String SHARED_PREFS = "ThmmySharedPrefs"; //Display Metrics private static float dpWidth; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index db3794c9..bc145117 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,6 +15,7 @@ OK Cancel "To use mTHMMY you have to agree to our Privacy Policy by choosing one of the options below. Choose \"Yes, I want to help\", if you consent to the collection of anonymized data that will help us improve the app. Otherwise, choose \"Nope, leave me alone\". You can change your preferences any time through the app's Settings. + user_consent_shared_preference_key thmmy.gr