-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor improvements
- Loading branch information
Showing
29 changed files
with
436 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// ContactList.swift | ||
// Monal | ||
// | ||
// Created by Jan on 15.12.22. | ||
// Copyright © 2022 monal-im.org. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import monalxmpp | ||
|
||
struct ContactEntry: View { | ||
let contact : MLContact | ||
|
||
var body:some View { | ||
ZStack(alignment: .topLeading) { | ||
HStack(alignment: .center) { | ||
Image(uiImage: contact.avatar) | ||
.resizable() | ||
.frame(width: 40, height: 40, alignment: .center) | ||
VStack(alignment: .leading) { | ||
Text(contact.contactDisplayName as String) | ||
Text(contact.contactJid as String).font(.footnote).opacity(0.6) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct ContactList: View { | ||
@State var contacts : [MLContact] | ||
@State var selectedContact : MLContact? | ||
@State var searchFieldInput = "" | ||
|
||
func matchesSearch(contact : MLContact) -> Bool { | ||
// TODO better lookup | ||
if searchFieldInput.isEmpty == true { | ||
return true | ||
} else { | ||
return contact.contactDisplayName.lowercased().contains(searchFieldInput.lowercased()) || | ||
contact.contactJid.contains(searchFieldInput.lowercased()) | ||
} | ||
} | ||
|
||
var body: some View { | ||
if(contacts.isEmpty) { | ||
Text("No contacts to show :(") | ||
.navigationTitle("Contact Lists") | ||
} else { | ||
List { | ||
Section { | ||
TextField("Search contacts", text: $searchFieldInput) | ||
} | ||
ForEach(contacts, id: \.self) { contact in | ||
if matchesSearch(contact: contact) { | ||
ContactEntry(contact: contact) | ||
} | ||
} | ||
.onDelete { | ||
print(contacts.remove(atOffsets: $0)) | ||
} | ||
.onInsert(of: [""], perform: { _,_ in | ||
}) | ||
} | ||
.listStyle(.inset) | ||
.navigationBarTitle("Contact List", displayMode: .inline) | ||
.toolbar { | ||
EditButton() | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct ContactList_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContactList(contacts: [ | ||
MLContact.makeDummyContact(0), | ||
MLContact.makeDummyContact(1), | ||
MLContact.makeDummyContact(2), | ||
MLContact.makeDummyContact(3)] | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// | ||
// AddContactMenu.swift | ||
// Monal | ||
// | ||
// Created by Jan on 27.10.22. | ||
// Copyright © 2022 monal-im.org. All rights reserved. | ||
// | ||
|
||
import MobileCoreServices | ||
import UniformTypeIdentifiers | ||
import SwiftUI | ||
import monalxmpp | ||
|
||
struct CreateGroupMenu: View { | ||
var delegate: SheetDismisserProtocol | ||
|
||
@State private var connectedAccounts: [xmpp] | ||
@State private var selectedAccount: Int | ||
@State private var groupName: String = "" | ||
|
||
@State private var showAlert = false | ||
// note: dismissLabel is not accessed but defined at the .alert() section | ||
@State private var alertPrompt = AlertPrompt(dismissLabel: Text("Close")) | ||
|
||
@ObservedObject private var overlay = LoadingOverlayState() | ||
|
||
@State private var showQRCodeScanner = false | ||
@State private var success = false | ||
|
||
private let dismissWithNewGroup: (MLContact) -> () | ||
|
||
init(delegate: SheetDismisserProtocol, dismissWithNewGroup: @escaping (MLContact) -> (), prefillJid: String = "", preauthToken:String? = nil) { | ||
// FIXME | ||
self.delegate = delegate | ||
self.dismissWithNewGroup = dismissWithNewGroup | ||
self.groupName = prefillJid | ||
// self.preauthToken = preauthToken | ||
|
||
let connectedAccounts = MLXMPPManager.sharedInstance().connectedXMPP as! [xmpp] | ||
self.connectedAccounts = connectedAccounts | ||
self.selectedAccount = connectedAccounts.first != nil ? 0 : -1; | ||
} | ||
|
||
// FIXME duplicate code from WelcomeLogIn.swift, maybe move to SwiftuiHelpers | ||
|
||
private func errorAlert(title: Text, message: Text = Text("")) { | ||
alertPrompt.title = title | ||
alertPrompt.message = message | ||
showAlert = true | ||
} | ||
|
||
private func successAlert(title: Text, message: Text) { | ||
alertPrompt.title = title | ||
alertPrompt.message = message | ||
self.success = true // < dismiss entire view on close | ||
showAlert = true | ||
} | ||
|
||
private var buttonColor: Color { | ||
return Color(UIColor.systemBlue) | ||
} | ||
|
||
var body: some View { | ||
Form { | ||
if(connectedAccounts.isEmpty) { | ||
Text("Please make sure at least one account has connected before trying to create new group.") | ||
.foregroundColor(.secondary) | ||
} | ||
else | ||
{ | ||
Section() { | ||
if(connectedAccounts.count > 1) { | ||
Picker("Use account", selection: $selectedAccount) { | ||
ForEach(Array(self.connectedAccounts.enumerated()), id: \.element) { idx, account in | ||
Text(account.connectionProperties.identity.jid).tag(idx) | ||
} | ||
} | ||
.pickerStyle(.menu) | ||
} | ||
TextField("Group Name (optional)", text: $groupName) | ||
.autocorrectionDisabled() | ||
.autocapitalization(.none) | ||
.addClearButton(text:$groupName) | ||
|
||
NavigationLink(destination: LazyClosureView(ContactList(contacts: DataLayer.sharedInstance().contactList() as! [MLContact])), label: { | ||
Text("Group Members") | ||
}) | ||
} | ||
Section { | ||
Button(action: {}, label: { | ||
Text("Create new group") | ||
}) | ||
} | ||
} | ||
} | ||
.alert(isPresented: $showAlert) { | ||
Alert(title: alertPrompt.title, message: alertPrompt.message, dismissButton:.default(Text("Close"), action: { | ||
showAlert = false | ||
if self.success == true { | ||
// TODO dismissWithNewGroup | ||
} | ||
})) | ||
} | ||
.addLoadingOverlay(overlay) | ||
.navigationBarTitle("Create new group", displayMode: .inline) | ||
.navigationViewStyle(.stack) | ||
} | ||
} | ||
|
||
struct CreateGroupMenu_Previews: PreviewProvider { | ||
static var delegate = SheetDismisserProtocol() | ||
static var previews: some View { | ||
CreateGroupMenu(delegate: delegate, dismissWithNewGroup: { c in | ||
}) | ||
} | ||
} |
Oops, something went wrong.