Skip to content

Commit

Permalink
complete localizable.strings
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyuexit committed Sep 14, 2017
1 parent b8ba7a1 commit ee20320
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 33 deletions.
12 changes: 8 additions & 4 deletions LPAlbum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
731A48291F623B3E00AC5513 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 731A48271F623B3E00AC5513 /* LaunchScreen.storyboard */; };
7337B6741F6850C800F1FE84 /* PhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7337B6731F6850C800F1FE84 /* PhotoCell.swift */; };
737FCD111F6241CC00C44C3D /* AlbumViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737FCD101F6241CC00C44C3D /* AlbumViewController.swift */; };
738C26041F67934D00040E4E /* AlbumDetailController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738C26031F67934D00040E4E /* AlbumDetailController.swift */; };
738C26041F67934D00040E4E /* PhotosPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738C26031F67934D00040E4E /* PhotosPreviewController.swift */; };
738C26061F67C94500040E4E /* TakeCameraCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738C26051F67C94500040E4E /* TakeCameraCell.swift */; };
738C260B1F67E43200040E4E /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738C260A1F67E43200040E4E /* Extensions.swift */; };
739180FB1F6677BE001EACFF /* LPAlbum.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 731A47FE1F623AF000AC5513 /* LPAlbum.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand All @@ -32,6 +32,7 @@
7391811D1F66A33C001EACFF /* DropMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7391811B1F66A33C001EACFF /* DropMenuView.swift */; };
7391811F1F66B3A4001EACFF /* TitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7391811C1F66A33C001EACFF /* TitleView.swift */; };
73A85A881F68EDF000C3096E /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73A85A871F68EDF000C3096E /* Config.swift */; };
73BF7BF01F6A24E400A0BEC1 /* PhotoPreviewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73BF7BEF1F6A24E400A0BEC1 /* PhotoPreviewCell.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -73,7 +74,7 @@
731A482A1F623B3E00AC5513 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7337B6731F6850C800F1FE84 /* PhotoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoCell.swift; sourceTree = "<group>"; };
737FCD101F6241CC00C44C3D /* AlbumViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlbumViewController.swift; sourceTree = "<group>"; };
738C26031F67934D00040E4E /* AlbumDetailController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlbumDetailController.swift; sourceTree = "<group>"; };
738C26031F67934D00040E4E /* PhotosPreviewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosPreviewController.swift; sourceTree = "<group>"; };
738C26051F67C94500040E4E /* TakeCameraCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TakeCameraCell.swift; sourceTree = "<group>"; };
738C260A1F67E43200040E4E /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
739181071F669FC9001EACFF /* LPAlbum.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LPAlbum.swift; sourceTree = "<group>"; };
Expand All @@ -87,6 +88,7 @@
7391811B1F66A33C001EACFF /* DropMenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropMenuView.swift; sourceTree = "<group>"; };
7391811C1F66A33C001EACFF /* TitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TitleView.swift; sourceTree = "<group>"; };
73A85A871F68EDF000C3096E /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
73BF7BEF1F6A24E400A0BEC1 /* PhotoPreviewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoPreviewCell.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -176,7 +178,7 @@
children = (
739181071F669FC9001EACFF /* LPAlbum.swift */,
739181081F669FC9001EACFF /* LPNavigationController.swift */,
738C26031F67934D00040E4E /* AlbumDetailController.swift */,
738C26031F67934D00040E4E /* PhotosPreviewController.swift */,
);
path = Controllers;
sourceTree = "<group>";
Expand All @@ -202,6 +204,7 @@
7391811C1F66A33C001EACFF /* TitleView.swift */,
739181191F669FD2001EACFF /* AlbumCollectionCell.swift */,
738C26051F67C94500040E4E /* TakeCameraCell.swift */,
73BF7BEF1F6A24E400A0BEC1 /* PhotoPreviewCell.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -357,9 +360,10 @@
files = (
739181091F669FC9001EACFF /* LPAlbum.swift in Sources */,
7391811D1F66A33C001EACFF /* DropMenuView.swift in Sources */,
738C26041F67934D00040E4E /* AlbumDetailController.swift in Sources */,
738C26041F67934D00040E4E /* PhotosPreviewController.swift in Sources */,
7391811A1F669FD2001EACFF /* AlbumCollectionCell.swift in Sources */,
738C26061F67C94500040E4E /* TakeCameraCell.swift in Sources */,
73BF7BF01F6A24E400A0BEC1 /* PhotoPreviewCell.swift in Sources */,
739181131F669FCE001EACFF /* AlbumManager.swift in Sources */,
73A85A881F68EDF000C3096E /* Config.swift in Sources */,
739181141F669FCE001EACFF /* AuthorizationTool.swift in Sources */,
Expand Down
19 changes: 0 additions & 19 deletions LPAlbum/Controllers/AlbumDetailController.swift

This file was deleted.

33 changes: 27 additions & 6 deletions LPAlbum/Controllers/LPAlbum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
//
// Created by 郜宇 on 2017/9/8.
// Copyright © 2017年 Loopeer. All rights reserved.
// TODO: 1. add CompleteSelectAssetsBlock
/**
TODO: 1. add CompleteSelectAssetsBlock
2. add Photo Cache
3. 文本国际化
4. 图片详情展示
5. 选取单个图片的情形
6. 支持裁剪(正方形, 圆形)
7. take photo statusBarAnimation
8. 是否要加Observer
9. 完善demo(照片墙, 权限跳转)
10. 加一些动画效果
11. 添加注释
12. 是否内部对图片处理画一遍
*/

import UIKit
import Photos
Expand All @@ -21,9 +34,6 @@ public class LPAlbum: UIViewController {
fileprivate var errorBlock: ErrorBlock?
fileprivate var targetSizeBlock: TargetSizeBlock?

fileprivate var cameraStatus: AVAuthorizationStatus!
fileprivate var albumStatus: PHAuthorizationStatus!

fileprivate var albumManager: AlbumManager!
fileprivate var collectionView: UICollectionView!
fileprivate var titleView: TitleView!
Expand Down Expand Up @@ -117,8 +127,8 @@ public class LPAlbum: UIViewController {
extension LPAlbum {

func setupUI() {
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", style: .plain, target: self, action: #selector(cancel))
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "完成", style: .plain, target: self, action: #selector(confirm))
navigationItem.leftBarButtonItem = UIBarButtonItem(title: String.local("取消"), style: .plain, target: self, action: #selector(cancel))
navigationItem.rightBarButtonItem = UIBarButtonItem(title: String.local("完成"), style: .plain, target: self, action: #selector(confirm))

titleView = TitleView(frame: .zero)
navigationItem.titleView = titleView
Expand Down Expand Up @@ -197,6 +207,17 @@ extension LPAlbum: UICollectionViewDelegate, UICollectionViewDataSource {
AuthorizationTool.cameraRequestAuthorization{
$0 == .authorized ? self.takePhoto() : self.errorBlock?(self, AlbumError.noCameraPermission)
}
}else{
let previewVc = PhotosPreviewController()
previewVc.assetModels = albumModels[currentAlbumIndex].assetModels
previewVc.currentIndex = config.hasCamera ? indexPath.row - 1 : indexPath.row
previewVc.chooseAction = {[weak self] in
guard let `self` = self else { return }
self.albumModels = self.albumModels.change(assetModel: $0)
let currentIndex = self.config.hasCamera ? $1 + 1 : $1
self.collectionView.reloadItems(at: [IndexPath(row: currentIndex, section: 0)])
}
navigationController?.pushViewController(previewVc, animated: true)
}
}

Expand Down
96 changes: 96 additions & 0 deletions LPAlbum/Controllers/PhotosPreviewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// AlbumDetailController.swift
// LPAlbum
//
// Created by 郜宇 on 2017/9/12.
// Copyright © 2017年 Loopeer. All rights reserved.
//

import UIKit

class PhotosPreviewController: UIViewController {

var assetModels: [AssetModel]!
var currentIndex: Int!

var chooseAction: ((AssetModel, Int) -> Void)?

fileprivate var collectionView: UICollectionView!
fileprivate let itemPadding: CGFloat = 20.0
fileprivate let chooseButton = UIButton()

override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
}

extension PhotosPreviewController {

func setupUI(){
// 将collectionView多余的部分切到
view.clipsToBounds = true

chooseButton.frame = CGRect(x: 0, y: 0, width: 25, height: 25)
chooseButton.setBackgroundImage(LPAlbum.Style.selectedBox, for: .selected)
chooseButton.setBackgroundImage(LPAlbum.Style.normalBox, for: .normal)
chooseButton.isSelected = assetModels[currentIndex].isSelect
chooseButton.addTarget(self, action: #selector(chooseClick), for: .touchUpInside)
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: chooseButton)

let layout = UICollectionViewFlowLayout()
let itemSize = CGSize(width: view.bounds.width + 20, height: view.bounds.height - 64)
layout.itemSize = itemSize
layout.minimumLineSpacing = 0
layout.minimumInteritemSpacing = 0
layout.scrollDirection = .horizontal
collectionView = UICollectionView(frame: CGRect(x: -10, y: 0, width: itemSize.width, height: itemSize.height),
collectionViewLayout: layout)
collectionView.isPagingEnabled = true
collectionView.showsHorizontalScrollIndicator = false
collectionView.delegate = self
collectionView.dataSource = self
view.addSubview(collectionView)
collectionView.register(PhotoPreviewCell.self, forCellWithReuseIdentifier: PhotoPreviewCell.description())
collectionView.performBatchUpdates(nil){ _ in
self.collectionView.setContentOffset(CGPoint(x: itemSize.width * self.currentIndex.cgFloat, y: 0), animated: false)
}
}
func chooseClick() {
chooseButton.isSelected = !chooseButton.isSelected
assetModels[currentIndex].isSelect = chooseButton.isSelected

var model = assetModels[currentIndex]
model.isSelect = chooseButton.isSelected
chooseAction?(model, currentIndex)
}
}

extension PhotosPreviewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return assetModels.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoPreviewCell.description(), for: indexPath) as! PhotoPreviewCell
cell.assetModel = assetModels[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
(cell as? PhotoPreviewCell)?.resetZoomScale()
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
currentIndex = (scrollView.contentOffset.x / scrollView.bounds.width).roundInt
chooseButton.isSelected = assetModels[currentIndex].isSelect
}
}









8 changes: 4 additions & 4 deletions LPAlbum/Others/AlbumError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public enum AlbumError: Error {

public var localizedDescription: String {
switch self {
case .noAlbumPermission: return "没有相册访问权限"
case .noCameraPermission: return "没有相机访问权限"
case .moreThanLargestChoiceCount: return "超出了可选择图片数量的上限"
case .savePhotoError: return "保存图片失败"
case .noAlbumPermission: return String.local("没有相册访问权限")
case .noCameraPermission: return String.local("没有摄像头访问权限")
case .moreThanLargestChoiceCount: return String.local("达到了图片选择最大数量")
case .savePhotoError: return String.local("保存图片失败")
}
}
}
15 changes: 15 additions & 0 deletions LPAlbum/Others/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Foundation
extension CGFloat {
static var screenWidth = UIScreen.main.bounds.width
static var screenHeight = UIScreen.main.bounds.height

var roundInt: Int { return Int(self.rounded()) }
}

extension Int {
Expand All @@ -37,6 +39,15 @@ extension Bundle {
let path = bundle.path(forResource: imageName, ofType: "png") else { return nil }
return UIImage(contentsOfFile: path)
}

static func localizedString(key: String) -> String {
guard let code = Locale.current.languageCode else { return key }
var language = "zh"
if code == "en" { language = "en" }
guard let path = albumBundle.path(forResource: language, ofType: "lproj"),
let bundle = Bundle(path: path) else { return key }
return bundle.localizedString(forKey: key, value: nil, table: nil)
}
}


Expand Down Expand Up @@ -145,6 +156,10 @@ extension String {
var isAvailableAlbum: Bool {
return !(isEmpty || contains("Hidden") || contains("已隐藏") || contains("Deleted") || contains("最近删除"))
}

static func local(_ key: String) -> String {
return Bundle.localizedString(key: key)
}
}


Expand Down
Binary file not shown.
Binary file not shown.
71 changes: 71 additions & 0 deletions LPAlbum/Views/PhotoPreviewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// PhotoPreviewCell.swift
// LPAlbum
//
// Created by 郜宇 on 2017/9/14.
// Copyright © 2017年 Loopeer. All rights reserved.
//

import UIKit

class PhotoPreviewCell: UICollectionViewCell {

var assetModel: AssetModel! {
didSet{

AlbumManager.getPhoto(asset: assetModel.asset, targetSize: bounds.size) { (image, _) in
self.photoView.image = image
}
}
}
func resetZoomScale() { scrollView.setZoomScale(1.0, animated: false) }

fileprivate let photoView = UIImageView()
fileprivate let scrollView = UIScrollView()

override init(frame: CGRect) {
super.init(frame: frame)

scrollView.frame = bounds.insetBy(dx: 10, dy: 0)
scrollView.minimumZoomScale = 1
scrollView.maximumZoomScale = 3
scrollView.bouncesZoom = true
scrollView.delaysContentTouches = true
scrollView.canCancelContentTouches = true
scrollView.delegate = self

photoView.contentMode = .scaleAspectFit
photoView.frame = scrollView.bounds
scrollView.addSubview(photoView)
contentView.addSubview(scrollView)

}

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

extension PhotoPreviewCell: UIScrollViewDelegate {
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return photoView
}

func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
scrollView.contentInset = .zero
}

func scrollViewDidZoom(_ scrollView: UIScrollView) {
// let scrollViewW = scrollView.frame.width
// let scrollViewH = scrollView.frame.height
// let contentSizeW = scrollView.contentSize.width
// let contentSizeH = scrollView.contentSize.height
//
// let offsetX = scrollViewW > contentSizeW ? scrollViewW - contentSizeW * 0.5 : 0
// let offsetY = scrollViewH > contentSizeH ? scrollViewH - contentSizeH * 0.5 : 0
// photoView.center = CGPoint(x: contentSizeW * 0.5 + offsetX, y: contentSizeH * 0.5 + offsetY)
}

}


0 comments on commit ee20320

Please sign in to comment.