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

NetP iOS notifications settings #541

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// NetworkProtectionNotificationsPresenterTogglableDecorator.swift
// DuckDuckGo
//
// Copyright © 2023 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

final public class NetworkProtectionNotificationsPresenterTogglableDecorator: NetworkProtectionNotificationsPresenter {
private let notificationSettingsStore: NetworkProtectionNotificationsSettingsStore
private let wrappeePresenter: NetworkProtectionNotificationsPresenter

public init(notificationSettingsStore: NetworkProtectionNotificationsSettingsStore, wrappee: NetworkProtectionNotificationsPresenter) {
self.notificationSettingsStore = notificationSettingsStore
self.wrappeePresenter = wrappee
}

public func showConnectedNotification(serverLocation: String?) {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showConnectedNotification(serverLocation: serverLocation)
}

public func showReconnectingNotification() {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showReconnectingNotification()
}

public func showConnectionFailureNotification() {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showConnectionFailureNotification()
}

public func showSupersededNotification() {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showSupersededNotification()
}

public func showTestNotification() {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showTestNotification()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// NetworkProtectionNotificationsSettingsStore.swift
// DuckDuckGo
//
// Copyright © 2023 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

public protocol NetworkProtectionNotificationsSettingsStore {
var alertsEnabled: Bool { get set }
}

final public class NetworkProtectionNotificationsSettingsUserDefaultsStore: NetworkProtectionNotificationsSettingsStore {
private enum Key {
static let alerts = "com.duckduckgo.notificationSettings.alertsEnabled"
graeme marked this conversation as resolved.
Show resolved Hide resolved
}

private static let alertsEnabledKey = "com.duckduckgo.notificationSettings"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooops. Will remove

private let userDefaults: UserDefaults

public init(userDefaults: UserDefaults) {
self.userDefaults = userDefaults
}

public var alertsEnabled: Bool {
get {
guard self.userDefaults.object(forKey: Key.alerts) != nil else {
return true
}
return self.userDefaults.bool(forKey: Key.alerts)
}
set {
self.userDefaults.set(newValue, forKey: Key.alerts)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// MockNetworkProtectionNotificationsSettingsStore.swift
// DuckDuckGo
//
// Copyright © 2023 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import NetworkProtection

public class MockNetworkProtectionNotificationsSettingsStore: NetworkProtectionNotificationsSettingsStore {
public var alertsEnabled: Bool = false
}
Loading