Skip to content

Commit

Permalink
Update action
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyu committed May 7, 2022
1 parent 71f534d commit c08b7d4
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 221 deletions.
17 changes: 4 additions & 13 deletions Mixin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@
7CF9503F277D8839000AECC7 /* MediasPreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CF9503E277D8839000AECC7 /* MediasPreviewViewController.swift */; };
7CF95041277D8904000AECC7 /* SelectedMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CF95040277D8904000AECC7 /* SelectedMediaCell.swift */; };
7CFF1387277D5C3400FA745D /* MediasPreviewWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CFF1386277D5C3400FA745D /* MediasPreviewWindow.swift */; };
7CFF1389277D5C6600FA745D /* MediaPreviewWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7CFF1388277D5C6600FA745D /* MediaPreviewWindow.xib */; };
7CFF1389277D5C6600FA745D /* MediasPreviewWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7CFF1388277D5C6600FA745D /* MediasPreviewWindow.xib */; };
811C8154F03C8CBB72DBA1F4 /* Pods_MixinShare.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A8E0E9B65F16ADB27E6F25 /* Pods_MixinShare.framework */; };
842347EE2695BA6400009A39 /* InitializeBotJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842347ED2695BA6400009A39 /* InitializeBotJob.swift */; };
94046B91272DC265007C1D4A /* GroupCallMembersDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94046B90272DC265007C1D4A /* GroupCallMembersDataSource.swift */; };
Expand Down Expand Up @@ -1619,7 +1619,7 @@
7CF9503E277D8839000AECC7 /* MediasPreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediasPreviewViewController.swift; sourceTree = "<group>"; };
7CF95040277D8904000AECC7 /* SelectedMediaCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedMediaCell.swift; sourceTree = "<group>"; };
7CFF1386277D5C3400FA745D /* MediasPreviewWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediasPreviewWindow.swift; sourceTree = "<group>"; };
7CFF1388277D5C6600FA745D /* MediaPreviewWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MediaPreviewWindow.xib; sourceTree = "<group>"; };
7CFF1388277D5C6600FA745D /* MediasPreviewWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MediasPreviewWindow.xib; sourceTree = "<group>"; };
842347ED2695BA6400009A39 /* InitializeBotJob.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitializeBotJob.swift; sourceTree = "<group>"; };
8C43D9D96FCB101481DFD90F /* Pods-Mixin.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mixin.release.xcconfig"; path = "Pods/Target Support Files/Pods-Mixin/Pods-Mixin.release.xcconfig"; sourceTree = "<group>"; };
94046B90272DC265007C1D4A /* GroupCallMembersDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupCallMembersDataSource.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2177,7 +2177,6 @@
94D63DD52646C29100FD7EE8 /* MessageViewModelFactory.swift */,
7CC7304F2745F95D002780F5 /* StickerStore.swift */,
7CF7416D27DAD93000DA0004 /* SnapCenterFlowLayout.swift */,
7C247AA6277AEDD100112A30 /* StackedPhotoLayout.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -2568,13 +2567,6 @@
path = ReCaptcha;
sourceTree = "<group>";
};
7C0E1D0B2786E9F400762FBE /* Model */ = {
isa = PBXGroup;
children = (
);
path = Model;
sourceTree = "<group>";
};
7C35D1CF2689C04F002B5BBC /* Cells */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2933,7 +2925,6 @@
DF016B2C2098B35F00B8FFDE /* Windows */ = {
isa = PBXGroup;
children = (
7C0E1D0B2786E9F400762FBE /* Model */,
DF53BB6D202362A9002BF028 /* Cells */,
DF53BB6620233647002BF028 /* Views */,
DF43304422648B32006D971D /* AssetInfoWindow.swift */,
Expand Down Expand Up @@ -2973,7 +2964,7 @@
7C6132B527953B15002777EE /* DeleteAccountAbortWindow.swift */,
7C6132B727953B4F002777EE /* DeleteAccountAbortWindow.xib */,
7CFF1386277D5C3400FA745D /* MediasPreviewWindow.swift */,
7CFF1388277D5C6600FA745D /* MediaPreviewWindow.xib */,
7CFF1388277D5C6600FA745D /* MediasPreviewWindow.xib */,
);
path = Windows;
sourceTree = "<group>";
Expand Down Expand Up @@ -3933,7 +3924,7 @@
DF44B0CE20C6897D00A099B6 /* EmptyView.xib in Resources */,
277FF70C1F909A1200DBB2EB /* Assets.xcassets in Resources */,
7BF19C20241D40FA00B192D5 /* LocationSearchView.xib in Resources */,
7CFF1389277D5C6600FA745D /* MediaPreviewWindow.xib in Resources */,
7CFF1389277D5C6600FA745D /* MediasPreviewWindow.xib in Resources */,
7B8BB590234F36C000991ACB /* Colors.xcassets in Resources */,
94B8D18A266E41D300F43CBB /* DatabaseDiagnosticView.xib in Resources */,
7BFCB7762419FC5B00E7BC43 /* LocationCell.xib in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PhotoInputGridCell: UICollectionViewCell {
overlayView.isHidden = true
}

func updateSelectedIndex(_ index: Int?) {
func updateBadge(with index: Int?) {
if let index = index {
badge.text = "\(index + 1)"
badge.borderWidth = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SelectedMediaCell: UICollectionViewCell {
@IBOutlet weak var imageView: SDAnimatedImageView!
@IBOutlet weak var mediaTypeView: MediaTypeOverlayView!

var onRemove: (() -> Void)?
var deselectAsset: (() -> Void)?

private lazy var imageRequestOptions: PHImageRequestOptions = {
let options = PHImageRequestOptions()
Expand Down Expand Up @@ -43,7 +43,7 @@ class SelectedMediaCell: UICollectionViewCell {
}

@IBAction func closeAction(_ sender: Any) {
onRemove?()
deselectAsset?()
}

}
103 changes: 47 additions & 56 deletions Mixin/UserInterface/Controllers/Chat/ConversationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ class ConversationViewController: UIViewController {
private(set) lazy var imagePickerController = ImagePickerController(initialCameraPosition: .rear, cropImageAfterPicked: false, parent: self, delegate: self)

private lazy var userHandleViewController = R.storyboard.chat.user_handle()!
private lazy var multipleSelectionActionView: MultipleSelectionActionView = {
let view = R.nib.multipleSelectionActionView(owner: self)!
view.delegate = self
view.showCancelButton = false
return view
}()
private lazy var multipleSelectionActionView = R.nib.multipleSelectionActionView(owner: self)!
private lazy var announcementBadgeContentView = R.nib.announcementBadgeContentView(owner: self)!

private lazy var strangerHintView: StrangerHintView = {
Expand Down Expand Up @@ -521,6 +516,51 @@ class ConversationViewController: UIViewController {
}
}

@IBAction func multipleSelectionAction(_ sender: Any) {
switch multipleSelectionActionView.intent {
case .forward:
let messages = dataSource.selectedViewModels.values
.map({ $0.message })
.sorted(by: { $0.createdAt < $1.createdAt })
let containsTranscriptMessage = messages.contains {
$0.category.hasSuffix("_TRANSCRIPT")
}
if messages.count == 1 || containsTranscriptMessage {
let vc = MessageReceiverViewController.instance(content: .messages(messages))
navigationController?.pushViewController(vc, animated: true)
} else {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: R.string.localizable.chat_forward_one_by_one(), style: .default, handler: { (_) in
let vc = MessageReceiverViewController.instance(content: .messages(messages))
self.navigationController?.pushViewController(vc, animated: true)
}))
alert.addAction(UIAlertAction(title: R.string.localizable.chat_forward_combined(), style: .default, handler: { (_) in
let vc = MessageReceiverViewController.instance(content: .transcript(messages))
self.navigationController?.pushViewController(vc, animated: true)
}))
alert.addAction(UIAlertAction(title: R.string.localizable.dialog_button_cancel(), style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
case .delete:
let viewModels = dataSource.selectedViewModels.values.map({ $0 })
let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
if !viewModels.contains(where: { $0.message.userId != myUserId || !$0.message.canRecall }) {
controller.addAction(UIAlertAction(title: Localized.ACTION_DELETE_EVERYONE, style: .destructive, handler: { (_) in
if AppGroupUserDefaults.User.hasShownRecallTips {
self.deleteForEveryone(viewModels: viewModels)
} else {
self.showRecallTips(viewModels: viewModels)
}
}))
}
controller.addAction(UIAlertAction(title: Localized.ACTION_DELETE_ME, style: .destructive, handler: { (_) in
self.deleteForMe(viewModels: viewModels)
}))
controller.addAction(UIAlertAction(title: Localized.DIALOG_BUTTON_CANCEL, style: .cancel, handler: nil))
self.present(controller, animated: true, completion: nil)
}
}

@IBAction func dismissAnnouncementBadgeAction(_ sender: Any) {
if dataSource.category == .group {
AppGroupUserDefaults.User.hasUnreadAnnouncement.removeValue(forKey: conversationId)
Expand Down Expand Up @@ -1299,55 +1339,6 @@ class ConversationViewController: UIViewController {

}

extension ConversationViewController: MultipleSelectionActionViewDelegate {

func multipleSelectionActionViewDidTapAction(_ view: MultipleSelectionActionView) {
switch view.intent {
case .forward:
let messages = dataSource.selectedViewModels.values
.map({ $0.message })
.sorted(by: { $0.createdAt < $1.createdAt })
let containsTranscriptMessage = messages.contains {
$0.category.hasSuffix("_TRANSCRIPT")
}
if messages.count == 1 || containsTranscriptMessage {
let vc = MessageReceiverViewController.instance(content: .messages(messages))
navigationController?.pushViewController(vc, animated: true)
} else {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: R.string.localizable.chat_forward_one_by_one(), style: .default, handler: { (_) in
let vc = MessageReceiverViewController.instance(content: .messages(messages))
self.navigationController?.pushViewController(vc, animated: true)
}))
alert.addAction(UIAlertAction(title: R.string.localizable.chat_forward_combined(), style: .default, handler: { (_) in
let vc = MessageReceiverViewController.instance(content: .transcript(messages))
self.navigationController?.pushViewController(vc, animated: true)
}))
alert.addAction(UIAlertAction(title: R.string.localizable.dialog_button_cancel(), style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
case .delete:
let viewModels = dataSource.selectedViewModels.values.map({ $0 })
let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
if !viewModels.contains(where: { $0.message.userId != myUserId || !$0.message.canRecall }) {
controller.addAction(UIAlertAction(title: Localized.ACTION_DELETE_EVERYONE, style: .destructive, handler: { (_) in
if AppGroupUserDefaults.User.hasShownRecallTips {
self.deleteForEveryone(viewModels: viewModels)
} else {
self.showRecallTips(viewModels: viewModels)
}
}))
}
controller.addAction(UIAlertAction(title: Localized.ACTION_DELETE_ME, style: .destructive, handler: { (_) in
self.deleteForMe(viewModels: self.dataSource.selectedViewModels.values.map({ $0 }))
}))
controller.addAction(UIAlertAction(title: Localized.DIALOG_BUTTON_CANCEL, style: .cancel, handler: nil))
self.present(controller, animated: true, completion: nil)
}
}

}

// MARK: - UIGestureRecognizerDelegate
extension ConversationViewController: UIGestureRecognizerDelegate {

Expand Down Expand Up @@ -1965,7 +1956,7 @@ extension ConversationViewController {
SendMessageService.shared.sendPinMessages(items: [message], conversationId: conversationId, action: .pin)
case .unpin:
dataSource.postponeMessagePinningUpdate(with: message.messageId)
SendMessageService.shared.sendPinMessages(items: [message], conversationId: conversationId, action: .pin)
SendMessageService.shared.sendPinMessages(items: [message], conversationId: conversationId, action: .unpin)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ final class MediasPreviewViewController: UIViewController {
extension MediasPreviewViewController {

func add(_ asset: PHAsset) {
guard !assets.contains(asset) else {
return
}
assets.append(asset)
collectionView.insertItems(at: [IndexPath(item: assets.count - 1, section: 0)])
collectionView.scrollToItem(at: IndexPath(item: assets.count - 1, section: 0),
at: .centeredHorizontally,
animated: true)
let index = IndexPath(item: assets.count - 1, section: 0)
collectionView.insertItems(at: [index])
collectionView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)
}

func remove(_ asset: PHAsset) {
Expand Down Expand Up @@ -78,7 +80,7 @@ extension MediasPreviewViewController: UICollectionViewDataSource {
if indexPath.item < assets.count {
let asset = assets[indexPath.item]
cell.load(asset: asset, size: cellSizeForItemAt(indexPath.item))
cell.onRemove = { [weak self] in
cell.deselectAsset = { [weak self] in
guard let self = self else {
return
}
Expand Down Expand Up @@ -117,13 +119,13 @@ extension MediasPreviewViewController {
let width: CGFloat
let ratio = CGFloat(asset.pixelWidth) / CGFloat(asset.pixelHeight)
if ratio > 1 {
width = height / 3 * 4
width = ceil(height / 3 * 4)
} else if ratio < 1 {
width = height / 4 * 3
width = ceil(height / 4 * 3)
} else {
width = height
}
let size = CGSize(width: ceil(width), height: ceil(height))
let size = CGSize(width: width, height: height)
cellSizeCache[asset.localIdentifier] = size
return size
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class ConversationDataSource {
private var messageProcessingIsCancelled = false
private var didInitializedData = false
private var pendingPinningUpdateMessageId: String?
private var stackedPhotoMessages = [MessageItem]()

var layoutSize: CGSize {
Queue.main.autoSync {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ extension PhotoInputGridViewController: UICollectionViewDataSource {
cell.imageView.contentMode = .scaleAspectFill
cell.imageView.backgroundColor = .background
cell.badge.isHidden = false
cell.updateSelectedIndex(selectedAssets.firstIndex(of: asset))
cell.updateBadge(with: selectedAssets.firstIndex(of: asset))
imageManager.requestImage(for: asset, targetSize: thumbnailSize, contentMode: .aspectFill, options: imageRequestOptions) { [weak cell] (image, _) in
guard let cell = cell, cell.identifier == asset.localIdentifier else {
return
Expand Down
Loading

0 comments on commit c08b7d4

Please sign in to comment.