Loading components/feature/contextmenu/src/main/java/mozilla/components/feature/contextmenu/ContextMenuCandidate.kt +15 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import mozilla.components.browser.state.state.content.DownloadState import mozilla.components.concept.engine.HitResult import mozilla.components.feature.tabs.TabsUseCases import mozilla.components.feature.app.links.AppLinksUseCases import mozilla.components.support.ktx.android.content.share /** * A candidate for an item to be displayed in the context menu. Loading Loading @@ -60,6 +61,7 @@ data class ContextMenuCandidate( createCopyLinkCandidate(context, snackBarParentView, snackbarDelegate), createDownloadLinkCandidate(context, contextMenuUseCases), createShareLinkCandidate(context), createShareImageCandidate(context), createOpenImageInNewTabCandidate( context, tabsUseCases, Loading Loading @@ -274,6 +276,19 @@ data class ContextMenuCandidate( } ) /** * Context Menu item: "Share image" */ fun createShareImageCandidate( context: Context, action: (SessionState, HitResult) -> Unit = { _, hitResult -> context.share(hitResult.src) } ) = ContextMenuCandidate( id = "mozac.feature.contextmenu.share_image", label = context.getString(R.string.mozac_feature_contextmenu_share_image), showFor = { _, hitResult -> hitResult.isImage() }, action = action ) /** * Context Menu item: "Copy Link". */ Loading components/feature/contextmenu/src/main/res/values/strings.xml +2 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,8 @@ <string name="mozac_feature_contextmenu_download_link">Download link</string> <!-- Text for context menu item to share the link with an other app. --> <string name="mozac_feature_contextmenu_share_link">Share link</string> <!-- Text for context menu item to share the image with an other app. --> <string name="mozac_feature_contextmenu_share_image">Share image</string> <!-- Text for context menu item to copy the link to the clipboard. --> <string name="mozac_feature_contextmenu_copy_link">Copy link</string> <!-- Text for context menu item to copy the URL pointing to the image to the clipboard. --> Loading components/feature/contextmenu/src/test/java/mozilla/components/feature/contextmenu/ContextMenuCandidateTest.kt +38 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager import mozilla.components.browser.state.selector.selectedTab import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.ContentState import mozilla.components.browser.state.state.TabSessionState import mozilla.components.browser.state.state.createTab import mozilla.components.browser.state.store.BrowserStore import mozilla.components.concept.engine.EngineSession Loading Loading @@ -53,7 +56,7 @@ class ContextMenuCandidateTest { val candidates = ContextMenuCandidate.defaultCandidates(testContext, mock(), mock(), mock()) // Just a sanity check: When changing the list of default candidates be aware that this will affect all // consumers of this component using the default list. assertEquals(9, candidates.size) assertEquals(10, candidates.size) } @Test Loading Loading @@ -649,6 +652,40 @@ class ContextMenuCandidateTest { verify(context).startActivity(any()) } @Test fun `Candidate "Share image"`() { val context = spy(testContext) val shareImage = ContextMenuCandidate.createShareImageCandidate(context) // showFor assertTrue(shareImage.showFor( createTab("https://www.mozilla.org"), HitResult.IMAGE("https://www.mozilla.org"))) assertTrue(shareImage.showFor( createTab("https://www.mozilla.org"), HitResult.IMAGE_SRC("https://www.mozilla.org", "https://www.mozilla.org"))) assertFalse(shareImage.showFor( createTab("https://www.mozilla.org"), HitResult.AUDIO("https://www.mozilla.org"))) // action val store = BrowserStore(initialState = BrowserState( tabs = listOf(TabSessionState("123", ContentState("https://www.mozilla.org"))) )) shareImage.action.invoke( store.state.tabs.first(), HitResult.IMAGE_SRC("https://firefox.com", "https://getpocket.com") ) verify(context).startActivity(any()) } @Test fun `Candidate "Copy Link"`() { val parentView = CoordinatorLayout(testContext) Loading components/support/ktx/src/main/java/mozilla/components/support/ktx/android/content/Context.kt +0 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ import android.content.Intent import android.content.Intent.ACTION_SEND import android.content.Intent.EXTRA_SUBJECT import android.content.Intent.EXTRA_TEXT import android.content.Intent.EXTRA_TITLE import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.pm.PackageManager.PERMISSION_GRANTED import android.hardware.camera2.CameraManager Loading Loading @@ -84,7 +83,6 @@ fun Context.share(text: String, subject: String = getString(R.string.mozac_suppo return try { val intent = Intent(ACTION_SEND).apply { type = "text/plain" putExtra(EXTRA_TITLE, subject) putExtra(EXTRA_SUBJECT, subject) putExtra(EXTRA_TEXT, text) flags = FLAG_ACTIVITY_NEW_TASK Loading docs/changelog.md +4 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Config.kt) * **feature-contextmenu** * Add "Share image" to context menu. # 47.0.0 * [Commits](https://github.com/mozilla-mobile/android-components/compare/v46.0.0...v47.0.0) Loading Loading
components/feature/contextmenu/src/main/java/mozilla/components/feature/contextmenu/ContextMenuCandidate.kt +15 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import mozilla.components.browser.state.state.content.DownloadState import mozilla.components.concept.engine.HitResult import mozilla.components.feature.tabs.TabsUseCases import mozilla.components.feature.app.links.AppLinksUseCases import mozilla.components.support.ktx.android.content.share /** * A candidate for an item to be displayed in the context menu. Loading Loading @@ -60,6 +61,7 @@ data class ContextMenuCandidate( createCopyLinkCandidate(context, snackBarParentView, snackbarDelegate), createDownloadLinkCandidate(context, contextMenuUseCases), createShareLinkCandidate(context), createShareImageCandidate(context), createOpenImageInNewTabCandidate( context, tabsUseCases, Loading Loading @@ -274,6 +276,19 @@ data class ContextMenuCandidate( } ) /** * Context Menu item: "Share image" */ fun createShareImageCandidate( context: Context, action: (SessionState, HitResult) -> Unit = { _, hitResult -> context.share(hitResult.src) } ) = ContextMenuCandidate( id = "mozac.feature.contextmenu.share_image", label = context.getString(R.string.mozac_feature_contextmenu_share_image), showFor = { _, hitResult -> hitResult.isImage() }, action = action ) /** * Context Menu item: "Copy Link". */ Loading
components/feature/contextmenu/src/main/res/values/strings.xml +2 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,8 @@ <string name="mozac_feature_contextmenu_download_link">Download link</string> <!-- Text for context menu item to share the link with an other app. --> <string name="mozac_feature_contextmenu_share_link">Share link</string> <!-- Text for context menu item to share the image with an other app. --> <string name="mozac_feature_contextmenu_share_image">Share image</string> <!-- Text for context menu item to copy the link to the clipboard. --> <string name="mozac_feature_contextmenu_copy_link">Copy link</string> <!-- Text for context menu item to copy the URL pointing to the image to the clipboard. --> Loading
components/feature/contextmenu/src/test/java/mozilla/components/feature/contextmenu/ContextMenuCandidateTest.kt +38 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager import mozilla.components.browser.state.selector.selectedTab import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.ContentState import mozilla.components.browser.state.state.TabSessionState import mozilla.components.browser.state.state.createTab import mozilla.components.browser.state.store.BrowserStore import mozilla.components.concept.engine.EngineSession Loading Loading @@ -53,7 +56,7 @@ class ContextMenuCandidateTest { val candidates = ContextMenuCandidate.defaultCandidates(testContext, mock(), mock(), mock()) // Just a sanity check: When changing the list of default candidates be aware that this will affect all // consumers of this component using the default list. assertEquals(9, candidates.size) assertEquals(10, candidates.size) } @Test Loading Loading @@ -649,6 +652,40 @@ class ContextMenuCandidateTest { verify(context).startActivity(any()) } @Test fun `Candidate "Share image"`() { val context = spy(testContext) val shareImage = ContextMenuCandidate.createShareImageCandidate(context) // showFor assertTrue(shareImage.showFor( createTab("https://www.mozilla.org"), HitResult.IMAGE("https://www.mozilla.org"))) assertTrue(shareImage.showFor( createTab("https://www.mozilla.org"), HitResult.IMAGE_SRC("https://www.mozilla.org", "https://www.mozilla.org"))) assertFalse(shareImage.showFor( createTab("https://www.mozilla.org"), HitResult.AUDIO("https://www.mozilla.org"))) // action val store = BrowserStore(initialState = BrowserState( tabs = listOf(TabSessionState("123", ContentState("https://www.mozilla.org"))) )) shareImage.action.invoke( store.state.tabs.first(), HitResult.IMAGE_SRC("https://firefox.com", "https://getpocket.com") ) verify(context).startActivity(any()) } @Test fun `Candidate "Copy Link"`() { val parentView = CoordinatorLayout(testContext) Loading
components/support/ktx/src/main/java/mozilla/components/support/ktx/android/content/Context.kt +0 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ import android.content.Intent import android.content.Intent.ACTION_SEND import android.content.Intent.EXTRA_SUBJECT import android.content.Intent.EXTRA_TEXT import android.content.Intent.EXTRA_TITLE import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.pm.PackageManager.PERMISSION_GRANTED import android.hardware.camera2.CameraManager Loading Loading @@ -84,7 +83,6 @@ fun Context.share(text: String, subject: String = getString(R.string.mozac_suppo return try { val intent = Intent(ACTION_SEND).apply { type = "text/plain" putExtra(EXTRA_TITLE, subject) putExtra(EXTRA_SUBJECT, subject) putExtra(EXTRA_TEXT, text) flags = FLAG_ACTIVITY_NEW_TASK Loading
docs/changelog.md +4 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Config.kt) * **feature-contextmenu** * Add "Share image" to context menu. # 47.0.0 * [Commits](https://github.com/mozilla-mobile/android-components/compare/v46.0.0...v47.0.0) Loading