From fa462344a289ba0cb2c411e56dd3372767133d63 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Thu, 2 Jan 2025 13:07:31 +0100 Subject: [PATCH] Show initial and color if no image is set (#2468) Due to WidgetKit, we have to use an Image to show the background color. The image seems to be the only View-element that can override the tint/accent-color # Conflicts: # DcWidget/DcWidget.swift --- DcWidget/DcWidget.swift | 10 +++++++--- DcWidget/WidgetProvider.swift | 9 ++++++--- deltachat-ios.xcodeproj/project.pbxproj | 2 ++ deltachat-ios/View/ContactCell.swift | 12 ++++++------ 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/DcWidget/DcWidget.swift b/DcWidget/DcWidget.swift index e9c9b0838..a12f31c39 100644 --- a/DcWidget/DcWidget.swift +++ b/DcWidget/DcWidget.swift @@ -47,11 +47,15 @@ struct ChatShortcutView: View { var body: some View { Link(destination: chat.url) { if let image = chat.image { - // Use Circle as mask Image(uiImage: image) .fullColor() - } else { - Color(.systemBackground) + } else if let colorImage = UIImage(color: chat.color) { + ZStack { + Image(uiImage: colorImage) + Text(chat.title.first?.uppercased() ?? "🫶") + .foregroundStyle(.white) + .font(.system(size: 34)) + } } } .frame(width: 56, height: 56) diff --git a/DcWidget/WidgetProvider.swift b/DcWidget/WidgetProvider.swift index a05e36790..e7dcf0dc5 100644 --- a/DcWidget/WidgetProvider.swift +++ b/DcWidget/WidgetProvider.swift @@ -18,10 +18,10 @@ struct Provider: TimelineProvider { .app(AppShortcut(accountId: 0, chatId: 0, messageId: 0, image: UIImage(named: "checklist"), title: "checklist")), .app(AppShortcut(accountId: 0, chatId: 1, messageId: 1, image: UIImage(named: "hello"), title: "hello")), .app(AppShortcut(accountId: 0, chatId: 2, messageId: 2, image: UIImage(named: "packabunchas"), title: "packabunchas")), - .chat(ChatShortcut(accountId: 0, chatId: 3, title: "Messages to self", image: UIImage(named: "saved-messages"))), + .chat(ChatShortcut(accountId: 0, chatId: 3, title: "Messages to self", image: UIImage(named: "saved-messages"), color: .green)), .app(AppShortcut(accountId: 0, chatId: 4, messageId: 4, image: UIImage(named: "pixel"), title: "pixel")), .app(AppShortcut(accountId: 0, chatId: 5, messageId: 5, image: UIImage(named: "webxdc"), title: "webxdc")), - .chat(ChatShortcut(accountId: 0, chatId: 6, title: "Broadcast", image: UIImage(named: "broadcast"))), + .chat(ChatShortcut(accountId: 0, chatId: 6, title: "Broadcast", image: UIImage(named: "broadcast"), color: .red)), ] return UsedWebxdcEntry(date: Date(), shortcuts: Array(shortcuts.prefix(limit))) @@ -74,12 +74,14 @@ struct Provider: TimelineProvider { let chat = dcContext.getChat(chatId: chatId) let title = chat.name let image = chat.profileImage + let color = chat.color return .chat(ChatShortcut( accountId: entry.accountId, chatId: chatId, title: title, - image: image + image: image, + color: color )) } } @@ -120,6 +122,7 @@ struct ChatShortcut: Identifiable, Hashable { let chatId: Int let title: String let image: UIImage? + let color: UIColor var url: URL { var urlComponents = URLComponents() diff --git a/deltachat-ios.xcodeproj/project.pbxproj b/deltachat-ios.xcodeproj/project.pbxproj index 2ce30a1a8..1eb7e0e2d 100644 --- a/deltachat-ios.xcodeproj/project.pbxproj +++ b/deltachat-ios.xcodeproj/project.pbxproj @@ -215,6 +215,7 @@ D8083AD02D14384F005DCB7D /* UserDefaults+Widgets.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8083ACF2D14384F005DCB7D /* UserDefaults+Widgets.swift */; }; D8083AD12D143868005DCB7D /* UserDefaults+Widgets.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8083ACF2D14384F005DCB7D /* UserDefaults+Widgets.swift */; }; D80F62792B59D1CC00877059 /* DefaultReactions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D80F62782B59D1CC00877059 /* DefaultReactions.swift */; }; + D82AD20F2D26B087009D6026 /* UIImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E45E4321D3F14A00D4B15E /* UIImage+Extension.swift */; }; D84738D22BBC1C2C00ECD52B /* LegacyMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84738D12BBC1C2C00ECD52B /* LegacyMenuItem.swift */; }; D84AED242B55E8EB00D753F6 /* ReactionsOverviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84AED232B55E8EB00D753F6 /* ReactionsOverviewViewController.swift */; }; D84AED272B566C0700D753F6 /* ReactionsOverviewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84AED262B566C0700D753F6 /* ReactionsOverviewTableViewCell.swift */; }; @@ -1829,6 +1830,7 @@ buildActionMask = 2147483647; files = ( D89C45732D0B0166005B1491 /* WidgetEntry.swift in Sources */, + D82AD20F2D26B087009D6026 /* UIImage+Extension.swift in Sources */, D8083AD12D143868005DCB7D /* UserDefaults+Widgets.swift in Sources */, D8C7B6982CF87F5E003A6AD1 /* DcMsg+Extension.swift in Sources */, ); diff --git a/deltachat-ios/View/ContactCell.swift b/deltachat-ios/View/ContactCell.swift index cd91f9de8..e2691132b 100644 --- a/deltachat-ios/View/ContactCell.swift +++ b/deltachat-ios/View/ContactCell.swift @@ -437,12 +437,12 @@ class ContactCell: UITableViewCell { } avatar.setRecentlySeen(false) setStatusIndicators(unreadCount: 0, - status: 0, - visibility: 0, - isLocationStreaming: false, - isContactRequest: false, - isArchiveLink: false, - isVerified: false) + status: 0, + visibility: 0, + isLocationStreaming: false, + isContactRequest: false, + isArchiveLink: false, + isVerified: false) } accessibilityLabel = (titleLabel.text != nil ? ((titleLabel.text ?? "")+"\n") : "")