Closes AC#3695 - Add UI to open current page in external app

nightly-build-test
James Hugman 5 years ago committed by Emily Kager
parent 6da6ddb095
commit 62850430b7

@ -175,12 +175,14 @@ class BrowserFragment : Fragment(), BackHandler {
this,
QuickActionViewModel::class.java
) {
val appLink = requireComponents.useCases.appLinksUseCases.appLinkRedirect
QuickActionViewModel(
QuickActionState(
readable = getSessionById()?.readerable ?: false,
bookmarked = findBookmarkedURL(getSessionById()),
readerActive = getSessionById()?.readerMode ?: false,
bounceNeeded = false
bounceNeeded = false,
isAppLink = getSessionById()?.let { appLink.invoke(it.url).hasExternalApp() } ?: false
)
)
}
@ -538,6 +540,20 @@ class BrowserFragment : Fragment(), BackHandler {
feature.showControls()
}
}
is QuickActionAction.OpenAppLinkPressed -> {
appLinksFeature.withFeature { feature ->
val getRedirect = requireComponents.useCases.appLinksUseCases.appLinkRedirect
val redirect = getSessionById()?.let { session ->
getRedirect.invoke(session.url)
} ?: return@withFeature
redirect.appIntent?.flags = Intent.FLAG_ACTIVITY_NEW_TASK
val openAppLink = requireComponents.useCases.appLinksUseCases.openAppLink
openAppLink.invoke(redirect)
}
}
}
}
@ -874,6 +890,7 @@ class BrowserFragment : Fragment(), BackHandler {
override fun onUrlChanged(session: Session, url: String) {
super.onUrlChanged(session, url)
updateBookmarkState(session)
updateAppLinksState(session)
}
}
getSessionById()?.register(observer, this)
@ -916,6 +933,13 @@ class BrowserFragment : Fragment(), BackHandler {
}
}
private fun updateAppLinksState(session: Session) {
val url = session.url
val appLinks = requireComponents.useCases.appLinksUseCases.appLinkRedirect
getManagedEmitter<QuickActionChange>()
.onNext(QuickActionChange.AppLinkStateChange(appLinks.invoke(url).hasExternalApp()))
}
private val collectionStorageObserver = object : TabCollectionStorage.Observer {
override fun onCollectionCreated(title: String, sessions: List<Session>) {
super.onCollectionCreated(title, sessions)

@ -8,6 +8,7 @@ import android.content.Context
import mozilla.components.browser.search.SearchEngineManager
import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.engine.Settings
import mozilla.components.feature.app.links.AppLinksUseCases
import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.feature.session.SettingsUseCases
@ -44,4 +45,6 @@ class UseCases(
* Use cases that provide settings management.
*/
val settingsUseCases by lazy { SettingsUseCases(engineSettings, sessionManager) }
val appLinksUseCases by lazy { AppLinksUseCases(context.applicationContext) }
}

@ -36,7 +36,8 @@ data class QuickActionState(
val readable: Boolean,
val bookmarked: Boolean,
val readerActive: Boolean,
val bounceNeeded: Boolean
val bounceNeeded: Boolean,
val isAppLink: Boolean
) : ViewState
sealed class QuickActionAction : Action {
@ -47,12 +48,14 @@ sealed class QuickActionAction : Action {
object BookmarkPressed : QuickActionAction()
object ReadPressed : QuickActionAction()
object ReadAppearancePressed : QuickActionAction()
object OpenAppLinkPressed : 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()
data class AppLinkStateChange(val isAppLink: Boolean) : QuickActionChange()
object BounceNeededChange : QuickActionChange()
}
@ -74,6 +77,9 @@ class QuickActionViewModel(
is QuickActionChange.ReaderActiveStateChange -> {
state.copy(readerActive = change.active)
}
is QuickActionChange.AppLinkStateChange -> {
state.copy(isAppLink = change.isAppLink)
}
}
}
}

@ -79,6 +79,10 @@ class QuickActionUIView(
actionEmitter.onNext(QuickActionAction.ReadAppearancePressed)
quickActionSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
}
view.quick_action_open_app_link.setOnClickListener {
actionEmitter.onNext(QuickActionAction.OpenAppLinkPressed)
quickActionSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
}
}
/**
@ -133,6 +137,10 @@ class QuickActionUIView(
if (it.bounceNeeded && Settings.getInstance(view.context).shouldAutoBounceQuickActionSheet) {
quickActionSheet.bounceSheet()
}
view.quick_action_open_app_link.apply {
visibility = if (it.isAppLink) View.VISIBLE else View.GONE
}
}
private fun updateReaderModeButton(withNotification: Boolean) {

@ -0,0 +1,30 @@
<?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/library_app_links_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/library_app_links_icon"
android:pathData="M4.5,7C3.12,7 2,5.88 2,4.5S3.12,2 4.5,2 7,3.12 7,4.5 5.88,7 4.5,7zM4.5,22C3.12,22 2,20.88 2,19.5S3.12,17 4.5,17 7,18.12 7,19.5 5.88,22 4.5,22zM4.5,14.5C3.12,14.5 2,13.38 2,12s1.12,-2.5 2.5,-2.5S7,10.62 7,12s-1.12,2.5 -2.5,2.5zM19.5,7C18.12,7 17,5.88 17,4.5S18.12,2 19.5,2 22,3.12 22,4.5 20.88,7 19.5,7zM19.5,22c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5zM19.5,14.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5S22,10.62 22,12s-1.12,2.5 -2.5,2.5zM12,7c-1.38,0 -2.5,-1.12 -2.5,-2.5S10.62,2 12,2s2.5,1.12 2.5,2.5S13.38,7 12,7zM12,22c-1.38,0 -2.5,-1.12 -2.5,-2.5S10.62,17 12,17s2.5,1.12 2.5,2.5S13.38,22 12,22zM12,14.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"
/>
</vector>
</item>
</layer-list>

@ -91,6 +91,20 @@
android:textSize="12sp"
android:visibility="gone" />
<Button
android:id="@+id/quick_action_open_app_link"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackgroundBorderless"
android:drawableTop="@drawable/library_icon_app_links_circle_background"
android:drawablePadding="5dp"
android:text="@string/quick_action_open_app_link"
android:textAllCaps="false"
android:textColor="?primaryText"
android:textSize="12sp"
android:visibility="gone" />
<Button
android:id="@+id/quick_action_read"
android:layout_width="0dp"

@ -120,6 +120,9 @@
<color name="library_downloads_icon_background">#D4C1FA</color>
<color name="library_downloads_icon">#2E2060</color>
<color name="library_app_links_icon_background">#E0E0E6</color>
<color name="library_app_links_icon">#20123A</color>
<color name="bookmarks_icon_background_filled">#C60084</color>
<color name="bookmarks_icon_filled">#FFB4DB</color>
<color name="bookmarks_icon_background_outline">#FFB4DB</color>

@ -256,6 +256,8 @@
<string name="quick_action_read">Read</string>
<!-- Button in the browser chrome to exit reader mode -->
<string name="quick_action_read_close">Close</string>
<!-- Button in the browser chrome to open the current page in an external app -->
<string name="quick_action_open_app_link">Open in App</string>
<!-- Button in the browser chrome to configure reader mode appearance e.g. the used font type and size -->
<string name="quick_action_read_appearance">Appearance</string>
<!-- Content description (not visible, for screen readers etc.): Quick action sheet handle to provide users

Loading…
Cancel
Save