show text details, dismiss before action to avoid problems when action presents

pull/1/head
Michael Kirk 7 years ago
parent 5c2a5b00aa
commit 6079ae2439

@ -1988,6 +1988,15 @@ typedef enum : NSUInteger {
[self updateShouldObserveDBModifications]; [self updateShouldObserveDBModifications];
} }
- (void)messageActionsShowDetailsForItem:(ConversationViewItem *)conversationViewItem
{
[self showDetailViewForViewItem:conversationViewItem];
}
- (void)messageActionsReplyToItem:(ConversationViewItem *)conversationViewItem
{
}
#pragma mark - ConversationViewCellDelegate #pragma mark - ConversationViewCellDelegate
- (void)conversationCell:(ConversationViewCell *)cell didLongpressMediaViewItem:(ConversationViewItem *)viewItem - (void)conversationCell:(ConversationViewCell *)cell didLongpressMediaViewItem:(ConversationViewItem *)viewItem
@ -2447,7 +2456,7 @@ typedef enum : NSUInteger {
return @(groupIndex); return @(groupIndex);
} }
- (void)showMetadataViewForViewItem:(ConversationViewItem *)conversationItem - (void)showDetailViewForViewItem:(ConversationViewItem *)conversationItem
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
OWSAssert(conversationItem); OWSAssert(conversationItem);
@ -5066,7 +5075,7 @@ typedef enum : NSUInteger {
OWSAssert(self.navigationController.delegate == nil); OWSAssert(self.navigationController.delegate == nil);
self.navigationController.delegate = self; self.navigationController.delegate = self;
[self showMetadataViewForViewItem:conversationItem]; [self showDetailViewForViewItem:conversationItem];
} else { } else {
OWSFail(@"%@ Can't show message metadata for message of type: %@", self.logTag, [interaction class]); OWSFail(@"%@ Can't show message metadata for message of type: %@", self.logTag, [interaction class]);
} }

@ -111,6 +111,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
#pragma mark - UIMenuController #pragma mark - UIMenuController
@property (nonatomic, readonly) BOOL hasBodyTextActionContent;
- (NSArray<UIMenuItem *> *)textMenuControllerItems; - (NSArray<UIMenuItem *> *)textMenuControllerItems;
- (NSArray<UIMenuItem *> *)mediaMenuControllerItems; - (NSArray<UIMenuItem *> *)mediaMenuControllerItems;
- (NSArray<UIMenuItem *> *)defaultMenuControllerItems; - (NSArray<UIMenuItem *> *)defaultMenuControllerItems;

