Skip to content

Commit

Permalink
Merge pull request #899 from Infomaniak/update-file-icons
Browse files Browse the repository at this point in the history
feat: Update attachments icons
  • Loading branch information
valentinperignon committed Jul 26, 2023
2 parents f9f437a + 5906c19 commit 118573e
Show file tree
Hide file tree
Showing 58 changed files with 581 additions and 227 deletions.
71 changes: 71 additions & 0 deletions Mail/Components/AttachmentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2022 Infomaniak Network SA
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import MailResources
import SwiftUI

struct AttachmentView<Content: View>: View {
let attachment: Attachment
let subtitle: String
@ViewBuilder let accessory: () -> Content?

init(attachment: Attachment, subtitle: String, accessory: @escaping () -> Content? = { EmptyView() }) {
self.attachment = attachment
self.subtitle = subtitle
self.accessory = accessory
}

var body: some View {
VStack(spacing: 0) {
HStack {
attachment.icon.swiftUIImage
.resizable()
.frame(width: 24, height: 24)

HStack(spacing: 8) {
VStack(alignment: .leading, spacing: 0) {
Text(attachment.name)
.textStyle(.bodySmall)
.lineLimit(1)
.truncationMode(.middle)

Text(subtitle)
.textStyle(.labelSecondary)
}

accessory()
}
}
.padding(.horizontal, 8)
.padding(.vertical, 4)
}
.background(
RoundedRectangle(cornerRadius: 6)
.stroke(MailResourcesAsset.elementsColor.swiftUIColor, lineWidth: 1)
)
.cornerRadius(6)
.frame(maxWidth: 200)
}
}

struct AttachmentView_Previews: PreviewProvider {
static var previews: some View {
AttachmentView(attachment: PreviewHelper.sampleAttachment, subtitle: "24ko")
}
}
59 changes: 19 additions & 40 deletions Mail/Views/New Message/Attachments/AttachmentUploadCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,39 @@ import MailResources
import SwiftUI

