2021-04-01 08:39:15 +02:00
|
|
|
//
|
|
|
|
// ProfilePagingViewModel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-29.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
|
|
|
import Pageboy
|
|
|
|
import Tabman
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
|
|
|
import MastodonLocalization
|
2021-04-01 08:39:15 +02:00
|
|
|
|
|
|
|
final class ProfilePagingViewModel: NSObject {
|
|
|
|
|
|
|
|
let postUserTimelineViewController = UserTimelineViewController()
|
|
|
|
let repliesUserTimelineViewController = UserTimelineViewController()
|
|
|
|
let mediaUserTimelineViewController = UserTimelineViewController()
|
2022-01-27 14:23:39 +01:00
|
|
|
let profileAboutViewController = ProfileAboutViewController()
|
2021-04-01 08:39:15 +02:00
|
|
|
|
|
|
|
init(
|
|
|
|
postsUserTimelineViewModel: UserTimelineViewModel,
|
|
|
|
repliesUserTimelineViewModel: UserTimelineViewModel,
|
2022-01-27 14:23:39 +01:00
|
|
|
mediaUserTimelineViewModel: UserTimelineViewModel,
|
|
|
|
profileAboutViewModel: ProfileAboutViewModel
|
2021-04-01 08:39:15 +02:00
|
|
|
) {
|
|
|
|
postUserTimelineViewController.viewModel = postsUserTimelineViewModel
|
|
|
|
repliesUserTimelineViewController.viewModel = repliesUserTimelineViewModel
|
|
|
|
mediaUserTimelineViewController.viewModel = mediaUserTimelineViewModel
|
2022-01-27 14:23:39 +01:00
|
|
|
profileAboutViewController.viewModel = profileAboutViewModel
|
2021-04-01 08:39:15 +02:00
|
|
|
super.init()
|
|
|
|
}
|
|
|
|
|
|
|
|
var viewControllers: [ScrollViewContainer] {
|
|
|
|
return [
|
|
|
|
postUserTimelineViewController,
|
|
|
|
repliesUserTimelineViewController,
|
|
|
|
mediaUserTimelineViewController,
|
2022-01-27 14:23:39 +01:00
|
|
|
profileAboutViewController,
|
2021-04-01 08:39:15 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
let barItems: [TMBarItemable] = {
|
|
|
|
let items = [
|
|
|
|
TMBarItem(title: L10n.Scene.Profile.SegmentedControl.posts),
|
2022-02-15 07:45:34 +01:00
|
|
|
TMBarItem(title: L10n.Scene.Profile.SegmentedControl.postsAndReplies), // TODO: i18n
|
2021-04-01 08:39:15 +02:00
|
|
|
TMBarItem(title: L10n.Scene.Profile.SegmentedControl.media),
|
2022-02-15 07:45:34 +01:00
|
|
|
TMBarItem(title: L10n.Scene.Profile.SegmentedControl.about),
|
2021-04-01 08:39:15 +02:00
|
|
|
]
|
|
|
|
return items
|
|
|
|
}()
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
os_log("%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - PageboyViewControllerDataSource
|
|
|
|
extension ProfilePagingViewModel: PageboyViewControllerDataSource {
|
|
|
|
|
|
|
|
func numberOfViewControllers(in pageboyViewController: PageboyViewController) -> Int {
|
|
|
|
return viewControllers.count
|
|
|
|
}
|
|
|
|
|
|
|
|
func viewController(for pageboyViewController: PageboyViewController, at index: PageboyViewController.PageIndex) -> UIViewController? {
|
|
|
|
return viewControllers[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyViewController.Page? {
|
|
|
|
return .first
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-01-27 14:23:39 +01:00
|
|
|
|
|
|
|
// MARK: - TMBarDataSource
|
|
|
|
extension ProfilePagingViewModel: TMBarDataSource {
|
|
|
|
func barItem(for bar: TMBar, at index: Int) -> TMBarItemable {
|
|
|
|
return barItems[index]
|
|
|
|
}
|
|
|
|
}
|