Merge branch 'mkirk/hide-all-media-from-settings-gallery'

This commit is contained in:
Michael Kirk 2018-03-20 11:14:48 -04:00
commit 999b0f0f9c
8 changed files with 41 additions and 28 deletions

View file

@ -2033,8 +2033,10 @@ typedef enum : NSUInteger {
}
TSMessage *mediaMessage = (TSMessage *)viewItem.interaction;
MediaGalleryViewController *vc = [[MediaGalleryViewController alloc] initWithThread:self.thread
uiDatabaseConnection:self.uiDatabaseConnection];
MediaGalleryViewController *vc = [[MediaGalleryViewController alloc]
initWithThread:self.thread
uiDatabaseConnection:self.uiDatabaseConnection
options:MediaGalleryOptionSliderEnabled | MediaGalleryOptionShowAllMediaButton];
[vc presentDetailViewFromViewController:self mediaMessage:mediaMessage replacingView:imageView];
}
@ -2055,8 +2057,10 @@ typedef enum : NSUInteger {
}
TSMessage *mediaMessage = (TSMessage *)viewItem.interaction;
MediaGalleryViewController *vc = [[MediaGalleryViewController alloc] initWithThread:self.thread
uiDatabaseConnection:self.uiDatabaseConnection];
MediaGalleryViewController *vc = [[MediaGalleryViewController alloc]
initWithThread:self.thread
uiDatabaseConnection:self.uiDatabaseConnection
options:MediaGalleryOptionSliderEnabled | MediaGalleryOptionShowAllMediaButton];
[vc presentDetailViewFromViewController:self mediaMessage:mediaMessage replacingView:imageView];
}

View file

@ -10,6 +10,11 @@ NS_ASSUME_NONNULL_BEGIN
@class GalleryItemBox;
@class MediaDetailViewController;
typedef NS_OPTIONS(NSInteger, MediaGalleryOption) {
MediaGalleryOptionSliderEnabled = 1 << 0,
MediaGalleryOptionShowAllMediaButton = 1 << 1
};
@protocol MediaDetailViewControllerDelegate <NSObject>
- (void)dismissSelfAnimated:(BOOL)isAnimated completion:(void (^_Nullable)(void))completionBlock;

View file

