-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from cocoatype/34-albums-list-does-not-refresh
Fix refreshing of albums and images
- Loading branch information
Showing
44 changed files
with
268 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Modules/Capabilities/AlbumsData/Resources/en.lproj/Localizable.strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
Localizable.strings | ||
Highlighter | ||
|
||
Created by Geoff Pado on 7/1/24. | ||
Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
*/ | ||
|
||
// Header for the user albums section in the albums list | ||
"PhotoCollectionsDataSource.userAlbumsHeader" = "Albums"; | ||
|
||
// Header for the smart albums section in the albums list | ||
"PhotoCollectionsDataSource.smartAlbumsHeader" = "Library"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Modules/Capabilities/AlbumsData/Sources/EmptyCollection.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Created by Geoff Pado on 7/1/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
import DesignSystem | ||
|
||
struct EmptyCollection: PhotoCollection { | ||
var title: String? { nil } | ||
var icon: String { Icons.standardCollection } | ||
var identifier: String { "" } | ||
} |
8 changes: 8 additions & 0 deletions
8
Modules/Capabilities/AlbumsData/Sources/PhotoCollection.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Created by Geoff Pado on 5/16/20. | ||
// Copyright © 2020 Cocoatype, LLC. All rights reserved. | ||
|
||
public protocol PhotoCollection { | ||
var title: String? { get } | ||
var icon: String { get } | ||
var identifier: String { get } | ||
} |
12 changes: 12 additions & 0 deletions
12
Modules/Capabilities/AlbumsData/Sources/PhotoCollectionSection.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Created by Geoff Pado on 7/1/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
public struct PhotoCollectionSection { | ||
public let title: String | ||
public let collections: [PhotoCollection] | ||
|
||
public init(title: String, collections: [PhotoCollection]) { | ||
self.title = title | ||
self.collections = collections | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Modules/Capabilities/AlbumsData/Sources/PhotoCollectionsDataSource.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Created by Geoff Pado on 5/16/20. | ||
// Copyright © 2020 Cocoatype, LLC. All rights reserved. | ||
|
||
import ErrorHandling | ||
import Photos | ||
import UIKit | ||
|
||
public class PhotoCollectionsDataSource: NSObject, ObservableObject, PHPhotoLibraryChangeObserver { | ||
@Published public var collectionsData: [PhotoCollectionSection] | ||
|
||
public override init() { | ||
collectionsData = Self.allSections() | ||
super.init() | ||
|
||
PHPhotoLibrary.shared().register(self) | ||
} | ||
|
||
// MARK: Change Observer | ||
|
||
public func photoLibraryDidChange(_ changeInstance: PHChange) { | ||
Task { @MainActor in | ||
collectionsData = Self.allSections() | ||
} | ||
} | ||
|
||
// MARK: Boilerplate | ||
|
||
private static func allSections() -> [PhotoCollectionSection] { | ||
return [ | ||
Self.section(title: AlbumsDataStrings.PhotoCollectionsDataSource.smartAlbumsHeader, types: [.library, .screenshots, .favorites]), | ||
Self.section(title: AlbumsDataStrings.PhotoCollectionsDataSource.userAlbumsHeader, types: [.userAlbum]), | ||
] | ||
} | ||
|
||
private static func section(title: String, types: [PhotoCollectionType]) -> PhotoCollectionSection { | ||
PhotoCollectionSection( | ||
title: title, | ||
collections: types | ||
.map { $0.fetchResult } | ||
.flatMap { $0.objects(at: IndexSet(integersIn: 0..<$0.count)) } | ||
.map(AssetCollection.init) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// | ||
// AlbumsDataTest.swift | ||
// Highlighter | ||
// | ||
// Created by Geoff Pado on 7/1/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
// |
10 changes: 10 additions & 0 deletions
10
Modules/Capabilities/AlbumsUI/Resources/en.lproj/Localizable.strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Localizable.strings | ||
Highlighter | ||
|
||
Created by Geoff Pado on 7/1/24. | ||
Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
*/ | ||
|
||
// Navigation title for the albums list | ||
"AlbumsViewController.navigationTitle" = "Albums"; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
6 changes: 4 additions & 2 deletions
6
...es/Photo Selection/Albums/AlbumsRow.swift → ...bilities/AlbumsUI/Sources/AlbumsRow.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
32 changes: 13 additions & 19 deletions
32
...lection/Albums/AlbumsViewController.swift → ...bumsUI/Sources/AlbumsViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// | ||
// AlbumsTests.swift | ||
// Highlighter | ||
// | ||
// Created by Geoff Pado on 7/1/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
// |
19 changes: 19 additions & 0 deletions
19
Modules/Capabilities/AppNavigation/Sources/CollectionPresenting.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Created by Geoff Pado on 10/2/20. | ||
// Copyright © 2020 Cocoatype, LLC. All rights reserved. | ||
|
||
import AlbumsData | ||
import UIKit | ||
|
||
public protocol PhotoCollectionPresenting { | ||
func present(_ collection: PhotoCollection) | ||
} | ||
|
||
extension UIResponder { | ||
public var collectionPresenter: PhotoCollectionPresenting? { | ||
if let presenter = (self as? PhotoCollectionPresenting) { | ||
return presenter | ||
} | ||
|
||
return next?.collectionPresenter | ||
} | ||
} |
Oops, something went wrong.