mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Use navigation bar for image editor buttons.
This commit is contained in:
parent
87646b1798
commit
a630974e76
4 changed files with 129 additions and 0 deletions
|
@ -1269,6 +1269,34 @@ typedef enum : NSUInteger {
|
|||
self.actionOnOpen = ConversationViewActionNone;
|
||||
|
||||
[self updateInputToolbarLayout];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
ConversationMediaAlbumItem *_Nullable firstMediaAlbumItem;
|
||||
for (id<ConversationViewItem> item in self.viewItems) {
|
||||
if (item.mediaAlbumItems.count < 1) {
|
||||
continue;
|
||||
}
|
||||
ConversationMediaAlbumItem *mediaAlbumItem = item.mediaAlbumItems[0];
|
||||
if (mediaAlbumItem.attachmentStream && mediaAlbumItem.attachmentStream.isImage) {
|
||||
firstMediaAlbumItem = mediaAlbumItem;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!firstMediaAlbumItem) {
|
||||
return;
|
||||
}
|
||||
DataSource *_Nullable dataSource =
|
||||
[DataSourcePath dataSourceWithURL:firstMediaAlbumItem.attachmentStream.originalMediaURL
|
||||
shouldDeleteOnDeallocation:NO];
|
||||
if (!dataSource) {
|
||||
OWSFailDebug(@"attachment data was unexpectedly empty for picked document");
|
||||
return;
|
||||
}
|
||||
NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:firstMediaAlbumItem.attachmentStream.contentType];
|
||||
SignalAttachment *attachment =
|
||||
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal];
|
||||
[self showApprovalDialogForAttachment:attachment];
|
||||
});
|
||||
}
|
||||
|
||||
// `viewWillDisappear` is called whenever the view *starts* to disappear,
|
||||
|
|
|
@ -672,6 +672,12 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
|
|||
[self.searchResultsController viewDidAppear:animated];
|
||||
|
||||
self.hasEverAppeared = YES;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
TSThread *thread =
|
||||
[self threadForIndexPath:[NSIndexPath indexPathForRow:0 inSection:HomeViewControllerSectionConversations]];
|
||||
[self presentThread:thread action:ConversationViewActionNone animated:YES];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated
|
||||
|
|
|
@ -239,12 +239,16 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
|
|||
return
|
||||
}
|
||||
navigationBar.overrideTheme(type: .clear)
|
||||
|
||||
updateNavigationBar()
|
||||
}
|
||||
|
||||
override public func viewDidAppear(_ animated: Bool) {
|
||||
Logger.debug("")
|
||||
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
updateNavigationBar()
|
||||
}
|
||||
|
||||
override public func viewWillDisappear(_ animated: Bool) {
|
||||
|
@ -265,6 +269,20 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
|
|||
return true
|
||||
}
|
||||
|
||||
// MARK: - Navigation Bar
|
||||
|
||||
public func updateNavigationBar() {
|
||||
var navigationBarItems = [UIBarButtonItem]()
|
||||
|
||||
if let viewControllers = viewControllers,
|
||||
viewControllers.count == 1,
|
||||
let firstViewController = viewControllers.first as? AttachmentPrepViewController {
|
||||
navigationBarItems = firstViewController.navigationBarItems()
|
||||
}
|
||||
|
||||
self.navigationItem.rightBarButtonItems = navigationBarItems
|
||||
}
|
||||
|
||||
// MARK: - View Helpers
|
||||
|
||||
func remove(attachmentItem: SignalAttachmentItem) {
|
||||
|
@ -340,6 +358,8 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
|
|||
updateMediaRail()
|
||||
}
|
||||
}
|
||||
|
||||
updateNavigationBar()
|
||||
}
|
||||
|
||||
// MARK: - UIPageViewControllerDataSource
|
||||
|
@ -582,6 +602,10 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
|
|||
func prepViewController(_ prepViewController: AttachmentPrepViewController, didUpdateCaptionForAttachmentItem attachmentItem: SignalAttachmentItem) {
|
||||
self.approvalDelegate?.attachmentApproval?(self, changedCaptionOfAttachment: attachmentItem.attachment)
|
||||
}
|
||||
|
||||
func prepViewControllerUpdateNavigationBar() {
|
||||
self.updateNavigationBar()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: GalleryRail
|
||||
|
@ -633,6 +657,8 @@ enum KeyboardScenario {
|
|||
|
||||
protocol AttachmentPrepViewControllerDelegate: class {
|
||||
func prepViewController(_ prepViewController: AttachmentPrepViewController, didUpdateCaptionForAttachmentItem attachmentItem: SignalAttachmentItem)
|
||||
|
||||
func prepViewControllerUpdateNavigationBar()
|
||||
}
|
||||
|
||||
public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarDelegate, OWSVideoPlayerDelegate {
|
||||
|
@ -657,6 +683,7 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
|
|||
private(set) var scrollView: UIScrollView!
|
||||
private(set) var contentContainer: UIView!
|
||||
private(set) var playVideoButton: UIView?
|
||||
private var imageEditorView: ImageEditorView?
|
||||
|
||||
// MARK: - Initializers
|
||||
|
||||
|
@ -731,6 +758,8 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
|
|||
|
||||
let imageEditorView = ImageEditorView(model: imageEditorModel, delegate: self)
|
||||
if imageEditorView.configureSubviews() {
|
||||
self.imageEditorView = imageEditorView
|
||||
|
||||
mediaMessageView.isHidden = true
|
||||
|
||||
// TODO: Is this necessary?
|
||||
|
@ -813,6 +842,22 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
|
|||
touchInterceptorView.isHidden = true
|
||||
}
|
||||
|
||||
override public func viewWillAppear(_ animated: Bool) {
|
||||
Logger.debug("")
|
||||
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
prepDelegate?.prepViewControllerUpdateNavigationBar()
|
||||
}
|
||||
|
||||
override public func viewDidAppear(_ animated: Bool) {
|
||||
Logger.debug("")
|
||||
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
prepDelegate?.prepViewControllerUpdateNavigationBar()
|
||||
}
|
||||
|
||||
override public func viewWillLayoutSubviews() {
|
||||
Logger.debug("")
|
||||
super.viewWillLayoutSubviews()
|
||||
|
@ -823,6 +868,15 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
|
|||
ensureAttachmentViewScale(animated: false)
|
||||
}
|
||||
|
||||
// MARK: - Navigation Bar
|
||||
|
||||
public func navigationBarItems() -> [UIBarButtonItem] {
|
||||
guard let imageEditorView = imageEditorView else {
|
||||
return []
|
||||
}
|
||||
return imageEditorView.navigationBarItems()
|
||||
}
|
||||
|
||||
// MARK: - Event Handlers
|
||||
|
||||
@objc
|
||||
|
@ -1087,6 +1141,10 @@ extension AttachmentPrepViewController: ImageEditorViewDelegate {
|
|||
let view = AttachmentCaptionViewController(delegate: self, attachmentItem: attachmentItem)
|
||||
self.imageEditor(presentFullScreenOverlay: view, withNavigation: true)
|
||||
}
|
||||
|
||||
public func imageEditorUpdateNavigationBar() {
|
||||
prepDelegate?.prepViewControllerUpdateNavigationBar()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
|
|
@ -9,6 +9,7 @@ public protocol ImageEditorViewDelegate: class {
|
|||
func imageEditor(presentFullScreenOverlay viewController: UIViewController,
|
||||
withNavigation: Bool)
|
||||
func imageEditorPresentCaptionView()
|
||||
func imageEditorUpdateNavigationBar()
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
@ -182,6 +183,8 @@ public class ImageEditorView: UIView {
|
|||
paletteView.autoPinLeadingToSuperviewMargin(withInset: 10)
|
||||
|
||||
updateButtons()
|
||||
|
||||
delegate?.imageEditorUpdateNavigationBar()
|
||||
}
|
||||
|
||||
private func configure(button: UIButton,
|
||||
|
@ -235,6 +238,36 @@ public class ImageEditorView: UIView {
|
|||
paletteView.isHidden = !hasPalette
|
||||
}
|
||||
|
||||
// MARK: - Navigation Bar
|
||||
|
||||
private func navigationBarButton(imageName: String,
|
||||
selector: Selector) -> UIBarButtonItem {
|
||||
let button = UIBarButtonItem(image: UIImage(named: imageName), style: .plain, target: self, action: selector)
|
||||
button.tintColor = .white
|
||||
return button
|
||||
}
|
||||
|
||||
public func navigationBarItems() -> [UIBarButtonItem] {
|
||||
let undoButton = navigationBarButton(imageName: "image_editor_undo",
|
||||
selector: #selector(didTapUndo(sender:)))
|
||||
let brushButton = navigationBarButton(imageName: "image_editor_brush",
|
||||
selector: #selector(didTapBrush(sender:)))
|
||||
let cropButton = navigationBarButton(imageName: "image_editor_crop",
|
||||
selector: #selector(didTapCrop(sender:)))
|
||||
let newTextButton = navigationBarButton(imageName: "image_editor_checkmark_full",
|
||||
selector: #selector(didTapNewText(sender:)))
|
||||
// let doneButton = navigationBarButton(imageName:"image_editor_brush",
|
||||
// selector: #selector(didTapDone(sender:)))
|
||||
let captionButton = navigationBarButton(imageName: "image_editor_caption",
|
||||
selector: #selector(didTapCaption(sender:)))
|
||||
|
||||
if model.canUndo() {
|
||||
return [undoButton, newTextButton, brushButton, cropButton, captionButton].reversed()
|
||||
} else {
|
||||
return [newTextButton, brushButton, cropButton, captionButton].reversed()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@objc func didTapUndo(sender: UIButton) {
|
||||
|
@ -654,10 +687,14 @@ extension ImageEditorView: ImageEditorModelObserver {
|
|||
public func imageEditorModelDidChange(before: ImageEditorContents,
|
||||
after: ImageEditorContents) {
|
||||
updateButtons()
|
||||
|
||||
delegate?.imageEditorUpdateNavigationBar()
|
||||
}
|
||||
|
||||
public func imageEditorModelDidChange(changedItemIds: [String]) {
|
||||
updateButtons()
|
||||
|
||||
delegate?.imageEditorUpdateNavigationBar()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue