injecting the context directly to the handler
This commit is contained in:
parent
d19346b9c6
commit
59ef8e10c8
|
@ -23,6 +23,7 @@ import javax.inject.Inject
|
|||
|
||||
class ShareIntentHandler @Inject constructor(
|
||||
private val multiPickerIncomingFiles: MultiPickerIncomingFiles,
|
||||
private val context: Context,
|
||||
) {
|
||||
|
||||
/**
|
||||
|
@ -30,7 +31,7 @@ class ShareIntentHandler @Inject constructor(
|
|||
*
|
||||
* @return true if it can handle the intent data, false otherwise
|
||||
*/
|
||||
fun handleIncomingShareIntent(context: Context, intent: Intent, onFile: (List<ContentAttachmentData>) -> Unit, onPlainText: (String) -> Unit): Boolean {
|
||||
fun handleIncomingShareIntent(intent: Intent, onFile: (List<ContentAttachmentData>) -> Unit, onPlainText: (String) -> Unit): Boolean {
|
||||
val type = intent.resolveType(context) ?: return false
|
||||
return when {
|
||||
type == "text/plain" -> handlePlainText(intent, onPlainText)
|
||||
|
|
|
@ -1619,7 +1619,7 @@ class TimelineFragment @Inject constructor(
|
|||
|
||||
private fun sendUri(uri: Uri): Boolean {
|
||||
val shareIntent = Intent(Intent.ACTION_SEND, uri)
|
||||
val isHandled = shareIntentHandler.handleIncomingShareIntent(requireContext(), shareIntent, ::onContentAttachmentsReady, onPlainText = {
|
||||
val isHandled = shareIntentHandler.handleIncomingShareIntent(shareIntent, ::onContentAttachmentsReady, onPlainText = {
|
||||
fatalError("Should not happen as we're generating a File based share Intent", vectorPreferences.failFast())
|
||||
})
|
||||
if (!isHandled) {
|
||||
|
|
|
@ -116,7 +116,6 @@ class IncomingShareFragment @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleIncomingShareIntent(intent: Intent) = shareIntentHandler.handleIncomingShareIntent(
|
||||
requireContext(),
|
||||
intent,
|
||||
onFile = {
|
||||
val sharedData = SharedData.Attachments(it)
|
||||
|
|
|
@ -36,7 +36,7 @@ class ShareIntentHandlerTest {
|
|||
private val onFile = FakeFunction1<List<ContentAttachmentData>>()
|
||||
private val onPlainText = FakeFunction1<String>()
|
||||
|
||||
private val shareIntentHandler = ShareIntentHandler(fakeMultiPickerIncomingFiles.instance)
|
||||
private val shareIntentHandler = ShareIntentHandler(fakeMultiPickerIncomingFiles.instance, A_CONTEXT)
|
||||
|
||||
@Test
|
||||
fun `given an unhandled sharing intent type, when handling intent, then is not handled`() {
|
||||
|
@ -161,6 +161,6 @@ class ShareIntentHandlerTest {
|
|||
}
|
||||
|
||||
private fun handleIncomingShareIntent(intent: FakeIntent): Boolean {
|
||||
return shareIntentHandler.handleIncomingShareIntent(A_CONTEXT, intent.instance, onFile.capture, onPlainText.capture)
|
||||
return shareIntentHandler.handleIncomingShareIntent(intent.instance, onFile.capture, onPlainText.capture)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue