Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show correct location streaming state #2598

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Unify buttons and icons (#2584)
- Hide unneeded buttons in contact profiles (#2589, #2590)
- Fix: Allow to share contacts that do not have a chat (#2583)
- Fix: update attach menu when location streaming is enabled/disabled (#2598)


## v1.52.2
Expand Down
89 changes: 43 additions & 46 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1157,24 +1157,27 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
messageInputBar.padding = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 12)
messageInputBar.shouldManageSendButtonEnabledState = false

let leftItems = [
InputBarButtonItem()
.configure {
$0.spacing = .fixed(0)
let clipperIcon = UIImage(named: "ic_attach_file_36pt")?.withRenderingMode(.alwaysTemplate)
$0.image = clipperIcon
$0.tintColor = DcColors.primary
$0.setSize(CGSize(width: 40, height: 40), animated: false)
$0.accessibilityLabel = String.localized("menu_add_attachment")
$0.accessibilityTraits = .button
$0.showsMenuAsPrimaryAction = true
$0.menu = clipperButtonMenu()
}.onSelected {
$0.tintColor = UIColor.themeColor(light: .lightGray, dark: .darkGray)
}.onDeselected {
$0.tintColor = DcColors.primary
}
]
let attachButton = InputBarButtonItem()
.configure {
$0.spacing = .fixed(0)
let clipperIcon = UIImage(named: "ic_attach_file_36pt")?.withRenderingMode(.alwaysTemplate)
$0.image = clipperIcon
$0.tintColor = DcColors.primary
$0.setSize(CGSize(width: 40, height: 40), animated: false)
$0.accessibilityLabel = String.localized("menu_add_attachment")
$0.accessibilityTraits = .button
}.onSelected {
$0.tintColor = UIColor.themeColor(light: .lightGray, dark: .darkGray)
}.onDeselected {
$0.tintColor = DcColors.primary
}
attachButton.showsMenuAsPrimaryAction = true
attachButton.menu = UIMenu() // otherwise .menuActionTriggered is not triggered
attachButton.addAction(UIAction { [weak self] _ in
attachButton.menu = self?.clipperButtonMenu()
}, for: .menuActionTriggered)

let leftItems = [attachButton]

messageInputBar.setStackViewItems(leftItems, forStack: .left, animated: false)

Expand Down Expand Up @@ -1202,37 +1205,31 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
}

private func clipperButtonMenu() -> UIMenu {
return UIMenu(children: [
UIDeferredMenuElement({ [weak self] completion in
guard let self else { return }
var actions = [UIMenuElement]()
func action(_ localized: String, _ systemImage: String, attributes: UIMenuElement.Attributes = [], _ handler: @escaping () -> Void) -> UIAction {
UIAction(title: String.localized(localized), image: UIImage(systemName: systemImage), attributes: attributes, handler: { _ in handler() })
}

var actions = [UIMenuElement]()
func action(_ localized: String, _ systemImage: String, attributes: UIMenuElement.Attributes = [], _ handler: @escaping () -> Void) -> UIAction {
UIAction(title: String.localized(localized), image: UIImage(systemName: systemImage), attributes: attributes, handler: { _ in handler() })
}
actions.append(UIMenu(options: [.displayInline], children: [
action("camera", "camera", showCameraViewController),
action("gallery", "photo.on.rectangle", showPhotoVideoLibrary)
]))

actions.append(UIMenu(options: [.displayInline], children: [
action("camera", "camera", showCameraViewController),
action("gallery", "photo.on.rectangle", showPhotoVideoLibrary)
]))

actions.append(action("files", "folder", self.showDocumentLibrary))
actions.append(action("webxdc_apps", "square.grid.2x2", showAppPicker))
actions.append(action("voice_message", "mic", showVoiceMessageRecorder))
if let config = dcContext.getConfig("webrtc_instance"), !config.isEmpty {
let videoChatImage = if #available(iOS 17, *) { "video.bubble" } else { "video" }
actions.append(action("videochat", videoChatImage, videoChatButtonPressed))
}
if UserDefaults.standard.bool(forKey: "location_streaming") {
let isLocationStreaming = dcContext.isSendingLocationsToChat(chatId: chatId)
actions.append(action(isLocationStreaming ? "stop_sharing_location" : "location", isLocationStreaming ? "location.slash" : "location",
attributes: isLocationStreaming ? .destructive : [], locationStreamingButtonPressed))
}
actions.append(action("contact", "person.crop.circle", showContactList))
actions.append(action("files", "folder", self.showDocumentLibrary))
actions.append(action("webxdc_apps", "square.grid.2x2", showAppPicker))
actions.append(action("voice_message", "mic", showVoiceMessageRecorder))
if let config = dcContext.getConfig("webrtc_instance"), !config.isEmpty {
let videoChatImage = if #available(iOS 17, *) { "video.bubble" } else { "video" }
actions.append(action("videochat", videoChatImage, videoChatButtonPressed))
}
if UserDefaults.standard.bool(forKey: "location_streaming") {
let isLocationStreaming = dcContext.isSendingLocationsToChat(chatId: chatId)
actions.append(action(isLocationStreaming ? "stop_sharing_location" : "location", isLocationStreaming ? "location.slash" : "location",
attributes: isLocationStreaming ? .destructive : [], locationStreamingButtonPressed))
}
actions.append(action("contact", "person.crop.circle", showContactList))

completion(actions)
})
])
return UIMenu(children: actions)
}

private func confirmationAlert(title: String, actionTitle: String, actionStyle: UIAlertAction.Style = .default, actionHandler: @escaping ((UIAlertAction) -> Void), cancelHandler: ((UIAlertAction) -> Void)? = nil) {
Expand Down
Loading