converting if/else to when

This commit is contained in:
Adam Brown 2022-07-04 16:15:01 +01:00
parent abf35d730d
commit 8811f752e5

View file

@ -196,33 +196,39 @@ class AttachmentsHelper(val context: Context, val callback: Callback) : Restorab
*/ */
fun handleShareIntent(context: Context, intent: Intent): Boolean { fun handleShareIntent(context: Context, intent: Intent): Boolean {
val type = intent.resolveType(context) ?: return false val type = intent.resolveType(context) ?: return false
if (type.startsWith("image")) { when {
type.startsWith("image") -> {
callback.onContentAttachmentsReady( callback.onContentAttachmentsReady(
MultiPicker.get(MultiPicker.IMAGE).getIncomingFiles(context, intent).map { MultiPicker.get(MultiPicker.IMAGE).getIncomingFiles(context, intent).map {
it.toContentAttachmentData() it.toContentAttachmentData()
} }
) )
} else if (type.startsWith("video")) { }
type.startsWith("video") -> {
callback.onContentAttachmentsReady( callback.onContentAttachmentsReady(
MultiPicker.get(MultiPicker.VIDEO).getIncomingFiles(context, intent).map { MultiPicker.get(MultiPicker.VIDEO).getIncomingFiles(context, intent).map {
it.toContentAttachmentData() it.toContentAttachmentData()
} }
) )
} else if (type.startsWith("audio")) { }
type.startsWith("audio") -> {
callback.onContentAttachmentsReady( callback.onContentAttachmentsReady(
MultiPicker.get(MultiPicker.AUDIO).getIncomingFiles(context, intent).map { MultiPicker.get(MultiPicker.AUDIO).getIncomingFiles(context, intent).map {
it.toContentAttachmentData() it.toContentAttachmentData()
} }
) )
} else if (type.startsWith("application") || type.startsWith("file") || type.startsWith("text") || type.startsWith("*")) { }
type.startsWith("application") || type.startsWith("file") || type.startsWith("text") || type.startsWith("*") -> {
callback.onContentAttachmentsReady( callback.onContentAttachmentsReady(
MultiPicker.get(MultiPicker.FILE).getIncomingFiles(context, intent).map { MultiPicker.get(MultiPicker.FILE).getIncomingFiles(context, intent).map {
it.toContentAttachmentData() it.toContentAttachmentData()
} }
) )
} else { }
else -> {
return false return false
} }
}
return true return true
} }
} }