Set toggle-values for notification-settings (IOS-14)

This commit is contained in:
Nathan Mattes 2023-09-26 15:36:01 +02:00
parent f2180034ee
commit fcb19b9734
4 changed files with 36 additions and 4 deletions

View File

@ -18,6 +18,5 @@ class NotificationPolicyTableViewCell: UITableViewCell {
}
contentConfiguration = content
}
}

View File

@ -26,8 +26,21 @@ class NotificationSettingTableViewToggleCell: ToggleTableViewCell {
func configure(with alert: NotificationAlert, viewModel: NotificationSettingsViewModel) {
self.alert = alert
let toggleIsOn: Bool
switch alert {
case .mentionsAndReplies:
toggleIsOn = viewModel.notifyMentions
case .boosts:
toggleIsOn = viewModel.notifyBoosts
case .favorites:
toggleIsOn = viewModel.notifyFavorites
case .newFollowers:
toggleIsOn = viewModel.notifyNewFollowers
}
label.text = alert.title
toggle.isOn = toggleIsOn
}
@objc

View File

@ -19,7 +19,14 @@ class NotificationSettingsViewController: UIViewController {
var viewModel: NotificationSettingsViewModel
init(currentSetting: Setting?) {
viewModel = NotificationSettingsViewModel(selectedPolicy: currentSetting?.activeSubscription?.notificationPolicy ?? .noone)
let activeSubscription = currentSetting?.activeSubscription
let alert = activeSubscription?.alert
viewModel = NotificationSettingsViewModel(selectedPolicy: activeSubscription?.notificationPolicy ?? .noone,
notifyMentions: alert?.mention ?? false,
notifyBoosts: alert?.reblog ?? false,
notifyFavorites: alert?.favourite ?? false,
notifyNewFollowers: alert?.follow ?? false)
sections = [
NotificationSettingsSection(entries: [.policy]),
NotificationSettingsSection(entries: NotificationAlert.allCases.map { NotificationSettingEntry.alert($0) } )

View File

@ -3,9 +3,22 @@
import Foundation
class NotificationSettingsViewModel {
var selectedPolicy: NotificationPolicy
init(selectedPolicy: NotificationPolicy) {
var selectedPolicy: NotificationPolicy
var notifyMentions: Bool
var notifyBoosts: Bool
var notifyFavorites: Bool
var notifyNewFollowers: Bool
var updated: Bool
init(selectedPolicy: NotificationPolicy, notifyMentions: Bool, notifyBoosts: Bool, notifyFavorites: Bool, notifyNewFollowers: Bool) {
self.selectedPolicy = selectedPolicy
self.notifyMentions = notifyMentions
self.notifyBoosts = notifyBoosts
self.notifyFavorites = notifyFavorites
self.notifyNewFollowers = notifyNewFollowers
self.updated = false
}
}