Merge branch 'mkirk/fix-delete-share' into release/2.32.0

pull/1/head
Michael Kirk 7 years ago
commit a94ce98553

@ -9,19 +9,32 @@ public enum GalleryDirection {
} }
class MediaGalleryAlbum { class MediaGalleryAlbum {
private(set) var items: [MediaGalleryItem]
private var originalItems: [MediaGalleryItem]
var items: [MediaGalleryItem] {
get {
guard let mediaGalleryDataSource = self.mediaGalleryDataSource else {
owsFailDebug("mediaGalleryDataSource was unexpectedly nil")
return originalItems
}
return originalItems.filter { !mediaGalleryDataSource.deletedGalleryItems.contains($0) }
}
}
weak var mediaGalleryDataSource: MediaGalleryDataSource?
init(items: [MediaGalleryItem]) { init(items: [MediaGalleryItem]) {
self.items = items self.originalItems = items
} }
func add(item: MediaGalleryItem) { func add(item: MediaGalleryItem) {
guard !items.contains(item) else { guard !originalItems.contains(item) else {
return return
} }
items.append(item) originalItems.append(item)
items.sort { (lhs, rhs) -> Bool in originalItems.sort { (lhs, rhs) -> Bool in
return lhs.albumIndex < rhs.albumIndex return lhs.albumIndex < rhs.albumIndex
} }
} }
@ -205,6 +218,9 @@ protocol MediaGalleryDataSource: class {
var sections: [GalleryDate: [MediaGalleryItem]] { get } var sections: [GalleryDate: [MediaGalleryItem]] { get }
var sectionDates: [GalleryDate] { get } var sectionDates: [GalleryDate] { get }
var deletedAttachments: Set<TSAttachment> { get }
var deletedGalleryItems: Set<MediaGalleryItem> { get }
func ensureGalleryItemsLoaded(_ direction: GalleryDirection, item: MediaGalleryItem, amount: UInt, completion: ((IndexSet, [IndexPath]) -> Void)?) func ensureGalleryItemsLoaded(_ direction: GalleryDirection, item: MediaGalleryItem, amount: UInt, completion: ((IndexSet, [IndexPath]) -> Void)?)
func galleryItem(before currentItem: MediaGalleryItem) -> MediaGalleryItem? func galleryItem(before currentItem: MediaGalleryItem) -> MediaGalleryItem?
@ -301,6 +317,9 @@ class MediaGallery: NSObject, MediaGalleryDataSource, MediaTileViewControllerDel
@objc @objc
weak public var navigationController: MediaGalleryNavigationController! weak public var navigationController: MediaGalleryNavigationController!
var deletedAttachments: Set<TSAttachment> = Set()
var deletedGalleryItems: Set<MediaGalleryItem> = Set()
private var pageViewController: MediaPageViewController? private var pageViewController: MediaPageViewController?
private let uiDatabaseConnection: YapDatabaseConnection private let uiDatabaseConnection: YapDatabaseConnection
@ -732,7 +751,7 @@ class MediaGallery: NSObject, MediaGalleryDataSource, MediaTileViewControllerDel
guard let existingAlbum = galleryAlbums[albumMessageId] else { guard let existingAlbum = galleryAlbums[albumMessageId] else {
let newAlbum = MediaGalleryAlbum(items: [item]) let newAlbum = MediaGalleryAlbum(items: [item])
galleryAlbums[albumMessageId] = newAlbum galleryAlbums[albumMessageId] = newAlbum
newAlbum.mediaGalleryDataSource = self
return newAlbum return newAlbum
} }
@ -889,9 +908,6 @@ class MediaGallery: NSObject, MediaGalleryDataSource, MediaTileViewControllerDel
dataSourceDelegates.append(Weak(value: dataSourceDelegate)) dataSourceDelegates.append(Weak(value: dataSourceDelegate))
} }
var deletedAttachments: Set<TSAttachment> = Set()
var deletedGalleryItems: Set<MediaGalleryItem> = Set()
func delete(items: [MediaGalleryItem], initiatedBy: MediaGalleryDataSourceDelegate) { func delete(items: [MediaGalleryItem], initiatedBy: MediaGalleryDataSourceDelegate) {
AssertIsOnMainThread() AssertIsOnMainThread()

@ -269,13 +269,13 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
// MARK: Bar Buttons // MARK: Bar Buttons
let shareBarButton: UIBarButtonItem = { lazy var shareBarButton: UIBarButtonItem = {
let shareBarButton = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(didPressShare)) let shareBarButton = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(didPressShare))
shareBarButton.tintColor = Theme.darkThemePrimaryColor shareBarButton.tintColor = Theme.darkThemePrimaryColor
return shareBarButton return shareBarButton
}() }()
let deleteBarButton: UIBarButtonItem = { lazy var deleteBarButton: UIBarButtonItem = {
let deleteBarButton = UIBarButtonItem(barButtonSystemItem: .trash, let deleteBarButton = UIBarButtonItem(barButtonSystemItem: .trash,
target: self, target: self,
action: #selector(didPressDelete)) action: #selector(didPressDelete))

Loading…
Cancel
Save