Implement FileType.kt for ComposerAttachmentUiModelMapper.kt
MAILAND-1669
This commit is contained in:
parent
9841199f95
commit
717b3dae19
|
@ -23,6 +23,7 @@ import ch.protonmail.android.attachments.domain.model.ImportAttachmentResult
|
|||
import ch.protonmail.android.compose.presentation.model.ComposerAttachmentUiModel
|
||||
import ch.protonmail.android.compose.presentation.model.ComposerAttachmentUiModel.Icon
|
||||
import ch.protonmail.android.compose.presentation.model.ComposerAttachmentUiModel.State
|
||||
import ch.protonmail.android.domain.entity.FileType
|
||||
import ch.protonmail.android.mapper.UiModelMapper
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -67,9 +68,20 @@ class ComposerAttachmentUiModelMapper @Inject constructor() :
|
|||
state = state
|
||||
)
|
||||
|
||||
// TODO
|
||||
private fun iconFor(extension: String): Icon =
|
||||
when (extension) {
|
||||
else -> Icon.GENERIC
|
||||
when (FileType.byExtension(extension)) {
|
||||
FileType.Generic -> Icon.Generic
|
||||
FileType.Archive -> Icon.Archive
|
||||
FileType.Audio -> Icon.Audio
|
||||
FileType.Doc -> Icon.Doc
|
||||
FileType.Image -> Icon.Image
|
||||
FileType.Keynote -> Icon.Keynote
|
||||
FileType.Numbers -> Icon.Numbers
|
||||
FileType.Pages -> Icon.Pages
|
||||
FileType.Pdf -> Icon.Pdf
|
||||
FileType.Presentation -> Icon.Presentation
|
||||
FileType.Video -> Icon.Video
|
||||
FileType.Xls -> Icon.Xls
|
||||
FileType.Xml -> Icon.Xml
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,19 @@ sealed class ComposerAttachmentUiModel {
|
|||
}
|
||||
|
||||
enum class Icon(@DrawableRes val drawableId: Int) {
|
||||
GENERIC(R.drawable.ic_attachments)
|
||||
Generic(R.drawable.ic_attachments),
|
||||
Archive(R.drawable.ic_attachments),
|
||||
Audio(R.drawable.ic_attachments),
|
||||
Doc(R.drawable.ic_attachments),
|
||||
Image(R.drawable.ic_attachments),
|
||||
Keynote(R.drawable.ic_attachments),
|
||||
Numbers(R.drawable.ic_attachments),
|
||||
Pages(R.drawable.ic_attachments),
|
||||
Pdf(R.drawable.ic_attachments),
|
||||
Presentation(R.drawable.ic_attachments),
|
||||
Video(R.drawable.ic_attachments),
|
||||
Xls(R.drawable.ic_attachments),
|
||||
Xml(R.drawable.ic_attachments)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package ch.protonmail.android.compose.presentation.mapper
|
||||
|
||||
import android.net.Uri
|
||||
import assert4k.*
|
||||
import ch.protonmail.android.attachments.domain.model.ImportAttachmentResult
|
||||
import ch.protonmail.android.compose.presentation.model.ComposerAttachmentUiModel
|
||||
import ch.protonmail.android.compose.presentation.model.ComposerAttachmentUiModel.Icon
|
||||
|
@ -89,7 +88,7 @@ class ComposerAttachmentUiModelMapperTest {
|
|||
displayName = testFileName,
|
||||
extension = testFileExtension,
|
||||
size = testFileSize,
|
||||
icon = Icon.GENERIC,
|
||||
icon = Icon.Image,
|
||||
state = State.Importing
|
||||
)
|
||||
|
||||
|
@ -114,7 +113,7 @@ class ComposerAttachmentUiModelMapperTest {
|
|||
displayName = testFileName,
|
||||
extension = testFileExtension,
|
||||
size = testFileSize,
|
||||
icon = Icon.GENERIC,
|
||||
icon = Icon.Image,
|
||||
state = State.Ready
|
||||
)
|
||||
|
||||
|
@ -156,7 +155,7 @@ class ComposerAttachmentUiModelMapperTest {
|
|||
displayName = testFileName,
|
||||
extension = testFileExtension,
|
||||
size = testFileSize,
|
||||
icon = Icon.GENERIC,
|
||||
icon = Icon.Image,
|
||||
state = State.Error
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Proton Technologies AG
|
||||
*
|
||||
* This file is part of ProtonMail.
|
||||
*
|
||||
* ProtonMail is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ProtonMail is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ProtonMail. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
package ch.protonmail.android.domain.entity
|
||||
|
||||
import me.proton.core.util.kotlin.equalsNoCase
|
||||
|
||||
enum class FileType(val extensions: Set<String>) {
|
||||
|
||||
Generic(emptySet()),
|
||||
|
||||
Archive(setOf("7zip", "rar", "zip")),
|
||||
Audio(setOf("mp3", "wav")),
|
||||
Doc(setOf("doc", "docx")),
|
||||
Image(setOf("jpg", "jpeg", "png")),
|
||||
Keynote(setOf("keynote")),
|
||||
Numbers(setOf("numbers")),
|
||||
Pages(setOf("pages")),
|
||||
Pdf(setOf("pdf")),
|
||||
Presentation(setOf("pot", "ppt", "pptx")),
|
||||
Video(setOf("3gp", "mkv", "mp4")),
|
||||
Xls(setOf("xls", "xlsx")),
|
||||
Xml(setOf("xml", "xliff"));
|
||||
|
||||
companion object {
|
||||
|
||||
fun byExtension(string: String): FileType =
|
||||
values().find { fileType ->
|
||||
fileType.extensions.any { it equalsNoCase string }
|
||||
} ?: Generic
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue