-
Notifications
You must be signed in to change notification settings - Fork 1
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
Sync system notification settings; filter out Abacus notifications #258
Changes from 15 commits
184cbdd
703f1b4
4bbd466
c104737
8bf7cee
a46598e
ebd0129
f82cfe3
34d13e9
a99b555
c548132
4a2c545
c46824b
cab4129
d07c24b
5b36393
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// dydxPushNotifcationToggleWorker.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 dydxPushNotifcationToggleWorker: 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) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,5 +46,8 @@ private class dydxNotificationPrimerViewPresenter: HostedViewPresenter<dydxNotif | |
} | ||
} | ||
} | ||
viewModel?.cancelAction = { | ||
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss", params: nil), animated: true, completion: nil) | ||
} | ||
Comment on lines
+49
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙏 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,14 @@ private class dydxNotificationsSettingsViewPresenter: SettingsViewPresenter { | |
viewModel?.headerViewModel = header | ||
} | ||
|
||
override func start() { | ||
super.start() | ||
|
||
changeObservation(from: nil, to: NotificationService.shared, keyPath: #keyPath(NotificationHandler.permission)) { [weak self] _, _, _, _ in | ||
self?.reloadSettings() | ||
} | ||
} | ||
|
||
override func onInputValueChanged(input: FieldInput) { | ||
if input.fieldName == "should_display_in_app_notifications" { | ||
promptToToggleNotification() | ||
|
@@ -57,7 +65,10 @@ private class dydxNotificationsSettingsViewPresenter: SettingsViewPresenter { | |
cancelTitle: DataLocalizer.shared?.localize(path: "APP.GENERAL.CANCEL", params: nil) ?? "Cancel" | ||
) | ||
} | ||
// sync the settings with the system permission | ||
reloadSettings() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would this get called while user is being prompted to turn on notifications? Does this have an effect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah.. it gets called, which sets the value back... But when the system notification value changes, it will be synced again. |
||
} | ||
|
||
private func reloadSettings() { | ||
let pushNotificationEnabled = NotificationService.shared?.permission == .authorized | ||
SettingsStore.shared?.setValue(pushNotificationEnabled, forKey: dydxSettingsStoreKey.shouldDisplayInAppNotifications.rawValue) | ||
loadSettings() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,10 @@ public class dydxAbacusDataLocalizer: DataLocalizerProtocol, AbacusLocalizerProt | |
let language = keyValueStore?.value(forKey: _languageTag) as? String | ||
UIImplementations.reset(language: language) | ||
if let language = language { | ||
setLanguage(language: language) { _ in | ||
setLanguage(language: language) { success in | ||
if !success { | ||
Console.shared.log("dydxAbacusDataLocalizer setLanguage failed") | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -49,21 +52,25 @@ public class dydxAbacusDataLocalizer: DataLocalizerProtocol, AbacusLocalizerProt | |
|
||
public func setLanguage(language: String, callback: @escaping (KotlinBoolean, ParsingError?) -> Void) { | ||
if let code = language.components(separatedBy: "-").first { | ||
(UIImplementations.shared?.localizer as? DynamicLocalizer)?.setLanguage(language: code, callback: { [weak self] successful, error in | ||
self?.language = (UIImplementations.shared?.localizer as? DynamicLocalizer)?.language | ||
if successful.boolValue { | ||
if let self = self { | ||
self.keyValueStore?.setValue(code, forKey: self._languageTag) | ||
let localizer = UIImplementations.shared?.localizer as? DynamicLocalizer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some logging; no functional change |
||
if let localizer = localizer { | ||
localizer.setLanguage(language: code, callback: { [weak self] successful, error in | ||
self?.language = localizer.language | ||
if successful.boolValue { | ||
if let self = self { | ||
self.keyValueStore?.setValue(code, forKey: self._languageTag) | ||
} | ||
} | ||
} | ||
callback(successful, error) | ||
}) | ||
callback(successful, error) | ||
}) | ||
} else { | ||
callback(false, nil) | ||
} | ||
} else { | ||
callback(false, nil) | ||
} | ||
} | ||
|
||
|
||
private func json(params: [String: String]?) -> String? { | ||
if let params = params { | ||
if let data = try? JSONSerialization.data(withJSONObject: params, options: .prettyPrinted) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notification*