A WIP iOS app for Mastodon and Pleroma.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

//
// MainTabBarViewController.swift
// Tusker
//
// Created by Shadowfactson 8/21/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
class MainTabBarViewController: UITabBarController {
lazy var router = AppRouter(root: self)
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(for: .home, router: router)
case .federated:
return TimelineTableViewController(for: .public(local: false), router: router)
case .local:
return TimelineTableViewController(for: .public(local: true), router: router)
case .myProfile:
let myProfile = ProfileTableViewController(accountID: nil, router: router)
myProfile.title = "My Profile"
MastodonController.getOwnAccount { (account) in
myProfile.accountID = account.id
}
return myProfile
case .notifications:
return NotificationsTableViewController(router: router)
case .preferences:
return PreferencesTableViewController.create()
}
}
func embedInNavigationController(_ vc: UIViewController) -> UINavigationController {
if let vc = vc as? UINavigationController {
return vc
} else {
return UINavigationController(rootViewController: vc)
}
}
}