Dactyloidae iOS initial commit
23
mobile/ios/Extensions/ShareTo/Images.xcassets/AddToBookmarks.imageset/Contents.json
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "menu-Bookmark.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "menu-Bookmark@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "menu-Bookmark@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
BIN
mobile/ios/Extensions/ShareTo/Images.xcassets/AddToBookmarks.imageset/menu-Bookmark.png
vendored
Normal file
|
After Width: | Height: | Size: 924 B |
BIN
mobile/ios/Extensions/ShareTo/Images.xcassets/AddToBookmarks.imageset/menu-Bookmark@2x.png
vendored
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
mobile/ios/Extensions/ShareTo/Images.xcassets/AddToBookmarks.imageset/menu-Bookmark@3x.png
vendored
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
23
mobile/ios/Extensions/ShareTo/Images.xcassets/AddToReadingList.imageset/Contents.json
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "reading-list-add.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "reading-list-add@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "reading-list-add@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
BIN
mobile/ios/Extensions/ShareTo/Images.xcassets/AddToReadingList.imageset/reading-list-add.png
vendored
Normal file
|
After Width: | Height: | Size: 316 B |
BIN
mobile/ios/Extensions/ShareTo/Images.xcassets/AddToReadingList.imageset/reading-list-add@2x.png
vendored
Normal file
|
After Width: | Height: | Size: 478 B |
BIN
mobile/ios/Extensions/ShareTo/Images.xcassets/AddToReadingList.imageset/reading-list-add@3x.png
vendored
Normal file
|
After Width: | Height: | Size: 695 B |
23
mobile/ios/Extensions/ShareTo/Images.xcassets/Icon-Small.imageset/Contents.json
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "icon-40.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "icon-40@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "icon-40@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
BIN
mobile/ios/Extensions/ShareTo/Images.xcassets/Icon-Small.imageset/icon-40.png
vendored
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
mobile/ios/Extensions/ShareTo/Images.xcassets/Icon-Small.imageset/icon-40@2x.png
vendored
Normal file
|
After Width: | Height: | Size: 5.6 KiB |
BIN
mobile/ios/Extensions/ShareTo/Images.xcassets/Icon-Small.imageset/icon-40@3x.png
vendored
Normal file
|
After Width: | Height: | Size: 9.9 KiB |
48
mobile/ios/Extensions/ShareTo/Info.plist
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>MozDevelopmentTeam</key>
|
||||
<string>$(DEVELOPMENT_TEAM)</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>$(MOZ_BUNDLE_DISPLAY_NAME)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>10.6</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionAttributes</key>
|
||||
<dict>
|
||||
<key>NSExtensionActivationRule</key>
|
||||
<string>SUBQUERY ( extensionItems, $extensionItem, SUBQUERY ( $extensionItem.attachments, $attachment, ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url").@count == 1 ).@count == 1</string>
|
||||
</dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.share-services</string>
|
||||
<key>NSExtensionPrincipalClass</key>
|
||||
<string>InitialViewController</string>
|
||||
</dict>
|
||||
<key>UIAppFonts</key>
|
||||
<array>
|
||||
<string>FiraSans-Regular.ttf</string>
|
||||
<string>FiraSans-SemiBold.ttf</string>
|
||||
<string>FiraSans-Light.ttf</string>
|
||||
<string>FiraSans-UltraLight.ttf</string>
|
||||
<string>FiraSans-Medium.ttf</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
136
mobile/ios/Extensions/ShareTo/InitialViewController.swift
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import UIKit
|
||||
import Shared
|
||||
import Storage
|
||||
|
||||
private let LastUsedShareDestinationsKey = "LastUsedShareDestinations"
|
||||
|
||||
@objc(InitialViewController)
|
||||
class InitialViewController: UIViewController, ShareControllerDelegate {
|
||||
var shareDialogController: ShareDialogController!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
self.view.backgroundColor = UIColor(white: 0.0, alpha: 0.66) // TODO: Is the correct color documented somewhere?
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
ExtensionUtils.extractSharedItemFromExtensionContext(self.extensionContext, completionHandler: { (item, error) -> Void in
|
||||
if let item = item, error == nil {
|
||||
DispatchQueue.main.async {
|
||||
guard item.isShareable else {
|
||||
let alert = UIAlertController(title: Strings.SendToErrorTitle, message: Strings.SendToErrorMessage, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: Strings.SendToErrorOKButton, style: .default) { _ in self.finish() })
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
return
|
||||
}
|
||||
|
||||
self.presentShareDialog(item)
|
||||
}
|
||||
} else {
|
||||
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
func shareControllerDidCancel(_ shareController: ShareDialogController) {
|
||||
UIView.animate(withDuration: 0.25, animations: { () -> Void in
|
||||
self.shareDialogController.view.alpha = 0.0
|
||||
}, completion: { (Bool) -> Void in
|
||||
self.dismissShareDialog()
|
||||
self.finish()
|
||||
})
|
||||
}
|
||||
|
||||
func finish() {
|
||||
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
|
||||
}
|
||||
|
||||
func shareController(_ shareController: ShareDialogController, didShareItem item: ShareItem, toDestinations destinations: NSSet) {
|
||||
setLastUsedShareDestinations(destinations)
|
||||
|
||||
UIView.animate(withDuration: 0.25, animations: { () -> Void in
|
||||
self.shareDialogController.view.alpha = 0.0
|
||||
}, completion: { (Bool) -> Void in
|
||||
self.dismissShareDialog()
|
||||
|
||||
let profile = BrowserProfile(localName: "profile")
|
||||
|
||||
if destinations.contains(ShareDestinationReadingList) {
|
||||
profile.readingList?.createRecordWithURL(item.url, title: item.title ?? "", addedBy: UIDevice.current.name)
|
||||
}
|
||||
|
||||
if destinations.contains(ShareDestinationBookmarks) {
|
||||
_ = profile.bookmarks.shareItem(item).value // Blocks until database has settled
|
||||
}
|
||||
|
||||
profile.shutdown()
|
||||
|
||||
self.finish()
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// TODO: use Set.
|
||||
func getLastUsedShareDestinations() -> NSSet {
|
||||
if let destinations = UserDefaults.standard.object(forKey: LastUsedShareDestinationsKey) as? NSArray {
|
||||
return NSSet(array: destinations as [AnyObject])
|
||||
}
|
||||
return NSSet(object: ShareDestinationBookmarks)
|
||||
}
|
||||
|
||||
func setLastUsedShareDestinations(_ destinations: NSSet) {
|
||||
UserDefaults.standard.set(destinations.allObjects, forKey: LastUsedShareDestinationsKey)
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
|
||||
func presentShareDialog(_ item: ShareItem) {
|
||||
shareDialogController = ShareDialogController()
|
||||
shareDialogController.delegate = self
|
||||
shareDialogController.item = item
|
||||
shareDialogController.initialShareDestinations = getLastUsedShareDestinations()
|
||||
|
||||
self.addChildViewController(shareDialogController)
|
||||
shareDialogController.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.view.addSubview(shareDialogController.view)
|
||||
shareDialogController.didMove(toParentViewController: self)
|
||||
|
||||
// Setup constraints for the dialog. We keep the dialog centered with 16 points of padding on both
|
||||
// sides. The dialog grows to max 380 points wide so that it does not look too big on landscape or
|
||||
// iPad devices.
|
||||
|
||||
let views: NSDictionary = ["dialog": shareDialogController.view]
|
||||
|
||||
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-(16@751)-[dialog(<=380@1000)]-(16@751)-|",
|
||||
options: NSLayoutFormatOptions(), metrics: nil, views: (views as? [String: AnyObject])!))
|
||||
|
||||
let cx = NSLayoutConstraint(item: shareDialogController.view, attribute: NSLayoutAttribute.centerX,
|
||||
relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerX, multiplier: 1.0, constant: 0)
|
||||
cx.priority = 1000 // TODO: Why does UILayoutPriorityRequired give a linker error? SDK Bug?
|
||||
view.addConstraint(cx)
|
||||
|
||||
view.addConstraint(NSLayoutConstraint(item: shareDialogController.view, attribute: NSLayoutAttribute.centerY,
|
||||
relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerY, multiplier: 1.0, constant: 0))
|
||||
|
||||
// Fade the dialog in
|
||||
|
||||
shareDialogController.view.alpha = 0.0
|
||||
UIView.animate(withDuration: 0.25, animations: { () -> Void in
|
||||
self.shareDialogController.view.alpha = 1.0
|
||||
}, completion: nil)
|
||||
}
|
||||
|
||||
func dismissShareDialog() {
|
||||
shareDialogController.willMove(toParentViewController: nil)
|
||||
shareDialogController.view.removeFromSuperview()
|
||||
shareDialogController.removeFromParentViewController()
|
||||
}
|
||||
}
|
||||
245
mobile/ios/Extensions/ShareTo/ShareViewController.swift
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import UIKit
|
||||
import Shared
|
||||
import Storage
|
||||
|
||||
struct ShareDestination {
|
||||
let code: String
|
||||
let name: String
|
||||
let image: String
|
||||
}
|
||||
|
||||
// TODO: See if we can do this with an Enum instead. Previous attempts failed because for example NSSet does not take (string) enum values.
|
||||
let ShareDestinationBookmarks: String = "Bookmarks"
|
||||
let ShareDestinationReadingList: String = "ReadingList"
|
||||
|
||||
let ShareDestinations = [
|
||||
ShareDestination(code: ShareDestinationReadingList, name: NSLocalizedString("Add to Reading List", tableName: "ShareTo", comment: "On/off toggle to select adding this url to your reading list"), image: "AddToReadingList"),
|
||||
ShareDestination(code: ShareDestinationBookmarks, name: NSLocalizedString("Add to Bookmarks", tableName: "ShareTo", comment: "On/off toggle to select adding this url to your bookmarks"), image: "AddToBookmarks")
|
||||
]
|
||||
|
||||
protocol ShareControllerDelegate {
|
||||
func shareControllerDidCancel(_ shareController: ShareDialogController)
|
||||
func shareController(_ shareController: ShareDialogController, didShareItem item: ShareItem, toDestinations destinations: NSSet)
|
||||
}
|
||||
|
||||
private struct ShareDialogControllerUX {
|
||||
static let CornerRadius: CGFloat = 4 // Corner radius of the dialog
|
||||
|
||||
static let NavigationBarTintColor = UIColor(rgb: 0xf37c00) // Tint color changes the text color in the navigation bar
|
||||
static let NavigationBarCancelButtonFont = UIFont.systemFont(ofSize: UIFont.buttonFontSize) // System default
|
||||
static let NavigationBarAddButtonFont = UIFont.boldSystemFont(ofSize: UIFont.buttonFontSize) // System default
|
||||
static let NavigationBarIconSize = 40 // Width and height of the icon
|
||||
static let NavigationBarBottomPadding = 12
|
||||
|
||||
static let ItemTitleFontMedium = UIFont.systemFont(ofSize: 15, weight: UIFontWeightMedium)
|
||||
static let ItemTitleFont = UIFont.systemFont(ofSize: 15)
|
||||
static let ItemTitleMaxNumberOfLines = 2
|
||||
static let ItemTitleLeftPadding = 44
|
||||
static let ItemTitleRightPadding = 44
|
||||
static let ItemTitleBottomPadding = 12
|
||||
|
||||
static let ItemLinkFont = UIFont.systemFont(ofSize: 12)
|
||||
static let ItemLinkMaxNumberOfLines = 3
|
||||
static let ItemLinkLeftPadding = 44
|
||||
static let ItemLinkRightPadding = 44
|
||||
static let ItemLinkBottomPadding = 14
|
||||
|
||||
static let DividerColor = UIColor.lightGray // Divider between the item and the table with destinations
|
||||
static let DividerHeight = 0.5
|
||||
|
||||
static let TableRowHeight: CGFloat = 44 // System default
|
||||
static let TableRowFont = UIFont.systemFont(ofSize: 14)
|
||||
static let TableRowFontMinScale: CGFloat = 0.8
|
||||
static let TableRowTintColor = UIColor(red: 0.427, green: 0.800, blue: 0.102, alpha: 1.0) // Green tint for the checkmark
|
||||
static let TableRowTextColor = UIColor(rgb: 0x555555)
|
||||
|
||||
static let TableHeight = 88 // Height of 2 standard 44px cells
|
||||
}
|
||||
|
||||
class ShareDialogController: UIViewController, UITableViewDataSource, UITableViewDelegate {
|
||||
var delegate: ShareControllerDelegate!
|
||||
var item: ShareItem!
|
||||
var initialShareDestinations: NSSet = NSSet(object: ShareDestinationBookmarks)
|
||||
|
||||
var selectedShareDestinations: NSMutableSet = NSMutableSet()
|
||||
var navBar: UINavigationBar!
|
||||
var navItem: UINavigationItem!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
selectedShareDestinations = NSMutableSet(set: initialShareDestinations)
|
||||
|
||||
self.view.backgroundColor = UIColor.white
|
||||
self.view.layer.cornerRadius = ShareDialogControllerUX.CornerRadius
|
||||
self.view.clipsToBounds = true
|
||||
|
||||
// Setup the NavigationBar
|
||||
|
||||
navBar = UINavigationBar()
|
||||
navBar.translatesAutoresizingMaskIntoConstraints = false
|
||||
navBar.tintColor = ShareDialogControllerUX.NavigationBarTintColor
|
||||
navBar.isTranslucent = false
|
||||
self.view.addSubview(navBar)
|
||||
|
||||
// Setup the NavigationItem
|
||||
|
||||
navItem = UINavigationItem()
|
||||
navItem.leftBarButtonItem = UIBarButtonItem(
|
||||
title: Strings.ShareToCancelButton,
|
||||
style: .plain,
|
||||
target: self,
|
||||
action: #selector(ShareDialogController.cancel)
|
||||
)
|
||||
navItem.leftBarButtonItem?.setTitleTextAttributes([NSFontAttributeName: ShareDialogControllerUX.NavigationBarCancelButtonFont], for: UIControlState())
|
||||
navItem.leftBarButtonItem?.accessibilityIdentifier = "ShareDialogController.navigationItem.leftBarButtonItem"
|
||||
|
||||
navItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Add", tableName: "ShareTo", comment: "Add button in the share dialog"), style: UIBarButtonItemStyle.done, target: self, action: #selector(ShareDialogController.add))
|
||||
navItem.rightBarButtonItem?.setTitleTextAttributes([NSFontAttributeName: ShareDialogControllerUX.NavigationBarAddButtonFont], for: UIControlState())
|
||||
|
||||
let logo = UIImageView(image: UIImage(named: "Icon-Small"))
|
||||
logo.contentMode = UIViewContentMode.scaleAspectFit // TODO Can go away if icon is provided in correct size
|
||||
navItem.titleView = logo
|
||||
|
||||
navBar.pushItem(navItem, animated: false)
|
||||
|
||||
// Setup the title view
|
||||
|
||||
let titleView = UILabel()
|
||||
titleView.translatesAutoresizingMaskIntoConstraints = false
|
||||
titleView.numberOfLines = ShareDialogControllerUX.ItemTitleMaxNumberOfLines
|
||||
titleView.lineBreakMode = NSLineBreakMode.byTruncatingTail
|
||||
titleView.text = item.title
|
||||
titleView.font = ShareDialogControllerUX.ItemTitleFontMedium
|
||||
view.addSubview(titleView)
|
||||
|
||||
// Setup the link view
|
||||
|
||||
let linkView = UILabel()
|
||||
linkView.translatesAutoresizingMaskIntoConstraints = false
|
||||
linkView.numberOfLines = ShareDialogControllerUX.ItemLinkMaxNumberOfLines
|
||||
linkView.lineBreakMode = NSLineBreakMode.byTruncatingTail
|
||||
linkView.text = item.url
|
||||
linkView.font = ShareDialogControllerUX.ItemLinkFont
|
||||
view.addSubview(linkView)
|
||||
|
||||
// Setup the icon
|
||||
|
||||
let iconView = UIImageView()
|
||||
iconView.translatesAutoresizingMaskIntoConstraints = false
|
||||
iconView.image = UIImage(named: "defaultFavicon")
|
||||
view.addSubview(iconView)
|
||||
|
||||
// Setup the divider
|
||||
|
||||
let dividerView = UIView()
|
||||
dividerView.translatesAutoresizingMaskIntoConstraints = false
|
||||
dividerView.backgroundColor = ShareDialogControllerUX.DividerColor
|
||||
view.addSubview(dividerView)
|
||||
|
||||
// Setup the table with destinations
|
||||
|
||||
let tableView = UITableView()
|
||||
tableView.translatesAutoresizingMaskIntoConstraints = false
|
||||
tableView.separatorInset = UIEdgeInsets.zero
|
||||
tableView.layoutMargins = UIEdgeInsets.zero
|
||||
tableView.isUserInteractionEnabled = true
|
||||
tableView.delegate = self
|
||||
tableView.allowsSelection = true
|
||||
tableView.dataSource = self
|
||||
tableView.isScrollEnabled = false
|
||||
view.addSubview(tableView)
|
||||
|
||||
// Setup constraints
|
||||
|
||||
let views = [
|
||||
"nav": navBar,
|
||||
"title": titleView,
|
||||
"link": linkView,
|
||||
"icon": iconView,
|
||||
"divider": dividerView,
|
||||
"table": tableView
|
||||
]
|
||||
|
||||
// TODO See Bug 1102516 - Use Snappy to define share extension layout constraints
|
||||
|
||||
let constraints = [
|
||||
"H:|[nav]|",
|
||||
"V:|[nav]",
|
||||
|
||||
"H:|-\(ShareDialogControllerUX.ItemTitleLeftPadding)-[title]-\(ShareDialogControllerUX.ItemTitleRightPadding)-|",
|
||||
"V:[nav]-\(ShareDialogControllerUX.NavigationBarBottomPadding)-[title]",
|
||||
|
||||
"H:|-\(ShareDialogControllerUX.ItemLinkLeftPadding)-[link]-\(ShareDialogControllerUX.ItemLinkLeftPadding)-|",
|
||||
"V:[title]-\(ShareDialogControllerUX.ItemTitleBottomPadding)-[link]",
|
||||
|
||||
"H:|[divider]|",
|
||||
"V:[divider(\(ShareDialogControllerUX.DividerHeight))]",
|
||||
"V:[link]-\(ShareDialogControllerUX.ItemLinkBottomPadding)-[divider]",
|
||||
|
||||
"H:|[table]|",
|
||||
"V:[divider][table]",
|
||||
"V:[table(\(ShareDialogControllerUX.TableHeight))]|"
|
||||
]
|
||||
|
||||
for constraint in constraints {
|
||||
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: constraint, options: NSLayoutFormatOptions(), metrics: nil, views: views))
|
||||
}
|
||||
}
|
||||
|
||||
// UITabBarItem Actions that map to our delegate methods
|
||||
|
||||
func cancel() {
|
||||
delegate?.shareControllerDidCancel(self)
|
||||
}
|
||||
|
||||
func add() {
|
||||
delegate?.shareController(self, didShareItem: item, toDestinations: NSSet(set: selectedShareDestinations))
|
||||
}
|
||||
|
||||
// UITableView Delegate and DataSource
|
||||
|
||||
func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return ShareDestinations.count
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||
return ShareDialogControllerUX.TableRowHeight
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = UITableViewCell()
|
||||
cell.textLabel?.textColor = UIAccessibilityDarkerSystemColorsEnabled() ? UIColor.darkGray : ShareDialogControllerUX.TableRowTextColor
|
||||
cell.textLabel?.font = ShareDialogControllerUX.TableRowFont
|
||||
cell.accessoryType = selectedShareDestinations.contains(ShareDestinations[indexPath.row].code) ? UITableViewCellAccessoryType.checkmark : UITableViewCellAccessoryType.none
|
||||
cell.tintColor = ShareDialogControllerUX.TableRowTintColor
|
||||
cell.layoutMargins = UIEdgeInsets.zero
|
||||
cell.textLabel?.text = ShareDestinations[indexPath.row].name
|
||||
cell.textLabel?.adjustsFontSizeToFitWidth = true
|
||||
cell.textLabel?.minimumScaleFactor = ShareDialogControllerUX.TableRowFontMinScale
|
||||
cell.imageView?.image = UIImage(named: ShareDestinations[indexPath.row].image)
|
||||
return cell
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: false)
|
||||
|
||||
let code = ShareDestinations[indexPath.row].code
|
||||
if selectedShareDestinations.contains(code) {
|
||||
selectedShareDestinations.remove(code)
|
||||
} else {
|
||||
selectedShareDestinations.add(code)
|
||||
}
|
||||
tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
|
||||
|
||||
navItem.rightBarButtonItem?.isEnabled = (selectedShareDestinations.count != 0)
|
||||
}
|
||||
}
|
||||