Commit 1c72d523 authored by Carola Nitz's avatar Carola Nitz

MediaSubcategoryViewController: add delegate

remove ButtonBarItemSpec and added constraints to position
ButtonBarView and the containerView
parent b24eb3c4
......@@ -95,7 +95,6 @@
"DOWNLOAD_FROM_HTTP_HELP" = "Enter an address to download the file to your %@.";
"DOWNLOAD_FROM_HTTP" = "Downloads";
"ERROR_NUMBER" = "Error %i occured";
"DOWNLOAD_FAILED" = "Download failed";
"FILE_NOT_SUPPORTED" = "File format not supported";
"FILE_NOT_SUPPORTED_LONG" = "The file format used by %@ is not supported by this version of VLC for iOS.";
"SCHEME_NOT_SUPPORTED" = "Address scheme not supported";
......
//
// ButtonBarView.swift
// VLC-iOS
//
// Created by Carola Nitz on 6/1/18.
// Copyright © 2018 VideoLAN. All rights reserved.
//
import Foundation
open class ButtonBarView: UICollectionView {
open lazy var selectedBar: UIView = { [unowned self] in
let bar = UIView(frame: CGRect(x: 0, y: self.frame.size.height - CGFloat(self.selectedBarHeight), width: 0, height: CGFloat(self.selectedBarHeight)))
bar.layer.zPosition = 9999
return bar
}()
internal var selectedBarHeight: CGFloat = 4 {
didSet {
updateSelectedBarYPosition()
}
}
var selectedIndex = 0
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
addSubview(selectedBar)
}
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
addSubview(selectedBar)
}
open func moveTo(index: Int, animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) {
selectedIndex = index
updateSelectedBarPosition(animated, swipeDirection: swipeDirection, pagerScroll: pagerScroll)
}
open func move(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat, pagerScroll: PagerScroll) {
selectedIndex = progressPercentage > 0.5 ? toIndex : fromIndex
let fromFrame = layoutAttributesForItem(at: IndexPath(item: fromIndex, section: 0))!.frame
let numberOfItems = dataSource!.collectionView(self, numberOfItemsInSection: 0)
var toFrame: CGRect
if toIndex < 0 || toIndex > numberOfItems - 1 {
if toIndex < 0 {
let cellAtts = layoutAttributesForItem(at: IndexPath(item: 0, section: 0))
toFrame = cellAtts!.frame.offsetBy(dx: -cellAtts!.frame.size.width, dy: 0)
} else {
let cellAtts = layoutAttributesForItem(at: IndexPath(item: (numberOfItems - 1), section: 0))
toFrame = cellAtts!.frame.offsetBy(dx: cellAtts!.frame.size.width, dy: 0)
}
} else {
toFrame = layoutAttributesForItem(at: IndexPath(item: toIndex, section: 0))!.frame
}
var targetFrame = fromFrame
targetFrame.size.height = selectedBar.frame.size.height
targetFrame.size.width += (toFrame.size.width - fromFrame.size.width) * progressPercentage
targetFrame.origin.x += (toFrame.origin.x - fromFrame.origin.x) * progressPercentage
selectedBar.frame = CGRect(x: targetFrame.origin.x, y: selectedBar.frame.origin.y, width: targetFrame.size.width, height: selectedBar.frame.size.height)
var targetContentOffset: CGFloat = 0.0
if contentSize.width > frame.size.width {
let toContentOffset = contentOffsetForCell(withFrame: toFrame, andIndex: toIndex)
let fromContentOffset = contentOffsetForCell(withFrame: fromFrame, andIndex: fromIndex)
targetContentOffset = fromContentOffset + ((toContentOffset - fromContentOffset) * progressPercentage)
}
setContentOffset(CGPoint(x: targetContentOffset, y: 0), animated: false)
}
open func updateSelectedBarPosition(_ animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) {
var selectedBarFrame = selectedBar.frame
let selectedCellIndexPath = IndexPath(item: selectedIndex, section: 0)
let attributes = layoutAttributesForItem(at: selectedCellIndexPath)
let selectedCellFrame = attributes!.frame
updateContentOffset(animated: animated, pagerScroll: pagerScroll, toFrame: selectedCellFrame, toIndex: (selectedCellIndexPath as NSIndexPath).row)
selectedBarFrame.size.width = selectedCellFrame.size.width
selectedBarFrame.origin.x = selectedCellFrame.origin.x
if animated {
UIView.animate(withDuration: 0.3, animations: { [weak self] in
self?.selectedBar.frame = selectedBarFrame
})
} else {
selectedBar.frame = selectedBarFrame
}
}
// MARK: - Helpers
private func updateContentOffset(animated: Bool, pagerScroll: PagerScroll, toFrame: CGRect, toIndex: Int) {
guard pagerScroll != .no || (pagerScroll != .scrollOnlyIfOutOfScreen && (toFrame.origin.x < contentOffset.x || toFrame.origin.x >= (contentOffset.x + frame.size.width - contentInset.left))) else { return }
let targetContentOffset = contentSize.width > frame.size.width ? contentOffsetForCell(withFrame: toFrame, andIndex: toIndex) : 0
setContentOffset(CGPoint(x: targetContentOffset, y: 0), animated: animated)
}
private func contentOffsetForCell(withFrame cellFrame: CGRect, andIndex index: Int) -> CGFloat {
let alignmentOffset = (frame.size.width - cellFrame.size.width) * 0.5
var contentOffset = cellFrame.origin.x - alignmentOffset
contentOffset = max(0, contentOffset)
contentOffset = min(contentSize.width - frame.size.width, contentOffset)
return contentOffset
}
private func updateSelectedBarYPosition() {
var selectedBarFrame = selectedBar.frame
selectedBarFrame.origin.y = frame.size.height - selectedBarHeight
selectedBarFrame.size.height = selectedBarHeight
selectedBar.frame = selectedBarFrame
}
override open func layoutSubviews() {
super.layoutSubviews()
updateSelectedBarYPosition()
}
}
......@@ -18,7 +18,9 @@ class VLCVideoSubcategoryViewController: VLCMediaSubcategoryViewController
let movies = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .allVideos))
let episodes = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .episodes))
let playlists = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .videoPlaylists))
return [movies, episodes, playlists]
let viewControllers = [movies, episodes, playlists]
viewControllers.forEach{ $0.delegate = self.mediaDelegate }
return viewControllers
}
}
......@@ -30,24 +32,20 @@ class VLCAudioSubcategoryViewController: VLCMediaSubcategoryViewController
let artists = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .artists))
let albums = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .albums))
let playlists = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .audioPlaylists))
return [tracks, genres, artists, albums, playlists]
let viewControllers = [tracks, genres, artists, albums, playlists]
viewControllers.forEach{ $0.delegate = self.mediaDelegate }
return viewControllers
}
}
class VLCMediaSubcategoryViewController: BaseButtonBarPagerTabStripViewController<LabelCell> {
internal var services: Services
public weak var mediaDelegate: VLCMediaViewControllerDelegate?
init(services: Services) {
self.services = services
super.init(nibName: nil, bundle: nil)
buttonBarItemSpec = ButtonBarItemSpec.nibFile(nibName: "LabelCell", bundle: Bundle.main, width: { _ in
return 70.0
})
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
......
......@@ -56,7 +56,7 @@ class VLCTabbarCooordinator: NSObject, VLCMediaViewControllerDelegate {
displayController.didMove(toParentViewController: tabBarController)
let videoVC = VLCVideoSubcategoryViewController(services: services)
//videoVC.delegate = self
videoVC.mediaDelegate = self
videoVC.title = NSLocalizedString("VIDEO", comment: "")
videoVC.tabBarItem = UITabBarItem(
title: NSLocalizedString("VIDEO", comment: ""),
......@@ -66,7 +66,7 @@ class VLCTabbarCooordinator: NSObject, VLCMediaViewControllerDelegate {
// Audio
let audioVC = VLCAudioSubcategoryViewController(services: services)
//audioVC.delegate = self
audioVC.mediaDelegate = self
audioVC.title = NSLocalizedString("AUDIO", comment: "")
audioVC.tabBarItem = UITabBarItem(
title: NSLocalizedString("AUDIO", comment: ""),
......
......@@ -46,6 +46,7 @@
41B93C081A53853B00102E8B /* VLCCloudServiceCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41B93C071A53853B00102E8B /* VLCCloudServiceCell.xib */; };
41CD695C1A29D72600E60BCE /* VLCBoxController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41CD69591A29D72600E60BCE /* VLCBoxController.m */; };
41CD695D1A29D72600E60BCE /* VLCBoxTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41CD695B1A29D72600E60BCE /* VLCBoxTableViewController.m */; };
41D7DD0520C1853E00AD94F6 /* ButtonBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41D7DD0420C1853E00AD94F6 /* ButtonBarView.swift */; };
41E6BECD207E64E900E158BA /* RemoteNetworkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41E6BECC207E64E900E158BA /* RemoteNetworkCell.swift */; };
41EA74C120C02DFC001E5D57 /* VLCDropboxController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3784AA183A9906009EE944 /* VLCDropboxController.m */; };
41EA74C320C02F8E001E5D57 /* VLCBoxController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41CD69591A29D72600E60BCE /* VLCBoxController.m */; };
......@@ -580,6 +581,7 @@
41CD69591A29D72600E60BCE /* VLCBoxController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCBoxController.m; path = Sources/VLCBoxController.m; sourceTree = SOURCE_ROOT; };
41CD695A1A29D72600E60BCE /* VLCBoxTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCBoxTableViewController.h; path = Sources/VLCBoxTableViewController.h; sourceTree = SOURCE_ROOT; };
41CD695B1A29D72600E60BCE /* VLCBoxTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCBoxTableViewController.m; path = Sources/VLCBoxTableViewController.m; sourceTree = SOURCE_ROOT; };
41D7DD0420C1853E00AD94F6 /* ButtonBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ButtonBarView.swift; path = Sources/ButtonBarView.swift; sourceTree = "<group>"; };
41E6BECC207E64E900E158BA /* RemoteNetworkCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteNetworkCell.swift; sourceTree = "<group>"; };
41EB91DB1F7BFF8400821AA5 /* VLCMetadata.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCMetadata.h; sourceTree = "<group>"; };
41EB91DC1F7BFF8400821AA5 /* VLCMetadata.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCMetadata.m; sourceTree = "<group>"; };
......@@ -1548,11 +1550,11 @@
8F91EC78195CEC7900F5BCBA /* VLCOpenInActivity.m */,
41F5C0761F41ED55005EB9CB /* VLCLibrarySearchDisplayDataSource.h */,
41F5C0771F41ED55005EB9CB /* VLCLibrarySearchDisplayDataSource.m */,
412831632093323700FAA307 /* VLCMediaDataSource.swift */,
4170152B209A1D3600802E44 /* MediaSubcategoryViewController.swift */,
41701545209B36E800802E44 /* BaseButtonBarPagerTabStripViewController.swift */,
41EB94B3209B46E9002F4C30 /* ButtonCell.xib */,
41EB94B5209B4869002F4C30 /* LabelCell.xib */,
41D7DD0420C1853E00AD94F6 /* ButtonBarView.swift */,
);
name = "Everything Playlist";
sourceTree = "<group>";
......@@ -3262,6 +3264,7 @@
7D30F3C2183AB24C00FFC021 /* VLCHTTPConnection.m in Sources */,
DD3EFF371BDEBCE500B68579 /* VLCLocalNetworkServiceNetService.m in Sources */,
DD3EFF511BDEBCE500B68579 /* VLCPlexWebAPI.m in Sources */,
41D7DD0520C1853E00AD94F6 /* ButtonBarView.swift in Sources */,
DD3EFF2D1BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserFTP.m in Sources */,
7D30F3C3183AB24C00FFC021 /* VLCHTTPFileDownloader.m in Sources */,
41273A3C1A955C4100A2EF77 /* VLCMigrationViewController.m in Sources */,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment