75 lines
2.4 KiB
Swift
75 lines
2.4 KiB
Swift
//
|
|
// MainTabBarViewController.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfactson 8/21/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class MainTabBarViewController: UITabBarController {
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
updateTabs(animated: false)
|
|
}
|
|
|
|
func updateTabs(animated: Bool) {
|
|
let currentTabs = Preferences.shared.tabs.filter { $1 >= 0 }.sorted { $1.1 > $0.1 }.map { $0.key }
|
|
let viewControllers: [UIViewController] = currentTabs.map { (tab) in
|
|
if tab == .preferences, let preferences = selectedViewController {
|
|
return preferences
|
|
} else {
|
|
return embedInNavigationController(createVC(for: tab))
|
|
}
|
|
}
|
|
setViewControllers(viewControllers, animated: animated)
|
|
}
|
|
|
|
func createVC(for tab: Tab) -> UIViewController {
|
|
switch tab {
|
|
case .home:
|
|
return TimelineTableViewController.create(for: .home)
|
|
case .federated:
|
|
return TimelineTableViewController.create(for: .public(local: false))
|
|
case .local:
|
|
return TimelineTableViewController.create(for: .public(local: true))
|
|
case .myProfile:
|
|
let myProfile = ProfileTableViewController.createForPending()
|
|
myProfile.title = "My Profile"
|
|
MastodonController.getOwnAccount { (account) in
|
|
myProfile.accountID = account.id
|
|
}
|
|
return myProfile
|
|
case .notifications:
|
|
return NotificationsTableViewController.create()
|
|
case .preferences:
|
|
return PreferencesTableViewController.create()
|
|
}
|
|
}
|
|
|
|
func embedInNavigationController(_ vc: UIViewController) -> UINavigationController {
|
|
if let vc = vc as? UINavigationController {
|
|
return vc
|
|
} else {
|
|
return UINavigationController(rootViewController: vc)
|
|
}
|
|
}
|
|
|
|
/*
|
|
// MARK: - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
// Get the new view controller using segue.destination.
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
*/
|
|
|
|
@IBAction func unwindToTabBarController(segue: UIStoryboardSegue) {
|
|
}
|
|
|
|
}
|