From 6a167f6c2c5c2b307f9ef88de3aaa3380239295c Mon Sep 17 00:00:00 2001 From: fmodf Date: Wed, 7 Aug 2024 21:07:39 +0200 Subject: [PATCH] wip --- .../Helpers/String+Extensions.swift | 47 +++++++++ .../Screens/Chats/ChatsCreateMainScreen.swift | 96 +++++++++---------- .../View/Screens/Chats/ChatsListScreen.swift | 28 +----- .../Screens/Contacts/ContactsScreen.swift | 50 +++++----- .../ConversationMessageContainer.swift | 8 +- .../Conversation/ConversationMessageRow.swift | 5 +- .../Sharing/SharingContactsPickerView.swift | 33 +------ .../View/SharedComponents/SharedListRow.swift | 64 ++++++++++--- 8 files changed, 192 insertions(+), 139 deletions(-) diff --git a/ConversationsClassic/Helpers/String+Extensions.swift b/ConversationsClassic/Helpers/String+Extensions.swift index 23eaf66..1bbdc25 100644 --- a/ConversationsClassic/Helpers/String+Extensions.swift +++ b/ConversationsClassic/Helpers/String+Extensions.swift @@ -1,5 +1,6 @@ import CoreLocation import Foundation +import SwiftUI extension String { var firstLetter: String { @@ -57,3 +58,49 @@ extension String { } } } + +extension String { + var firstLetterColor: Color { + let firstLetter = self.firstLetter + switch firstLetter { + case "A", "M", "Y": + return Color.Rainbow.tortoiseLight500 + + case "B", "N", "Z": + return Color.Rainbow.orangeLight500 + + case "C", "O": + return Color.Rainbow.yellowLight500 + + case "D", "P": + return Color.Rainbow.greenLight500 + + case "E", "Q": + return Color.Rainbow.blueLight500 + + case "F", "R": + return Color.Rainbow.magentaLight500 + + case "G", "S": + return Color.Rainbow.tortoiseDark500 + + case "H", "T": + return Color.Rainbow.orangeDark500 + + case "I", "U": + return Color.Rainbow.yellowDark500 + + case "J", "V": + return Color.Rainbow.greenDark500 + + case "K", "W": + return Color.Rainbow.blueDark500 + + case "L", "X": + return Color.Rainbow.magentaDark500 + + default: + return Color.Rainbow.tortoiseLight500 + } + } +} diff --git a/ConversationsClassic/View/Screens/Chats/ChatsCreateMainScreen.swift b/ConversationsClassic/View/Screens/Chats/ChatsCreateMainScreen.swift index d70b51b..c25b8f8 100644 --- a/ConversationsClassic/View/Screens/Chats/ChatsCreateMainScreen.swift +++ b/ConversationsClassic/View/Screens/Chats/ChatsCreateMainScreen.swift @@ -24,22 +24,22 @@ struct ChatsCreateMainScreen: View { // List List { - ChatsCreateRowButton( - title: L10n.Chats.Create.Main.createGroup, - image: "person.2.fill", - action: {} - ) - ChatsCreateRowButton( - title: L10n.Chats.Create.Main.createPrivateGroup, - image: "person.2.fill", - action: {} - ) - ChatsCreateRowButton( - title: L10n.Chats.Create.Main.findGroup, - image: "magnifyingglass", - action: {} - ) - + // ChatsCreateRowButton( + // title: L10n.Chats.Create.Main.createGroup, + // image: "person.2.fill", + // action: {} + // ) + // ChatsCreateRowButton( + // title: L10n.Chats.Create.Main.createPrivateGroup, + // image: "person.2.fill", + // action: {} + // ) + // ChatsCreateRowButton( + // title: L10n.Chats.Create.Main.findGroup, + // image: "magnifyingglass", + // action: {} + // ) + // for contacts list let rosters = store.state.rostersState.rosters.filter { !$0.locallyDeleted } if rosters.isEmpty { @@ -54,37 +54,37 @@ struct ChatsCreateMainScreen: View { } } -private struct ChatsCreateRowButton: View { - var title: String - var image: String - var action: () -> Void - - var body: some View { - VStack(alignment: .center, spacing: 0) { - Spacer() - HStack(alignment: .center, spacing: 16) { - Image(systemName: image) - .font(.head2) - .foregroundColor(.Material.Elements.active) - .padding(.leading, 16) - Text(title) - .font(.body1) - .foregroundColor(.Material.Text.main) - Spacer() - } - Spacer() - Rectangle() - .frame(maxWidth: .infinity) - .frame(height: 1) - .foregroundColor(.Material.Background.dark) - } - .sharedListRow() - .frame(height: 48) - .onTapGesture { - action() - } - } -} +// private struct ChatsCreateRowButton: View { +// var title: String +// var image: String +// var action: () -> Void +// +// var body: some View { +// VStack(alignment: .center, spacing: 0) { +// Spacer() +// HStack(alignment: .center, spacing: 16) { +// Image(systemName: image) +// .font(.head2) +// .foregroundColor(.Material.Elements.active) +// .padding(.leading, 16) +// Text(title) +// .font(.body1) +// .foregroundColor(.Material.Text.main) +// Spacer() +// } +// Spacer() +// Rectangle() +// .frame(maxWidth: .infinity) +// .frame(height: 1) +// .foregroundColor(.Material.Background.dark) +// } +// .sharedListRow() +// .frame(height: 48) +// .onTapGesture { +// action() +// } +// } +// } private struct ChatsCreateRowSeparator: View { var body: some View { @@ -175,7 +175,7 @@ private struct ChatsCreateRowSeparator: View { state.rostersState.rosters = [ .init(contactBareJid: "test@me.com", subscription: "both", ask: true, data: .init(groups: [], annotations: [])) ] - + return state } } diff --git a/ConversationsClassic/View/Screens/Chats/ChatsListScreen.swift b/ConversationsClassic/View/Screens/Chats/ChatsListScreen.swift index 9a8f079..572c23c 100644 --- a/ConversationsClassic/View/Screens/Chats/ChatsListScreen.swift +++ b/ConversationsClassic/View/Screens/Chats/ChatsListScreen.swift @@ -53,31 +53,9 @@ private struct ChatsRow: View { var chat: Chat var body: some View { - VStack(spacing: 0) { - HStack(spacing: 8) { - ZStack { - Circle() - .frame(width: 44, height: 44) - .foregroundColor(.red) - Text(chat.participant.firstLetter) - .foregroundColor(.white) - .font(.body1) - } - Text(chat.participant) - .foregroundColor(Color.Material.Text.main) - .font(.body2) - Spacer() + SharedListRow(iconType: .charCircle(chat.participant), text: chat.participant) + .onTapGesture { + store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant))) } - .padding(.horizontal, 16) - .padding(.vertical, 4) - Rectangle() - .frame(maxWidth: .infinity) - .frame(height: 1) - .foregroundColor(.Material.Background.dark) - } - .sharedListRow() - .onTapGesture { - store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant))) - } } } diff --git a/ConversationsClassic/View/Screens/Contacts/ContactsScreen.swift b/ConversationsClassic/View/Screens/Contacts/ContactsScreen.swift index 3de89a3..d47c736 100644 --- a/ConversationsClassic/View/Screens/Contacts/ContactsScreen.swift +++ b/ConversationsClassic/View/Screens/Contacts/ContactsScreen.swift @@ -76,29 +76,33 @@ private struct ContactsScreenRow: View { @Binding var isShowingLoader: Bool var body: some View { - VStack(spacing: 0) { - HStack(spacing: 8) { - ZStack { - Circle() - .frame(width: 44, height: 44) - .foregroundColor(.red) - Text(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter) - .foregroundColor(.white) - .font(.body1) - } - Text(roster.contactBareJid) - .foregroundColor(Color.Material.Text.main) - .font(.body2) - Spacer() - } - .padding(.horizontal, 16) - .padding(.vertical, 4) - Rectangle() - .frame(maxWidth: .infinity) - .frame(height: 1) - .foregroundColor(.Material.Background.dark) - } - .sharedListRow() + SharedListRow( + iconType: .charCircle(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter), + text: roster.contactBareJid + ) + // VStack(spacing: 0) { + // HStack(spacing: 8) { + // ZStack { + // Circle() + // .frame(width: 44, height: 44) + // .foregroundColor(.red) + // Text(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter) + // .foregroundColor(.white) + // .font(.body1) + // } + // Text(roster.contactBareJid) + // .foregroundColor(Color.Material.Text.main) + // .font(.body2) + // Spacer() + // } + // .padding(.horizontal, 16) + // .padding(.vertical, 4) + // Rectangle() + // .frame(maxWidth: .infinity) + // .frame(height: 1) + // .foregroundColor(.Material.Background.dark) + // } + // .sharedListRow() .onTapGesture { store.dispatch(.chatsAction(.startChat(accountJid: roster.bareJid, participantJid: roster.contactBareJid))) } diff --git a/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift b/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift index bbff7de..36cae1f 100644 --- a/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift +++ b/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift @@ -77,8 +77,8 @@ private struct ContactView: View { ZStack { Circle() .frame(width: 44, height: 44) - .foregroundColor(.red) - Text(message.body?.getContactJid.firstLetter ?? "?") + .foregroundColor(contactName.firstLetterColor) + Text(contactName.firstLetter) .foregroundColor(.white) .font(.body1) } @@ -92,6 +92,10 @@ private struct ContactView: View { // TODO: Jump to add roster from here } } + + private var contactName: String { + message.body?.getContactJid ?? "?" + } } private struct AttachmentView: View { diff --git a/ConversationsClassic/View/Screens/Conversation/ConversationMessageRow.swift b/ConversationsClassic/View/Screens/Conversation/ConversationMessageRow.swift index 3db46bd..b3fa2df 100644 --- a/ConversationsClassic/View/Screens/Conversation/ConversationMessageRow.swift +++ b/ConversationsClassic/View/Screens/Conversation/ConversationMessageRow.swift @@ -57,7 +57,10 @@ struct ConversationMessageRow: View { } ) } - .sharedListRow() + .listRowInsets(.zero) + .listRowSeparator(.hidden) + .frame(maxWidth: .infinity, maxHeight: .infinity) + .background(Color.Material.Background.light) } private func isOutgoing() -> Bool { diff --git a/ConversationsClassic/View/Screens/Sharing/SharingContactsPickerView.swift b/ConversationsClassic/View/Screens/Sharing/SharingContactsPickerView.swift index 0817297..8c7588e 100644 --- a/ConversationsClassic/View/Screens/Sharing/SharingContactsPickerView.swift +++ b/ConversationsClassic/View/Screens/Sharing/SharingContactsPickerView.swift @@ -53,35 +53,10 @@ private struct ContactRow: View { @Binding var selectedContact: Roster? var body: some View { - VStack(spacing: 0) { - HStack(spacing: 8) { - ZStack { - Circle() - .frame(width: 44, height: 44) - .foregroundColor(.red) - Text(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter) - .foregroundColor(.white) - .font(.body1) - } - Text(roster.contactBareJid) - .foregroundColor(Color.Material.Text.main) - .font(.body2) - Spacer() - if selectedContact == roster { - Image(systemName: "checkmark") - .foregroundColor(.Material.Text.main) - .font(.body1) - .padding(.trailing, 8) - } - } - .padding(.horizontal, 16) - .padding(.vertical, 4) - Rectangle() - .frame(maxWidth: .infinity) - .frame(height: 1) - .foregroundColor(.Material.Background.dark) - } - .sharedListRow() + SharedListRow( + iconType: .charCircle(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter), + text: roster.contactBareJid + ) .onTapGesture { selectedContact = roster } diff --git a/ConversationsClassic/View/SharedComponents/SharedListRow.swift b/ConversationsClassic/View/SharedComponents/SharedListRow.swift index 4ca11cf..7e5fa74 100644 --- a/ConversationsClassic/View/SharedComponents/SharedListRow.swift +++ b/ConversationsClassic/View/SharedComponents/SharedListRow.swift @@ -1,17 +1,59 @@ import SwiftUI -extension View { - func sharedListRow() -> some View { - modifier(SharedListRow()) - } +enum SharedListRowIconType { + case charCircle(String) + case image(Image, Color) } -struct SharedListRow: ViewModifier { - public func body(content: Content) -> some View { - content - .listRowInsets(.zero) - .listRowSeparator(.hidden) - .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(Color.Material.Background.light) +struct SharedListRow: View { + let iconType: SharedListRowIconType + let text: String + + var body: some View { + VStack(spacing: 0) { + HStack(spacing: 8) { + // Icon + switch iconType { + case .charCircle(let str): + let char = str.firstLetter + let color = str.firstLetterColor + ZStack { + Circle() + .frame(width: 44, height: 44) + .foregroundColor(color) + Text(char) + .foregroundColor(.white) + .font(.body1) + } + + case .image(let image, let color): + ZStack { + Circle() + .frame(width: 44, height: 44) + .foregroundColor(.clearTappable) + .overlay { + image + .foregroundColor(color) + } + } + } + + // Text + Text(text) + .foregroundColor(Color.Material.Text.main) + .font(.body2) + Spacer() + } + .padding(.horizontal, 16) + .padding(.vertical, 4) + Rectangle() + .frame(maxWidth: .infinity) + .frame(height: 1) + .foregroundColor(.Material.Background.dark) + } + .listRowInsets(.zero) + .listRowSeparator(.hidden) + .frame(maxWidth: .infinity, maxHeight: .infinity) + .background(Color.Material.Background.light) } }