mirror of
https://github.com/metabolist/metatext.git
synced 2025-01-05 03:28:41 +00:00
Refresh modifications
This commit is contained in:
parent
08d4e43ddb
commit
6800055ced
2 changed files with 17 additions and 3 deletions
|
@ -96,6 +96,10 @@ final class NewStatusViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension NewStatusViewController {
|
||||||
|
static let newStatusPostedNotification = Notification.Name("com.metabolist.metatext.new-status-posted-notification")
|
||||||
|
}
|
||||||
|
|
||||||
extension NewStatusViewController: PHPickerViewControllerDelegate {
|
extension NewStatusViewController: PHPickerViewControllerDelegate {
|
||||||
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
|
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
|
||||||
mediaSelections.send(results)
|
mediaSelections.send(results)
|
||||||
|
@ -169,6 +173,7 @@ private extension NewStatusViewController {
|
||||||
stackView.isUserInteractionEnabled = false
|
stackView.isUserInteractionEnabled = false
|
||||||
stackView.alpha = 0.5
|
stackView.alpha = 0.5
|
||||||
case .done:
|
case .done:
|
||||||
|
NotificationCenter.default.post(.init(name: Self.newStatusPostedNotification))
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class TableViewController: UITableViewController {
|
||||||
refreshControl = UIRefreshControl()
|
refreshControl = UIRefreshControl()
|
||||||
refreshControl?.addAction(
|
refreshControl?.addAction(
|
||||||
UIAction { [weak self] _ in
|
UIAction { [weak self] _ in
|
||||||
self?.viewModel.request(maxId: nil, minId: nil, search: nil) },
|
self?.refreshIfAble() },
|
||||||
for: .valueChanged)
|
for: .valueChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,12 +69,14 @@ class TableViewController: UITableViewController {
|
||||||
])
|
])
|
||||||
|
|
||||||
setupViewModelBindings()
|
setupViewModelBindings()
|
||||||
|
|
||||||
|
viewModel.request(maxId: nil, minId: nil, search: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
|
|
||||||
viewModel.request(maxId: nil, minId: nil, search: nil)
|
refreshIfAble()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||||
|
@ -289,7 +291,8 @@ private extension TableViewController {
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
NotificationCenter.default.publisher(for: UIScene.willEnterForegroundNotification)
|
NotificationCenter.default.publisher(for: UIScene.willEnterForegroundNotification)
|
||||||
.sink { [weak self] _ in self?.viewModel.request(maxId: nil, minId: nil, search: nil) }
|
.merge(with: NotificationCenter.default.publisher(for: NewStatusViewController.newStatusPostedNotification))
|
||||||
|
.sink { [weak self] _ in self?.refreshIfAble() }
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,5 +495,11 @@ private extension TableViewController {
|
||||||
|
|
||||||
present(activityViewController, animated: true, completion: nil)
|
present(activityViewController, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refreshIfAble() {
|
||||||
|
if viewModel.canRefresh {
|
||||||
|
viewModel.request(maxId: nil, minId: nil, search: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// swiftlint:enable file_length
|
// swiftlint:enable file_length
|
||||||
|
|
Loading…
Reference in a new issue