Commit b544cab0 authored by Kevin Bettin's avatar Kevin Bettin Committed by Soomin Lee

Fix inconsistent code

Fixes:
- trailing colon for todos
- blank line around marks
- multiple spaces instead of one
- pace inside / at start of comments
- trailing spaces for empty lines
- space inside brackets
- space inside parens
- space inside braces
- space around operators
- code indent
- order for access specifiers
- redundant self reference
- hex formatting
- unnecessary nil initialization
- no new trailing blank lines from inside braces, brackets, parens or chevrons
- sorted imports
parent 56bc34bb
......@@ -34,7 +34,7 @@ public class MediaDataSourceAndDelegate: NSObject, UICollectionViewDataSource, U
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return Int(services.mediaDataSource.numberOfFiles(subcategory: mediaType.subcategory))
return Int(services.mediaDataSource.numberOfFiles(subcategory: mediaType.subcategory))
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
......@@ -60,7 +60,7 @@ public class MediaDataSourceAndDelegate: NSObject, UICollectionViewDataSource, U
var cellWidth = collectionView.bounds.size.width / numberOfCells
cellWidth = cellWidth - ceil(((numberOfCells + 1) * cellPadding) / numberOfCells)
return CGSize(width:cellWidth, height:cellWidth * aspectRatio)
return CGSize(width: cellWidth, height: cellWidth * aspectRatio)
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
......@@ -70,6 +70,7 @@ public class MediaDataSourceAndDelegate: NSObject, UICollectionViewDataSource, U
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return cellPadding
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return cellPadding
}
......
......@@ -75,12 +75,13 @@ extension Notification.Name {
static var current: PresentationTheme = {
let isDarkTheme = UserDefaults.standard.bool(forKey: kVLCSettingAppTheme)
return isDarkTheme ? PresentationTheme.darkTheme : PresentationTheme.brightTheme
}() {
}() {
didSet {
NotificationCenter.default.post(name: .VLCThemeDidChangeNotification, object: self)
AppearanceManager.setupAppearance(theme: self.current)
}
}
public init(colors: ColorPalette) {
self.colors = colors
}
......@@ -91,9 +92,9 @@ extension Notification.Name {
@objc public extension UIColor {
public convenience init(_ rgbValue: UInt32, _ alpha: CGFloat = 1.0) {
let r = CGFloat((rgbValue & 0xFF0000) >> 16)/255.0
let g = CGFloat((rgbValue & 0xFF00) >> 8)/255.0
let b = CGFloat(rgbValue & 0xFF)/255.0
let r = CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0
let g = CGFloat((rgbValue & 0xFF00) >> 8) / 255.0
let b = CGFloat(rgbValue & 0xFF) / 255.0
self.init(red: r, green: g, blue: b, alpha: 1.0)
}
......@@ -124,33 +125,33 @@ extension Notification.Name {
}
let brightPalette = ColorPalette(isDark: false,
name: "Default",
background: UIColor(0xf9f9f7),
cellBackgroundA: UIColor(0xf9f9f7),
cellBackgroundB: UIColor(0xe5e5e3),
cellDetailTextColor: UIColor(0xa9a9a9),
cellTextColor: UIColor(0x000000),
lightTextColor: UIColor(0x888888),
sectionHeaderTextColor: UIColor(0xf9f9f7),
sectionHeaderTintColor: UIColor(0xe5efe3),
settingsBackground: UIColor(0xdcdcdc),
settingsCellBackground: UIColor(0xf9f9f7),
settingsSeparatorColor: UIColor(0xd3d3d3),
tabBarColor: UIColor(0xffffff),
orangeUI: UIColor(0xff8800))
name: "Default",
background: UIColor(0xF9F9F7),
cellBackgroundA: UIColor(0xF9F9F7),
cellBackgroundB: UIColor(0xE5E5E3),
cellDetailTextColor: UIColor(0xA9A9A9),
cellTextColor: UIColor(0x000000),
lightTextColor: UIColor(0x888888),
sectionHeaderTextColor: UIColor(0xF9F9F7),
sectionHeaderTintColor: UIColor(0xE5EFE3),
settingsBackground: UIColor(0xDCDCDC),
settingsCellBackground: UIColor(0xF9F9F7),
settingsSeparatorColor: UIColor(0xD3D3D3),
tabBarColor: UIColor(0xFFFFFF),
orangeUI: UIColor(0xFF8800))
let darkPalette = ColorPalette(isDark: true,
name: "Dark",
background: UIColor(0x292b36),
cellBackgroundA: UIColor(0x292b36),
background: UIColor(0x292B36),
cellBackgroundA: UIColor(0x292B36),
cellBackgroundB: UIColor(0x000000),
cellDetailTextColor: UIColor(0xd3d3d3),
cellTextColor: UIColor(0xffffff),
lightTextColor: UIColor(0xb8b8b8),
cellDetailTextColor: UIColor(0xD3D3D3),
cellTextColor: UIColor(0xFFFFFF),
lightTextColor: UIColor(0xB8B8B8),
sectionHeaderTextColor: UIColor(0x828282),
sectionHeaderTintColor: UIColor(0x3c3c3c),
settingsBackground: UIColor(0x292b36),
settingsCellBackground: UIColor(0x3d3f40),
settingsSeparatorColor: UIColor(0xa9a9a9),
tabBarColor: UIColor(0xffffff),
orangeUI: UIColor(0xff8800))
sectionHeaderTintColor: UIColor(0x3C3C3C),
settingsBackground: UIColor(0x292B36),
settingsCellBackground: UIColor(0x3D3F40),
settingsSeparatorColor: UIColor(0xA9A9A9),
tabBarColor: UIColor(0xFFFFFF),
orangeUI: UIColor(0xFF8800))
......@@ -31,8 +31,8 @@ class AppearanceManager: NSObject {
if #available(iOS 11.0, *) {
UINavigationBar.appearance().prefersLargeTitles = true
UINavigationBar.appearance(whenContainedInInstancesOf:[VLCPlaybackNavigationController.self]).prefersLargeTitles = false
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white]
UINavigationBar.appearance(whenContainedInInstancesOf: [VLCPlaybackNavigationController.self]).prefersLargeTitles = false
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
}
// For the edit selection indicators
UITableView.appearance().tintColor = theme.colors.orangeUI
......
......@@ -29,7 +29,7 @@ public class Services: NSObject {
}
@objc public func start() {
let tabbarCoordinator = VLCTabbarCooordinator(tabBarController: self.tabBarController, services:services)
let tabbarCoordinator = VLCTabbarCooordinator(tabBarController: tabBarController, services: services)
tabbarCoordinator.start()
childCoordinators.append(tabbarCoordinator)
}
......
......@@ -16,6 +16,6 @@ public enum SortOption: String {
case size = "Size"
var localizedDescription: String {
return NSLocalizedString(self.rawValue, comment: "")
return NSLocalizedString(rawValue, comment: "")
}
}
......@@ -11,14 +11,13 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
import Foundation
import CoreMotion
import Foundation
@objc(VLCDeviceMotionDelegate)
protocol DeviceMotionDelegate: NSObjectProtocol {
func deviceMotionHasAttitude(deviceMotion: DeviceMotion, pitch: Double, yaw: Double, roll: Double)
}
struct EulerAngles {
......@@ -32,10 +31,10 @@ class DeviceMotion: NSObject {
let motion = CMMotionManager()
let sqrt2 = 0.5.squareRoot()
var lastEulerAngle: EulerAngles? = nil
var beginningQuaternion: CMQuaternion? = nil
var lastEulerAngle: EulerAngles?
var beginningQuaternion: CMQuaternion?
@objc weak var delegate: DeviceMotionDelegate? = nil
@objc weak var delegate: DeviceMotionDelegate?
private func multQuaternion(q1: CMQuaternion, q2: CMQuaternion) -> CMQuaternion {
var ret = CMQuaternion()
......@@ -50,13 +49,13 @@ class DeviceMotion: NSObject {
private func quaternionToEuler(qIn: CMQuaternion) -> EulerAngles {
// Change the axes
var q = CMQuaternion(x:qIn.y, y:qIn.z, z:qIn.x, w:qIn.w)
var q = CMQuaternion(x: qIn.y, y: qIn.z, z: qIn.x, w: qIn.w)
// Rotation of 90°
let qRot = CMQuaternion(x: 0, y: 0, z: -sqrt2 / 2, w: sqrt2 / 2)
// Perform the rotation
q = multQuaternion(q1:qRot, q2:q)
q = multQuaternion(q1: qRot, q2: q)
// Now, we can perform the conversion and manage ourself the singularities
......@@ -95,13 +94,13 @@ class DeviceMotion: NSObject {
@objc func startDeviceMotion() {
if motion.isDeviceMotionAvailable {
motion.gyroUpdateInterval = 1.0 / 60.0 // 60 Hz
motion.gyroUpdateInterval = 1.0 / 60.0 // 60 Hz
motion.startDeviceMotionUpdates(using: .xArbitraryZVertical, to: .main) {
[weak self] (data, error) in
guard let strongSelf = self, let data = data else {
return
}
//get the first quaternion that we started with
// get the first quaternion that we started with
if strongSelf.beginningQuaternion == nil {
strongSelf.beginningQuaternion = data.attitude.quaternion
}
......@@ -109,18 +108,18 @@ class DeviceMotion: NSObject {
// if we panned we will have a lastEuler value that we need to take as beginning angle
if let lastEulerAngle = strongSelf.lastEulerAngle {
//we get the devicemotion diff between start and currentangle
// we get the devicemotion diff between start and currentangle
let beginningEuler = strongSelf.quaternionToEuler(qIn: strongSelf.beginningQuaternion!)
let diffYaw = currentEuler.yaw - beginningEuler.yaw
let diffPitch = currentEuler.pitch - beginningEuler.pitch
let diffRoll = currentEuler.roll - beginningEuler.roll
//and add that to the angle that we had after we lifted our finger
// and add that to the angle that we had after we lifted our finger
currentEuler.yaw = lastEulerAngle.yaw + diffYaw
currentEuler.pitch = lastEulerAngle.pitch + diffPitch
currentEuler.roll = lastEulerAngle.roll + diffRoll
}
strongSelf.delegate?.deviceMotionHasAttitude(deviceMotion:strongSelf, pitch:currentEuler.pitch, yaw:currentEuler.yaw, roll:currentEuler.roll)
strongSelf.delegate?.deviceMotionHasAttitude(deviceMotion: strongSelf, pitch: currentEuler.pitch, yaw: currentEuler.yaw, roll: currentEuler.roll)
}
}
}
......
......@@ -17,14 +17,14 @@ import LocalAuthentication
class KeychainCoordinator: NSObject, PAPasscodeViewControllerDelegate {
@objc class var passcodeLockEnabled: Bool {
return UserDefaults.standard.bool(forKey:kVLCSettingPasscodeOnKey)
return UserDefaults.standard.bool(forKey: kVLCSettingPasscodeOnKey)
}
//Since FaceID and TouchID are both set to 1 when the defaults are registered
//we have to double check for the biometry type to not return true even though the setting is not visible
//and that type is not supported by the device
// Since FaceID and TouchID are both set to 1 when the defaults are registered
// we have to double check for the biometry type to not return true even though the setting is not visible
// and that type is not supported by the device
private var touchIDEnabled: Bool {
var touchIDEnabled = UserDefaults.standard.bool(forKey:kVLCSettingPasscodeAllowTouchID)
var touchIDEnabled = UserDefaults.standard.bool(forKey: kVLCSettingPasscodeAllowTouchID)
let laContext = LAContext()
if #available(iOS 11.0.1, *), laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
......@@ -32,8 +32,9 @@ class KeychainCoordinator: NSObject, PAPasscodeViewControllerDelegate {
}
return touchIDEnabled
}
private var faceIDEnabled: Bool {
var faceIDEnabled = UserDefaults.standard.bool(forKey:kVLCSettingPasscodeAllowFaceID)
var faceIDEnabled = UserDefaults.standard.bool(forKey: kVLCSettingPasscodeAllowFaceID)
let laContext = LAContext()
if #available(iOS 11.0.1, *), laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
......@@ -44,7 +45,7 @@ class KeychainCoordinator: NSObject, PAPasscodeViewControllerDelegate {
static let passcodeService = "org.videolan.vlc-ios.passcode"
var completion: (() -> Void)? = nil
var completion: (() -> Void)?
private var avoidPromptingTouchOrFaceID = false
......@@ -121,19 +122,19 @@ class KeychainCoordinator: NSObject, PAPasscodeViewControllerDelegate {
avoidPromptingTouchOrFaceID = true
laContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
localizedReason: NSLocalizedString("BIOMETRIC_UNLOCK", comment: ""),
reply: { [weak self ] success, _ in
DispatchQueue.main.async {
if success {
UIApplication.shared.delegate?.window??.rootViewController?.dismiss(animated: true, completion: {
self?.completion?()
self?.completion = nil
self?.avoidPromptingTouchOrFaceID = false
})
} else {
//user hit cancel and wants to enter the passcode
self?.avoidPromptingTouchOrFaceID = true
}
}
reply: { [weak self] success, _ in
DispatchQueue.main.async {
if success {
UIApplication.shared.delegate?.window??.rootViewController?.dismiss(animated: true, completion: {
self?.completion?()
self?.completion = nil
self?.avoidPromptingTouchOrFaceID = false
})
} else {
// user hit cancel and wants to enter the passcode
self?.avoidPromptingTouchOrFaceID = true
}
}
})
}
}
......@@ -147,6 +148,7 @@ class KeychainCoordinator: NSObject, PAPasscodeViewControllerDelegate {
}
// MARK: PAPassCodeDelegate
func paPasscodeViewControllerDidEnterPasscode(_ controller: PAPasscodeViewController!) {
avoidPromptingTouchOrFaceID = false
UIApplication.shared.delegate?.window??.rootViewController?.dismiss(animated: true, completion: {
......@@ -154,5 +156,4 @@ class KeychainCoordinator: NSObject, PAPasscodeViewControllerDelegate {
self.completion = nil
})
}
}
......@@ -27,6 +27,7 @@ enum RemoteNetworkCellType: Int {
protocol RemoteNetworkDataSourceDelegate {
func showViewController(_ viewController: UIViewController)
}
@objc(VLCRemoteNetworkDataSourceAndDelegate)
public class RemoteNetworkDataSource: NSObject, UITableViewDataSource, UITableViewDelegate {
let cloudVC = VLCCloudServicesTableViewController(nibName: "VLCCloudServicesTableViewController", bundle: Bundle.main)
......@@ -36,6 +37,7 @@ public class RemoteNetworkDataSource: NSObject, UITableViewDataSource, UITableVi
@objc weak var delegate: RemoteNetworkDataSourceDelegate?
// MARK: - DataSource
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return RemoteNetworkCellType.count
}
......@@ -80,6 +82,7 @@ public class RemoteNetworkDataSource: NSObject, UITableViewDataSource, UITableVi
}
// MARK: - Delegate
public func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
return RemoteNetworkCellType(rawValue: indexPath.row) == .wifi ? nil : indexPath
}
......@@ -90,7 +93,7 @@ public class RemoteNetworkDataSource: NSObject, UITableViewDataSource, UITableVi
delegate?.showViewController(vc)
}
}
@objc func viewController(indexPath: IndexPath) -> UIViewController? {
guard let cellType = RemoteNetworkCellType(rawValue: indexPath.row) else {
assertionFailure("We're having more rows than types of cells that should never happen")
......
......@@ -34,7 +34,7 @@ public class VLCMediaViewController: UICollectionViewController, UISearchResults
dragAndDropManager.delegate = services.mediaDataSource
return dragAndDropManager
}()
lazy var emptyView: VLCEmptyLibraryView = {
let name = String(describing: VLCEmptyLibraryView.self)
let nib = Bundle.main.loadNibNamed(name, owner: self, options: nil)
......@@ -51,7 +51,7 @@ public class VLCMediaViewController: UICollectionViewController, UISearchResults
init(services: Services, type: VLCMediaType) {
self.services = services
mediaType = type
self.rendererButton = services.rendererDiscovererManager.setupRendererButton()
rendererButton = services.rendererDiscovererManager.setupRendererButton()
super.init(collectionViewLayout: UICollectionViewFlowLayout())
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
if mediaType.category == .video {
......@@ -67,11 +67,11 @@ public class VLCMediaViewController: UICollectionViewController, UISearchResults
}
@available(*, unavailable)
required public init?(coder aDecoder: NSCoder) {
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder: ) has not been implemented")
}
override public func viewDidLoad() {
public override func viewDidLoad() {
super.viewDidLoad()
setupCollectionView()
setupSearchController()
......@@ -95,9 +95,9 @@ public class VLCMediaViewController: UICollectionViewController, UISearchResults
}
func setupCollectionView() {
mediaDataSourceAndDelegate = MediaDataSourceAndDelegate(services: services, type:mediaType)
mediaDataSourceAndDelegate = MediaDataSourceAndDelegate(services: services, type: mediaType)
mediaDataSourceAndDelegate?.delegate = self
let playlistnib = UINib(nibName: "VLCPlaylistCollectionViewCell", bundle:nil)
let playlistnib = UINib(nibName: "VLCPlaylistCollectionViewCell", bundle: nil)
collectionView?.register(playlistnib, forCellWithReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier())
collectionView?.backgroundColor = PresentationTheme.current.colors.background
collectionView?.alwaysBounceVertical = true
......@@ -109,11 +109,11 @@ public class VLCMediaViewController: UICollectionViewController, UISearchResults
}
}
override public func viewDidAppear(_ animated: Bool) {
public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
reloadData()
}
func setupSearchController() {
searchController = UISearchController(searchResultsController: nil)
searchController?.searchResultsUpdater = self
......@@ -137,12 +137,13 @@ public class VLCMediaViewController: UICollectionViewController, UISearchResults
func setupNavigationBar() {
navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
}
func displayEmptyViewIfNeeded() {
collectionView?.backgroundView = collectionView?.numberOfItems(inSection: 0) == 0 ? emptyView : nil
}
// MARK: Renderer
private func setupRendererButton() {
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
}
......@@ -151,16 +152,18 @@ public class VLCMediaViewController: UICollectionViewController, UISearchResults
delegate?.mediaViewControllerDidSelectSort(self)
}
override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
public override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
collectionView?.collectionViewLayout.invalidateLayout()
}
// MARK: - MediaDatasourceAndDelegate
override public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
public override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
delegate?.mediaViewControllerDidSelectMediaObject(self, mediaObject: services.mediaDataSource.object(at: indexPath.row, subcategory: mediaType.subcategory))
}
// MARK: - Search
public func updateSearchResults(for searchController: UISearchController) {
searchDataSource.shouldReloadTable(forSearch: searchController.searchBar.text, searchableFiles: services.mediaDataSource.allObjects(for: mediaType.subcategory))
collectionView?.reloadData()
......
......@@ -24,6 +24,7 @@ import UIKit
}
// MARK: VLCActionSheet
class VLCActionSheet: UIViewController {
private let cellHeight: CGFloat = 50
......@@ -118,6 +119,7 @@ class VLCActionSheet: UIViewController {
}
// MARK: Private methods
fileprivate func setuplHeaderViewConstraints() {
NSLayoutConstraint.activate([
headerView.heightAnchor.constraint(equalToConstant: cellHeight),
......@@ -166,6 +168,7 @@ class VLCActionSheet: UIViewController {
}
// MARK: UIViewController
override func viewDidLoad() {
super.viewDidLoad()
......@@ -230,6 +233,7 @@ class VLCActionSheet: UIViewController {
}
// MARK: UICollectionViewDelegateFlowLayout
extension VLCActionSheet: UICollectionViewDelegateFlowLayout {
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: collectionView.frame.width, height: cellHeight)
......@@ -237,6 +241,7 @@ extension VLCActionSheet: UICollectionViewDelegateFlowLayout {
}
// MARK: UICollectionViewDelegate
extension VLCActionSheet: UICollectionViewDelegate {
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let delegate = delegate, let item = delegate.itemAtIndexPath(indexPath) {
......@@ -248,6 +253,7 @@ extension VLCActionSheet: UICollectionViewDelegate {
}
// MARK: UICollectionViewDataSource
extension VLCActionSheet: UICollectionViewDataSource {
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if let dataSource = dataSource {
......
......@@ -70,6 +70,6 @@ class VLCActionSheetCell: UICollectionViewCell {
stackView.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -20),
stackView.heightAnchor.constraint(equalTo: heightAnchor),
stackView.topAnchor.constraint(equalTo: topAnchor)
])
])
}
}
......@@ -55,7 +55,7 @@ class VLCActionSheetSectionHeader: UIView {
separator.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -20),
separator.heightAnchor.constraint(equalToConstant: 0.5),
separator.topAnchor.constraint(equalTo: bottomAnchor, constant: -1)
])
])
}
fileprivate func setupTitle() {
......@@ -65,6 +65,6 @@ class VLCActionSheetSectionHeader: UIView {
title.centerYAnchor.constraint(equalTo: centerYAnchor),
title.centerXAnchor.constraint(equalTo: centerXAnchor),
title.topAnchor.constraint(equalTo: topAnchor)
])
])
}
}
......@@ -10,8 +10,8 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
import UIKit
import MobileCoreServices
import UIKit
@available(iOS 11.0, *)
struct DropError: Error {
......@@ -22,6 +22,7 @@ struct DropError: Error {
let kind: ErrorKind
}
@available(iOS 11.0, *)
@objc protocol VLCDragAndDropManagerDelegate: NSObjectProtocol {
func dragAndDropManagerRequestsFile(manager: VLCDragAndDropManager, atIndexPath indexPath: IndexPath) -> AnyObject?
......@@ -36,7 +37,7 @@ class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableView
@objc weak var delegate: VLCDragAndDropManagerDelegate?
let utiTypeIdentifiers: [String] = VLCDragAndDropManager.supportedTypeIdentifiers()
var mediaType: VLCMediaType
var mediaType: VLCMediaType
/// Returns the supported type identifiers that VLC can process.
/// It fetches the identifiers in LSItemContentTypes from all the CFBundleDocumentTypes in the info.plist.
/// Video, Audio and Subtitle formats
......@@ -63,7 +64,9 @@ class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableView
mediaType = type
super.init()
}
// MARK: - TableView
func tableView(_ tableView: UITableView, canHandle session: UIDropSession) -> Bool {
return canHandleDropSession(session: session)
}
......@@ -73,7 +76,7 @@ class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableView
}
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
return dragItems(forIndexPath: indexPath)
return dragItems(forIndexPath: indexPath)
}
func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal {
......@@ -88,24 +91,24 @@ class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableView
for item in coordinator.items {
let itemProvider = item.dragItem.itemProvider
//we're not gonna handle moving of folders
// we're not gonna handle moving of folders
if let sourceItem = item.dragItem.localObject, fileIsCollection(file: sourceItem as AnyObject) {
continue
}
if fileIsFolder(atIndexPath:destinationPath) { //handle dropping onto a folder
addDragItem(tableView:tableView, dragItem:item, toFolderAt:destinationPath)
if fileIsFolder(atIndexPath: destinationPath) { // handle dropping onto a folder
addDragItem(tableView: tableView, dragItem: item, toFolderAt: destinationPath)
continue
}
if item.sourceIndexPath != nil { //element within VLC
moveItem(tableView:tableView, item:item, toIndexPath:destinationPath)
if item.sourceIndexPath != nil { // element within VLC
moveItem(tableView: tableView, item: item, toIndexPath: destinationPath)
continue
}
//Element dragging from another App
// Element dragging from another App
let placeholder = UITableViewDropPlaceholder(insertionIndexPath: destinationPath, reuseIdentifier: VLCPlaylistTableViewCell.cellIdentifier(), rowHeight: VLCPlaylistTableViewCell.heightOfCell())
let placeholderContext = coordinator.drop(item.dragItem, to: placeholder)
createFileWith(itemProvider:itemProvider) {
createFileWith(itemProvider: itemProvider) {
[weak self] file, error in
guard let strongSelf = self else { return }
......@@ -133,33 +136,34 @@ class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableView
tableView.performBatchUpdates({
tableView.insertRows(at: [destinationPath], with: .automatic)
delegate?.dragAndDropManagerInsertItem(manager: self, item: mlFile, atIndexPath: destinationPath)
delegate?.dragAndDropManagerRemoveFileFromFolder(manager:self, file:mlFile)
}, completion:nil)
delegate?.dragAndDropManagerRemoveFileFromFolder(manager: self, file: mlFile)
}, completion: nil)
}
}
private func addDragItem(tableView: UITableView, dragItem item: UITableViewDropItem, toFolderAt index: IndexPath) {
if let sourcepath = item.sourceIndexPath { //local file that just needs to be moved
if let sourcepath = item.sourceIndexPath { // local file that just needs to be moved
tableView.performBatchUpdates({
if let file = delegate?.dragAndDropManagerRequestsFile(manager:self, atIndexPath: sourcepath) as? MLFile {
if let file = delegate?.dragAndDropManagerRequestsFile(manager: self, atIndexPath: sourcepath) as? MLFile {
tableView.deleteRows(at: [sourcepath], with: .automatic)
addFile(file:file, toFolderAt:index)
delegate?.dragAndDropManagerDeleteItem(manager: self, atIndexPath:sourcepath)
addFile(file: file, toFolderAt: index)
delegate?.dragAndDropManagerDeleteItem(manager: self, atIndexPath: sourcepath)
}
}, completion:nil)
}, completion: nil)
return
}
// file from other app
createFileWith(itemProvider:item.dragItem.itemProvider) {
createFileWith(itemProvider: item.dragItem.itemProvider) {
[weak self] file, error in
if let strongSelf = self, let file = file {
strongSelf.addFile(file:file, toFolderAt:index)
strongSelf.addFile(file: file, toFolderAt: index)
}
}
}
// MARK: - Collectionview
func collectionView(_ collectionView: UICollectionView, canHandle session: UIDropSession) -> Bool {
return canHandleDropSession(session: session)
}
......@@ -183,21 +187,21 @@ class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableView
let destinationPath = coordinator.destinationIndexPath ?? IndexPath(row: row, section: section)
for item in coordinator.items {
if let sourceItem = item.dragItem.localObject, fileIsCollection(file: sourceItem as AnyObject) { //We're not handling moving of Collection
if let sourceItem = item.dragItem.localObject, fileIsCollection(file: sourceItem as AnyObject) { // We're not handling moving of Collection
continue
}
if fileIsFolder(atIndexPath:destinationPath) { //handle dropping onto a folder
addDragItem(collectionView:collectionView, dragItem:item, toFolderAt:destinationPath)
if fileIsFolder(atIndexPath: destinationPath) { // handle dropping onto a folder
addDragItem(collectionView: collectionView, dragItem: item, toFolderAt: destinationPath)
continue
}
if item.sourceIndexPath != nil { //element within VLC
moveItem(collectionView:collectionView, item:item, toIndexPath:destinationPath)
if item.sourceIndexPath != nil { // element within VLC
moveItem(collectionView: collectionView, item: item, toIndexPath: destinationPath)
continue
}
//Element from another App
// Element from another App
let placeholder = UICollectionViewDropPlaceholder(insertionIndexPath: destinationPath, reuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier())
let placeholderContext = coordinator.drop(item.dragItem, to: placeholder)
createFileWith(itemProvider:item.dragItem.itemProvider) {
createFileWith(itemProvider: item.dragItem.itemProvider) {
[weak self] file, error in
guard let strongSelf = self else { return }
......@@ -221,27 +225,27 @@ class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableView
collectionView.performBatchUpdates({
collectionView.insertItems(at: [destinationPath])
delegate?.dragAndDropManagerInsertItem(manager: self, item: mlFile, atIndexPath: destinationPath)
delegate?.dragAndDropManagerRemoveFileFromFolder(manager:self, file:mlFile)
}, completion:nil)
delegate?.dragAndDropManagerRemoveFileFromFolder(manager: self, file: mlFile)
}, completion: nil)
}
}
private func addDragItem(collectionView: UICollectionView, dragItem item: UICollectionViewDropItem, toFolderAt index: IndexPath) {
if let sourcepath = item.sourceIndexPath {
//local file that just needs to be moved
// local file that just needs to be moved
collectionView.performBatchUpdates({
if let file = delegate?.dragAndDropManagerRequestsFile(manager:self, atIndexPath: sourcepath) as? MLFile {
collectionView.deleteItems(at:[sourcepath])
addFile(file:file, toFolderAt:index)
delegate?.dragAndDropManagerDeleteItem(manager: self, atIndexPath:sourcepath)
if let file = delegate?.dragAndDropManagerRequestsFile(manager: self, atIndexPath: sourcepath) as? MLFile {
collectionView.deleteItems(at: [sourcepath])
addFile(file: file, toFolderAt: index)
delegate?.dragAndDropManagerDeleteItem(manager: self, atIndexPath: sourcepath)
}
}, completion:nil)
}, completion: nil)
} else {
// file from other app
createFileWith(itemProvider:item.dragItem.itemProvider) {
createFileWith(itemProvider: item.dragItem.itemProvider) {
[weak self] file, error in
if let strongSelf = self, let file = file {
strongSelf.addFile(file:file, toFolderAt:index)
strongSelf.addFile(file: file, toFolderAt: index)
}
}
}
......@@ -259,17 +263,18 @@ class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableView
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
for item in session.items {
createFileWith(itemProvider:item.itemProvider) {
createFileWith(itemProvider: item.itemProvider) {
[weak self] _, error in
if let error = error as? DropError {
self?.handleError(error: error, itemProvider: item.itemProvider)
}
//no need to handle the file case since the libraryVC updates itself after getting a file
// no need to handle the file case since the libraryVC updates itself after getting a file
}
}
}
// MARK: - Shared Methods
// Checks if the session has items conforming to typeidentifiers
private func canHandleDropSession(session: UIDropSession) -> Bool {
if session.localDragSession != nil {
......@@ -287,27 +292,27 @@ class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableView