Skip to content

Commit

Permalink
Merge pull request #125 from nohana/release/0.9.6
Browse files Browse the repository at this point in the history
0.9.6
  • Loading branch information
tyokujin authored Dec 2, 2021
2 parents 70d7ce7 + f288809 commit 10e97c2
Show file tree
Hide file tree
Showing 15 changed files with 723 additions and 14 deletions.
12 changes: 12 additions & 0 deletions Demo/DemoListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
Cell(title: "No toolbar", selector: #selector(DemoListViewController.showNoToolbarPicker)),
Cell(title: "Disable to pick assets", selector: #selector(DemoListViewController.showDisableToPickAssetsPicker)),
Cell(title: "Custom UI", selector: #selector(DemoListViewController.showCustomUIPicker)),
Cell(title: "Selectable Album Date Section", selector: #selector(DemoListViewController.showSelectableDateSectionPicker)),
]

override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -136,6 +137,13 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
present(picker, animated: true, completion: nil)
}

@objc func showSelectableDateSectionPicker() {
let picker = NohanaImagePickerController()
picker.canPickDateSection = true
picker.delegate = self
present(picker, animated: true, completion: nil)
}

// MARK: - NohanaImagePickerControllerDelegate

func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController) {
Expand Down Expand Up @@ -169,6 +177,10 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
func nohanaImagePicker(_ picker: NohanaImagePickerController, didSelectPhotoKitAsset asset: PHAsset) {
print("🐷\(#function)\n\tasset = \(asset)\n\t")
}

func nohanaImagePicker(_ picker: NohanaImagePickerController, didSelectAssetDateSectionAssets assets: [PHAsset], date: Date?) {
print("🐷\(#function)\n\tasset = \(assets)\n\tDate = \(String(describing: date))")
}

func nohanaImagePicker(_ picker: NohanaImagePickerController, didSelectPhotoKitAssetList assetList: PHAssetCollection) {
print("🐷\(#function)\n\t\tassetList = \(assetList)\n\t")
Expand Down
20 changes: 20 additions & 0 deletions NohanaImagePicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

/* Begin PBXBuildFile section */
3569CAA91EC1918E000C41C0 /* NohanaImagePicker.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3569CAA61EC1918E000C41C0 /* NohanaImagePicker.xcassets */; };
F117F732273B6A2600E11BC7 /* AssetDateSectionCreater.swift in Sources */ = {isa = PBXBuildFile; fileRef = F117F731273B6A2600E11BC7 /* AssetDateSectionCreater.swift */; };
F181095026A5361A001C2BDE /* MomentDetailListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */; };
F1A26CCD2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */; };
F1A26CCF2738E7E400433E9F /* AssetListSelectableDateSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A26CCE2738E7E400433E9F /* AssetListSelectableDateSectionController.swift */; };
F1A26CD12738E88700433E9F /* AssetDateSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A26CD02738E88700433E9F /* AssetDateSection.swift */; };
F1A26CD32739194300433E9F /* AssetDateSectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A26CD22739194300433E9F /* AssetDateSectionHeaderView.swift */; };
F1E5DE7D26A57F0B004B9EDE /* DetailListViewControllerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1E5DE7C26A57F0B004B9EDE /* DetailListViewControllerProtocol.swift */; };
F1E5DE8026A58346004B9EDE /* MomentInfoSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1E5DE7F26A58346004B9EDE /* MomentInfoSection.swift */; };
F1E5DE8226A58386004B9EDE /* MomentInfoSectionCreater.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1E5DE8126A58386004B9EDE /* MomentInfoSectionCreater.swift */; };
Expand Down Expand Up @@ -77,7 +82,12 @@
23D1CD93207CEB1200F8115E /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/NohanaImagePicker.strings; sourceTree = "<group>"; };
3569CAA61EC1918E000C41C0 /* NohanaImagePicker.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = NohanaImagePicker.xcassets; sourceTree = "<group>"; };
3590F1F51EC1A79400F32E06 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/NohanaImagePicker.strings; sourceTree = "<group>"; };
F117F731273B6A2600E11BC7 /* AssetDateSectionCreater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetDateSectionCreater.swift; sourceTree = "<group>"; };
F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MomentDetailListViewController.swift; sourceTree = "<group>"; };
F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AssetListSelectableDateSection.storyboard; sourceTree = "<group>"; };
F1A26CCE2738E7E400433E9F /* AssetListSelectableDateSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetListSelectableDateSectionController.swift; sourceTree = "<group>"; };
F1A26CD02738E88700433E9F /* AssetDateSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetDateSection.swift; sourceTree = "<group>"; };
F1A26CD22739194300433E9F /* AssetDateSectionHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetDateSectionHeaderView.swift; sourceTree = "<group>"; };
F1E5DE7C26A57F0B004B9EDE /* DetailListViewControllerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailListViewControllerProtocol.swift; sourceTree = "<group>"; };
F1E5DE7F26A58346004B9EDE /* MomentInfoSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MomentInfoSection.swift; sourceTree = "<group>"; };
F1E5DE8126A58386004B9EDE /* MomentInfoSectionCreater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MomentInfoSectionCreater.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -153,6 +163,8 @@
children = (
F1E5DE7F26A58346004B9EDE /* MomentInfoSection.swift */,
F1E5DE8126A58386004B9EDE /* MomentInfoSectionCreater.swift */,
F1A26CD02738E88700433E9F /* AssetDateSection.swift */,
F117F731273B6A2600E11BC7 /* AssetDateSectionCreater.swift */,
);
name = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -180,6 +192,7 @@
F25C69871CA23A0A005935D6 /* MomentCell.swift */,
F2FE1F761C901D9400FDBE7B /* MomentSectionHeaderView.swift */,
F25C69911CA28728005935D6 /* AlbumListEmptyIndicator.swift */,
F1A26CD22739194300433E9F /* AssetDateSectionHeaderView.swift */,
);
name = Views;
sourceTree = "<group>";
Expand All @@ -188,6 +201,7 @@
isa = PBXGroup;
children = (
F23554251C69D19C00796DCA /* NohanaImagePicker.storyboard */,
F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */,
F27029CD1C71C43A001647AB /* NohanaImagePicker.strings */,
F237249A1C6DCF96005D1E8A /* NohanaImagePicker.xcassets */,
);
Expand Down Expand Up @@ -272,6 +286,7 @@
F2DF3B2A1C6CC4DB00C1C0E4 /* AssetDetailListViewController.swift */,
F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */,
F1E5DE7C26A57F0B004B9EDE /* DetailListViewControllerProtocol.swift */,
F1A26CCE2738E7E400433E9F /* AssetListSelectableDateSectionController.swift */,
);
name = ViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -388,6 +403,7 @@
F23554261C69D19C00796DCA /* NohanaImagePicker.storyboard in Resources */,
F27029CB1C71C43A001647AB /* NohanaImagePicker.strings in Resources */,
F237249B1C6DCF96005D1E8A /* NohanaImagePicker.xcassets in Resources */,
F1A26CCD2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -416,19 +432,23 @@
F25C10C21C8ED9BF007453C3 /* MomentViewController.swift in Sources */,
F25C69881CA23A0A005935D6 /* MomentCell.swift in Sources */,
F2FE1F781C901D9400FDBE7B /* MomentSectionHeaderView.swift in Sources */,
F1A26CD12738E88700433E9F /* AssetDateSection.swift in Sources */,
F23554281C69D5DB00796DCA /* NohanaImagePickerController.swift in Sources */,
F1E5DE8026A58346004B9EDE /* MomentInfoSection.swift in Sources */,
F181095026A5361A001C2BDE /* MomentDetailListViewController.swift in Sources */,
F25C69921CA28728005935D6 /* AlbumListEmptyIndicator.swift in Sources */,
F2131F431C79615700797887 /* SwipeInteractionController.swift in Sources */,
F2DF3B2D1C6D780100C1C0E4 /* AssetDetailCell.swift in Sources */,
F25C69901CA27311005935D6 /* EmptyIndicatable.swift in Sources */,
F117F732273B6A2600E11BC7 /* AssetDateSectionCreater.swift in Sources */,
F2DA29771C7749D600B0A8E3 /* NotificationInfo.swift in Sources */,
F1A26CCF2738E7E400433E9F /* AssetListSelectableDateSectionController.swift in Sources */,
F1E5DE7D26A57F0B004B9EDE /* DetailListViewControllerProtocol.swift in Sources */,
F218D7DE1C6C3A5B001FCED1 /* AlbumCell.swift in Sources */,
F26775E11C7046C7002E786C /* ExpandingAnimationController.swift in Sources */,
F28F4AC51C6C59A500B7D725 /* PhotoKitAsset.swift in Sources */,
F2DF3B151C6C76E500C1C0E4 /* AssetListViewController.swift in Sources */,
F1A26CD32739194300433E9F /* AssetDateSectionHeaderView.swift in Sources */,
F26775E51C70574F002E786C /* AnimatableNavigationController.swift in Sources */,
F2DF3B2B1C6CC4DB00C1C0E4 /* AssetDetailListViewController.swift in Sources */,
F218D7D61C6B3D22001FCED1 /* PhotoKitAlbumList.swift in Sources */,
Expand Down
22 changes: 18 additions & 4 deletions NohanaImagePicker/AlbumListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
case .moment:
nohanaImagePickerController.delegate?.nohanaImagePickerDidSelectMoment?(nohanaImagePickerController)
case .albums:
if nohanaImagePickerController.canPickDateSection {
performSegue(withIdentifier: "toAssetListViewSelectableDateSectionController", sender: nil)
} else {
performSegue(withIdentifier: "toAssetListViewController", sender: nil)
}
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAssetList: photoKitAlbumList[indexPath.row].assetList)
}
}
Expand Down Expand Up @@ -156,7 +161,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
)
let albumCount = albumList.count
if albumCount > 0 {
let lastAsset = albumList[albumCount - 1]
let lastAsset = nohanaImagePickerController?.canPickDateSection ?? false ? albumList[0] : albumList[albumCount - 1]
lastAsset.image(targetSize: imageSize, handler: { (imageData) -> Void in
DispatchQueue.main.async(execute: { () -> Void in
if let imageData = imageData {
Expand Down Expand Up @@ -184,9 +189,18 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
let momentViewController = segue.destination as! MomentViewController
momentViewController.nohanaImagePickerController = nohanaImagePickerController
case .albums:
let assetListViewController = segue.destination as! AssetListViewController
assetListViewController.photoKitAssetList = photoKitAlbumList[tableView.indexPathForSelectedRow!.row]
assetListViewController.nohanaImagePickerController = nohanaImagePickerController
switch segue.identifier {
case "toAssetListViewController":
let assetListViewController = segue.destination as! AssetListViewController
assetListViewController.photoKitAssetList = photoKitAlbumList[tableView.indexPathForSelectedRow!.row]
assetListViewController.nohanaImagePickerController = nohanaImagePickerController
case "toAssetListViewSelectableDateSectionController":
let assetListSelectableDateSectionController = segue.destination as! AssetListSelectableDateSectionController
assetListSelectableDateSectionController.photoKitAssetList = photoKitAlbumList[tableView.indexPathForSelectedRow!.row]
assetListSelectableDateSectionController.nohanaImagePickerController = nohanaImagePickerController
default:
fatalError("unexpected segue identifer")
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions NohanaImagePicker/AssetCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
*/
import UIKit

protocol AssetCellDelegate: AnyObject {
func didPushPickButton(cell: AssetCell)
}

class AssetCell: UICollectionViewCell {

@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var pickButton: UIButton!
@IBOutlet weak var overlayView: UIView!

weak var delegate: AssetCellDelegate?
weak var nohanaImagePickerController: NohanaImagePickerController?
var asset: Asset?

Expand Down Expand Up @@ -49,6 +54,7 @@ class AssetCell: UICollectionViewCell {
}
}
self.overlayView.isHidden = !pickButton.isSelected
delegate?.didPushPickButton(cell: self)
}

func update(asset: Asset, nohanaImagePickerController: NohanaImagePickerController) {
Expand Down
22 changes: 22 additions & 0 deletions NohanaImagePicker/AssetDateSection.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2021 nohana, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import Photos

struct AssetDateSection {
let creationDate: Date
let assetResult: [PHAsset]
}
46 changes: 46 additions & 0 deletions NohanaImagePicker/AssetDateSectionCreater.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2021 nohana, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import Photos

final class AssetDateSectionCreater {
func createSections(assetList: PHAssetCollection, options: PHFetchOptions) -> [AssetDateSection] {
var albumDateSectionList = [AssetDateSection]()
let fetchAssetlist = PHAsset.fetchAssets(in: assetList, options: options)
let allAssets = fetchAssetlist.objects(at: IndexSet(0..<fetchAssetlist.count))
let calender = Calendar.current
var assetsByDate = [(DateComponents, [PHAsset])]()
var assetsByDateIndex = 0
for asset in allAssets {
if assetsByDateIndex > 0 {
if assetsByDate[assetsByDateIndex - 1].0 == calender.dateComponents([.day, .year, .month], from: (asset.creationDate ?? Date(timeIntervalSince1970: 0))) {
assetsByDate[assetsByDateIndex - 1].1.append(asset)
} else {
let value = (calender.dateComponents([.day, .year, .month], from: (asset.creationDate ?? Date(timeIntervalSince1970: 0))), [asset])
assetsByDate.append(value)
assetsByDateIndex += 1
}
} else if assetsByDate.count == assetsByDateIndex {
let value = (calender.dateComponents([.day, .year, .month], from: (asset.creationDate ?? Date(timeIntervalSince1970: 0))), [asset])
assetsByDate.append(value)
assetsByDateIndex += 1
}
}
albumDateSectionList = assetsByDate.map { AssetDateSection(creationDate: calender.date(from: $0.0) ?? Date(timeIntervalSince1970: 0), assetResult: $0.1) }

return albumDateSectionList
}
}
Loading

0 comments on commit 10e97c2

Please sign in to comment.