@ -90,6 +90,7 @@ public abstract class BaseActivity extends AppCompatActivity {
private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey" ;
private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey" ;
protected Bookmark thisPageBookmark ;
protected Bookmark thisPageBookmark ;
private MenuItem thisPageBookmarkMenuButton ;
private MenuItem thisPageBookmarkMenuButton ;
private SharedPreferences sharedPreferences ;
private SharedPreferences bookmarksFile ;
private SharedPreferences bookmarksFile ;
private ArrayList < Bookmark > topicsBookmarked ;
private ArrayList < Bookmark > topicsBookmarked ;
private ArrayList < Bookmark > boardsBookmarked ;
private ArrayList < Bookmark > boardsBookmarked ;
@ -99,10 +100,14 @@ public abstract class BaseActivity extends AppCompatActivity {
protected Drawer drawer ;
protected Drawer drawer ;
private MainActivity mainActivity ;
private MainActivity mainActivity ;
private boolean isMainActivity ;
@Override
@Override
protected void onCreate ( Bundle savedInstanceState ) {
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState ) ;
super . onCreate ( savedInstanceState ) ;
isMainActivity = this instanceof MainActivity ;
if ( client = = null )
if ( client = = null )
client = BaseApplication . getInstance ( ) . getClient ( ) ; //must check every time - e.g.
client = BaseApplication . getInstance ( ) . getClient ( ) ; //must check every time - e.g.
@ -115,6 +120,8 @@ public abstract class BaseActivity extends AppCompatActivity {
loadSavedBookmarks ( ) ;
loadSavedBookmarks ( ) ;
}
}
sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( this ) ;
BaseViewModel baseViewModel = ViewModelProviders . of ( this ) . get ( BaseViewModel . class ) ;
BaseViewModel baseViewModel = ViewModelProviders . of ( this ) . get ( BaseViewModel . class ) ;
baseViewModel . getCurrentPageBookmark ( ) . observe ( this , thisPageBookmark - > setTopicBookmark ( thisPageBookmarkMenuButton ) ) ;
baseViewModel . getCurrentPageBookmark ( ) . observe ( this , thisPageBookmark - > setTopicBookmark ( thisPageBookmarkMenuButton ) ) ;
}
}
@ -123,7 +130,7 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void onResume ( ) {
protected void onResume ( ) {
super . onResume ( ) ;
super . onResume ( ) ;
updateDrawer ( ) ;
updateDrawer ( ) ;
if ( LaunchType . getLaunchType ( ) = = FIRST_LAUNCH_EVER | | LaunchType . getLaunchType ( ) = = INDETERMINATE )
if ( ! sharedPreferences . getBoolean ( getString ( R . string . user_consent_shared_preference_key ) , false ) )
showUserConsentDialog ( ) ;
showUserConsentDialog ( ) ;
}
}
@ -338,7 +345,7 @@ public abstract class BaseActivity extends AppCompatActivity {
. withAccountHeader ( accountHeader )
. withAccountHeader ( accountHeader )
. withOnDrawerItemClickListener ( ( view , position , drawerItem ) - > {
. withOnDrawerItemClickListener ( ( view , position , drawerItem ) - > {
if ( drawerItem . equals ( HOME_ID ) ) {
if ( drawerItem . equals ( HOME_ID ) ) {
if ( ! ( BaseAct ivity . this instanceof MainActivity ) ) {
if ( ! is MainActivity ) {
Intent intent = new Intent ( BaseActivity . this , MainActivity . class ) ;
Intent intent = new Intent ( BaseActivity . this , MainActivity . class ) ;
startActivity ( intent ) ;
startActivity ( intent ) ;
}
}
@ -392,7 +399,7 @@ public abstract class BaseActivity extends AppCompatActivity {
drawer = drawerBuilder . build ( ) ;
drawer = drawerBuilder . build ( ) ;
if ( ! ( BaseAct ivity . this instanceof MainActivity ) )
if ( ! is MainActivity )
drawer . getActionBarDrawerToggle ( ) . setDrawerIndicatorEnabled ( false ) ;
drawer . getActionBarDrawerToggle ( ) . setDrawerIndicatorEnabled ( false ) ;
drawer . setOnDrawerNavigationListener ( clickedView - > {
drawer . setOnDrawerNavigationListener ( clickedView - > {
@ -742,11 +749,15 @@ public abstract class BaseActivity extends AppCompatActivity {
builder . setTitle ( "User Agreement" ) ;
builder . setTitle ( "User Agreement" ) ;
builder . setMessage ( R . string . user_agreement_dialog_text ) ;
builder . setMessage ( R . string . user_agreement_dialog_text ) ;
builder . setPositiveButton ( "Yes, I want to help" , ( dialogInterface , i ) - > {
builder . setPositiveButton ( "Yes, I want to help" , ( dialogInterface , i ) - > {
addUserConsent ( ) ;
FirebaseMessaging . getInstance ( ) . setAutoInitEnabled ( true ) ;
FirebaseMessaging . getInstance ( ) . setAutoInitEnabled ( true ) ;
BaseApplication . getInstance ( ) . startFirebaseCrashlyticsCollection ( ) ;
BaseApplication . getInstance ( ) . startFirebaseCrashlyticsCollection ( ) ;
BaseApplication . getInstance ( ) . setFirebaseAnalyticsCollection ( true ) ;
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 . setNeutralButton ( "Privacy Policy" , ( dialog , which ) - > { /*Will be overridden below*/ } ) ;
builder . setCancelable ( false ) ;
builder . setCancelable ( false ) ;
AlertDialog alertDialog = builder . create ( ) ;
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----------------------
//----------------------------------MISC----------------------
protected void setMainActivity ( MainActivity mainActivity ) {
protected void setMainActivity ( MainActivity mainActivity ) {
this . mainActivity = mainActivity ;
this . mainActivity = mainActivity ;