From 9509ce1b12caee0e26b4f0bb749f98d3924727a5 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Tue, 21 May 2019 10:35:00 -0700 Subject: [PATCH] For #911: Adds reader mode notification on first launch --- .../quickactionsheet/QuickActionUIView.kt | 21 ++++++++ .../res/drawable/notification_indicator.xml | 13 +++++ .../res/drawable/quick_action_icon_read.xml | 52 +++++++++---------- ...ick_action_icon_read_with_notification.xml | 40 ++++++++++++++ .../reader_two_state_with_notification.xml | 10 ++++ app/src/main/res/values/preference_keys.xml | 7 ++- 6 files changed, 115 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/drawable/notification_indicator.xml create mode 100644 app/src/main/res/drawable/quick_action_icon_read_with_notification.xml create mode 100644 app/src/main/res/drawable/reader_two_state_with_notification.xml diff --git a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt index 975f73389..ccdf33ced 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt @@ -16,6 +16,7 @@ import io.reactivex.functions.Consumer import kotlinx.android.synthetic.main.fragment_browser.* import kotlinx.android.synthetic.main.layout_quick_action_sheet.* import kotlinx.android.synthetic.main.layout_quick_action_sheet.view.* +import kotlinx.android.synthetic.main.onboarding_privacy_notice.view.* import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components @@ -105,6 +106,11 @@ class QuickActionUIView( override fun updateView() = Consumer { view.quick_action_read.apply { visibility = if (it.readable) View.VISIBLE else View.GONE + + val shouldNotify = Settings.getInstance(context).preferences + .getBoolean(context.getString(R.string.pref_key_reader_mode_notification), true) + updateReaderModeButton(it.readable && shouldNotify) + isSelected = it.readerActive text = if (it.readerActive) { context.getString(R.string.quick_action_read_close) @@ -119,4 +125,19 @@ class QuickActionUIView( quickActionSheet.bounceSheet() } } + + private fun updateReaderModeButton(withNotification: Boolean) { + if (withNotification) { + quickActionSheet.bounceSheet() + val readerTwoStateDrawable = view.context.getDrawable(R.drawable.reader_two_state_with_notification) + view.quick_action_read + .setCompoundDrawablesWithIntrinsicBounds(null, readerTwoStateDrawable, null, null) + Settings.getInstance(view.context).preferences.edit() + .putBoolean(view.context.getString(R.string.pref_key_reader_mode_notification), false).apply() + } else { + val readerTwoStateDrawable = view.context.getDrawable(R.drawable.reader_two_state) + view.quick_action_read + .setCompoundDrawablesWithIntrinsicBounds(null, readerTwoStateDrawable, null, null) + } + } } diff --git a/app/src/main/res/drawable/notification_indicator.xml b/app/src/main/res/drawable/notification_indicator.xml new file mode 100644 index 000000000..8090acf6d --- /dev/null +++ b/app/src/main/res/drawable/notification_indicator.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/quick_action_icon_read.xml b/app/src/main/res/drawable/quick_action_icon_read.xml index c0a5c691d..8002b4340 100644 --- a/app/src/main/res/drawable/quick_action_icon_read.xml +++ b/app/src/main/res/drawable/quick_action_icon_read.xml @@ -1,29 +1,29 @@ - + - - - - - - - - - - - + + + + + + + + + + + diff --git a/app/src/main/res/drawable/quick_action_icon_read_with_notification.xml b/app/src/main/res/drawable/quick_action_icon_read_with_notification.xml new file mode 100644 index 000000000..b3f703140 --- /dev/null +++ b/app/src/main/res/drawable/quick_action_icon_read_with_notification.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/reader_two_state_with_notification.xml b/app/src/main/res/drawable/reader_two_state_with_notification.xml new file mode 100644 index 000000000..c25045f32 --- /dev/null +++ b/app/src/main/res/drawable/reader_two_state_with_notification.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 05f13ad91..f22615a49 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -43,9 +43,8 @@ pref_key_show_search_suggestions - - pref_key_bounce_quick_action pref_key_show_visited_sites_bookmarks + pref_key_optimize pref_key_show_site_exceptions @@ -68,4 +67,8 @@ pref_key_tracking_protection_settings pref_key_tracking_protection pref_key_tracking_protection_exceptions + + + pref_key_bounce_quick_action + pref_key_reader_mode_notification