struct AttachmentUploadCell: View {
let attachment: Attachment
@ObservedObject var uploadTask: AttachmentUploadTask

let attachment: Attachment
let attachmentRemoved: ((Attachment) -> Void)?

var body: some View {
VStack(spacing: 0) {
HStack {
attachment.icon.swiftUIImage

VStack(alignment: .leading, spacing: 0) {
Text(attachment.name)
.textStyle(.bodySmall)
.lineLimit(1)
.truncationMode(.middle)
if let error = uploadTask.error {
Text(error.localizedDescription)
.textStyle(.labelSecondary)
} else {
Text(attachment.size, format: .defaultByteCount)
.textStyle(.labelSecondary)
.opacity(attachment.size == 0 ? 0 : 1)
}
AttachmentView(
attachment: attachment,
subtitle: uploadTask.error != nil ? uploadTask.error!.localizedDescription : attachment.size
.formatted(.defaultByteCount)
) {
Button {
if let attachmentRemoved {
attachmentRemoved(attachment)
}

Button {
if let attachmentRemoved {
attachmentRemoved(attachment)
}
} label: {
MailResourcesAsset.closeSmall.swiftUIImage
.resizable()
.foregroundColor(MailResourcesAsset.textSecondaryColor)
.frame(width: 16, height: 16)
}
.buttonStyle(.borderless)
.padding(.leading, 8)
} label: {
MailResourcesAsset.closeSmall.swiftUIImage
.resizable()
.foregroundColor(MailResourcesAsset.textSecondaryColor)
.frame(width: 12, height: 12)
}
.padding(6)
.buttonStyle(.borderless)
}
.overlay(alignment: .bottom) {
IndeterminateProgressView(indeterminate: uploadTask.progress == 0, progress: uploadTask.progress)
.opacity(uploadTask.progress == 1 ? 0 : 1)
}
.background(
RoundedRectangle(cornerRadius: 6)
.stroke(MailResourcesAsset.elementsColor.swiftUIColor, lineWidth: 1)
)
.cornerRadius(6)
.frame(maxWidth: 200)
.padding(.top, 16)
}
}

struct AttachmentUploadCell_Previews: PreviewProvider {
static var previews: some View {
AttachmentUploadCell(attachment: PreviewHelper.sampleAttachment, uploadTask: AttachmentUploadTask()) { _ in
AttachmentUploadCell(uploadTask: AttachmentUploadTask(), attachment: PreviewHelper.sampleAttachment) { _ in
/* Preview */
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ struct AttachmentsHeaderView: View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 8) {
ForEach(attachmentsManager.attachments) { attachment in
AttachmentUploadCell(attachment: attachment,
uploadTask: attachmentsManager
.attachmentUploadTaskOrFinishedTask(for: attachment
.uuid)) { attachmentRemoved in
AttachmentUploadCell(
uploadTask: attachmentsManager.attachmentUploadTaskOrFinishedTask(for: attachment.uuid),
attachment: attachment
) { attachmentRemoved in
attachmentsManager.removeAttachment(attachmentRemoved)
}
}
}
.padding(.vertical, 1)
.padding(.horizontal, 16)
}
.padding(.top, 16)
}
}
.customAlert(item: $attachmentsManager.globalError) { error in
Expand Down
23 changes: 1 addition & 22 deletions Mail/Views/Thread/AttachmentCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,7 @@ struct AttachmentCell: View {
let attachment: Attachment

var body: some View {
VStack(spacing: 0) {
HStack {
attachment.icon.swiftUIImage

VStack(alignment: .leading, spacing: 0) {
Text(attachment.name)
.textStyle(.bodySmall)
.lineLimit(1)
.truncationMode(.middle)
Text(attachment.size, format: .defaultByteCount)
.textStyle(.labelSecondary)
.opacity(attachment.size == 0 ? 0 : 1)
}
}
.padding(4)
}
.background(
RoundedRectangle(cornerRadius: 6)
.stroke(MailResourcesAsset.elementsColor.swiftUIColor, lineWidth: 1)
)
.cornerRadius(6)
.frame(maxWidth: 200)
AttachmentView(attachment: attachment, subtitle: attachment.size.formatted(.defaultByteCount))
}
}

Expand Down
41 changes: 26 additions & 15 deletions MailCore/Models/Attachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,35 @@ public class Attachment: /* Hashable, */ EmbeddedObject, Codable, Identifiable {

public var icon: MailResourcesImages {
guard let uti else { return MailResourcesAsset.unknownFile }
if uti.conforms(to: .audio) {
return MailResourcesAsset.audioFile
} else if uti.conforms(to: .archive) {
return MailResourcesAsset.zipFile

if uti.conforms(to: .pdf) {
return MailResourcesAsset.pdfFile
} else if uti.conforms(to: .calendarEvent) || uti.conforms(to: .ics) {
return MailResourcesAsset.icsFile
} else if uti.conforms(to: .vCard) {
return MailResourcesAsset.vcardFile
} else if uti.conforms(to: .image) {
return MailResourcesAsset.imageFileLandscape
} else if uti.conforms(to: .pdf) {
return MailResourcesAsset.officeFileAdobe
} else if uti.conforms(to: .plainText) {
return MailResourcesAsset.commonFileText
} else if uti.conforms(to: .presentation) {
return MailResourcesAsset.officeFileGraph
} else if uti.conforms(to: .spreadsheet) {
return MailResourcesAsset.officeFileSheet
return MailResourcesAsset.imageFile
} else if uti.conforms(to: .audio) {
return MailResourcesAsset.audioFile
} else if uti.conforms(to: .movie) {
return MailResourcesAsset.videoFilePlay
return MailResourcesAsset.videoFile
} else if uti.conforms(to: .spreadsheet) {
return MailResourcesAsset.gridFile
} else if uti.conforms(to: .presentation) {
return MailResourcesAsset.pointFile
} else if uti.conforms(to: .sourceCode) || uti.conforms(to: .html) || uti.conforms(to: .json) || uti.conforms(to: .xml) {
return MailResourcesAsset.codeFile
} else if uti.conforms(to: .text) || uti.conforms(to: .pages) || uti.conforms(to: .onlyOffice)
|| uti.conforms(to: .wordDoc) || uti.conforms(to: .wordDocm) || uti.conforms(to: .wordDocx) {
return MailResourcesAsset.docFile
} else if uti.conforms(to: .archive) {
return MailResourcesAsset.archiveFile
} else if uti.conforms(to: .font) {
return MailResourcesAsset.fontFile
} else {
return MailResourcesAsset.unknownFile
}
return MailResourcesAsset.unknownFile
}

private enum CodingKeys: String, CodingKey {
Expand Down
30 changes: 30 additions & 0 deletions MailCore/Utils/UTType+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2022 Infomaniak Network SA
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/

import Foundation
import UniformTypeIdentifiers

public extension UTType {
static let pages = UTType("com.apple.iwork.pages.sffpages")!
static let wordDoc = UTType("com.microsoft.word.doc")!
static let wordDocm = UTType(mimeType: "application/vnd.ms-word")!
static let wordDocx = UTType("org.openxmlformats.wordprocessingml.document")!
static let onlyOffice = UTType("org.oasis-open.opendocument.text")!

static let ics = UTType(mimeType: "application/ics")!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"images" : [
{
"filename" : "archive-file-light.svg",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "archive-file-dark.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
{
"images" : [
{
"filename" : "audio-file.svg",
"filename" : "audio-file-light.svg",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "audio-file-dark.svg",
"idiom" : "universal"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 118573e

Please sign in to comment.