Closes AC#3695 - Add UI to open current page in external app
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) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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…
Reference in New Issue