-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TRCL-3689 Add primer screen to prompt the user to enable notification (…
…#251) * WIP * WIP * Settings * Lint * Clean up * Clean up * Code review feedback * Clean up
- Loading branch information
Showing
24 changed files
with
321 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...resenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxPushNotificationToggleWorker.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// dydxPushNotificationToggleWorker.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 13/09/2024. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import dydxStateManager | ||
import ParticlesKit | ||
import RoutingKit | ||
import Utilities | ||
|
||
public final class dydxPushNotificationToggleWorker: BaseWorker { | ||
|
||
public override func start() { | ||
super.start() | ||
|
||
// Sync the app settings value to the system notification settings | ||
changeObservation(from: nil, to: NotificationService.shared, keyPath: #keyPath(NotificationHandler.permission)) { _, _, _, _ in | ||
let pushNotificationEnabled = NotificationService.shared?.permission == .authorized | ||
SettingsStore.shared?.setValue(pushNotificationEnabled, forKey: dydxSettingsStoreKey.shouldDisplayInAppNotifications.rawValue) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
dydx/dydxPresenters/dydxPresenters/_v4/Primers/dydxNotificationPrimerViewPresenter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// dydxNotificationPrimerViewPresenter.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 11/09/2024. | ||
// | ||
|
||
import Utilities | ||
import dydxViews | ||
import PlatformParticles | ||
import RoutingKit | ||
import ParticlesKit | ||
import PlatformUI | ||
|
||
public class dydxNotificationPrimerViewBuilder: NSObject, ObjectBuilderProtocol { | ||
public func build<T>() -> T? { | ||
let presenter = dydxNotificationPrimerViewPresenter() | ||
let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView() | ||
return dydxNotificationPrimerViewController(presenter: presenter, view: view, configuration: .default) as? T | ||
} | ||
} | ||
|
||
private class dydxNotificationPrimerViewController: HostingViewController<PlatformView, dydxNotificationPrimerViewModel> { | ||
override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool { | ||
if request?.path == "/primer/notification" { | ||
return true | ||
} | ||
return false | ||
} | ||
} | ||
|
||
private protocol dydxNotificationPrimerViewPresenterProtocol: HostedViewPresenterProtocol { | ||
var viewModel: dydxNotificationPrimerViewModel? { get } | ||
} | ||
|
||
private class dydxNotificationPrimerViewPresenter: HostedViewPresenter<dydxNotificationPrimerViewModel>, dydxNotificationPrimerViewPresenterProtocol { | ||
override init() { | ||
super.init() | ||
|
||
viewModel = dydxNotificationPrimerViewModel() | ||
viewModel?.ctaAction = { | ||
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss", params: nil), animated: true) { _, _ in | ||
let notificationPermission = NotificationService.shared?.authorization | ||
if notificationPermission?.authorization == .notDetermined { | ||
notificationPermission?.promptToAuthorize() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.