Commit e7dc6290 authored by Carola Nitz's avatar Carola Nitz

MediaSubcategoryViewcontroller: various code fixes

removed publics, opens and internalsi, move variables to top
added a cellidentifier to VLClabelCell
removed code that was the default like bounces etc
BaseButtonBarPageerTabStripViewController: adjust height of the subcategorybar
parent 8da49e4e
......@@ -11,7 +11,7 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="2CI-9N-dP3" userLabel="Icon Label Cell" customClass="VLCLabelCell" customModule="VLC_iOS" customModuleProvider="target">
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="VLCLabelCell" id="2CI-9N-dP3" userLabel="Icon Label Cell" customClass="VLCLabelCell" customModule="VLC_iOS" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="74" height="70"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
......@@ -19,19 +19,19 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rwk-fy-4KB">
<rect key="frame" x="0.0" y="45" width="74" height="20"/>
<rect key="frame" x="0.0" y="25" width="74" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="kWi-HY-P6M"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</view>
<constraints>
<constraint firstItem="rwk-fy-4KB" firstAttribute="centerY" secondItem="2CI-9N-dP3" secondAttribute="centerY" id="GxY-Zz-FHR"/>
<constraint firstItem="rwk-fy-4KB" firstAttribute="leading" secondItem="2CI-9N-dP3" secondAttribute="leading" id="HFm-qh-fCk"/>
<constraint firstAttribute="bottom" secondItem="rwk-fy-4KB" secondAttribute="bottom" constant="5" id="Q0g-pb-bbf"/>
<constraint firstAttribute="trailing" secondItem="rwk-fy-4KB" secondAttribute="trailing" id="YuE-x9-9EY"/>
</constraints>
<size key="customSize" width="74" height="50"/>
......
......@@ -14,11 +14,11 @@ import Foundation
open class ButtonBarView: UICollectionView {
open var selectedBar: UIView!
open var separatorView: UIView!
var selectedBar: UIView!
var separatorView: UIView!
internal let selectedBarHeight: CGFloat = 4
internal let separatorHeight: CGFloat = 1.5
let selectedBarHeight: CGFloat = 4
let separatorHeight: CGFloat = 1.5
var selectedIndex = 0
......@@ -27,7 +27,7 @@ open class ButtonBarView: UICollectionView {
fatalError()
}
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
setup()
NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
......@@ -37,6 +37,7 @@ open class ButtonBarView: UICollectionView {
func setup() {
scrollsToTop = false
showsHorizontalScrollIndicator = false
register(UINib(nibName: "VLCLabelCell", bundle: .main), forCellWithReuseIdentifier:VLCLabelCell.cellIdentifier)
separatorView = UIView(frame: CGRect(x: 0, y: self.frame.size.height - separatorHeight, width: self.frame.size.width, height: separatorHeight))
addSubview(separatorView)
......@@ -53,12 +54,12 @@ open class ButtonBarView: UICollectionView {
separatorView.backgroundColor = PresentationTheme.current.colors.mediaCategorySeparatorColor
}
open func moveTo(index: Int, animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) {
func moveTo(index: Int, animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) {
selectedIndex = index
updateSubviewPositions(animated, swipeDirection: swipeDirection, pagerScroll: pagerScroll)
}
open func move(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat, pagerScroll: PagerScroll) {
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
......@@ -96,7 +97,7 @@ open class ButtonBarView: UICollectionView {
setContentOffset(CGPoint(x: targetContentOffset, y: 0), animated: false)
}
open func updateSubviewPositions(_ animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) {
func updateSubviewPositions(_ animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) {
var selectedBarFrame = selectedBar.frame
let selectedCellIndexPath = IndexPath(item: selectedIndex, section: 0)
......@@ -124,7 +125,7 @@ open class ButtonBarView: UICollectionView {
// 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 }
guard pagerScroll != .no || (pagerScroll != .onlyIfOutOfScreen && (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)
}
......
......@@ -13,7 +13,7 @@
import UIKit
class VLCRemoteNetworkCell: UITableViewCell {
@objc static var cellIdentifier = "RemoteNetworkCell"
@objc static let cellIdentifier = "RemoteNetworkCell"
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
......
......@@ -18,7 +18,7 @@ class VLCVideoSubcategoryViewController: VLCMediaSubcategoryViewController {
let episodes = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .episodes))
let playlists = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .videoPlaylists))
let viewControllers = [movies, episodes, playlists]
viewControllers.forEach { $0.delegate = self.mediaDelegate }
viewControllers.forEach { $0.delegate = mediaDelegate }
return viewControllers
}
}
......@@ -31,15 +31,15 @@ class VLCAudioSubcategoryViewController: VLCMediaSubcategoryViewController {
let albums = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .albums))
let playlists = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .audioPlaylists))
let viewControllers = [tracks, genres, artists, albums, playlists]
viewControllers.forEach { $0.delegate = self.mediaDelegate }
viewControllers.forEach { $0.delegate = mediaDelegate }
return viewControllers
}
}
class VLCMediaSubcategoryViewController: BaseButtonBarPagerTabStripViewController<VLCLabelCell> {
internal var services: Services
public weak var mediaDelegate: VLCMediaViewControllerDelegate?
var services: Services
weak var mediaDelegate: VLCMediaViewControllerDelegate?
init(services: Services) {
self.services = services
......
......@@ -14,20 +14,28 @@ import Foundation
open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
public var containerView: UIScrollView!
var containerView: UIScrollView!
open weak var delegate: PagerTabStripIsProgressiveDelegate?
open weak var datasource: PagerTabStripDataSource?
weak var delegate: PagerTabStripIsProgressiveDelegate?
weak var datasource: PagerTabStripDataSource?
open private(set) var viewControllers = [UIViewController]()
open private(set) var currentIndex = 0
open private(set) var preCurrentIndex = 0 // used *only* to store the index to which move when the pager becomes visible
private(set) var viewControllers = [UIViewController]()
private(set) var currentIndex = 0
private(set) var preCurrentIndex = 0 // used *only* to store the index to which move when the pager becomes visible
open var pageWidth: CGFloat {
private var pagerTabStripChildViewControllersForScrolling: [UIViewController]?
private var lastPageNumber = 0
private var lastContentOffset: CGFloat = 0.0
private var pageBeforeRotate = 0
private var lastSize = CGSize(width: 0, height: 0)
var isViewRotating = false
var isViewAppearing = false
var pageWidth: CGFloat {
return containerView.bounds.width
}
open var scrollPercentage: CGFloat {
var scrollPercentage: CGFloat {
if swipeDirection != .right {
let module = fmod(containerView.contentOffset.x, pageWidth)
return module == 0.0 ? 1.0 : module / pageWidth
......@@ -35,7 +43,7 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
return 1 - fmod(containerView.contentOffset.x >= 0 ? containerView.contentOffset.x : pageWidth + containerView.contentOffset.x, pageWidth) / pageWidth
}
open var swipeDirection: SwipeDirection {
var swipeDirection: SwipeDirection {
if containerView.contentOffset.x > lastContentOffset {
return .left
} else if containerView.contentOffset.x < lastContentOffset {
......@@ -50,9 +58,7 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
containerView = UIScrollView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height))
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.bounces = true
containerView.alwaysBounceHorizontal = true
containerView.alwaysBounceVertical = false
containerView.scrollsToTop = false
containerView.delegate = self
containerView.showsVerticalScrollIndicator = false
......@@ -81,7 +87,7 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
childViewControllers.forEach { $0.beginAppearanceTransition(true, animated: animated) }
}
override open func viewDidAppear(_ animated: Bool) {
open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
lastSize = containerView.bounds.size
updateIfNeeded()
......@@ -103,7 +109,7 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
childViewControllers.forEach { $0.endAppearanceTransition() }
}
override open func viewDidLayoutSubviews() {
open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
updateIfNeeded()
}
......@@ -112,7 +118,7 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
return false
}
open func moveToViewController(at index: Int, animated: Bool = true) {
func moveToViewController(at index: Int, animated: Bool = true) {
guard isViewLoaded && view.window != nil && currentIndex != index else {
preCurrentIndex = index
return
......@@ -135,58 +141,58 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
}
}
open func moveTo(viewController: UIViewController, animated: Bool = true) {
func moveTo(viewController: UIViewController, animated: Bool = true) {
moveToViewController(at: viewControllers.index(of: viewController)!, animated: animated)
}
// MARK: - PagerTabStripDataSource
open func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
assertionFailure("Sub-class must implement the PagerTabStripDataSource viewControllers(for:) method")
return []
}
// MARK: - Helpers
open func updateIfNeeded() {
func updateIfNeeded() {
if isViewLoaded && !lastSize.equalTo(containerView.bounds.size) {
updateContent()
}
}
open func canMoveTo(index: Int) -> Bool {
func canMoveTo(index: Int) -> Bool {
return currentIndex != index && viewControllers.count > index
}
open func pageOffsetForChild(at index: Int) -> CGFloat {
func pageOffsetForChild(at index: Int) -> CGFloat {
return CGFloat(index) * containerView.bounds.width
}
open func offsetForChild(at index: Int) -> CGFloat {
func offsetForChild(at index: Int) -> CGFloat {
return (CGFloat(index) * containerView.bounds.width) + ((containerView.bounds.width - view.bounds.width) * 0.5)
}
public enum PagerTabStripError: Error {
enum PagerTabStripError: Error {
case viewControllerOutOfBounds
}
open func offsetForChild(viewController: UIViewController) throws -> CGFloat {
func offsetForChild(viewController: UIViewController) throws -> CGFloat {
guard let index = viewControllers.index(of: viewController) else {
throw PagerTabStripError.viewControllerOutOfBounds
}
return offsetForChild(at: index)
}
open func pageFor(contentOffset: CGFloat) -> Int {
func pageFor(contentOffset: CGFloat) -> Int {
let result = virtualPageFor(contentOffset: contentOffset)
return pageFor(virtualPage: result)
}
open func virtualPageFor(contentOffset: CGFloat) -> Int {
func virtualPageFor(contentOffset: CGFloat) -> Int {
return Int((contentOffset + 1.5 * pageWidth) / pageWidth) - 1
}
open func pageFor(virtualPage: Int) -> Int {
func pageFor(virtualPage: Int) -> Int {
if virtualPage < 0 {
return 0
}
......@@ -196,7 +202,7 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
return virtualPage
}
open func updateContent() {
func updateContent() {
if lastSize.width != containerView.bounds.size.width {
lastSize = containerView.bounds.size
containerView.contentOffset = CGPoint(x: pageOffsetForChild(at: currentIndex), y: 0)
......@@ -246,7 +252,7 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
}
}
open func reloadPagerTabStripView() {
func reloadPagerTabStripView() {
guard isViewLoaded else { return }
for childController in viewControllers where childController.parent != nil {
childController.beginAppearanceTransition(false, animated: false)
......@@ -267,20 +273,20 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
// MARK: - UIScrollViewDelegate
open func scrollViewDidScroll(_ scrollView: UIScrollView) {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
if containerView == scrollView {
updateContent()
lastContentOffset = scrollView.contentOffset.x
}
}
open func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
if containerView == scrollView {
lastPageNumber = pageFor(contentOffset: scrollView.contentOffset.x)
}
}
open func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
if containerView == scrollView {
pagerTabStripChildViewControllersForScrolling = nil
(navigationController?.view ?? view).isUserInteractionEnabled = true
......@@ -350,12 +356,4 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
viewControllers.forEach { if !($0 is IndicatorInfoProvider) { fatalError("Every view controller provided by PagerTabStripDataSource's viewControllers(for:) method must conform to IndicatorInfoProvider") }}
}
private var pagerTabStripChildViewControllersForScrolling: [UIViewController]?
private var lastPageNumber = 0
private var lastContentOffset: CGFloat = 0.0
private var pageBeforeRotate = 0
private var lastSize = CGSize(width: 0, height: 0)
internal var isViewRotating = false
internal var isViewAppearing = false
}
<?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/>
</plist>
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