Skip to content

Commit

Permalink
Add two simple UI blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AgapovOne committed Mar 23, 2019
1 parent cb39db9 commit 162a93e
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,59 @@
//

import UIKit
import Cartography

public final class PermissionsViewController: UIViewController {

// MARK: - UI Elements
private lazy var headlineLabel: UILabel = {
let label = UILabel.UI.headline
label.text = "Allow Photos Access"
return label
}()

private lazy var statusLabel: UILabel = {
let label = UILabel.UI.body
label.text = "Photos access is unknown"
return label
}()

private lazy var button: UIButton = {
let button = UIButton.UI.big(title: "Allow Photos", color: .brown)
button.addTarget(self, action: #selector(tapAllowPhotos), for: .touchUpInside)
return button
}()

// MARK: - Lifecycle
public override func viewDidLoad() {
super.viewDidLoad()

setupUI()
}

// MARK: - Private methods
private func setupUI() {
view.backgroundColor = .white

view.addSubview(headlineLabel)
view.addSubview(button)
view.addSubview(statusLabel)

constrain(button, headlineLabel, statusLabel) { b, h, s in
[b, h, s].forEach {
$0.leading == $0.superview!.leading + 16
$0.trailing == $0.superview!.trailing - 16
}

h.top == h.superview!.top + 40
b.top == h.bottom + 16
s.top == b.bottom + 24
s.bottom <= s.superview!.bottom + 40
}
}

// MARK: - Actions
@objc private func tapAllowPhotos() {
statusLabel.text = statusLabel.text == "x" ? "TAP HAPPENED" : "x"
}
}
40 changes: 40 additions & 0 deletions LivePhotoToVideo/Modules/Photos/PhotoCollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// PhotoCollectionViewCell.swift
// UI
//
// Created by Alex Agapov on 23/03/2019.
// Copyright © 2019 agapovco. All rights reserved.
//

import UIKit
import Reusable
import Cartography

class PhotoCollectionViewCell: UICollectionViewCell, Reusable {

private let imageView = UIImageView()

init() {
super.init(frame: .zero)
setup()
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setup() {
addSubview(imageView)

constrain(imageView) { i in
i.edges == i.superview!.edges
}
}

var image: UIImage? {
didSet {
imageView.image = image
}
}

}
21 changes: 21 additions & 0 deletions LivePhotoToVideo/Modules/Photos/PhotoCollectionViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<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="gTV-IL-0wX" customClass="PhotoCollectionViewCell" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
</collectionViewCell>
</objects>
</document>
34 changes: 23 additions & 11 deletions LivePhotoToVideo/Modules/Photos/PhotosViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,35 @@ import RxCocoa
import RxDataSources
import Photos

class PhotosViewController: UIViewController {
public protocol PhotosViewModel {}

public final class PhotosViewController: UIViewController {

let disposeBag = DisposeBag()

lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let side = self.view.frame.width / 2
let side = self.view.frame.width / 2 - 8
layout.itemSize = CGSize(width: side, height: side)
layout.minimumLineSpacing = 16
let c = UICollectionView(frame: .zero, collectionViewLayout: layout)
c.register(cellType: PhotoCollectionViewCell.self)
return c
}()

private var viewModel: PhotosViewModel!

override func viewDidLoad() {
super.viewDidLoad()
public init(viewModel: PhotosViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

viewModel = PhotosViewModel()
public override func viewDidLoad() {
super.viewDidLoad()

view.addSubview(collectionView)

Expand All @@ -47,7 +57,6 @@ class PhotosViewController: UIViewController {
private func setupBindings() {
// viewModel.photos


}

private var photos = PHFetchResult<PHAsset>()
Expand All @@ -65,23 +74,26 @@ class PhotosViewController: UIViewController {
}()

func fetchPhotos() {
DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async {
DispatchQueue.global(qos: .default).async {
let assets = PHAsset.fetchAssets(with: self.options)

DispatchQueue.main.async {
photos = assets
self.photos = assets
self.collectionView.reloadData()
}
}
}
}

extension PhotosViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return photos.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
<#code#>
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: PhotoCollectionViewCell = collectionView.dequeueReusableCell(for: indexPath)

return cell
}

}
4 changes: 2 additions & 2 deletions LivePhotoToVideo/Modules/Photos/PhotosViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Copyright © 2017 agapovco. All rights reserved.
//

import Foundation
import UI
import RxSwift
import RxCocoa

class PhotosViewModel {
class PhotosViewModelImpl: PhotosViewModel {
private var service: PhotosService

// MARK: - Input
Expand Down
6 changes: 5 additions & 1 deletion LivePhotoToVideo/Resources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: PermissionsViewController.self))
// let viewController = PermissionsViewController()
let viewController = PhotosViewController(viewModel: PhotosViewModelImpl())

window = UIWindow()
window?.rootViewController = viewController
window?.makeKeyAndVisible()

return true
}
Expand Down
33 changes: 33 additions & 0 deletions LivePhotoToVideo/Views/Button+Styles.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Button+Styles.swift
// UI
//
// Created by Alex Agapov on 23/03/2019.
// Copyright © 2019 agapovco. All rights reserved.
//

import UIKit

extension UIButton {
enum UI {
static func big(title: String, color: UIColor) -> UIButton {
let button = UIButton(type: .custom)

button.backgroundColor = color
button.layer.cornerRadius = 12

let font = UIFont.systemFont(ofSize: 20, weight: .light)

let normalTitle = NSAttributedString(string: title,
attributes: [.font: font,
.foregroundColor: UIColor.white])
button.setAttributedTitle(normalTitle, for: .normal)

let highlightedTitle = NSAttributedString(string: title,
attributes: [.font: font,
.foregroundColor: UIColor.white.withAlphaComponent(0.75)])
button.setAttributedTitle(highlightedTitle, for: .highlighted)
return button
}
}
}
41 changes: 41 additions & 0 deletions LivePhotoToVideo/Views/Label+Styles.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Label+Styles.swift
// LivePhotoToVideo
//
// Created by Alex Agapov on 23/03/2019.
// Copyright © 2019 agapovco. All rights reserved.
//

import UIKit

extension UILabel {
enum UI {
static var headline: UILabel {
let label = UILabel()
let font = UIFont.systemFont(ofSize: 50, weight: .black)

if #available(iOS 11.0, *) {
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: font)
} else {
label.font = font
}
label.textColor = UIColor(white: 0.1, alpha: 1)
label.numberOfLines = 0
return label
}

static var body: UILabel {
let label = UILabel()
let font = UIFont.systemFont(ofSize: 20, weight: .semibold)

if #available(iOS 11.0, *) {
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: font)
} else {
label.font = font
}
label.textColor = UIColor(white: 0.25, alpha: 1)
label.numberOfLines = 0
return label
}
}
}

0 comments on commit 162a93e

Please sign in to comment.