Repository: thunderbird/thunderbird-android
File: legacy/ui/legacy/src/main/java/com/fsck/k9/activity/misc/Attachment.kt (Kotlin)

Code before:
import com.fsck.k9.helper.MimeTypeUtil
import com.fsck.k9.message.Attachment.LoadingState

/**
 * Container class for information about an attachment.
 *
 * This is used by [com.fsck.k9.activity.MessageCompose] to fetch and manage attachments.
 *
 * @property uri The URI pointing to the source of the attachment.
 *   In most cases this will be a `content://`-URI.
 * @property state The current loading state.
 * @property loaderId The ID of the loader that is used to load the metadata or contents.
 * @property contentType The content type of the attachment.
 *   Valid iff [state] is [LoadingState.METADATA] or [LoadingState.COMPLETE].
 * @property allowMessageType `true` if we allow MIME types of `message/ *`, e.g. `message/rfc822`.
 * @property name The (file)name of the attachment.
 *   Valid iff [state] is [LoadingState.METADATA] or [LoadingState.COMPLETE].
 * @property size The size of the attachment. Valid iff [state] is
 *   [LoadingState.METADATA] or [LoadingState.COMPLETE].
 * @property fileName The name of the temporary file containing the local copy of the attachment.
 *   Valid iff [state] is [LoadingState.COMPLETE].
 * @property isInternalAttachment
 */
@Suppress("LongParameterList")
class Attachment(
    val uri: Uri,
    override val state: LoadingState,
    val loaderId: Int,
    override val contentType: String?,
    val allowMessageType: Boolean,
    override val name: String?,
    override val size: Long?,
    override val fileName: String?,
    override val isInternalAttachment: Boolean,
) : Parcelable, com.fsck.k9.message.Attachment {

    val isSupportedImage: Boolean
        get() {
            if (contentType == null) return false

            return MimeTypeUtil.isSupportedImageType(contentType) ||
                (
                    MimeTypeUtil.isSameMimeType(MimeTypeUtil.DEFAULT_ATTACHMENT_MIME_TYPE, contentType)
                        && fileName != null && MimeTypeUtil.isSupportedImageExtension(fileName)
                    )
        }

    private constructor(parcel: Parcel) : this(
        uri = requireNotNull(
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                parcel.readParcelable(Uri::class.java.classLoader, Uri::class.java)

Review comment (suggestion):
```suggestion
    @JvmField
    val uri: Uri,
```

You can mark these properties as `@JvmField` to get rid of `attachment.getUri()` changes in Java code.

Code after:
import com.fsck.k9.helper.MimeTypeUtil
import com.fsck.k9.message.Attachment.LoadingState

/**
 * Container class for information about an attachment.
 *
 * This is used by [com.fsck.k9.activity.MessageCompose] to fetch and manage attachments.
 *
 * @property uri The URI pointing to the source of the attachment.
 *   In most cases this will be a `content://`-URI.
 * @property state The current loading state.
 * @property loaderId The ID of the loader that is used to load the metadata or contents.
 * @property contentType The content type of the attachment.
 *   Valid iff [state] is [LoadingState.METADATA] or [LoadingState.COMPLETE].
 * @property allowMessageType `true` if we allow MIME types of `message/ *`, e.g. `message/rfc822`.
 * @property name The (file)name of the attachment.
 *   Valid iff [state] is [LoadingState.METADATA] or [LoadingState.COMPLETE].
 * @property size The size of the attachment. Valid iff [state] is
 *   [LoadingState.METADATA] or [LoadingState.COMPLETE].
 * @property fileName The name of the temporary file containing the local copy of the attachment.
 *   Valid iff [state] is [LoadingState.COMPLETE].
 * @property isInternalAttachment
 */
@Suppress("LongParameterList")
class Attachment(
    @JvmField val uri: Uri,
    override val state: LoadingState,
    @JvmField val loaderId: Int,
    override val contentType: String?,
    @JvmField val allowMessageType: Boolean,
    override val name: String?,
    override val size: Long?,
    override val fileName: String?,
    override val isInternalAttachment: Boolean,
) : Parcelable, com.fsck.k9.message.Attachment {

    val isSupportedImage: Boolean
        get() {
            if (contentType == null) return false

            return MimeTypeUtil.isSupportedImageType(contentType) ||
                (
                    MimeTypeUtil.isSameMimeType(MimeTypeUtil.DEFAULT_ATTACHMENT_MIME_TYPE, contentType) &&
                        fileName != null &&
                        MimeTypeUtil.isSupportedImageExtension(fileName)
                    )
        }

    private constructor(parcel: Parcel) : this(
        uri = requireNotNull(
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {