Set toggle-values for notification-settings (IOS-14)
This commit is contained in:
parent
f2180034ee
commit
fcb19b9734
|
@ -18,6 +18,5 @@ class NotificationPolicyTableViewCell: UITableViewCell {
|
|||
}
|
||||
|
||||
contentConfiguration = content
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) } )
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue