injecting the context directly to the handler

This commit is contained in:
Adam Brown 2022-07-06 12:02:45 +01:00
parent d19346b9c6
commit 59ef8e10c8
4 changed files with 5 additions and 5 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -116,7 +116,6 @@ class IncomingShareFragment @Inject constructor(
}
private fun handleIncomingShareIntent(intent: Intent) = shareIntentHandler.handleIncomingShareIntent(
requireContext(),
intent,
onFile = {
val sharedData = SharedData.Attachments(it)

View File

@ -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)
}
}