diff --git a/app/build.gradle b/app/build.gradle index 3cd2c4848..b5881b0b4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -287,6 +287,7 @@ dependencies { implementation Deps.mozilla_feature_findinpage implementation Deps.mozilla_feature_session_bundling implementation Deps.mozilla_feature_site_permissions + implementation Deps.mozilla_feature_readerview implementation Deps.mozilla_service_firefox_accounts implementation Deps.mozilla_service_fretboard diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index cf9ef2363..363a30936 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -39,6 +39,7 @@ import mozilla.components.feature.contextmenu.ContextMenuFeature import mozilla.components.feature.downloads.DownloadsFeature import mozilla.components.feature.intent.IntentProcessor import mozilla.components.feature.prompts.PromptFeature +import mozilla.components.feature.readerview.ReaderViewFeature import mozilla.components.feature.session.FullScreenFeature import mozilla.components.feature.session.SessionFeature import mozilla.components.feature.session.SessionUseCases @@ -101,6 +102,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, private val promptsFeature = ViewBoundFeatureWrapper() private val findInPageIntegration = ViewBoundFeatureWrapper() private val toolbarIntegration = ViewBoundFeatureWrapper() + private val readerViewFeature = ViewBoundFeatureWrapper() private val sitePermissionsFeature = ViewBoundFeatureWrapper() private val fullScreenFeature = ViewBoundFeatureWrapper() private val thumbnailsFeature = ViewBoundFeatureWrapper() @@ -286,6 +288,24 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, view = view ) + readerViewFeature.set( + feature = ReaderViewFeature( + requireContext(), + requireComponents.core.engine, + requireComponents.core.sessionManager, + view.readerViewControlsBar + ) { + getManagedEmitter().apply { + onNext(QuickActionChange.ReadableStateChange(it)) + onNext(QuickActionChange.ReaderActiveStateChange( + sessionManager.selectedSession?.readerMode ?: false) + ) + } + }, + owner = this, + view = view + ) + val actionEmitter = ActionBusFactory.get(this).getManagedEmitter(SearchAction::class.java) customTabSessionId?.let { @@ -380,8 +400,24 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, bookmarkTapped() } is QuickActionAction.ReadPressed -> { - requireComponents.analytics.metrics.track(Event.QuickActionSheetReadTapped) - ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "908") + readerViewFeature.withFeature { feature -> + requireComponents.analytics.metrics.track(Event.QuickActionSheetReadTapped) + val actionEmitter = getManagedEmitter() + val enabled = requireComponents.core.sessionManager.selectedSession?.readerMode ?: false + if (enabled) { + feature.hideReaderView() + actionEmitter.onNext(QuickActionChange.ReaderActiveStateChange(false)) + } else { + feature.showReaderView() + actionEmitter.onNext(QuickActionChange.ReaderActiveStateChange(true)) + } + } + } + is QuickActionAction.ReadAppearancePressed -> { + // TODO telemetry: https://github.com/mozilla-mobile/fenix/issues/2267 + readerViewFeature.withFeature { feature -> + feature.showControls() + } } } } @@ -454,6 +490,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, return when { findInPageIntegration.onBackPressed() -> true fullScreenFeature.onBackPressed() -> true + readerViewFeature.onBackPressed() -> true sessionFeature.onBackPressed() -> true else -> false } diff --git a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt index 6dbff2543..644666eb2 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt @@ -18,7 +18,8 @@ class QuickActionComponent( bus: ActionBusFactory, override var initialState: QuickActionState = QuickActionState( readable = false, - bookmarked = false + bookmarked = false, + readerActive = false ) ) : UIComponent( bus.getManagedEmitter(QuickActionAction::class.java), @@ -33,6 +34,9 @@ class QuickActionComponent( is QuickActionChange.ReadableStateChange -> { state.copy(readable = change.readable) } + is QuickActionChange.ReaderActiveStateChange -> { + state.copy(readerActive = change.active) + } } } @@ -44,7 +48,7 @@ class QuickActionComponent( } } -data class QuickActionState(val readable: Boolean, val bookmarked: Boolean) : ViewState +data class QuickActionState(val readable: Boolean, val bookmarked: Boolean, val readerActive: Boolean) : ViewState sealed class QuickActionAction : Action { object Opened : QuickActionAction() @@ -53,9 +57,11 @@ sealed class QuickActionAction : Action { object DownloadsPressed : QuickActionAction() object BookmarkPressed : QuickActionAction() object ReadPressed : QuickActionAction() + object ReadAppearancePressed : QuickActionAction() } sealed class QuickActionChange : Change { data class BookmarkedStateChange(val bookmarked: Boolean) : QuickActionChange() data class ReadableStateChange(val readable: Boolean) : QuickActionChange() + data class ReaderActiveStateChange(val active: Boolean) : QuickActionChange() } 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 1573e3c50..b5e49afe1 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt @@ -78,6 +78,10 @@ class QuickActionUIView( actionEmitter.onNext(QuickActionAction.ReadPressed) quickActionSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED } + view.quick_action_read_appearance.setOnClickListener { + actionEmitter.onNext(QuickActionAction.ReadAppearancePressed) + quickActionSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + } } /** @@ -105,7 +109,16 @@ class QuickActionUIView( } override fun updateView() = Consumer { - view.quick_action_read.visibility = if (it.readable) View.VISIBLE else View.GONE + view.quick_action_read.apply { + visibility = if (it.readable) View.VISIBLE else View.GONE + isSelected = it.readerActive + text = if (it.readerActive) { + context.getString(R.string.quick_action_read_close) + } else { + context.getString(R.string.quick_action_read) + } + } + view.quick_action_read_appearance.visibility = if (it.readerActive) View.VISIBLE else View.GONE view.quick_action_bookmark.isSelected = it.bookmarked } diff --git a/app/src/main/res/drawable/quick_action_icon_appearance.xml b/app/src/main/res/drawable/quick_action_icon_appearance.xml new file mode 100644 index 000000000..783a50da8 --- /dev/null +++ b/app/src/main/res/drawable/quick_action_icon_appearance.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/quick_action_icon_close.xml b/app/src/main/res/drawable/quick_action_icon_close.xml new file mode 100644 index 000000000..0249c6880 --- /dev/null +++ b/app/src/main/res/drawable/quick_action_icon_close.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/reader_two_state.xml b/app/src/main/res/drawable/reader_two_state.xml new file mode 100644 index 000000000..046ac7c9a --- /dev/null +++ b/app/src/main/res/drawable/reader_two_state.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/app/src/main/res/layout/fragment_browser.xml b/app/src/main/res/layout/fragment_browser.xml index cb88c16bb..c1fdaa405 100644 --- a/app/src/main/res/layout/fragment_browser.xml +++ b/app/src/main/res/layout/fragment_browser.xml @@ -38,4 +38,13 @@ mozac:findInPageButtonsTint="?primaryText" mozac:findInPageResultCountTextColor="?primaryText" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_quick_action_sheet.xml b/app/src/main/res/layout/layout_quick_action_sheet.xml index 85d2496cc..4fd69692d 100644 --- a/app/src/main/res/layout/layout_quick_action_sheet.xml +++ b/app/src/main/res/layout/layout_quick_action_sheet.xml @@ -77,13 +77,27 @@ android:textColor="?primaryText" android:textSize="12sp" /> +