- More work in progress.
This commit is contained in:
David Sinclair 2022-08-30 19:00:35 -07:00
parent 926181327a
commit f0f06ac21b
5 changed files with 53 additions and 25 deletions

View file

@ -250,6 +250,13 @@ class DetailViewController: BaseViewController {
tidyNavigationController() tidyNavigationController()
} }
/// Reloads the grid view, if it is displayed.
@objc func reloadGrid() {
if layout == .grid {
gridDetailViewController?.reload()
}
}
/// Adjusts the container when autoscrolling. Only applies to iPhone. /// Adjusts the container when autoscrolling. Only applies to iPhone.
@objc func adjustForAutoscroll() { @objc func adjustForAutoscroll() {
adjustTopConstraint() adjustTopConstraint()
@ -271,7 +278,7 @@ class DetailViewController: BaseViewController {
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator) super.viewWillTransition(to: size, with: coordinator)
if layout != .left { if [.top, .bottom].contains(layout) {
coordinator.animate { context in coordinator.animate { context in
self.dividerViewBottomConstraint.constant = self.dividerPosition self.dividerViewBottomConstraint.constant = self.dividerPosition
} }

View file

@ -658,6 +658,7 @@ typedef NS_ENUM(NSUInteger, MarkReadShowMenu)
[self.notifier hideIn:0]; [self.notifier hideIn:0];
[self beginOfflineTimer]; [self beginOfflineTimer];
[appDelegate.cacheImagesOperationQueue cancelAllOperations]; [appDelegate.cacheImagesOperationQueue cancelAllOperations];
[appDelegate.detailViewController reloadGrid];
} }
- (void)reloadStories { - (void)reloadStories {
@ -1340,6 +1341,8 @@ typedef NS_ENUM(NSUInteger, MarkReadShowMenu)
[self testForTryFeed]; [self testForTryFeed];
} }
[appDelegate.detailViewController reloadGrid];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0ul); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0ul);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC),
queue, ^(void) { queue, ^(void) {

View file

@ -10,14 +10,22 @@ import UIKit
/// A view controller to manage the Grid layout. /// A view controller to manage the Grid layout.
class GridDetailViewController: UIViewController { class GridDetailViewController: UIViewController {
/// Returns the shared app delegate.
var appDelegate: NewsBlurAppDelegate {
return NewsBlurAppDelegate.shared()
}
@IBOutlet var collectionView: UICollectionView! @IBOutlet var collectionView: UICollectionView!
enum SectionLayoutKind: Int, CaseIterable { enum SectionLayoutKind: Int, CaseIterable {
/// Feed cell kind. /// Feed cells before the story.
case feed case feedBeforeStory
/// Story cell kind. /// The selected story.
case story case selectedStory
/// Feed cells after the story.
case feedAfterStory
} }
var feedColumns: Int { var feedColumns: Int {
@ -36,6 +44,10 @@ class GridDetailViewController: UIViewController {
collectionView.collectionViewLayout = createLayout() collectionView.collectionViewLayout = createLayout()
configureDataSource() configureDataSource()
} }
@objc func reload() {
configureDataSource()
}
} }
extension GridDetailViewController { extension GridDetailViewController {
@ -47,22 +59,23 @@ extension GridDetailViewController {
return nil return nil
} }
let columns = sectionLayoutKind == .feed ? self.feedColumns : 1 let isStory = sectionLayoutKind == .selectedStory
let columns = isStory ? 1 : self.feedColumns
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0)) heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize) let item = NSCollectionLayoutItem(layoutSize: itemSize)
item.contentInsets = NSDirectionalEdgeInsets(top: 2, leading: 2, bottom: 2, trailing: 2) item.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)
let groupHeight = columns == 1 ? let groupHeight = isStory ?
NSCollectionLayoutDimension.absolute(44) : NSCollectionLayoutDimension.absolute(1000) :
NSCollectionLayoutDimension.fractionalWidth(0.2) NSCollectionLayoutDimension.fractionalWidth(0.4)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: groupHeight) heightDimension: groupHeight)
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: columns) let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: columns)
let section = NSCollectionLayoutSection(group: group) let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20) section.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 0, trailing: 10)
return section return section
} }
@ -74,32 +87,35 @@ extension GridDetailViewController {
extension GridDetailViewController { extension GridDetailViewController {
func configureDataSource() { func configureDataSource() {
let feedCellRegistration = UICollectionView.CellRegistration<GridFeedCell, Int> { (cell, indexPath, identifier) in let feedCellRegistration = UICollectionView.CellRegistration<GridFeedCell, Int> { (cell, indexPath, identifier) in
cell.contentView.backgroundColor = UIColor.red
cell.contentView.layer.borderColor = UIColor.black.cgColor
cell.contentView.layer.borderWidth = 1
// cell.contentView.layer.cornerRadius = SectionLayoutKind(rawValue: indexPath.section)! == .feed ? 8 : 0
//TODO: 🚧 //TODO: 🚧
} }
let storyCellRegistration = UICollectionView.CellRegistration<GridStoryCell, Int> { (cell, indexPath, identifier) in let storyCellRegistration = UICollectionView.CellRegistration<GridStoryCell, Int> { (cell, indexPath, identifier) in
//TODO: 🚧 //TODO: 🚧
cell.contentView.backgroundColor = UIColor.red cell.contentView.backgroundColor = UIColor.blue
cell.contentView.layer.borderColor = UIColor.black.cgColor
cell.contentView.layer.borderWidth = 1
cell.contentView.layer.cornerRadius = SectionLayoutKind(rawValue: indexPath.section)! == .feed ? 8 : 0
} }
dataSource = UICollectionViewDiffableDataSource<SectionLayoutKind, Int>(collectionView: collectionView) { dataSource = UICollectionViewDiffableDataSource<SectionLayoutKind, Int>(collectionView: collectionView) {
(collectionView: UICollectionView, indexPath: IndexPath, identifier: Int) -> UICollectionViewCell? in (collectionView: UICollectionView, indexPath: IndexPath, identifier: Int) -> UICollectionViewCell? in
return SectionLayoutKind(rawValue: indexPath.section)! == .story ? return SectionLayoutKind(rawValue: indexPath.section)! == .selectedStory ?
collectionView.dequeueConfiguredReusableCell(using: feedCellRegistration, for: indexPath, item: identifier) : collectionView.dequeueConfiguredReusableCell(using: storyCellRegistration, for: indexPath, item: identifier) : collectionView.dequeueConfiguredReusableCell(using: feedCellRegistration, for: indexPath, item: identifier)
collectionView.dequeueConfiguredReusableCell(using: storyCellRegistration, for: indexPath, item: identifier)
} }
let itemsPerSection = 10
var snapshot = NSDiffableDataSourceSnapshot<SectionLayoutKind, Int>() var snapshot = NSDiffableDataSourceSnapshot<SectionLayoutKind, Int>()
SectionLayoutKind.allCases.forEach { if let activeFeed = appDelegate.storiesCollection.activeFeedStories {
snapshot.appendSections([$0]) let numberOfStories = activeFeed.count
let itemOffset = $0.rawValue * itemsPerSection let selectedIndex = min(numberOfStories - 1, 8)
let itemUpperbound = itemOffset + itemsPerSection
snapshot.appendItems(Array(itemOffset..<itemUpperbound)) snapshot.appendSections(SectionLayoutKind.allCases)
snapshot.appendItems(Array(0..<selectedIndex - 1), toSection: .feedBeforeStory)
snapshot.appendItems([selectedIndex], toSection: .selectedStory)
snapshot.appendItems(Array(selectedIndex + 1..<numberOfStories), toSection: .feedAfterStory)
} }
dataSource.apply(snapshot, animatingDifferences: false) dataSource.apply(snapshot, animatingDifferences: false)

View file

@ -7,7 +7,6 @@
// //
#import "NewsBlurAppDelegate.h" #import "NewsBlurAppDelegate.h"
#import "NewsBlur-Swift.h"
@interface StoriesCollection : NSObject { @interface StoriesCollection : NSObject {
NSDictionary * activeFeed; NSDictionary * activeFeed;

View file

@ -10,7 +10,10 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "NewsBlurAppDelegate.h"
#import "ThemeManager.h" #import "ThemeManager.h"
#import "StoriesCollection.h"
#import "BaseViewController.h"
#import "FeedsObjCViewController.h" #import "FeedsObjCViewController.h"
#import "FeedDetailObjCViewController.h" #import "FeedDetailObjCViewController.h"
#import "StoryPagesObjCViewController.h" #import "StoryPagesObjCViewController.h"