Compare commits
No commits in common. "863867c5226b650ec140be3dc6b4252ac83be719" and "66fe86144286df9ba050be4bf0bfde1ec9d65dff" have entirely different histories.
863867c522
...
66fe861442
|
@ -51,7 +51,7 @@ public extension InstanceSelector {
|
|||
public let description: String
|
||||
public let proxiedThumbnailURL: URL
|
||||
public let language: String
|
||||
public let category: String
|
||||
public let category: Category
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case domain
|
||||
|
@ -62,3 +62,20 @@ public extension InstanceSelector {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension InstanceSelector {
|
||||
enum Category: String, Codable {
|
||||
// source: https://source.joinmastodon.org/mastodon/joinmastodon/blob/master/src/Wizard.js#L108
|
||||
case general
|
||||
case regional
|
||||
case art
|
||||
case journalism
|
||||
case activism
|
||||
case lgbt
|
||||
case games
|
||||
case tech
|
||||
case adult
|
||||
case furry
|
||||
case food
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,8 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
class LocalData: ObservableObject {
|
||||
class LocalData {
|
||||
|
||||
static let shared = LocalData()
|
||||
|
||||
|
@ -53,7 +52,6 @@ class LocalData: ObservableObject {
|
|||
}
|
||||
}
|
||||
set {
|
||||
objectWillChange.send()
|
||||
let array = newValue.map { (info) in
|
||||
return [
|
||||
"instanceURL": info.instanceURL.absoluteString,
|
||||
|
@ -73,7 +71,6 @@ class LocalData: ObservableObject {
|
|||
return defaults.string(forKey: mostRecentAccountKey)
|
||||
}
|
||||
set {
|
||||
objectWillChange.send()
|
||||
defaults.set(newValue, forKey: mostRecentAccountKey)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
|
||||
var window: UIWindow?
|
||||
|
||||
// let mastodonController = MastodonController.shared
|
||||
|
||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
||||
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
|
||||
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
|
||||
|
@ -109,12 +111,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
DraftsManager.save()
|
||||
}
|
||||
|
||||
func activateAccount(_ account: LocalData.UserAccountInfo) {
|
||||
LocalData.shared.mostRecentAccount = account.accessToken
|
||||
window!.windowScene!.session.mastodonController = MastodonController.getForAccount(account)
|
||||
showAppUI()
|
||||
}
|
||||
|
||||
func showAppUI() {
|
||||
let mastodonController = window!.windowScene!.session.mastodonController!
|
||||
mastodonController.getOwnAccount()
|
||||
|
@ -142,6 +138,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
|
||||
extension SceneDelegate: OnboardingViewControllerDelegate {
|
||||
func didFinishOnboarding(account: LocalData.UserAccountInfo) {
|
||||
activateAccount(account)
|
||||
LocalData.shared.mostRecentAccount = account.accessToken
|
||||
window!.windowScene!.session.mastodonController = MastodonController.getForAccount(account)
|
||||
showAppUI()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import SwiftUI
|
|||
class PreferencesNavigationController: UINavigationController {
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
let view = PreferencesView()
|
||||
let view = PreferencesView(currentAccount: mastodonController.accountInfo!)
|
||||
let hostingController = UIHostingController(rootView: view)
|
||||
super.init(rootViewController: hostingController)
|
||||
hostingController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
|
||||
|
@ -21,13 +21,6 @@ class PreferencesNavigationController: UINavigationController {
|
|||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(showAddAccount), name: .addAccount, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(activateAccount(_:)), name: .activateAccount, object: nil)
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
|
@ -39,35 +32,5 @@ class PreferencesNavigationController: UINavigationController {
|
|||
@objc func donePressed() {
|
||||
dismiss(animated: true)
|
||||
}
|
||||
|
||||
@objc func showAddAccount() {
|
||||
let onboardingController = OnboardingViewController()
|
||||
onboardingController.onboardingDelegate = self
|
||||
onboardingController.instanceSelector.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelAddAccount))
|
||||
show(onboardingController, sender: self)
|
||||
}
|
||||
|
||||
@objc func cancelAddAccount() {
|
||||
dismiss(animated: true)
|
||||
}
|
||||
|
||||
@objc func activateAccount(_ notification: Notification) {
|
||||
let account = notification.userInfo!["account"] as! LocalData.UserAccountInfo
|
||||
let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate
|
||||
dismiss(animated: true) {
|
||||
sceneDelegate.activateAccount(account)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Notification.Name {
|
||||
static let addAccount = Notification.Name("Tusker.addAccount")
|
||||
static let activateAccount = Notification.Name("Tusker.activateAccount")
|
||||
}
|
||||
|
||||
extension PreferencesNavigationController: OnboardingViewControllerDelegate {
|
||||
func didFinishOnboarding(account: LocalData.UserAccountInfo) {
|
||||
LocalData.shared.mostRecentAccount = account.accessToken
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
import SwiftUI
|
||||
|
||||
struct PreferencesView: View {
|
||||
@ObservedObject var localData = LocalData.shared
|
||||
struct PreferencesView : View {
|
||||
var currentAccount: LocalData.UserAccountInfo
|
||||
@State private var showingLogoutConfirmation = false
|
||||
|
||||
var body: some View {
|
||||
|
@ -16,35 +16,12 @@ struct PreferencesView: View {
|
|||
// NavigationView {
|
||||
List {
|
||||
Section {
|
||||
ForEach(localData.accounts, id: \.accessToken) { (account) in
|
||||
Button(action: {
|
||||
NotificationCenter.default.post(name: .activateAccount, object: nil, userInfo: ["account": account])
|
||||
}) {
|
||||
HStack {
|
||||
Text(account.username)
|
||||
.foregroundColor(.primary)
|
||||
Spacer()
|
||||
if account.accessToken == self.localData.mostRecentAccount {
|
||||
Image(systemName: "checkmark")
|
||||
.renderingMode(.template)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Button(action: {
|
||||
NotificationCenter.default.post(name: .addAccount, object: nil)
|
||||
self.showingLogoutConfirmation = true
|
||||
}) {
|
||||
Text("Add Account...")
|
||||
}
|
||||
if localData.mostRecentAccount != nil {
|
||||
Button(action: {
|
||||
self.showingLogoutConfirmation = true
|
||||
}) {
|
||||
Text("Logout from current")
|
||||
}.alert(isPresented: $showingLogoutConfirmation) {
|
||||
Alert(title: Text("Are you sure you want to logout?"), message: nil, primaryButton: .destructive(Text("Logout"), action: self.logoutPressed), secondaryButton: .cancel())
|
||||
}
|
||||
Text("Logout")
|
||||
}.alert(isPresented: $showingLogoutConfirmation) {
|
||||
Alert(title: Text("Are you sure you want to logout?"), message: nil, primaryButton: .destructive(Text("Logout"), action: self.logoutPressed), secondaryButton: .cancel())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,8 +50,7 @@ struct PreferencesView: View {
|
|||
}
|
||||
|
||||
func logoutPressed() {
|
||||
// LocalData.shared.removeAccount(currentAccount)
|
||||
localData.removeAccount(localData.getMostRecentAccount()!)
|
||||
LocalData.shared.removeAccount(currentAccount)
|
||||
NotificationCenter.default.post(name: .userLoggedOut, object: nil)
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +58,8 @@ struct PreferencesView: View {
|
|||
#if DEBUG
|
||||
struct PreferencesView_Previews : PreviewProvider {
|
||||
static var previews: some View {
|
||||
return PreferencesView()
|
||||
let account = LocalData.UserAccountInfo(instanceURL: URL(string: "https://mastodon.social")!, clientID: "clientID", clientSecret: "clientSecret", username: "example", accessToken: "accessToken")
|
||||
return PreferencesView(currentAccount: account)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -128,7 +128,7 @@ class ProfileTableViewController: EnhancedTableViewController {
|
|||
}
|
||||
|
||||
@objc func updateUIForPreferences() {
|
||||
guard let accountID = accountID, let account = mastodonController.cache.account(for: accountID) else { return }
|
||||
guard let account = mastodonController.cache.account(for: accountID) else { fatalError("Missing cached account \(accountID!)") }
|
||||
navigationItem.title = account.realDisplayName
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class InstanceTableViewCell: UITableViewCell {
|
|||
self.instance = nil
|
||||
|
||||
domainLabel.text = instance.domain
|
||||
adultLabel.isHidden = instance.category != "adult"
|
||||
adultLabel.isHidden = instance.category != .adult
|
||||
descriptionTextView.setTextFromHtml(instance.description)
|
||||
updateThumbnail(url: instance.proxiedThumbnailURL)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue