2021-04-12 10:31:53 +02:00
|
|
|
//
|
|
|
|
// NotificationViewModel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/12.
|
|
|
|
//
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
import os.log
|
2021-04-15 04:16:30 +02:00
|
|
|
import UIKit
|
2022-01-27 14:23:39 +01:00
|
|
|
import Combine
|
2022-10-08 07:43:06 +02:00
|
|
|
import Pageboy
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonLocalization
|
2021-04-12 10:31:53 +02:00
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
final class NotificationViewModel {
|
|
|
|
|
2021-04-12 10:31:53 +02:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
// input
|
|
|
|
let context: AppContext
|
2022-10-09 14:07:57 +02:00
|
|
|
let authContext: AuthContext
|
2021-04-13 15:31:49 +02:00
|
|
|
let viewDidLoad = PassthroughSubject<Void, Never>()
|
2021-04-12 10:31:53 +02:00
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
// output
|
|
|
|
let scopes = NotificationTimelineViewModel.Scope.allCases
|
|
|
|
@Published var viewControllers: [UIViewController] = []
|
|
|
|
@Published var currentPageIndex = 0
|
2021-04-15 04:16:30 +02:00
|
|
|
|
2021-04-14 13:04:11 +02:00
|
|
|
|
2022-10-09 14:07:57 +02:00
|
|
|
init(context: AppContext, authContext: AuthContext) {
|
2021-04-12 10:31:53 +02:00
|
|
|
self.context = context
|
2022-10-09 14:07:57 +02:00
|
|
|
self.authContext = authContext
|
2022-01-27 14:23:39 +01:00
|
|
|
// end init
|
2021-04-27 10:54:23 +02:00
|
|
|
}
|
2022-01-27 14:23:39 +01:00
|
|
|
}
|
2021-04-27 10:54:23 +02:00
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
extension NotificationTimelineViewModel.Scope {
|
|
|
|
var title: String {
|
|
|
|
switch self {
|
|
|
|
case .everything:
|
|
|
|
return L10n.Scene.Notification.Title.everything
|
|
|
|
case .mentions:
|
|
|
|
return L10n.Scene.Notification.Title.mentions
|
|
|
|
}
|
2021-04-27 10:54:23 +02:00
|
|
|
}
|
2021-04-12 10:31:53 +02:00
|
|
|
}
|
2021-04-16 07:45:54 +02:00
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
// MARK: - PageboyViewControllerDataSource
|
|
|
|
extension NotificationViewModel: PageboyViewControllerDataSource {
|
|
|
|
|
|
|
|
func numberOfViewControllers(in pageboyViewController: PageboyViewController) -> Int {
|
|
|
|
return viewControllers.count
|
2021-04-16 07:45:54 +02:00
|
|
|
}
|
2022-01-27 14:23:39 +01:00
|
|
|
|
|
|
|
func viewController(for pageboyViewController: PageboyViewController, at index: PageboyViewController.PageIndex) -> UIViewController? {
|
|
|
|
return viewControllers[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyViewController.Page? {
|
|
|
|
return .first
|
|
|
|
}
|
|
|
|
|
2021-04-16 07:45:54 +02:00
|
|
|
}
|
2022-01-27 14:23:39 +01:00
|
|
|
|