More button alert

This commit is contained in:
Chris Li 2017-01-24 14:06:24 -05:00
parent 975a94845a
commit 73736061f8
4 changed files with 24 additions and 2 deletions

View File

@ -152,8 +152,13 @@ class LibraryBooksController: CoreDataCollectionBaseController, UICollectionView
func didTapMoreButton(cell: LibraryCollectionCell) {
guard let indexPath = collectionView.indexPath(for: cell) else {return}
let book = fetchedResultController.object(at: indexPath)
let procedure = AlertProcedure.bookMore(context: self, book: book)
procedure.alert.modalPresentationStyle = .popover
procedure.alert.popoverPresentationController?.sourceView = cell.moreButton
procedure.alert.popoverPresentationController?.sourceRect = cell.moreButton.bounds
UIQueue.shared.add(operation: procedure)
}
// MARK: - NSFetchedResultsController
@ -192,6 +197,8 @@ class LibraryBooksController: CoreDataCollectionBaseController, UICollectionView
extension Localized {
class Library {
static let title = NSLocalizedString("Library", comment: "Library, Language Filter")
static let title = NSLocalizedString("Library", comment: "Library")
static let download = NSLocalizedString("Download", comment: "Library, more action sheet")
static let copyURL = NSLocalizedString("Copy URL", comment: "Library, more action sheet")
}
}

View File

@ -128,6 +128,7 @@
<outlet property="descriptionLabel" destination="wmd-Qv-2ia" id="SYF-xK-ewN"/>
<outlet property="hasPicLabel" destination="aKZ-e6-Ikq" id="ZgS-qb-zdm"/>
<outlet property="imageView" destination="Wbk-Lp-yTb" id="QZJ-hP-zJr"/>
<outlet property="moreButton" destination="nTw-d7-YqD" id="6wa-Hj-H7D"/>
<outlet property="subtitleLabel" destination="rmy-yO-cBy" id="sx5-Ij-QaQ"/>
<outlet property="titleLabel" destination="q2k-12-zti" id="LU3-St-SwQ"/>
</connections>

View File

@ -161,6 +161,7 @@ class LibraryCollectionCell: UICollectionViewCell {
@IBOutlet weak var subtitleLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var hasPicLabel: UILabel!
@IBOutlet weak var moreButton: UIButton!
}
protocol LibraryCollectionCellDelegate: class {

View File

@ -86,5 +86,18 @@ extension AlertProcedure {
alert.add(actionWithTitle: Localized.Alert.cancel, style: .cancel)
return alert
}
static func bookMore(context: UIViewController, book: Book) -> AlertProcedure {
let alert = AlertProcedure(presentAlertFrom: context, withPreferredStyle: .actionSheet, waitForDismissal: false)
alert.title = book.title
alert.add(actionWithTitle: Localized.Library.download, style: .default) { _ in
}
alert.add(actionWithTitle: Localized.Library.copyURL, style: .default) { _ in
guard let url = book.url else {return}
UIPasteboard.general.string = url.absoluteString
}
return alert
}
}