Add my account tab
This commit is contained in:
parent
57cbebecbd
commit
05e747a6f4
|
@ -54,11 +54,16 @@ class MastodonController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOwnAccount() {
|
func getOwnAccount(completion: ((Account) -> Void)? = nil) {
|
||||||
|
if account != nil {
|
||||||
|
completion?(account)
|
||||||
|
} else {
|
||||||
let request = client.getSelfAccount()
|
let request = client.getSelfAccount()
|
||||||
client.run(request) { response in
|
client.run(request) { response in
|
||||||
guard case let .success(account, _) = response else { fatalError() }
|
guard case let .success(account, _) = response else { fatalError() }
|
||||||
self.account = account
|
self.account = account
|
||||||
|
completion?(account)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,31 @@ class MainTabBarViewController: UITabBarController {
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
let home = TimelineTableViewController.create(for: .home)
|
||||||
|
|
||||||
|
let federated = TimelineTableViewController.create(for: .public(local: false))
|
||||||
|
|
||||||
|
let local = TimelineTableViewController.create(for: .public(local: true))
|
||||||
|
|
||||||
|
let ownProfile = ProfileTableViewController.createForPending()
|
||||||
|
ownProfile.title = "My Profile"
|
||||||
|
|
||||||
|
let notifications = NotificationsTableViewController.create()
|
||||||
|
|
||||||
|
let preferences = PreferencesTableViewController.create()
|
||||||
|
|
||||||
viewControllers = [
|
viewControllers = [
|
||||||
navigationController(for: TimelineTableViewController.create(for: .home)),
|
navigationController(for: home),
|
||||||
navigationController(for: TimelineTableViewController.create(for: .public(local: false))),
|
navigationController(for: federated),
|
||||||
navigationController(for: TimelineTableViewController.create(for: .public(local: true))),
|
navigationController(for: local),
|
||||||
NotificationsTableViewController.create(),
|
navigationController(for: ownProfile),
|
||||||
PreferencesTableViewController.create()
|
notifications,
|
||||||
|
preferences
|
||||||
]
|
]
|
||||||
|
|
||||||
|
MastodonController.shared.getOwnAccount { (account) in
|
||||||
|
ownProfile.accountID = account.id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func navigationController(for vc: UIViewController) -> UINavigationController {
|
func navigationController(for vc: UIViewController) -> UINavigationController {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import Pachyderm
|
||||||
|
|
||||||
class NotificationsTableViewController: UITableViewController {
|
class NotificationsTableViewController: UITableViewController {
|
||||||
|
|
||||||
static func create() -> UIViewController {
|
static func create() -> UINavigationController {
|
||||||
guard let navigationController = UIStoryboard(name: "Notifications", bundle: nil).instantiateInitialViewController() as? UINavigationController else { fatalError() }
|
guard let navigationController = UIStoryboard(name: "Notifications", bundle: nil).instantiateInitialViewController() as? UINavigationController else { fatalError() }
|
||||||
return navigationController
|
return navigationController
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import UIKit
|
||||||
|
|
||||||
class PreferencesTableViewController: UITableViewController {
|
class PreferencesTableViewController: UITableViewController {
|
||||||
|
|
||||||
static func create() -> UIViewController {
|
static func create() -> UINavigationController {
|
||||||
guard let navigationController = UIStoryboard(name: "Preferences", bundle: nil).instantiateInitialViewController() as? UINavigationController else { fatalError() }
|
guard let navigationController = UIStoryboard(name: "Preferences", bundle: nil).instantiateInitialViewController() as? UINavigationController else { fatalError() }
|
||||||
return navigationController
|
return navigationController
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,25 @@ import SafariServices
|
||||||
|
|
||||||
class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
|
class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
|
||||||
|
|
||||||
static func create(for accountID: String) -> UIViewController {
|
static func create(for accountID: String) -> ProfileTableViewController {
|
||||||
guard let profileController = UIStoryboard(name: "Profile", bundle: nil).instantiateInitialViewController() as? ProfileTableViewController else { fatalError() }
|
guard let profileController = UIStoryboard(name: "Profile", bundle: nil).instantiateInitialViewController() as? ProfileTableViewController else { fatalError() }
|
||||||
profileController.accountID = accountID
|
profileController.accountID = accountID
|
||||||
return profileController
|
return profileController
|
||||||
}
|
}
|
||||||
|
|
||||||
var accountID: String!
|
static func createForPending() -> ProfileTableViewController {
|
||||||
|
guard let profileController = UIStoryboard(name: "Profile", bundle: nil).instantiateInitialViewController() as? ProfileTableViewController else { fatalError() }
|
||||||
|
profileController.accountID = nil
|
||||||
|
return profileController
|
||||||
|
}
|
||||||
|
|
||||||
|
var accountID: String! {
|
||||||
|
didSet {
|
||||||
|
if shouldLoadOnAccountIDSet {
|
||||||
|
updateAccountUI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var statusIDs: [String] = [] {
|
var statusIDs: [String] = [] {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -31,6 +43,9 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
|
||||||
var older: RequestRange?
|
var older: RequestRange?
|
||||||
var newer: RequestRange?
|
var newer: RequestRange?
|
||||||
|
|
||||||
|
var shouldLoadOnAccountIDSet = false
|
||||||
|
var loadingVC: LoadingViewController? = nil
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
@ -40,11 +55,12 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
|
||||||
tableView.register(UINib(nibName: "StatusTableViewCell", bundle: nil), forCellReuseIdentifier: "statusCell")
|
tableView.register(UINib(nibName: "StatusTableViewCell", bundle: nil), forCellReuseIdentifier: "statusCell")
|
||||||
tableView.register(UINib(nibName: "ProfileHeaderTableViewCell", bundle: nil), forCellReuseIdentifier: "headerCell")
|
tableView.register(UINib(nibName: "ProfileHeaderTableViewCell", bundle: nil), forCellReuseIdentifier: "headerCell")
|
||||||
|
|
||||||
|
if let accountID = accountID {
|
||||||
if MastodonCache.account(for: accountID) != nil {
|
if MastodonCache.account(for: accountID) != nil {
|
||||||
updateAccountUI()
|
updateAccountUI()
|
||||||
} else {
|
} else {
|
||||||
let loadingVC = LoadingViewController()
|
loadingVC = LoadingViewController()
|
||||||
add(loadingVC)
|
add(loadingVC!)
|
||||||
MastodonCache.account(for: accountID) { (account) in
|
MastodonCache.account(for: accountID) { (account) in
|
||||||
guard account != nil else {
|
guard account != nil else {
|
||||||
let alert = UIAlertController(title: "Something Went Wrong", message: "Couldn't load the selected account", preferredStyle: .alert)
|
let alert = UIAlertController(title: "Something Went Wrong", message: "Couldn't load the selected account", preferredStyle: .alert)
|
||||||
|
@ -57,12 +73,15 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
loadingVC.remove()
|
|
||||||
self.updateAccountUI()
|
self.updateAccountUI()
|
||||||
self.tableView.reloadData()
|
self.tableView.reloadData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loadingVC = LoadingViewController()
|
||||||
|
add(loadingVC!)
|
||||||
|
shouldLoadOnAccountIDSet = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +100,8 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateAccountUI() {
|
func updateAccountUI() {
|
||||||
|
loadingVC?.remove()
|
||||||
|
|
||||||
updateUIForPreferences()
|
updateUIForPreferences()
|
||||||
|
|
||||||
getStatuses() { response in
|
getStatuses() { response in
|
||||||
|
@ -127,7 +148,7 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
switch section {
|
switch section {
|
||||||
case 0:
|
case 0:
|
||||||
return MastodonCache.account(for: accountID) == nil ? 0 : 1
|
return accountID == nil || MastodonCache.account(for: accountID) == nil ? 0 : 1
|
||||||
case 1:
|
case 1:
|
||||||
return statusIDs.count
|
return statusIDs.count
|
||||||
default:
|
default:
|
||||||
|
@ -201,7 +222,6 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
|
||||||
|
|
||||||
extension ProfileTableViewController: StatusTableViewCellDelegate {}
|
extension ProfileTableViewController: StatusTableViewCellDelegate {}
|
||||||
extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate {
|
extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate {
|
||||||
|
|
||||||
func showMoreOptions() {
|
func showMoreOptions() {
|
||||||
let account = MastodonCache.account(for: accountID)!
|
let account = MastodonCache.account(for: accountID)!
|
||||||
|
|
||||||
|
@ -245,6 +265,5 @@ extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
extension ProfileTableViewController: LargeImageViewControllerDelegate {}
|
extension ProfileTableViewController: LargeImageViewControllerDelegate {}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import Pachyderm
|
||||||
|
|
||||||
class TimelineTableViewController: UITableViewController {
|
class TimelineTableViewController: UITableViewController {
|
||||||
|
|
||||||
static func create(for timeline: Timeline) -> UIViewController {
|
static func create(for timeline: Timeline) -> TimelineTableViewController {
|
||||||
guard let timelineController = UIStoryboard(name: "Timeline", bundle: nil).instantiateInitialViewController() as? TimelineTableViewController else { fatalError() }
|
guard let timelineController = UIStoryboard(name: "Timeline", bundle: nil).instantiateInitialViewController() as? TimelineTableViewController else { fatalError() }
|
||||||
timelineController.timeline = timeline
|
timelineController.timeline = timeline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue