2019-09-14 19:55:06 +00:00
|
|
|
|
//
|
|
|
|
|
// TimelinesPageViewController.swift
|
|
|
|
|
// Tusker
|
|
|
|
|
//
|
|
|
|
|
// Created by Shadowfacts on 9/14/19.
|
|
|
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
2022-12-03 02:40:14 +00:00
|
|
|
|
import SwiftUI
|
2019-09-14 19:55:06 +00:00
|
|
|
|
|
2022-12-13 01:57:38 +00:00
|
|
|
|
class TimelinesPageViewController: SegmentedPageViewController<TimelinesPageViewController.Page> {
|
2019-09-14 19:55:06 +00:00
|
|
|
|
|
|
|
|
|
private let homeTitle = NSLocalizedString("Home", comment: "home timeline tab title")
|
|
|
|
|
private let federatedTitle = NSLocalizedString("Federated", comment: "federated timeline tab title")
|
|
|
|
|
private let localTitle = NSLocalizedString("Local", comment: "local timeline tab title")
|
|
|
|
|
|
2020-01-20 04:02:07 +00:00
|
|
|
|
weak var mastodonController: MastodonController!
|
2020-01-05 20:25:07 +00:00
|
|
|
|
|
|
|
|
|
init(mastodonController: MastodonController) {
|
|
|
|
|
self.mastodonController = mastodonController
|
|
|
|
|
|
2022-09-24 14:49:06 +00:00
|
|
|
|
let home = TimelineViewController(for: .home, mastodonController: mastodonController)
|
2019-09-14 19:55:06 +00:00
|
|
|
|
home.title = homeTitle
|
2022-12-13 16:35:09 +00:00
|
|
|
|
home.persistsState = true
|
2019-09-14 19:55:06 +00:00
|
|
|
|
|
2022-10-01 19:32:06 +00:00
|
|
|
|
let federated = TimelineViewController(for: .public(local: false), mastodonController: mastodonController)
|
2019-09-14 19:55:06 +00:00
|
|
|
|
federated.title = federatedTitle
|
2022-12-13 16:35:09 +00:00
|
|
|
|
federated.persistsState = true
|
2019-09-14 19:55:06 +00:00
|
|
|
|
|
2022-10-01 19:32:06 +00:00
|
|
|
|
let local = TimelineViewController(for: .public(local: true), mastodonController: mastodonController)
|
2019-09-14 19:55:06 +00:00
|
|
|
|
local.title = localTitle
|
2022-12-13 16:35:09 +00:00
|
|
|
|
local.persistsState = true
|
2019-09-14 19:55:06 +00:00
|
|
|
|
|
2022-12-13 01:57:38 +00:00
|
|
|
|
super.init(pages: [
|
|
|
|
|
(.home, "Home", home),
|
|
|
|
|
(.local, "Local", local),
|
|
|
|
|
(.federated, "Federated", federated),
|
2019-09-14 19:55:06 +00:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
title = homeTitle
|
|
|
|
|
tabBarItem.image = UIImage(systemName: "house.fill")
|
2022-12-03 02:40:14 +00:00
|
|
|
|
|
|
|
|
|
let filtersItem = UIBarButtonItem(image: UIImage(systemName: "line.3.horizontal.decrease.circle"), style: .plain, target: self, action: #selector(filtersPressed))
|
|
|
|
|
filtersItem.accessibilityLabel = "Filters"
|
|
|
|
|
navigationItem.leftBarButtonItem = filtersItem
|
2022-12-05 22:13:45 +00:00
|
|
|
|
|
|
|
|
|
let jumpToPresentName = NSMutableAttributedString("Jump to Present")
|
|
|
|
|
// otherwise it pronounces it as 'pɹizˈənt'
|
|
|
|
|
// its IPA is also bad, this should be an alveolar approximant not a trill
|
|
|
|
|
jumpToPresentName.addAttribute(.accessibilitySpeechIPANotation, value: "ˈprɛ.zənt", range: NSRange(location: "Jump to ".count, length: "Present".count))
|
|
|
|
|
segmentedControl.accessibilityCustomActions = [
|
|
|
|
|
UIAccessibilityCustomAction(attributedName: jumpToPresentName, actionHandler: { [unowned self] _ in
|
|
|
|
|
guard let vc = pageControllers[currentIndex] as? TimelineViewController else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
Task {
|
|
|
|
|
await vc.checkPresent(jumpImmediately: true)
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
})
|
|
|
|
|
]
|
2019-09-14 19:55:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
|
}
|
2022-11-23 16:35:25 +00:00
|
|
|
|
|
2022-11-28 21:33:19 +00:00
|
|
|
|
func stateRestorationActivity() -> NSUserActivity? {
|
|
|
|
|
return (pageControllers[currentIndex] as! TimelineViewController).stateRestorationActivity()
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 16:35:25 +00:00
|
|
|
|
func restoreActivity(_ activity: NSUserActivity) {
|
|
|
|
|
guard let timeline = UserActivityManager.getTimeline(from: activity) else {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-12-13 01:57:38 +00:00
|
|
|
|
let page: Page
|
2022-11-23 16:35:25 +00:00
|
|
|
|
switch timeline {
|
|
|
|
|
case .home:
|
2022-12-13 01:57:38 +00:00
|
|
|
|
page = .home
|
2022-11-23 16:35:25 +00:00
|
|
|
|
case .public(local: false):
|
2022-12-13 01:57:38 +00:00
|
|
|
|
page = .federated
|
2022-11-23 16:35:25 +00:00
|
|
|
|
case .public(local: true):
|
2022-12-13 01:57:38 +00:00
|
|
|
|
page = .local
|
2022-11-23 16:35:25 +00:00
|
|
|
|
default:
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-12-13 01:57:38 +00:00
|
|
|
|
selectPage(page, animated: false)
|
2022-11-23 16:35:25 +00:00
|
|
|
|
}
|
2022-12-03 02:40:14 +00:00
|
|
|
|
|
|
|
|
|
@objc private func filtersPressed() {
|
|
|
|
|
present(UIHostingController(rootView: FiltersView(mastodonController: mastodonController)), animated: true)
|
|
|
|
|
}
|
2022-12-13 01:57:38 +00:00
|
|
|
|
|
|
|
|
|
enum Page: Hashable {
|
|
|
|
|
case home
|
|
|
|
|
case local
|
|
|
|
|
case federated
|
|
|
|
|
}
|
2019-09-14 19:55:06 +00:00
|
|
|
|
|
|
|
|
|
}
|