Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthew Finkel
fenix
Commits
7be56ce4
Commit
7be56ce4
authored
Jun 25, 2020
by
Christian Sadilek
Browse files
For #11798: Allow sharing of reader view pages
parent
04aee11d
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/org/mozilla/fenix/share/ShareController.kt
View file @
7be56ce4
...
...
@@ -24,6 +24,7 @@ import mozilla.components.concept.sync.Device
import
mozilla.components.concept.sync.TabData
import
mozilla.components.feature.accounts.push.SendTabUseCases
import
mozilla.components.feature.share.RecentAppsStorage
import
mozilla.components.support.ktx.kotlin.isExtensionUrl
import
org.mozilla.fenix.R
import
org.mozilla.fenix.components.FenixSnackbar
import
org.mozilla.fenix.components.metrics.Event
...
...
@@ -172,7 +173,20 @@ class DefaultShareController(
@VisibleForTesting
fun
getShareText
()
=
shareData
.
joinToString
(
"\n\n"
)
{
data
->
data
.
url
.
orEmpty
()
val
url
=
data
.
url
.
orEmpty
()
if
(
url
.
isExtensionUrl
())
{
// Sharing moz-extension:// URLs is not practical in general, as
// they will only work on the current device.
// We solve this for URLs from our reader extension as they contain
// the original URL as a query parameter. This is a workaround for
// now and needs a clean fix once we have a reader specific protocol
// e.g. ext+reader://
// https://github.com/mozilla-mobile/android-components/issues/2879
Uri
.
parse
(
url
).
getQueryParameter
(
"url"
)
?:
url
}
else
{
url
}
}
// Navigation between app fragments uses ShareTab as arguments. SendTabUseCases uses TabData.
...
...
app/src/test/java/org/mozilla/fenix/share/ShareControllerTest.kt
View file @
7be56ce4
...
...
@@ -272,6 +272,22 @@ class ShareControllerTest {
assertEquals
(
textToShare
,
controller
.
getShareText
())
}
@Test
fun
`getShareText
attempts
to
use
original
URL
for
reader
pages`
()
{
val
shareData
=
listOf
(
ShareData
(
url
=
"moz-extension://eb8df45a-895b-4f3a-896a-c0c71ae4/page.html"
),
ShareData
(
url
=
"moz-extension://eb8df45a-895b-4f3a-896a-c0c71ae5/page.html?url=url0"
),
ShareData
(
url
=
"url1"
)
)
val
controller
=
DefaultShareController
(
context
,
shareData
,
sendTabUseCases
,
snackbar
,
navController
,
recentAppStorage
,
testCoroutineScope
,
dismiss
)
val
expectedShareText
=
"${shareData[0].url}\n\nurl0\n\n${shareData[2].url}"
assertEquals
(
expectedShareText
,
controller
.
getShareText
())
}
@Test
fun
`ShareTab
#
toTabData
maps
a
list
of
ShareTab
to
a
TabData
list`
()
{
var
tabData
:
List
<
TabData
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment