Add my account tab
This commit is contained in:
parent
2251d82574
commit
2afc7ce703
|
@ -54,11 +54,16 @@ class MastodonController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOwnAccount() {
|
func getOwnAccount(completion: ((Account) -> Void)? = nil) {
|
||||||
let request = client.getSelfAccount()
|
if account != nil {
|
||||||
client.run(request) { response in
|
completion?(account)
|
||||||
guard case let .success(account, _) = response else { fatalError() }
|
} else {
|
||||||
self.account = account
|
let request = client.getSelfAccount()
|
||||||
|
client.run(request) { response in
|
||||||
|
guard case let .success(account, _) = response else { fatalError() }
|
||||||
|
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,29 +55,33 @@ 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 MastodonCache.account(for: accountID) != nil {
|
if let accountID = accountID {
|
||||||
updateAccountUI()
|
if MastodonCache.account(for: accountID) != nil {
|
||||||
} else {
|
updateAccountUI()
|
||||||
let loadingVC = LoadingViewController()
|
} else {
|
||||||
add(loadingVC)
|
loadingVC = LoadingViewController()
|
||||||
MastodonCache.account(for: accountID) { (account) in
|
add(loadingVC!)
|
||||||
guard account != nil else {
|
MastodonCache.account(for: accountID) { (account) in
|
||||||
let alert = UIAlertController(title: "Something Went Wrong", message: "Couldn't load the selected account", preferredStyle: .alert)
|
guard account != nil else {
|
||||||
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in
|
let alert = UIAlertController(title: "Something Went Wrong", message: "Couldn't load the selected account", preferredStyle: .alert)
|
||||||
self.navigationController!.popViewController(animated: true)
|
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in
|
||||||
}))
|
self.navigationController!.popViewController(animated: true)
|
||||||
DispatchQueue.main.async {
|
}))
|
||||||
self.present(alert, animated: true)
|
DispatchQueue.main.async {
|
||||||
|
self.present(alert, animated: true)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.updateAccountUI()
|
||||||
|
self.tableView.reloadData()
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
loadingVC.remove()
|
|
||||||
self.updateAccountUI()
|
|
||||||
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