From c27a935a3fd3b374ba59f0984ff3642eda29dd93 Mon Sep 17 00:00:00 2001 From: fmodf Date: Thu, 19 Sep 2024 18:50:48 +0200 Subject: [PATCH] wip --- .../Resources/Strings/Localizable.strings | 5 ++ .../View/Main/ChatList/ChatsListScreen.swift | 2 +- .../View/Main/Contacts/ContactsScreen.swift | 3 +- .../Attachments/ContactsPickerView.swift | 3 +- .../Conversation/ConversationScreen.swift | 4 +- .../ConversationSettingsScreen.swift | 49 +++++++++++++++++++ .../View/SharedComponents/SharedListRow.swift | 25 ++++++++++ 7 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 ConversationsClassic/View/Main/Conversation/ConversationSettingsScreen.swift diff --git a/ConversationsClassic/Resources/Strings/Localizable.strings b/ConversationsClassic/Resources/Strings/Localizable.strings index 5f97a53..a88a61a 100644 --- a/ConversationsClassic/Resources/Strings/Localizable.strings +++ b/ConversationsClassic/Resources/Strings/Localizable.strings @@ -61,6 +61,11 @@ "Attachment.Send.contact" = "Send contact"; "Attachment.Downloading.retry" = "Retry"; +// MARK: Conversation settings title +"Conversation.settings.title.chat" = "Chat settings"; +"Conversation.settings.title.group" = "Group settings"; +"Conversation.settings.title.channel" = "Channel settings"; +"Conversation.settings.enableOmemo" = "Enable OMEMO"; diff --git a/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift b/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift index cfae0c1..f0427f8 100644 --- a/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift +++ b/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift @@ -49,7 +49,7 @@ private struct ChatsRow: View { var chat: Chat var body: some View { - SharedListRow(iconType: .charCircle(chat.participant), text: chat.participant) + SharedListRow(iconType: .charCircle(chat.participant), text: chat.participant, controlType: .none) .onTapGesture { Task { router.showModal { diff --git a/ConversationsClassic/View/Main/Contacts/ContactsScreen.swift b/ConversationsClassic/View/Main/Contacts/ContactsScreen.swift index be31e01..c5a3f97 100644 --- a/ConversationsClassic/View/Main/Contacts/ContactsScreen.swift +++ b/ConversationsClassic/View/Main/Contacts/ContactsScreen.swift @@ -53,7 +53,8 @@ private struct ContactsScreenRow: View { var body: some View { SharedListRow( iconType: .charCircle(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter), - text: roster.contactBareJid + text: roster.contactBareJid, + controlType: .none ) .onTapGesture { startChat() diff --git a/ConversationsClassic/View/Main/Conversation/Attachments/ContactsPickerView.swift b/ConversationsClassic/View/Main/Conversation/Attachments/ContactsPickerView.swift index ddb0fa6..3fc0a5f 100644 --- a/ConversationsClassic/View/Main/Conversation/Attachments/ContactsPickerView.swift +++ b/ConversationsClassic/View/Main/Conversation/Attachments/ContactsPickerView.swift @@ -60,7 +60,8 @@ private struct ContactRow: View { var body: some View { SharedListRow( iconType: .charCircle(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter), - text: roster.contactBareJid + text: roster.contactBareJid, + controlType: .none ) .onTapGesture { selectedContact = roster diff --git a/ConversationsClassic/View/Main/Conversation/ConversationScreen.swift b/ConversationsClassic/View/Main/Conversation/ConversationScreen.swift index b74a2cd..aa0e7d8 100644 --- a/ConversationsClassic/View/Main/Conversation/ConversationScreen.swift +++ b/ConversationsClassic/View/Main/Conversation/ConversationScreen.swift @@ -28,7 +28,9 @@ struct ConversationScreen: View { } ), centerText: .init(text: centerText(), action: { - print("Center text tapped") + router.showScreen(.fullScreenCover) { _ in + ConversationSettingsScreen() + } }) ) diff --git a/ConversationsClassic/View/Main/Conversation/ConversationSettingsScreen.swift b/ConversationsClassic/View/Main/Conversation/ConversationSettingsScreen.swift new file mode 100644 index 0000000..bee3304 --- /dev/null +++ b/ConversationsClassic/View/Main/Conversation/ConversationSettingsScreen.swift @@ -0,0 +1,49 @@ +import Combine +import Foundation +import Martin +import SwiftUI + +struct ConversationSettingsScreen: View { + @Environment(\.router) var router + @EnvironmentObject var messagesStore: MessagesStore + + @State private var omemoEnabled = true + + var body: some View { + ZStack { + // Background color + Color.Material.Background.light + .ignoresSafeArea() + + // Content + VStack(spacing: 0) { + // Header + SharedNavigationBar( + leftButton: .init( + image: Image(systemName: "chevron.left"), + action: { + router.dismissScreen() + } + ), + centerText: .init(text: centerText()) + ) + + // Settings list + ScrollView { + LazyVStack(spacing: 0) { + SharedListRow( + iconType: .none, + text: L10n.Conversation.Settings.enableOmemo, + controlType: .switcher(isOn: $omemoEnabled) + ) + } + } + } + } + } + + private func centerText() -> String { + // TODO: make center text depend on conversation type in future (chat, group chat, channel, etc.) + L10n.Conversation.Settings.Title.chat + } +} diff --git a/ConversationsClassic/View/SharedComponents/SharedListRow.swift b/ConversationsClassic/View/SharedComponents/SharedListRow.swift index 7e5fa74..a453172 100644 --- a/ConversationsClassic/View/SharedComponents/SharedListRow.swift +++ b/ConversationsClassic/View/SharedComponents/SharedListRow.swift @@ -3,11 +3,18 @@ import SwiftUI enum SharedListRowIconType { case charCircle(String) case image(Image, Color) + case none +} + +enum SharedListRowControlType { + case none + case switcher(isOn: Binding) } struct SharedListRow: View { let iconType: SharedListRowIconType let text: String + let controlType: SharedListRowControlType var body: some View { VStack(spacing: 0) { @@ -36,6 +43,11 @@ struct SharedListRow: View { .foregroundColor(color) } } + + case .none: + Rectangle() + .fill(Color.clear) + .frame(width: 0.1, height: 44) } // Text @@ -43,6 +55,19 @@ struct SharedListRow: View { .foregroundColor(Color.Material.Text.main) .font(.body2) Spacer() + + // If control is needed + switch controlType { + case .none: + Rectangle() + .fill(Color.clear) + .frame(width: 0.1, height: 44) + + case .switcher(let isOn): + Toggle("", isOn: isOn) + .toggleStyle(SwitchToggleStyle(tint: .Material.Elements.active)) + .frame(width: 49, height: 31) + } } .padding(.horizontal, 16) .padding(.vertical, 4)