mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2769 App | Design | Update icons for files (#1592)
This commit is contained in:
parent
50702931e6
commit
73d6c02418
16 changed files with 47 additions and 27 deletions
|
@ -771,7 +771,8 @@ fun GlobalSearchObjectIcon(
|
|||
fileName = icon.fileName.orEmpty(),
|
||||
mime = icon.mime.orEmpty(),
|
||||
modifier = modifier,
|
||||
iconSize = iconSize
|
||||
iconSize = iconSize,
|
||||
extension = icon.extensions
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -239,8 +239,7 @@ fun DVSortType.text(format: RelationFormat): Int = when (format) {
|
|||
}
|
||||
}
|
||||
|
||||
fun String?.getMimeIcon(name: String?): Int {
|
||||
val extension = MimeTypeMap.getFileExtensionFromUrl(name)
|
||||
fun String?.getMimeIcon(extension: String?): Int {
|
||||
var mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||
if (mime.isNullOrBlank()) {
|
||||
mime = this
|
||||
|
|
|
@ -16,7 +16,7 @@ class DVGridCellFileHolder(val binding: ItemViewerGridCellFileBinding) : Recycle
|
|||
in 0..MAX_VISIBLE_FILES_INDEX -> {
|
||||
getViewByIndex(index)?.let { view ->
|
||||
view.visible()
|
||||
view.setup(name = fileView.name, mime = fileView.mime)
|
||||
view.setup(name = fileView.name, mime = fileView.mime, extension = fileView.ext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class File(val binding: ItemBlockFileBinding) : Media(binding.root), Decoratable
|
|||
|
||||
applySearchHighlight(item)
|
||||
|
||||
val mimeIcon = item.mime.getMimeIcon(item.name)
|
||||
val mimeIcon = item.mime.getMimeIcon(item.fileExt)
|
||||
icon.setImageResource(mimeIcon)
|
||||
|
||||
applyBackground(item.background)
|
||||
|
|
|
@ -208,7 +208,7 @@ sealed class ListRelationViewHolder(
|
|||
in 0..MAX_VISIBLE_FILES_INDEX -> {
|
||||
getViewByIndex(index)?.let { view ->
|
||||
view.visible()
|
||||
view.setup(name = fileView.name, mime = fileView.mime)
|
||||
view.setup(name = fileView.name, mime = fileView.mime, extension = fileView.ext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,7 +416,7 @@ sealed class RelationBlockViewHolder(
|
|||
in 0..MAX_VISIBLE_FILES_INDEX -> {
|
||||
getViewByIndex(index)?.let { view ->
|
||||
view.visible()
|
||||
view.setup(name = fileView.name, mime = fileView.mime)
|
||||
view.setup(name = fileView.name, mime = fileView.mime, extension = fileView.ext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class RelationFileHolder(
|
|||
|
||||
fun bind(item: RelationValueView.File) = with(binding) {
|
||||
tvTitle.text = "${item.name}.${item.ext}"
|
||||
val mimeIcon = item.mime.getMimeIcon(item.name)
|
||||
val mimeIcon = item.mime.getMimeIcon(item.ext)
|
||||
iconMime.setImageResource(mimeIcon)
|
||||
fileSelectionIndex.visible()
|
||||
if (item.isSelected == true) {
|
||||
|
|
|
@ -303,7 +303,7 @@ class RelationValueAdapter(
|
|||
DragAndDropViewHolder {
|
||||
fun bind(item: RelationValueView.File) = with(binding) {
|
||||
tvTitle.text = "${item.name}.${item.ext}"
|
||||
val mimeIcon = item.mime.getMimeIcon(item.name)
|
||||
val mimeIcon = item.mime.getMimeIcon(item.ext)
|
||||
iconMime.setImageResource(mimeIcon)
|
||||
if (!item.removable) {
|
||||
btnRemoveFile.gone()
|
||||
|
|
|
@ -17,12 +17,12 @@ class GridCellFileItem @JvmOverloads constructor(
|
|||
LayoutInflater.from(context), this, true
|
||||
)
|
||||
|
||||
fun setup(name: String, mime: String?) = with(binding) {
|
||||
fun setup(name: String, mime: String?, extension: String?) = with(binding) {
|
||||
tvName.visible()
|
||||
tvName.text = name
|
||||
if (mime != null) {
|
||||
ivIcon.visible()
|
||||
val mimeIcon = mime.getMimeIcon(name)
|
||||
val mimeIcon = mime.getMimeIcon(extension)
|
||||
ivIcon.setImageResource(mimeIcon)
|
||||
} else {
|
||||
ivIcon.gone()
|
||||
|
|
|
@ -61,7 +61,8 @@ fun ListWidgetObjectIcon(
|
|||
fileName = icon.fileName.orEmpty(),
|
||||
mime = icon.mime.orEmpty(),
|
||||
modifier = modifier,
|
||||
iconSize = iconSize
|
||||
iconSize = iconSize,
|
||||
extension = icon.extensions
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
|
@ -243,9 +244,10 @@ fun DefaultFileObjectImageIcon(
|
|||
fileName: String,
|
||||
mime: String,
|
||||
modifier: Modifier,
|
||||
iconSize: Dp
|
||||
iconSize: Dp,
|
||||
extension: String?,
|
||||
) {
|
||||
val mimeIcon = mime.getMimeIcon(fileName)
|
||||
val mimeIcon = mime.getMimeIcon(extension)
|
||||
Image(
|
||||
painter = painterResource(id = mimeIcon),
|
||||
contentDescription = "File icon",
|
||||
|
|
|
@ -145,7 +145,8 @@ class ObjectIconWidget @JvmOverloads constructor(
|
|||
is ObjectIcon.None -> removeIcon()
|
||||
is ObjectIcon.File -> setFileImage(
|
||||
mime = icon.mime,
|
||||
fileName = icon.fileName
|
||||
fileName = icon.fileName,
|
||||
extension = icon.extensions
|
||||
)
|
||||
ObjectIcon.Deleted -> setDeletedIcon()
|
||||
is ObjectIcon.Checkbox -> setCheckbox(icon.isChecked)
|
||||
|
@ -238,8 +239,8 @@ class ObjectIconWidget @JvmOverloads constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun setFileImage(mime: String?, fileName: String?) {
|
||||
val icon = mime.getMimeIcon(fileName)
|
||||
private fun setFileImage(mime: String?, fileName: String?, extension: String?) {
|
||||
val icon = mime.getMimeIcon(extension)
|
||||
with(binding) {
|
||||
ivImage.visible()
|
||||
ivImage.scaleType = ImageView.ScaleType.CENTER_CROP
|
||||
|
|
|
@ -17,7 +17,11 @@ object MimeTypes {
|
|||
"image/gif",
|
||||
"image/avif",
|
||||
"image/apng",
|
||||
"image/bmp"
|
||||
"image/bmp",
|
||||
"image/vnd.dwg",
|
||||
"image/x-dwg",
|
||||
"image/tiff",
|
||||
"image/vnd.adobe.photoshop",
|
||||
)
|
||||
|
||||
private val TEXTS = listOf(
|
||||
|
@ -32,7 +36,8 @@ object MimeTypes {
|
|||
"application/vnd.openxmlformats-officedocument.wordprocessingml.template",
|
||||
"application/json",
|
||||
"application/ld+json",
|
||||
"text/comma-separated-values"
|
||||
"text/comma-separated-values",
|
||||
"text/xml"
|
||||
)
|
||||
|
||||
private val VIDEOS = listOf(
|
||||
|
@ -43,7 +48,10 @@ object MimeTypes {
|
|||
"video/H263",
|
||||
"video/mpv",
|
||||
"video/ogg",
|
||||
"video/x-msvideo"
|
||||
"video/x-msvideo",
|
||||
"video/x-flv",
|
||||
"video/x-ms-wmv",
|
||||
"video/quicktime"
|
||||
)
|
||||
|
||||
private val AUDIOS = listOf(
|
||||
|
@ -61,7 +69,8 @@ object MimeTypes {
|
|||
"audio/m4a",
|
||||
"audio/mp3",
|
||||
"audio/x-flac",
|
||||
"audio/flac"
|
||||
"audio/flac",
|
||||
"audio/x-aiff"
|
||||
)
|
||||
|
||||
private val ARCHIVE = listOf(
|
||||
|
@ -82,12 +91,16 @@ object MimeTypes {
|
|||
|
||||
private val TABLE = listOf(
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/csv"
|
||||
)
|
||||
|
||||
private val PRESENTATION = listOf(
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.template",
|
||||
"application/vnd.ms-powerpoint.template.macroEnabled.12",
|
||||
"application/vnd.ms-powerpoint.addin.macroEnabled.12"
|
||||
)
|
||||
|
||||
enum class Category {
|
||||
|
|
|
@ -23,7 +23,7 @@ sealed class ObjectIcon {
|
|||
|
||||
data class Bookmark(val image: Url) : ObjectIcon()
|
||||
|
||||
data class File(val mime: String?, val fileName: String?) : ObjectIcon()
|
||||
data class File(val mime: String?, val fileName: String?, val extensions: String?) : ObjectIcon()
|
||||
|
||||
object Deleted : ObjectIcon()
|
||||
data class Checkbox(val isChecked: Boolean) : ObjectIcon()
|
||||
|
@ -75,7 +75,7 @@ sealed class ObjectIcon {
|
|||
ObjectType.Layout.VIDEO,
|
||||
ObjectType.Layout.PDF -> {
|
||||
if (img.isNullOrBlank()) {
|
||||
File(mime = obj.fileMimeType, fileName = obj.name)
|
||||
File(mime = obj.fileMimeType, fileName = obj.name, extensions = obj.fileExt)
|
||||
} else {
|
||||
Basic.Image(hash = builder.thumbnail(img))
|
||||
}
|
||||
|
|
|
@ -324,7 +324,8 @@ suspend fun ObjectWrapper.Basic.files(
|
|||
ext = obj.fileExt.orEmpty(),
|
||||
icon = ObjectIcon.File(
|
||||
mime = obj.fileMimeType.orEmpty(),
|
||||
fileName = obj.name.orEmpty()
|
||||
fileName = obj.name.orEmpty(),
|
||||
extensions = obj.fileExt.orEmpty()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -305,7 +305,8 @@ private fun ObjectWrapper.Basic.getFileObjectIcon(): ObjectIcon {
|
|||
ObjectType.Layout.FILE, ObjectType.Layout.IMAGE ->
|
||||
ObjectIcon.File(
|
||||
mime = fileMimeType,
|
||||
fileName = getProperName()
|
||||
fileName = getProperName(),
|
||||
extensions = fileExt
|
||||
)
|
||||
|
||||
else -> ObjectIcon.None
|
||||
|
|
|
@ -100,6 +100,7 @@ suspend fun List<ColumnView>.buildGridRow(
|
|||
icon = ObjectIcon.File(
|
||||
mime = wrapper.fileMimeType.orEmpty(),
|
||||
fileName = wrapper.name.orEmpty(),
|
||||
extensions = wrapper.fileExt.orEmpty(),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -259,6 +260,7 @@ private fun ObjectWrapper.File.toView() : FileView {
|
|||
icon = ObjectIcon.File(
|
||||
mime = fileMimeType.orEmpty(),
|
||||
fileName = name.orEmpty(),
|
||||
extensions = fileExt.orEmpty(),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue