Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test flight main views navigation changes #360

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions com.stakwork.sphinx.desktop/Generated/StoryboardScenes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ internal enum StoryboardScene {

internal static let dashboardViewController = SceneType<DashboardViewController>(storyboard: Dashboard.self, identifier: "DashboardViewController")

internal static let dashboardPresenterViewController = SceneType<DashboardPresenterViewController>(storyboard: Dashboard.self, identifier: "DashboardPresenterViewController")

internal static let chatListViewController = SceneType<ChatListViewController>(storyboard: Dashboard.self, identifier: "ChatListViewController")

@available(macOS 10.15.1, *)
Expand Down
92 changes: 66 additions & 26 deletions com.stakwork.sphinx.desktop/Managers/Windows/WindowsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WindowsManager {

func saveWindowState() {
if let keyWindow = NSApplication.shared.keyWindow {
// let menuCollapsed = (keyWindow.contentViewController as? DashboardViewController)?.isLeftMenuCollapsed() ?? false
// let menuCollapsed = (keyWindow.contentViewController as? DashboardViewController)?.isLeftMenuCollapsed() ?? false
let menuCollapsed = false
let windowState = WindowState(frame: keyWindow.frame, minSize: keyWindow.minSize, menuCollapsed: menuCollapsed)

Expand Down Expand Up @@ -65,7 +65,7 @@ class WindowsManager {
let initialFrame = CGRect(x: centerPoint.x, y: centerPoint.y, width: size.width, height: size.height)
return WindowState(frame: initialFrame, minSize: size, menuCollapsed: false)
}

func showNewWindow(
with title: String,
size: CGSize,
Expand Down Expand Up @@ -112,6 +112,52 @@ class WindowsManager {
}
}

func dismissViewFromCurrentWindow() {
if let keyWindow = NSApplication.shared.keyWindow {
if let dashboardVC = keyWindow.contentViewController as? DashboardViewController {
dashboardVC.presenterContainerBGView.isHidden = true
dashboardVC.presenter?.dismissVC()
dashboardVC.presenter?.contentVC = nil
}
}
}

func showOnCurrentWindow(
with title: String,
identifier: String? = nil,
contentVC: NSViewController,
hideDivider: Bool = true,
replaceVC: Bool = true,
hideBackButton: Bool = true,
height: CGFloat = 629
) {
if let keyWindow = NSApplication.shared.keyWindow {
if let dashboardVC = keyWindow.contentViewController as? DashboardViewController {
dashboardVC.presenterContainerBGView.isHidden = false
dashboardVC.presenterBGView.layer?.cornerRadius = 12
dashboardVC.presenterContainerMainView.layer?.cornerRadius = 12
dashboardVC.presenterBackButton.isHidden = hideBackButton
dashboardVC.presenterViewHeightConstraint.constant = height
DispatchQueue.main.async {
dashboardVC.presenterBGView.layoutSubtreeIfNeeded()
}
if dashboardVC.presenterIdentifier != identifier {
if replaceVC {
dashboardVC.presenter?.dismissVC()
dashboardVC.presenter?.contentVC = nil
} else {
dashboardVC.presenter?.setParentVC()
dashboardVC.presenter?.dismissVC()
}
dashboardVC.presenter?.configurePresenterVC(contentVC)
dashboardVC.presenterTitleLabel.stringValue = title
dashboardVC.presenterIdentifier = identifier
dashboardVC.presenterHeaderDivider.isHidden = hideDivider
}
}
}
}

func showPubKeyWindow(vc: NSViewController, window: NSWindow?) {
showNewWindow(with: "pubkey".localized,
size: CGSize(width: 400, height: 600),
Expand Down Expand Up @@ -145,28 +191,24 @@ class WindowsManager {
}

func showProfileWindow(vc: NSViewController, window: NSWindow?) {
showNewWindow(with: "profile".localized,
size: CGSize(width: 400, height: 850),
centeredIn: window,
identifier: "profile-window",
contentVC: vc)
showOnCurrentWindow(with: "profile".localized,
identifier: "profile-custom-window",
contentVC: vc,
hideDivider: false)
}

func showTransationsListWindow(vc: NSViewController, window: NSWindow?) {
showNewWindow(with: "transactions".localized,
size: CGSize(width: 450, height: 750),
centeredIn: window,
identifier: "transactions-window",
contentVC: vc)
showOnCurrentWindow(with: "transactions".localized,
identifier: "transactions-custom-window",
contentVC: vc,
hideDivider: false)
}

func showContactWindow(vc: NSViewController, window: NSWindow?, title: String, identifier: String, size: CGSize) {
showNewWindow(with: title,
size: size,
centeredIn: window,
identifier: identifier,
contentVC: vc,
shouldClose: true)
showOnCurrentWindow(with: title.localized,
identifier: "contact-custom-window",
contentVC: vc,
height: size.height)
}

func showInviteCodeWindow(vc: NSViewController, window: NSWindow?) {
Expand All @@ -191,12 +233,10 @@ class WindowsManager {
vc: NSViewController,
window: NSWindow?
) {
showNewWindow(with: title,
size: CGSize(width: 400, height: 700),
centeredIn: window,
identifier: "create-tribe-window",
styleMask: [.closable, .titled],
contentVC: vc)
showOnCurrentWindow(with: "Create Tribe".localized,
identifier: "create-tribe-custom-window",
contentVC: vc,
hideDivider: false)
}

func showWebAppWindow(chat: Chat?, view: NSView, isAppURL: Bool = true) {
Expand All @@ -206,7 +246,7 @@ class WindowsManager {
let appTitle = chat.name ?? ""
let screen = NSApplication.shared.keyWindow
let frame : CGRect = screen?.frame ?? view.frame

let position = (screen?.frame.origin) ?? CGPoint(x: 0.0, y: 0.0)

showNewWindow(with: appTitle,
Expand All @@ -228,7 +268,7 @@ class WindowsManager {

let screen = NSApplication.shared.keyWindow
let frame : CGRect = screen?.frame ?? CGRect(x: 0, y: 0, width: 400, height: 400)

let position = (screen?.frame.origin) ?? CGPoint(x: 0.0, y: 0.0)

showNewWindow(with: appTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import Cocoa
class AddFriendViewController: NSViewController {

weak var delegate: NewContactChatDelegate?
weak var dismissDelegate: NewContactDismissDelegate?

static func instantiate(
delegate: NewContactChatDelegate? = nil
delegate: NewContactChatDelegate? = nil,
dismissDelegate: NewContactDismissDelegate? = nil
) -> AddFriendViewController {
let viewController = StoryboardScene.Contacts.addFriendViewController.instantiate()
viewController.delegate = delegate
viewController.dismissDelegate = dismissDelegate
return viewController
}

Expand All @@ -25,20 +28,30 @@ class AddFriendViewController: NSViewController {
}

@IBAction func newToSphinxButtonClicked(_ sender: Any) {
let inviteVC = NewInviteViewController.instantiate(delegate: self.delegate)
let inviteVC = NewInviteViewController.instantiate(delegate: self.delegate,
dismissDelegate: self.dismissDelegate)
advanceTo(vc: inviteVC)
}

@IBAction func alreadyOnSphinxButtonClicked(_ sender: Any) {
let contactVC = NewContactViewController.instantiate(delegate: self.delegate)
let contactVC = NewContactViewController.instantiate(delegate: self.delegate,
dismissDelegate: self.dismissDelegate)
advanceTo(vc: contactVC)
}

func advanceTo(vc: NSViewController) {
AnimationHelper.animateViewWith(duration: 0.3, animationsBlock: {
self.view.alphaValue = 0.0
}, completion: {
self.view.window?.replaceContentBy(vc: vc)
WindowsManager
.sharedInstance
.showOnCurrentWindow(with: "Contact".localized,
identifier: "new-contact-window",
contentVC: vc,
hideDivider: true,
replaceVC: false,
hideBackButton: false,
height: 629)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ protocol NewContactChatDelegate: AnyObject {
func shouldReloadContacts()
}

protocol NewContactDismissDelegate: AnyObject {
func shouldDismissView()
}

class NewContactViewController: NSViewController {

weak var delegate: NewContactChatDelegate?
weak var dismissDelegate: NewContactDismissDelegate?

@IBOutlet weak var contactAvatarView: ChatAvatarView!
@IBOutlet weak var fieldsTop: NSLayoutConstraint!
Expand Down Expand Up @@ -51,13 +56,15 @@ class NewContactViewController: NSViewController {

static func instantiate(
delegate: NewContactChatDelegate? = nil,
dismissDelegate: NewContactDismissDelegate? = nil,
contact: UserContact? = nil,
pubkey: String? = nil
) -> NewContactViewController {

let viewController = StoryboardScene.Contacts.newContactViewController.instantiate()
viewController.contact = contact
viewController.delegate = delegate
viewController.dismissDelegate = dismissDelegate
viewController.pubkey = pubkey

return viewController
Expand Down Expand Up @@ -136,7 +143,6 @@ class NewContactViewController: NSViewController {

@IBAction func saveButtonClicked(_ sender: Any) {
loading = true

if let _ = contact {
updateProfile()
} else {
Expand Down Expand Up @@ -201,7 +207,7 @@ class NewContactViewController: NSViewController {

func closeWindow() {
CoreDataManager.sharedManager.saveContext()
self.view.window?.close()
self.dismissDelegate?.shouldDismissView()
}

func showErrorAlert(message: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cocoa
class NewInviteViewController: NSViewController {

weak var delegate: NewContactChatDelegate?
weak var dismissDelegate: NewContactDismissDelegate?

@IBOutlet weak var nicknameField: NSTextField!
@IBOutlet var messageTextView: PlaceHolderTextView!
Expand All @@ -23,11 +24,13 @@ class NewInviteViewController: NSViewController {
let walletBalanceService = WalletBalanceService()

static func instantiate(
delegate: NewContactChatDelegate? = nil
delegate: NewContactChatDelegate? = nil,
dismissDelegate: NewContactDismissDelegate? = nil
) -> NewInviteViewController {

let viewController = StoryboardScene.Contacts.newInviteViewController.instantiate()
viewController.delegate = delegate
viewController.dismissDelegate = dismissDelegate

return viewController
}
Expand Down Expand Up @@ -110,7 +113,7 @@ class NewInviteViewController: NSViewController {

if let invite = contact["invite"].dictionary, let inviteString = invite["invite_string"]?.string, !inviteString.isEmpty {
self.delegate?.shouldReloadContacts()
self.view.window?.close()
self.dismissDelegate?.shouldDismissView()
}
}, errorCallback: {
self.loading = false
Expand Down
Loading