mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
parent
926181327a
commit
f0f06ac21b
5 changed files with 53 additions and 25 deletions
|
@ -250,6 +250,13 @@ class DetailViewController: BaseViewController {
|
|||
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.
|
||||
@objc func adjustForAutoscroll() {
|
||||
adjustTopConstraint()
|
||||
|
@ -271,7 +278,7 @@ class DetailViewController: BaseViewController {
|
|||
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
||||
super.viewWillTransition(to: size, with: coordinator)
|
||||
|
||||
if layout != .left {
|
||||
if [.top, .bottom].contains(layout) {
|
||||
coordinator.animate { context in
|
||||
self.dividerViewBottomConstraint.constant = self.dividerPosition
|
||||
}
|
||||
|
|
|
@ -658,6 +658,7 @@ typedef NS_ENUM(NSUInteger, MarkReadShowMenu)
|
|||
[self.notifier hideIn:0];
|
||||
[self beginOfflineTimer];
|
||||
[appDelegate.cacheImagesOperationQueue cancelAllOperations];
|
||||
[appDelegate.detailViewController reloadGrid];
|
||||
}
|
||||
|
||||
- (void)reloadStories {
|
||||
|
@ -1340,6 +1341,8 @@ typedef NS_ENUM(NSUInteger, MarkReadShowMenu)
|
|||
[self testForTryFeed];
|
||||
}
|
||||
|
||||
[appDelegate.detailViewController reloadGrid];
|
||||
|
||||
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),
|
||||
queue, ^(void) {
|
||||
|
|
|
@ -10,14 +10,22 @@ import UIKit
|
|||
|
||||
/// A view controller to manage the Grid layout.
|
||||
class GridDetailViewController: UIViewController {
|
||||
/// Returns the shared app delegate.
|
||||
var appDelegate: NewsBlurAppDelegate {
|
||||
return NewsBlurAppDelegate.shared()
|
||||
}
|
||||
|
||||
@IBOutlet var collectionView: UICollectionView!
|
||||
|
||||
enum SectionLayoutKind: Int, CaseIterable {
|
||||
/// Feed cell kind.
|
||||
case feed
|
||||
/// Feed cells before the story.
|
||||
case feedBeforeStory
|
||||
|
||||
/// Story cell kind.
|
||||
case story
|
||||
/// The selected story.
|
||||
case selectedStory
|
||||
|
||||
/// Feed cells after the story.
|
||||
case feedAfterStory
|
||||
}
|
||||
|
||||
var feedColumns: Int {
|
||||
|
@ -36,6 +44,10 @@ class GridDetailViewController: UIViewController {
|
|||
collectionView.collectionViewLayout = createLayout()
|
||||
configureDataSource()
|
||||
}
|
||||
|
||||
@objc func reload() {
|
||||
configureDataSource()
|
||||
}
|
||||
}
|
||||
|
||||
extension GridDetailViewController {
|
||||
|
@ -47,22 +59,23 @@ extension GridDetailViewController {
|
|||
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),
|
||||
heightDimension: .fractionalHeight(1.0))
|
||||
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 ?
|
||||
NSCollectionLayoutDimension.absolute(44) :
|
||||
NSCollectionLayoutDimension.fractionalWidth(0.2)
|
||||
let groupHeight = isStory ?
|
||||
NSCollectionLayoutDimension.absolute(1000) :
|
||||
NSCollectionLayoutDimension.fractionalWidth(0.4)
|
||||
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
|
||||
heightDimension: groupHeight)
|
||||
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: columns)
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -74,32 +87,35 @@ extension GridDetailViewController {
|
|||
extension GridDetailViewController {
|
||||
func configureDataSource() {
|
||||
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: 🚧
|
||||
}
|
||||
|
||||
let storyCellRegistration = UICollectionView.CellRegistration<GridStoryCell, Int> { (cell, indexPath, identifier) in
|
||||
//TODO: 🚧
|
||||
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
|
||||
cell.contentView.backgroundColor = UIColor.blue
|
||||
}
|
||||
|
||||
dataSource = UICollectionViewDiffableDataSource<SectionLayoutKind, Int>(collectionView: collectionView) {
|
||||
(collectionView: UICollectionView, indexPath: IndexPath, identifier: Int) -> UICollectionViewCell? in
|
||||
return SectionLayoutKind(rawValue: indexPath.section)! == .story ?
|
||||
collectionView.dequeueConfiguredReusableCell(using: feedCellRegistration, for: indexPath, item: identifier) :
|
||||
collectionView.dequeueConfiguredReusableCell(using: storyCellRegistration, for: indexPath, item: identifier)
|
||||
return SectionLayoutKind(rawValue: indexPath.section)! == .selectedStory ?
|
||||
collectionView.dequeueConfiguredReusableCell(using: storyCellRegistration, for: indexPath, item: identifier) : collectionView.dequeueConfiguredReusableCell(using: feedCellRegistration, for: indexPath, item: identifier)
|
||||
|
||||
}
|
||||
|
||||
let itemsPerSection = 10
|
||||
var snapshot = NSDiffableDataSourceSnapshot<SectionLayoutKind, Int>()
|
||||
|
||||
SectionLayoutKind.allCases.forEach {
|
||||
snapshot.appendSections([$0])
|
||||
let itemOffset = $0.rawValue * itemsPerSection
|
||||
let itemUpperbound = itemOffset + itemsPerSection
|
||||
snapshot.appendItems(Array(itemOffset..<itemUpperbound))
|
||||
if let activeFeed = appDelegate.storiesCollection.activeFeedStories {
|
||||
let numberOfStories = activeFeed.count
|
||||
let selectedIndex = min(numberOfStories - 1, 8)
|
||||
|
||||
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)
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
//
|
||||
|
||||
#import "NewsBlurAppDelegate.h"
|
||||
#import "NewsBlur-Swift.h"
|
||||
|
||||
@interface StoriesCollection : NSObject {
|
||||
NSDictionary * activeFeed;
|
||||
|
|
|
@ -10,7 +10,10 @@
|
|||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "NewsBlurAppDelegate.h"
|
||||
#import "ThemeManager.h"
|
||||
#import "StoriesCollection.h"
|
||||
#import "BaseViewController.h"
|
||||
#import "FeedsObjCViewController.h"
|
||||
#import "FeedDetailObjCViewController.h"
|
||||
#import "StoryPagesObjCViewController.h"
|
||||
|
|
Loading…
Add table
Reference in a new issue