@ -7,8 +7,8 @@ import Foundation
@objc @objc
protocol MessageActionsDelegate: class { protocol MessageActionsDelegate: class {
func messageActionsDidHide(_ messageActionsViewController: MessageActionsViewController) func messageActionsDidHide(_ messageActionsViewController: MessageActionsViewController)
func messageActions(_ messageActionsViewController: MessageActionsViewController, showInfoForItem conversationViewItem: ConversationViewItem) func messageActionsShowDetailsForItem(_ conversationViewItem: ConversationViewItem)
func messageActions(_ messageActionsViewController: MessageActionsViewController, replyToItem conversationViewItem: ConversationViewItem) func messageActionsReplyToItem(_ conversationViewItem: ConversationViewItem)
} }
struct MessageActionBuilder { struct MessageActionBuilder {
@ -16,7 +16,8 @@ struct MessageActionBuilder {
return MessageAction(image: #imageLiteral(resourceName: "table_ic_verify"), return MessageAction(image: #imageLiteral(resourceName: "table_ic_verify"),
title: NSLocalizedString("MESSAGE_ACTION_REPLY", comment: "Action sheet button title"), title: NSLocalizedString("MESSAGE_ACTION_REPLY", comment: "Action sheet button title"),
subtitle: nil, subtitle: nil,
block: { (_) in block: { [weak delegate] (_) in
delegate?.messageActionsReplyToItem(conversationViewItem)
}) })
} }
@ -29,6 +30,15 @@ struct MessageActionBuilder {
conversationViewItem.copyTextAction() conversationViewItem.copyTextAction()
}) })
} }
static func showDetails(conversationViewItem: ConversationViewItem, delegate: MessageActionsDelegate) -> MessageAction {
return MessageAction(image: #imageLiteral(resourceName: "system_message_security"),
title: NSLocalizedString("MESSAGE_ACTION_DETAILS", comment: "Action sheet button title"),
subtitle: nil,
block: { [weak delegate] (_) in
delegate?.messageActionsShowDetailsForItem(conversationViewItem)
})
}
} }
extension ConversationViewItem { extension ConversationViewItem {
@ -42,22 +52,22 @@ extension ConversationViewItem {
}) })
} }
var infoAction: MessageAction {
return MessageAction(image: #imageLiteral(resourceName: "system_message_security"),
title: NSLocalizedString("MESSAGE_ACTION_TITLE_INFO", comment: "Action sheet button title"),
subtitle: nil,
block: { (action) in
Logger.debug("\(self.logTag) in \(#function) action: \(action)")
})
}
@objc @objc
func textActions(delegate: MessageActionsDelegate) -> [MessageAction] { func textActions(delegate: MessageActionsDelegate) -> [MessageAction] {
var actions: [MessageAction] = [] var actions: [MessageAction] = []
if self.hasBodyText {
actions.append(MessageActionBuilder.copyText(conversationViewItem: self, delegate: delegate)) // [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_MESSAGE_METADATA_ACTION",
// @"Short name for edit menu item to show message metadata.")
// action:self.metadataActionSelector],
if self.hasBodyTextActionContent {
let copyTextAction = MessageActionBuilder.copyText(conversationViewItem: self, delegate: delegate)
actions.append(copyTextAction)
} }
let showInfoAction = MessageActionBuilder.showDetails(conversationViewItem: self, delegate: delegate)
actions.append(showInfoAction)
return actions return actions
// switch self.messageCellType() { // switch self.messageCellType() {
// case .unknown: // case .unknown:
@ -172,10 +182,10 @@ class MessageActionsViewController: UIViewController, MessageActionSheetDelegate
@objc @objc
func didTapBackground() { func didTapBackground() {
animateDismiss() animateDismiss(action: nil)
} }
func animateDismiss() { func animateDismiss(action: MessageAction?) {
self.actionSheetView.superview?.layoutIfNeeded() self.actionSheetView.superview?.layoutIfNeeded()
if let actionSheetViewVerticalConstraint = self.actionSheetViewVerticalConstraint { if let actionSheetViewVerticalConstraint = self.actionSheetViewVerticalConstraint {
@ -184,8 +194,9 @@ class MessageActionsViewController: UIViewController, MessageActionSheetDelegate
owsFail("\(self.logTag) in \(#function) actionSheetVerticalConstraint was unexpectedly nil") owsFail("\(self.logTag) in \(#function) actionSheetVerticalConstraint was unexpectedly nil")
} }
let dismissDuration: TimeInterval = 0.2
self.actionSheetViewVerticalConstraint = self.actionSheetView.autoPinEdge(.top, to: .bottom, of: self.view) self.actionSheetViewVerticalConstraint = self.actionSheetView.autoPinEdge(.top, to: .bottom, of: self.view)
UIView.animate(withDuration: 0.2, UIView.animate(withDuration: dismissDuration,
delay: 0, delay: 0,
options: .curveEaseOut, options: .curveEaseOut,
animations: { animations: {
@ -193,14 +204,18 @@ class MessageActionsViewController: UIViewController, MessageActionSheetDelegate
self.actionSheetView.superview?.layoutIfNeeded() self.actionSheetView.superview?.layoutIfNeeded()
}, },
completion: { _ in completion: { _ in
self.view.isHidden = true
self.delegate?.messageActionsDidHide(self) self.delegate?.messageActionsDidHide(self)
if let action = action {
action.block(action)
}
}) })
} }
// MARK: MessageActionSheetDelegate // MARK: MessageActionSheetDelegate
func actionSheet(_ actionSheet: MessageActionSheetView, didCompleteAction action: MessageAction) { func actionSheet(_ actionSheet: MessageActionSheetView, didSelectAction action: MessageAction) {
animateDismiss() animateDismiss(action: action)
} }
} }
@ -222,11 +237,11 @@ public class MessageAction: NSObject {
} }
protocol MessageActionSheetDelegate: class { protocol MessageActionSheetDelegate: class {
func actionSheet(_ actionSheet: MessageActionSheetView, didCompleteAction action: MessageAction) func actionSheet(_ actionSheet: MessageActionSheetView, didSelectAction action: MessageAction)
} }
protocol MessageActionViewDelegate: class { protocol MessageActionViewDelegate: class {
func actionView(_ actionView: MessageActionView, didCompleteAction action: MessageAction) func actionView(_ actionView: MessageActionView, didSelectAction action: MessageAction)
} }
class MessageActionView: UIView { class MessageActionView: UIView {
@ -282,8 +297,7 @@ class MessageActionView: UIView {
@objc @objc
func didPress(event: Any) { func didPress(event: Any) {
Logger.debug("\(logTag) in \(#function)") Logger.debug("\(logTag) in \(#function)")
self.action.block(action) self.delegate?.actionView(self, didSelectAction: action)
self.delegate?.actionView(self, didCompleteAction: action)
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
@ -337,8 +351,8 @@ class MessageActionSheetView: UIView, MessageActionViewDelegate {
// MARK: MessageActionViewDelegate // MARK: MessageActionViewDelegate
func actionView(_ actionView: MessageActionView, didCompleteAction action: MessageAction) { func actionView(_ actionView: MessageActionView, didSelectAction action: MessageAction) {
self.delegate?.actionSheet(self, didCompleteAction: action) self.delegate?.actionSheet(self, didSelectAction: action)
} }
// MARK: // MARK:

@ -1174,7 +1174,7 @@
"MESSAGE_ACTION_REPLY" = "Reply to this message"; "MESSAGE_ACTION_REPLY" = "Reply to this message";
/* Action sheet button title */ /* Action sheet button title */
"MESSAGE_ACTION_TITLE_INFO" = "More info"; "MESSAGE_ACTION_DETAILS" = "More info";
/* Title for the 'message approval' dialog. */ /* Title for the 'message approval' dialog. */
"MESSAGE_APPROVAL_DIALOG_TITLE" = "Message"; "MESSAGE_APPROVAL_DIALOG_TITLE" = "Message";

Loading…
Cancel
Save