2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/911: Adds reader mode notification on first launch

This commit is contained in:
Sawyer Blatz 2019-05-21 10:35:00 -07:00 committed by Jeff Boek
parent 36686f3fd8
commit 79e336a61a
6 changed files with 115 additions and 28 deletions

View File

@ -16,6 +16,7 @@ import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.fragment_browser.* 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.*
import kotlinx.android.synthetic.main.layout_quick_action_sheet.view.* 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.R
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
@ -105,6 +106,11 @@ class QuickActionUIView(
override fun updateView() = Consumer<QuickActionState> { override fun updateView() = Consumer<QuickActionState> {
view.quick_action_read.apply { view.quick_action_read.apply {
visibility = if (it.readable) View.VISIBLE else View.GONE 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 isSelected = it.readerActive
text = if (it.readerActive) { text = if (it.readerActive) {
context.getString(R.string.quick_action_read_close) context.getString(R.string.quick_action_read_close)
@ -119,4 +125,19 @@ class QuickActionUIView(
quickActionSheet.bounceSheet() 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)
}
}
} }

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="14dp"
android:height="14dp" />
<solid android:color="?accentBright" />
<stroke android:color="@color/light_grey_05"/>
</shape>

View File

@ -1,29 +1,29 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public <!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this - License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item> <item>
<shape android:shape="oval"> <shape android:shape="oval">
<size <size
android:width="40dp" android:width="40dp"
android:height="40dp" /> android:height="40dp" />
<solid android:color="@color/quick_action_read_icon_background" /> <solid android:color="@color/quick_action_read_icon_background" />
</shape> </shape>
</item> </item>
<item <item
android:bottom="8dp" android:bottom="8dp"
android:left="8dp" android:left="8dp"
android:right="8dp" android:right="8dp"
android:top="8dp"> android:top="8dp">
<vector <vector
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24"> android:viewportHeight="24">
<path <path
android:fillColor="@color/quick_action_read_icon" android:fillColor="@color/quick_action_read_icon"
android:pathData="M15,7L9,7a0.5,0.5 0,0 0,-0.5 0.5,0.5 0.5,0 0,0 0.5,0.5h6a0.5,0.5 0,0 0,0 -1zM15,10L9,10a0.5,0.5 0,0 0,0 1h6a0.5,0.5 0,0 0,0 -1zM15,13L9,13a0.5,0.5 0,0 0,0 1h6a0.5,0.5 0,0 0,0 -1zM11.57,16L9,16a0.5,0.5 0,0 0,0 1h2.57a0.5,0.5 0,0 0,0 -1zM16.69,3L7.31,3A3.31,3.31 0,0 0,4 6.31v11.38A3.31,3.31 0,0 0,7.31 21h9.38A3.31,3.31 0,0 0,20 17.69L20,6.31A3.31,3.31 0,0 0,16.69 3zM18,17.69A1.31,1.31 0,0 1,16.69 19L7.31,19A1.31,1.31 0,0 1,6 17.69L6,6.31A1.31,1.31 0,0 1,7.31 5h9.38A1.31,1.31 0,0 1,18 6.31z"/> android:pathData="M15,7L9,7a0.5,0.5 0,0 0,-0.5 0.5,0.5 0.5,0 0,0 0.5,0.5h6a0.5,0.5 0,0 0,0 -1zM15,10L9,10a0.5,0.5 0,0 0,0 1h6a0.5,0.5 0,0 0,0 -1zM15,13L9,13a0.5,0.5 0,0 0,0 1h6a0.5,0.5 0,0 0,0 -1zM11.57,16L9,16a0.5,0.5 0,0 0,0 1h2.57a0.5,0.5 0,0 0,0 -1zM16.69,3L7.31,3A3.31,3.31 0,0 0,4 6.31v11.38A3.31,3.31 0,0 0,7.31 21h9.38A3.31,3.31 0,0 0,20 17.69L20,6.31A3.31,3.31 0,0 0,16.69 3zM18,17.69A1.31,1.31 0,0 1,16.69 19L7.31,19A1.31,1.31 0,0 1,6 17.69L6,6.31A1.31,1.31 0,0 1,7.31 5h9.38A1.31,1.31 0,0 1,18 6.31z"/>
</vector> </vector>
</item> </item>
</layer-list> </layer-list>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size
android:width="40dp"
android:height="40dp" />
<solid android:color="@color/quick_action_read_icon_background" />
</shape>
</item>
<item
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp">
<vector
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/quick_action_read_icon"
android:pathData="M15,7L9,7a0.5,0.5 0,0 0,-0.5 0.5,0.5 0.5,0 0,0 0.5,0.5h6a0.5,0.5 0,0 0,0 -1zM15,10L9,10a0.5,0.5 0,0 0,0 1h6a0.5,0.5 0,0 0,0 -1zM15,13L9,13a0.5,0.5 0,0 0,0 1h6a0.5,0.5 0,0 0,0 -1zM11.57,16L9,16a0.5,0.5 0,0 0,0 1h2.57a0.5,0.5 0,0 0,0 -1zM16.69,3L7.31,3A3.31,3.31 0,0 0,4 6.31v11.38A3.31,3.31 0,0 0,7.31 21h9.38A3.31,3.31 0,0 0,20 17.69L20,6.31A3.31,3.31 0,0 0,16.69 3zM18,17.69A1.31,1.31 0,0 1,16.69 19L7.31,19A1.31,1.31 0,0 1,6 17.69L6,6.31A1.31,1.31 0,0 1,7.31 5h9.38A1.31,1.31 0,0 1,18 6.31z"/>
</vector>
</item>
<item android:left="32dp"
android:bottom="32dp">
<shape
android:shape="oval">
<stroke android:width="1dp" android:color="@color/light_grey_05" />
<solid android:color="?accentBright" />
<size android:width="14dp"
android:height="14dp"/>
</shape>
</item>
</layer-list>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false"
android:drawable="@drawable/quick_action_icon_read_with_notification" />
<item android:state_selected="true"
android:drawable="@drawable/quick_action_icon_close" />
</selector>

View File

@ -43,9 +43,8 @@
<!-- Search Settings --> <!-- Search Settings -->
<string name="pref_key_show_search_suggestions" translatable="false">pref_key_show_search_suggestions</string> <string name="pref_key_show_search_suggestions" translatable="false">pref_key_show_search_suggestions</string>
<string name="pref_key_bounce_quick_action" translatable="false">pref_key_bounce_quick_action</string>
<string name="pref_key_show_visited_sites_bookmarks" translatable="false">pref_key_show_visited_sites_bookmarks</string> <string name="pref_key_show_visited_sites_bookmarks" translatable="false">pref_key_show_visited_sites_bookmarks</string>
<!-- Site Permissions Settings --> <!-- Site Permissions Settings -->
<string name="pref_key_optimize" translatable="false">pref_key_optimize</string> <string name="pref_key_optimize" translatable="false">pref_key_optimize</string>
<string name="pref_key_show_site_exceptions" translatable="false">pref_key_show_site_exceptions</string> <string name="pref_key_show_site_exceptions" translatable="false">pref_key_show_site_exceptions</string>
@ -68,4 +67,8 @@
<string name="pref_key_tracking_protection_settings" translatable="false">pref_key_tracking_protection_settings</string> <string name="pref_key_tracking_protection_settings" translatable="false">pref_key_tracking_protection_settings</string>
<string name="pref_key_tracking_protection" translatable="false">pref_key_tracking_protection</string> <string name="pref_key_tracking_protection" translatable="false">pref_key_tracking_protection</string>
<string name="pref_key_tracking_protection_exceptions" translatable="false">pref_key_tracking_protection_exceptions</string> <string name="pref_key_tracking_protection_exceptions" translatable="false">pref_key_tracking_protection_exceptions</string>
<!-- Quick Action Sheet -->
<string name="pref_key_bounce_quick_action" translatable="false">pref_key_bounce_quick_action</string>
<string name="pref_key_reader_mode_notification" translatable="false">pref_key_reader_mode_notification</string>
</resources> </resources>