[fenix] For https://github.com/mozilla-mobile/fenix/issues/1068 - Adds the ability to quickly copy a URL

pull/600/head
Jeff Boek 6 years ago
parent eff2a2bf26
commit 9ea98e15b7

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #1237 - Added the ability to delete bookmark folders
- #1238 - Added the ability to edit bookmark folders
- #1239 - Added the ability to move bookmark folders
- #1068 - Adds the ability to quickly copy the URL by long clicking the URLBar
### Changed
- #1429 - Updated site permissions ui for MVP
### Removed

@ -4,6 +4,8 @@
package org.mozilla.fenix.browser
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
@ -282,7 +284,7 @@ class BrowserFragment : Fragment(), BackHandler {
getAutoDisposeObservable<SearchAction>()
.subscribe {
when (it) {
is SearchAction.ToolbarTapped -> {
is SearchAction.ToolbarClicked -> {
Navigation
.findNavController(toolbarComponent.getView())
.navigate(
@ -299,6 +301,9 @@ class BrowserFragment : Fragment(), BackHandler {
trackToolbarItemInteraction(it)
handleToolbarItemInteraction(it)
}
is SearchAction.ToolbarLongClicked -> {
getSessionByIdOrUseSelectedSession().copyUrl(requireContext())
}
}
}
@ -475,6 +480,17 @@ class BrowserFragment : Fragment(), BackHandler {
}
}
private fun Session.copyUrl(context: Context) {
val clipBoard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val uri = Uri.parse(url)
clipBoard.primaryClip = ClipData.newRawUri("Uri", uri)
val rootView = context.asActivity()?.window?.decorView?.findViewById<View>(android.R.id.content) as ViewGroup
FenixSnackbar.make(rootView, Snackbar.LENGTH_LONG)
.setText(context.getString(R.string.url_copied))
.show()
}
companion object {
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2

@ -81,7 +81,8 @@ data class SearchState(
sealed class SearchAction : Action {
data class UrlCommitted(val url: String, val session: String?, val engine: SearchEngine? = null) : SearchAction()
data class TextChanged(val query: String) : SearchAction()
object ToolbarTapped : SearchAction()
object ToolbarClicked : SearchAction()
object ToolbarLongClicked : SearchAction()
data class ToolbarMenuItemTapped(val item: ToolbarMenu.Item) : SearchAction()
object EditingCanceled : SearchAction()
}

@ -47,7 +47,7 @@ class ToolbarUIView(
false
}
onUrlClicked = {
actionEmitter.onNext(SearchAction.ToolbarTapped)
actionEmitter.onNext(SearchAction.ToolbarClicked)
false
}
@ -66,6 +66,11 @@ class ToolbarUIView(
actionEmitter.onNext(SearchAction.TextChanged(text))
}
})
setOnUrlLongClickListener {
actionEmitter.onNext(SearchAction.ToolbarLongClicked)
true
}
}
with(view.context) {

@ -314,4 +314,5 @@
<string name="bookmark_empty_title_error">Must have a title</string>
<string name="bookmark_invalid_url_error">Invalid URL</string>
<string name="bookmarks_empty_message">No bookmarks here</string>
<string name="url_copied">URL copied</string>
</resources>

Loading…
Cancel
Save