@ -178,7 +178,7 @@ class MediaGalleryViewController: UINavigationController, MediaGalleryDataSource
private var initialDetailItem: MediaGalleryItem?
private let thread: TSThread
private let includeGallery: Bool
private let options: MediaGalleryOption
// we start with a small range size for quick loading.
private let fetchRangeSize: UInt = 10
@ -187,15 +187,11 @@ class MediaGalleryViewController: UINavigationController, MediaGalleryDataSource
Logger.debug("\(logTag) deinit")
}
convenience init(thread: TSThread, uiDatabaseConnection: YapDatabaseConnection) {
self.init(thread: thread, uiDatabaseConnection: uiDatabaseConnection, includeGallery: true)
}
init(thread: TSThread, uiDatabaseConnection: YapDatabaseConnection, includeGallery: Bool) {
init(thread: TSThread, uiDatabaseConnection: YapDatabaseConnection, options: MediaGalleryOption = []) {
self.thread = thread
assert(uiDatabaseConnection.isInLongLivedReadTransaction())
self.uiDatabaseConnection = uiDatabaseConnection
self.includeGallery = includeGallery
self.options = options
self.mediaGalleryFinder = OWSMediaGalleryFinder(thread: thread)
super.init(nibName: nil, bundle: nil)
@ -264,7 +260,7 @@ class MediaGalleryViewController: UINavigationController, MediaGalleryDataSource
ensureGalleryItemsLoaded(.around, item: initialDetailItem, amount: 10)
self.initialDetailItem = initialDetailItem
let pageViewController = MediaPageViewController(initialItem: initialDetailItem, mediaGalleryDataSource: self, uiDatabaseConnection: self.uiDatabaseConnection, includeGallery: self.includeGallery)
let pageViewController = MediaPageViewController(initialItem: initialDetailItem, mediaGalleryDataSource: self, uiDatabaseConnection: self.uiDatabaseConnection, options: self.options)
self.pageViewController = pageViewController
self.setViewControllers([pageViewController], animated: false)

View file

@ -58,16 +58,14 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
private let uiDatabaseConnection: YapDatabaseConnection
private let includeGallery: Bool
private let showAllMediaButton: Bool
private let sliderEnabled: Bool
convenience init(initialItem: MediaGalleryItem, mediaGalleryDataSource: MediaGalleryDataSource, uiDatabaseConnection: YapDatabaseConnection) {
self.init(initialItem: initialItem, mediaGalleryDataSource: mediaGalleryDataSource, uiDatabaseConnection: uiDatabaseConnection, includeGallery: true)
}
init(initialItem: MediaGalleryItem, mediaGalleryDataSource: MediaGalleryDataSource, uiDatabaseConnection: YapDatabaseConnection, includeGallery: Bool) {
init(initialItem: MediaGalleryItem, mediaGalleryDataSource: MediaGalleryDataSource, uiDatabaseConnection: YapDatabaseConnection, options: MediaGalleryOption) {
assert(uiDatabaseConnection.isInLongLivedReadTransaction())
self.uiDatabaseConnection = uiDatabaseConnection
self.includeGallery = includeGallery
self.showAllMediaButton = options.contains(.showAllMediaButton)
self.sliderEnabled = options.contains(.sliderEnabled)
self.mediaGalleryDataSource = mediaGalleryDataSource
let kSpacingBetweenItems: CGFloat = 20
@ -106,9 +104,12 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
// Navigation
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(didPressDismissButton))
// Note: using a custom leftBarButtonItem breaks the interactive pop gesture, but we don't want to be able
// to swipe to go back in the pager view anyway, instead swiping back should show the next page.
let backButton = OWSViewController.createOWSBackButton(withTarget: self, selector: #selector(didPressDismissButton))
self.navigationItem.leftBarButtonItem = backButton
if includeGallery {
if showAllMediaButton {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: MediaStrings.allMedia, style: .plain, target: self, action: #selector(didPressAllMediaButton))
}
@ -129,9 +130,7 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
// Hack to avoid "page" bouncing when not in gallery view.
// e.g. when getting to media details via message details screen, there's only
// one "Page" so the bounce doesn't make sense.
if !self.includeGallery {
pagerScrollView.isScrollEnabled = false
}
pagerScrollView.isScrollEnabled = sliderEnabled
// FIXME dynamic title with sender/date
self.title = "Attachment"

View file

@ -762,7 +762,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
return
}
let mediaGalleryViewController = MediaGalleryViewController(thread: self.thread, uiDatabaseConnection: self.uiDatabaseConnection, includeGallery: false)
let mediaGalleryViewController = MediaGalleryViewController(thread: self.thread, uiDatabaseConnection: self.uiDatabaseConnection)
mediaGalleryViewController.presentDetailView(fromViewController: self, mediaMessage: self.message, replacingView: fromView)
}
}

View file

@ -1166,7 +1166,9 @@ NS_ASSUME_NONNULL_BEGIN
DDLogDebug(@"%@ in showMediaGallery", self.logTag);
MediaGalleryViewController *vc =
[[MediaGalleryViewController alloc] initWithThread:self.thread uiDatabaseConnection:self.uiDatabaseConnection];
[[MediaGalleryViewController alloc] initWithThread:self.thread
uiDatabaseConnection:self.uiDatabaseConnection
options:MediaGalleryOptionSliderEnabled];
// although we don't present the mediaGalleryViewController directly, we need to maintain a strong
// reference to it until we're dismissed.

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <UIKit/UIKit.h>
@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (UIBarButtonItem *)createOWSBackButton;
+ (UIBarButtonItem *)createOWSBackButtonWithTarget:(id)target selector:(SEL)selector;
@end
NS_ASSUME_NONNULL_END

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "UIView+OWS.h"
@ -42,6 +42,11 @@ NS_ASSUME_NONNULL_BEGIN
}
- (UIBarButtonItem *)createOWSBackButtonWithTarget:(id)target selector:(SEL)selector
{
return [[self class] createOWSBackButtonWithTarget:target selector:selector];
}
+ (UIBarButtonItem *)createOWSBackButtonWithTarget:(id)target selector:(SEL)selector
{
OWSAssert(target);
OWSAssert(selector);