Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from screeningeagledreamlab/add-carthage-support
Browse files Browse the repository at this point in the history
Add carthage support
  • Loading branch information
hujunfeng authored Jun 29, 2022
2 parents e624a3c + 7a3031c commit 43e1939
Show file tree
Hide file tree
Showing 30 changed files with 1,306 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ playground.xcworkspace
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
Pods/

# Carthage
#
Expand Down
677 changes: 677 additions & 0 deletions AssetsPicker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1330"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E94855A622F3D3300018A55A"
BuildableName = "AssetsPicker.framework"
BlueprintName = "AssetsPicker"
ReferencedContainer = "container:AssetsPicker.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E94855A622F3D3300018A55A"
BuildableName = "AssetsPicker.framework"
BlueprintName = "AssetsPicker"
ReferencedContainer = "container:AssetsPicker.xcodeproj">
</BuildableReference>
</MacroExpansion>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E94855A622F3D3300018A55A"
BuildableName = "AssetsPicker.framework"
BlueprintName = "AssetsPicker"
ReferencedContainer = "container:AssetsPicker.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
5 changes: 0 additions & 5 deletions AssetsPickerViewController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@ Fully customizable UI.
s.resource_bundles = {
'AssetsPickerViewController' => ['AssetsPickerViewController/Assets/*.*']
}

# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
s.dependency 'SnapKit'
s.dependency 'Device'
end
18 changes: 18 additions & 0 deletions AssetsPickerViewController/AssetsPicker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// AssetsPicker.h
// AssetsPicker
//
// Created by Junfeng Hu on 2/8/19.
//

#import <UIKit/UIKit.h>

//! Project version number for AssetsPicker.
FOUNDATION_EXPORT double AssetsPickerVersionNumber;

