fix: add missing home timeline bottom fetcher

This commit is contained in:
CMK 2022-02-10 16:43:26 +08:00
parent e7816f365f
commit c1e1d527fe
4 changed files with 24 additions and 102 deletions

View File

@ -100,7 +100,7 @@ extension HomeTimelineViewController {
self.view.backgroundColor = theme.secondarySystemBackgroundColor
}
.store(in: &disposeBag)
viewModel.displaySettingBarButtonItem
viewModel.$displaySettingBarButtonItem
.receive(on: DispatchQueue.main)
.sink { [weak self] displaySettingBarButtonItem in
guard let self = self else { return }
@ -125,7 +125,7 @@ extension HomeTimelineViewController {
settingBarButtonItem.action = #selector(HomeTimelineViewController.settingBarButtonItemPressed(_:))
#endif
viewModel.displayComposeBarButtonItem
viewModel.$displayComposeBarButtonItem
.receive(on: DispatchQueue.main)
.sink { [weak self] displayComposeBarButtonItem in
guard let self = self else { return }
@ -190,7 +190,18 @@ extension HomeTimelineViewController {
statusTableViewCellDelegate: self,
timelineMiddleLoaderTableViewCellDelegate: self
)
// setup batch fetch
viewModel.listBatchFetchViewModel.setup(scrollView: tableView)
viewModel.listBatchFetchViewModel.shouldFetch
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
guard let self = self else { return }
guard self.view.window != nil else { return }
self.viewModel.loadOldestStateMachine.enter(HomeTimelineViewModel.LoadOldestState.Loading.self)
}
.store(in: &disposeBag)
// bind refresh control
viewModel.didLoadLatest
.receive(on: DispatchQueue.main)
@ -282,10 +293,10 @@ extension HomeTimelineViewController {
viewModel.viewDidAppear.send()
if let timestamp = viewModel.lastAutomaticFetchTimestamp.value {
if let timestamp = viewModel.lastAutomaticFetchTimestamp {
let now = Date()
if now.timeIntervalSince(timestamp) > 60 {
self.viewModel.lastAutomaticFetchTimestamp.value = now
self.viewModel.lastAutomaticFetchTimestamp = now
self.viewModel.homeTimelineNeedRefresh.send()
} else {
// do nothing

View File

@ -26,13 +26,14 @@ final class HomeTimelineViewModel: NSObject {
// input
let context: AppContext
let fetchedResultsController: FeedFetchedResultsController
let timelinePredicate = CurrentValueSubject<NSPredicate?, Never>(nil)
let viewDidAppear = PassthroughSubject<Void, Never>()
let homeTimelineNavigationBarTitleViewModel: HomeTimelineNavigationBarTitleViewModel
let lastAutomaticFetchTimestamp = CurrentValueSubject<Date?, Never>(nil)
let listBatchFetchViewModel = ListBatchFetchViewModel()
let viewDidAppear = PassthroughSubject<Void, Never>()
@Published var lastAutomaticFetchTimestamp: Date? = nil
@Published var scrollPositionRecord: ScrollPositionRecord? = nil
let displaySettingBarButtonItem = CurrentValueSubject<Bool, Never>(true)
let displayComposeBarButtonItem = CurrentValueSubject<Bool, Never>(true)
@Published var displaySettingBarButtonItem = true
@Published var displayComposeBarButtonItem = true
weak var contentOffsetAdjustableTimelineViewControllerDelegate: ContentOffsetAdjustableTimelineViewControllerDelegate?
weak var tableView: UITableView?

View File

@ -92,13 +92,6 @@ extension UserTimelineViewController {
}
// MARK: - UIScrollViewDelegate
//extension UserTimelineViewController {
// func scrollViewDidScroll(_ scrollView: UIScrollView) {
// aspectScrollViewDidScroll(scrollView)
// }
//}
// MARK: - UITableViewDelegate
extension UserTimelineViewController: UITableViewDelegate, AutoGenerateTableViewDelegate {
// sourcery:inline:UserTimelineViewController.AutoGenerateTableViewDelegate
@ -126,96 +119,13 @@ extension UserTimelineViewController: UITableViewDelegate, AutoGenerateTableView
}
// sourcery:end
// func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
// aspectTableView(tableView, estimatedHeightForRowAt: indexPath)
// }
//
// func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
// aspectTableView(tableView, willDisplay: cell, forRowAt: indexPath)
// }
//
// func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
// aspectTableView(tableView, didEndDisplaying: cell, forRowAt: indexPath)
// }
//
// func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// aspectTableView(tableView, didSelectRowAt: indexPath)
// }
//
// func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
// return aspectTableView(tableView, contextMenuConfigurationForRowAt: indexPath, point: point)
// }
//
// func tableView(_ tableView: UITableView, previewForHighlightingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
// return aspectTableView(tableView, previewForHighlightingContextMenuWithConfiguration: configuration)
// }
//
// func tableView(_ tableView: UITableView, previewForDismissingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
// return aspectTableView(tableView, previewForDismissingContextMenuWithConfiguration: configuration)
// }
//
// func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
// aspectTableView(tableView, willPerformPreviewActionForMenuWith: configuration, animator: animator)
// }
}
//// MARK: - UITableViewDataSourcePrefetching
//extension UserTimelineViewController: UITableViewDataSourcePrefetching {
// func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
// aspectTableView(tableView, prefetchRowsAt: indexPaths)
// }
//}
// MARK: - AVPlayerViewControllerDelegate
//extension UserTimelineViewController: AVPlayerViewControllerDelegate {
//
// func playerViewController(_ playerViewController: AVPlayerViewController, willBeginFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
// aspectPlayerViewController(playerViewController, willBeginFullScreenPresentationWithAnimationCoordinator: coordinator)
// }
//
// func playerViewController(_ playerViewController: AVPlayerViewController, willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
// aspectPlayerViewController(playerViewController, willEndFullScreenPresentationWithAnimationCoordinator: coordinator)
// }
//
//}
// MARK: - TimelinePostTableViewCellDelegate
//extension UserTimelineViewController: StatusTableViewCellDelegate {
// weak var playerViewControllerDelegate: AVPlayerViewControllerDelegate? { return self }
// func parent() -> UIViewController { return self }
//}
// MARK: - CustomScrollViewContainerController
extension UserTimelineViewController: ScrollViewContainer {
var scrollView: UIScrollView { return tableView }
}
// MARK: - LoadMoreConfigurableTableViewContainer
//extension UserTimelineViewController: LoadMoreConfigurableTableViewContainer {
// typealias BottomLoaderTableViewCell = TimelineBottomLoaderTableViewCell
// typealias LoadingState = UserTimelineViewModel.State.Loading
//
// var loadMoreConfigurableTableView: UITable``````View { return tableView }
// var loadMoreConfigurableStateMachine: GKStateMachine { return viewModel.stateMachine }
//}
//extension UserTimelineViewController {
// override var keyCommands: [UIKeyCommand]? {
// return navigationKeyCommands + statusNavigationKeyCommands
// }
//}
//
//// MARK: - StatusTableViewControllerNavigateable
//extension UserTimelineViewController: StatusTableViewControllerNavigateable {
// @objc func navigateKeyCommandHandlerRelay(_ sender: UIKeyCommand) {
// navigateKeyCommandHandler(sender)
// }
//
// @objc func statusKeyCommandHandlerRelay(_ sender: UIKeyCommand) {
// statusKeyCommandHandler(sender)
// }
//}
// MARK: - StatusTableViewCellDelegate
extension UserTimelineViewController: StatusTableViewCellDelegate { }

View File

@ -38,8 +38,8 @@ final class ContentSplitViewController: UIViewController, NeedsDependency {
private(set) lazy var mainTabBarController: MainTabBarController = {
let mainTabBarController = MainTabBarController(context: context, coordinator: coordinator)
if let homeTimelineViewController = mainTabBarController.viewController(of: HomeTimelineViewController.self) {
homeTimelineViewController.viewModel.displayComposeBarButtonItem.value = false
homeTimelineViewController.viewModel.displaySettingBarButtonItem.value = false
homeTimelineViewController.viewModel.displayComposeBarButtonItem = false
homeTimelineViewController.viewModel.displaySettingBarButtonItem = false
}
return mainTabBarController
}()