- // Set the third-party cookies status.
- if (thirdPartyCookiesEnabledInt == 1) { // Third-party cookies are enabled.
- thirdPartyCookiesEnabledSwitch.setChecked(true);
- thirdPartyCookiesImageView.setEnabled(true);
- } else { // Third-party cookies are disabled.
- thirdPartyCookiesEnabledSwitch.setChecked(false);
- thirdPartyCookiesImageView.setEnabled(false);
+ // Only display third-party cookies if SDK_INT >= 21.
+ if (Build.VERSION.SDK_INT >= 21) { // Third-party cookies can be configured for API >= 21.
+ // Only enable third-party-cookies if first-party cookies are enabled.
+ if (firstPartyCookiesEnabledInt == 1) { // First-party cookies are enabled.
+ // Set the third-party cookies status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
+ if (thirdPartyCookiesEnabledInt == 1) { // Both first-party and third-party cookies are enabled.
+ thirdPartyCookiesEnabledSwitch.setChecked(true);
+ thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
+ } else { // First party cookies are enabled but third-party cookies are disabled.
+ thirdPartyCookiesEnabledSwitch.setChecked(false);
+ thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled));
+ }
+ } else { // First-party cookies are disabled.
+ // Set the status of third-party cookies, but disable it.
+ if (thirdPartyCookiesEnabledInt == 1) { // Third-party cookies are enabled but first-party cookies are disabled.
+ thirdPartyCookiesEnabledSwitch.setChecked(true);
+ thirdPartyCookiesEnabledSwitch.setEnabled(false);
+ thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted));
+ } else { // Both first party and third-party cookies are disabled.
+ thirdPartyCookiesEnabledSwitch.setChecked(false);
+ thirdPartyCookiesEnabledSwitch.setEnabled(false);
+ thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted));
+ }
+ }
+ } else { // Third-party cookies cannot be configured for API <= 21.
+ // Hide the `LinearLayout` for third-party cookies.
+ thirdPartyCookiesLinearLayout.setVisibility(View.GONE);