//! Project version string for AssetsPicker.
FOUNDATION_EXPORT const unsigned char AssetsPickerVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <AssetsPicker/PublicHeader.h>


Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ open class AssetsAlbumViewController: UIViewController {
setupCommon()
setupBarButtonItems()

collectionView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
collectionView.fillToSuperview()

AssetsManager.shared.authorize(completion: { [weak self] isAuthorized in
if isAuthorized {
Expand Down
38 changes: 19 additions & 19 deletions AssetsPickerViewController/Classes/Album/View/AssetsAlbumCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ open class AssetsAlbumCell: UICollectionViewCell, AssetsAlbumCellProtocol {
contentView.addSubview(titleLabel)
contentView.addSubview(countLabel)

imageView.snp.makeConstraints { (make) in
make.height.equalTo(imageView.snp.width)
make.top.equalToSuperview()
make.leading.equalToSuperview()
make.trailing.equalToSuperview()
}

titleLabel.snp.makeConstraints { (make) in
make.top.equalTo(imageView.snp.bottom).offset(8)
make.leading.equalToSuperview()
make.trailing.equalToSuperview()
make.height.equalTo(titleLabel.font.pointSize + 2)
}
imageView.anchor(
top: contentView.topAnchor,
leading: contentView.leadingAnchor,
trailing: contentView.trailingAnchor
)
imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor).isActive = true

countLabel.snp.makeConstraints { (make) in
make.top.equalTo(titleLabel.snp.bottom).offset(2)
make.leading.equalToSuperview()
make.trailing.equalToSuperview()
make.height.equalTo(countLabel.font.pointSize + 2)
}
titleLabel.anchor(
leading: contentView.leadingAnchor,
trailing: contentView.trailingAnchor,
heightConstant: titleLabel.font.pointSize + 2
)
titleLabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 8).isActive = true

countLabel.anchor(
leading: contentView.leadingAnchor,
trailing: contentView.trailingAnchor,
heightConstant: countLabel.font.pointSize + 2
)
countLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 2).isActive = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ open class AssetsAlbumHeaderView: UICollectionReusableView {

private func commonInit() {
addSubview(titleLabel)
titleLabel.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
titleLabel.fillToSuperview()
}
}
24 changes: 14 additions & 10 deletions AssetsPickerViewController/Classes/Assets/AssetsManager+Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Photos
// MARK: - PHPhotoLibraryChangeObserver & Sync
extension AssetsManager: PHPhotoLibraryChangeObserver {

func synchronizeAlbums(changeInstance: PHChange) -> [IndexSet] {
private func synchronizeAlbums(changeInstance: PHChange) -> [IndexSet] {

// updated index set
var updatedIndexSets = [IndexSet]()
Expand All @@ -24,6 +24,7 @@ extension AssetsManager: PHPhotoLibraryChangeObserver {

guard let albumsChangeDetail = changeInstance.changeDetails(for: albumsFetchResult) else { continue }

guard albumsFetchArray.count > section else { continue }
// update albumsFetchArray
albumsFetchArray[section] = albumsChangeDetail.fetchResultAfterChanges

Expand Down Expand Up @@ -58,9 +59,9 @@ extension AssetsManager: PHPhotoLibraryChangeObserver {
return updatedIndexSets
}

func synchronizeAssets(updatedAlbumIndexSets: [IndexSet], fetchMapBeforeChanges: [String: PHFetchResult<PHAsset>], changeInstance: PHChange) {
private func synchronizeAssets(updatedAlbumIndexSets: [IndexSet], fetchMapBeforeChanges: [String: PHFetchResult<PHAsset>], changeInstance: PHChange) {

var updatedIndexSets = updatedAlbumIndexSets
let updatedIndexSets = updatedAlbumIndexSets

// notify changes of assets
for (section, albums) in fetchedAlbumsArray.enumerated() {
Expand Down Expand Up @@ -191,13 +192,16 @@ extension AssetsManager: PHPhotoLibraryChangeObserver {
logw("Does not have access to photo library.")
return
}
let fetchMapBeforeChanges = fetchMap
let updatedAlbumIndexSets = synchronizeAlbums(changeInstance: changeInstance)
synchronizeAssets(
updatedAlbumIndexSets: updatedAlbumIndexSets,
fetchMapBeforeChanges: fetchMapBeforeChanges,
changeInstance: changeInstance
)
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
let fetchMapBeforeChanges = self.fetchMap
let updatedAlbumIndexSets = self.synchronizeAlbums(changeInstance: changeInstance)
self.synchronizeAssets(
updatedAlbumIndexSets: updatedAlbumIndexSets,
fetchMapBeforeChanges: fetchMapBeforeChanges,
changeInstance: changeInstance
)
}
}

public func removedIndexPaths(from newAlbums: [PHAssetCollection], oldAlbums: [PHAssetCollection], section: Int) -> (indexPaths: [IndexPath], albums: [PHAssetCollection]) {
Expand Down
40 changes: 27 additions & 13 deletions AssetsPickerViewController/Classes/Assets/AssetsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import Photos

// MARK: - AssetsManagerDelegate
public protocol AssetsManagerDelegate: class {
public protocol AssetsManagerDelegate: AnyObject {

func assetsManager(manager: AssetsManager, authorizationStatusChanged oldStatus: PHAuthorizationStatus, newStatus: PHAuthorizationStatus)
func assetsManager(manager: AssetsManager, reloadedAlbumsInSection section: Int)
Expand Down Expand Up @@ -52,7 +52,7 @@ open class AssetsManager: NSObject {
internal(set) open var assetArray = [PHAsset]()

fileprivate(set) open var defaultAlbum: PHAssetCollection?
fileprivate(set) open var cameraRollAlbum: PHAssetCollection!
fileprivate(set) open var cameraRollAlbum: PHAssetCollection?
fileprivate(set) open var selectedAlbum: PHAssetCollection?

fileprivate var isFetchedAlbums: Bool = false
Expand Down Expand Up @@ -113,10 +113,8 @@ extension AssetsManager {

open func notifySubscribers(_ action: @escaping ((AssetsManagerDelegate) -> Void), condition: Bool = true) {
if condition {
DispatchQueue.main.sync {
for subscriber in self.subscribers {
action(subscriber)
}
for subscriber in subscribers {
action(subscriber)
}
}
}
Expand All @@ -142,7 +140,8 @@ extension AssetsManager {
PHPhotoLibrary.requestAuthorization({ (status) in
DispatchQueue.main.async {
switch status {
case .authorized:
case .authorized,
.limited:
completion(true)
default:
completion(false)
Expand Down Expand Up @@ -381,7 +380,15 @@ extension AssetsManager {

@discardableResult
func notifyIfAuthorizationStatusChanged() -> Bool {
let newStatus = PHPhotoLibrary.authorizationStatus()

var newStatus: PHAuthorizationStatus

if #available(iOS 14, *) {
newStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite)
} else {
newStatus = PHPhotoLibrary.authorizationStatus()
}

if authorizationStatus != newStatus {
let oldStatus = authorizationStatus
authorizationStatus = newStatus
Expand All @@ -391,7 +398,11 @@ extension AssetsManager {
}
}
}
return authorizationStatus == .authorized
if #available(iOS 14, *) {
return authorizationStatus == .limited || authorizationStatus == .authorized
} else {
return authorizationStatus == .authorized
}
}

func isCountChanged(changeDetails: PHFetchResultChangeDetails<PHAsset>) -> Bool {
Expand Down Expand Up @@ -469,10 +480,13 @@ extension AssetsManager {
if isRefetch {
assetArray.removeAll()
}

// set default album
select(album: defaultAlbum ?? cameraRollAlbum)


guard let album = defaultAlbum ?? cameraRollAlbum else {
completion?([])
return
}

select(album: album)
completion?(assetArray)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//
//

import SnapKit

fileprivate let kDimmerViewKey = "kDimmerViewKey"
fileprivate let kDimmerView = "kDimmerView"
fileprivate let kDimmerViewRatio = "kDimmerViewRatio"
Expand Down Expand Up @@ -110,7 +108,7 @@ extension UIView {
} else {
addSubview(dimmer)
}
dimmer.snp.makeConstraints { $0.edges.equalToSuperview() }
dimmer.fillToSuperview()
dimmerView = dimmer
}
}
Expand Down Expand Up @@ -145,9 +143,9 @@ extension UIView {
} else {
addSubview(dimmerActivity)
}
dimmerActivity.snp.makeConstraints { (make) in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().multipliedBy(verticalRatio)
if let superview = dimmerActivity.superview {
dimmerActivity.centerXAnchor.constraint(equalTo: superview.centerXAnchor).isActive = true
dimmerActivity.centerYAnchor.constraint(equalTo: superview.centerYAnchor).isActive = true
}
dimmerActivity.startAnimating()
dimmerActivityView = dimmerActivity
Expand Down
Loading

0 comments on commit 43e1939

Please sign in to comment.