Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9d3a0df
Add MigrationDpendencyContainer, dependency injection container for w…
Nov 6, 2022
14ebd9d
Add MigrationNavigationController, custom, state-based navigation con…
Nov 6, 2022
48a4c65
Update MigrationFlowCoordinator, extract ui logic from coordinator
Nov 6, 2022
30a79ab
Add MigrationStepConfiguration, a refactor of existing configuration …
Nov 6, 2022
e2cdb12
Add MigrationStepView, a common base view for migration step screens
Nov 6, 2022
3b8216f
Add MigrationNotificationsViewController, view controller for the wp-…
Nov 6, 2022
45e1c2e
Add MigrationNotificationsViewModel, view model for the wp-to-jp migr…
Nov 6, 2022
8e7786a
Add MigrationDoneViewController, view controller for the wp-to-jp mig…
Nov 6, 2022
81dfb16
Add MigrationDoneViewModel, view model for the wp-to-jp migration-fin…
Nov 6, 2022
58bffd0
Update WindowManager, default optional completion to nil
Nov 6, 2022
6205faf
Update JetpackWindowManager, refactor to enable showing the wp-to-jp …
Nov 6, 2022
a89c8a2
Update MigrationStep, add missing steps and extract in separate file
Nov 6, 2022
e73c00e
Update MigrationActionsView, refactors based on the refactor of confi…
Nov 6, 2022
b1bb8e9
Update MigrationHeaderView, refactors based on the refactor of config…
Nov 6, 2022
493c694
Files and groups re-arranged in WordPress-to-Jetpack migration group
Nov 6, 2022
dadb84f
Update MigrationStepConfiguration, put separate types in separate files
Nov 6, 2022
be02a8b
Update MigrationDoneViewController, MigrationNotificationsViewControl…
Nov 7, 2022
f258dd3
Update MigrationDependencyContainer, remove incorrect comment
Nov 7, 2022
2660dca
Update MigrationStepView, remove unnecessary settings
Nov 7, 2022
85e8e05
Fix trailing space violations
Nov 7, 2022
b60e047
Update migration view models, improve code legibility
Nov 7, 2022
39864a3
Update MigrationDependencyContainer, extract view controller factory,…
Nov 7, 2022
a33da86
Update MigrationNavigationController, use view controller factory to …
Nov 7, 2022
ff32f03
Merge branch trunk into task/migration-notifications-premission
Nov 7, 2022
15e7a29
Update JetpackWindowManager, simplify logic and make sure that the ui…
Nov 7, 2022
3bf7ef7
Update MigrationFlowCoordinator, add logic to skip notifications perm…
Nov 7, 2022
3387916
Update MigrationNavigationController, always create and assign view c…
Nov 7, 2022
1d7ccdc
Update migration view models, add notification permission logic and f…
Nov 7, 2022
eabe689
Update MigrationDependencyContainer, changed to struct since we don't…
Nov 8, 2022
959f687
Update MigrationNavigationController, instantiate with rootViewContro…
Nov 8, 2022
40127da
Update MigrationViewControllerFactory, add method initialViewControll…
Nov 8, 2022
40be348
Update MigrationNavigationController, set initial root from factory a…
Nov 8, 2022
313c203
Update MigrationFlowCoordinator, add comments
Nov 8, 2022
5d9d95f
Update JetpackWindowManager, small refactor
Nov 8, 2022
750bafa
Update JetpackWindowManager, small refactor
Nov 8, 2022
670a52e
Update JetpackWindowManager, disable migration UI
Nov 8, 2022
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: 1 addition & 1 deletion WordPress/Classes/System/WindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class WindowManager: NSObject {
/// Shows the specified VC as the root VC for the managed window. Takes care of animating the transition whenever the existing
/// root VC isn't `nil` (this is because a `nil` VC means we're showing the initial VC on a call to this method).
///
func show(_ viewController: UIViewController, completion: Completion?) {
func show(_ viewController: UIViewController, completion: Completion? = nil) {
// When the App is launched, the root VC will be `nil`.
// When this is the case we'll simply show the VC without any type of animation.
guard window.rootViewController != nil else {
Expand Down
29 changes: 28 additions & 1 deletion WordPress/Jetpack/Classes/System/JetpackWindowManager.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Combine
import Foundation

class JetpackWindowManager: WindowManager {
/// receives migration flow updates in order to dismiss it when needed.
private var cancellable: AnyCancellable?

override func showUI(for blog: Blog?) {
// If the user is logged in and has blogs sync'd to their account
if AccountHelper.isLoggedIn && AccountHelper.hasBlogs {
showAppUI(for: blog)
shouldShowMigrationUI ? showMigrationUI(blog) : showAppUI(for: blog)
return
}

Expand All @@ -18,4 +22,27 @@ class JetpackWindowManager: WindowManager {
// the `logOutDefaultWordPressComAccount` method will trigger the `showSignInUI` automatically
AccountHelper.logOutDefaultWordPressComAccount()
}

private func showMigrationUI(_ blog: Blog?) {
let container = MigrationDependencyContainer()
cancellable = container.migrationCoordinator.$currentStep
.receive(on: DispatchQueue.main)
.sink { [weak self] step in
guard step == .dismiss else {
return
}
self?.switchToAppUI(for: blog)
}
self.show(container.makeInitialViewController())
}

private func switchToAppUI(for blog: Blog?) {
cancellable = nil
showAppUI(for: blog)
}

// TODO: Add logic in here to trigger migration UI if needed
private var shouldShowMigrationUI: Bool {
false
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import UIKit

class MigrationDoneViewController: UIViewController {

private let viewModel: MigrationDoneViewModel

init(viewModel: MigrationDoneViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func loadView() {
// TODO: replace this blank center view with the actual content
let centerView = UIView()
centerView.translatesAutoresizingMaskIntoConstraints = false
centerView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: .vertical)

view = MigrationStepView(headerView: MigrationHeaderView(configuration: viewModel.configuration.headerConfiguration),
actionsView: MigrationActionsView(configuration: viewModel.configuration.actionsConfiguration),
centerView: centerView)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class MigrationDoneViewModel {

let configuration: MigrationStepConfiguration

init(coordinator: MigrationFlowCoordinator) {

let headerConfiguration = MigrationHeaderConfiguration(step: .done)

let actionsConfiguration = MigrationActionsViewConfiguration(step: .done, primaryHandler: { [weak coordinator] in
coordinator?.transitionToNextStep()
})
configuration = MigrationStepConfiguration(headerConfiguration: headerConfiguration,
actionsConfiguration: actionsConfiguration)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
struct MigrationDependencyContainer {

let migrationCoordinator = MigrationFlowCoordinator()

func makeInitialViewController() -> UIViewController {
MigrationNavigationController(coordinator: migrationCoordinator,
factory: MigrationViewControllerFactory(coordinator: migrationCoordinator))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, it's better than passing a closure 👍

}
}

struct MigrationViewControllerFactory {

let coordinator: MigrationFlowCoordinator

init(coordinator: MigrationFlowCoordinator) {
self.coordinator = coordinator
}

func viewController(for step: MigrationStep) -> UIViewController? {
switch step {
case .welcome:
return makeWelcomeViewController()
case .notifications:
return makeNotificationsViewController()
case .done:
return makeDoneViewController()
case .dismiss:
return nil
}
}

func initialViewController() -> UIViewController? {
viewController(for: coordinator.currentStep)
}

private func makeAccount() -> WPAccount? {

let context = ContextManager.shared.mainContext
do {
return try WPAccount.lookupDefaultWordPressComAccount(in: context)
} catch {
DDLogError("Account lookup failed with error: \(error)")
return nil
}
}

private func makeWelcomeViewModel() -> MigrationWelcomeViewModel {
MigrationWelcomeViewModel(account: makeAccount(), coordinator: coordinator)
}

private func makeWelcomeViewController() -> UIViewController {
MigrationWelcomeViewController(viewModel: makeWelcomeViewModel())
}

private func makeNotificationsViewModel() -> MigrationNotificationsViewModel {
MigrationNotificationsViewModel(coordinator: coordinator)
}

private func makeNotificationsViewController() -> UIViewController {
MigrationNotificationsViewController(viewModel: makeNotificationsViewModel())
}

private func makeDoneViewModel() -> MigrationDoneViewModel {
MigrationDoneViewModel(coordinator: coordinator)
}

private func makeDoneViewController() -> UIViewController {
MigrationDoneViewController(viewModel: makeDoneViewModel())
}
}
Loading