Disable notifications if they aren't enabled (IOS-14)

This commit is contained in:
Nathan Mattes 2023-09-26 16:10:08 +02:00
parent f5365a9d6e
commit 85a82cbb9b
4 changed files with 37 additions and 22 deletions

View File

@ -6,18 +6,25 @@ import MastodonLocalization
class NotificationSettingTableViewCell: UITableViewCell {
static let reuseIdentifier = "NotificationSettingTableViewCell"
func configure(with entry: NotificationSettingEntry, viewModel: NotificationSettingsViewModel) {
func configure(with entry: NotificationSettingEntry, viewModel: NotificationSettingsViewModel, notificationsEnabled: Bool) {
switch entry {
case.alert(_):
// we use toggle cells for these
break
case .policy:
var content = UIListContentConfiguration.valueCell()
content.text = L10n.Scene.Settings.Notifications.Policy.title
content.secondaryText = viewModel.selectedPolicy.title
// we use toggle cells for these
break
case .policy:
var content = UIListContentConfiguration.valueCell()
content.text = L10n.Scene.Settings.Notifications.Policy.title
content.secondaryText = viewModel.selectedPolicy.title
if notificationsEnabled {
content.textProperties.color = .label
content.secondaryTextProperties.color = .secondaryLabel
} else {
content.textProperties.color = .secondaryLabel
content.secondaryTextProperties.color = .tertiaryLabel
}
contentConfiguration = content
contentConfiguration = content
}
}

View File

@ -24,7 +24,7 @@ class NotificationSettingTableViewToggleCell: ToggleTableViewCell {
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
func configure(with alert: NotificationAlert, viewModel: NotificationSettingsViewModel) {
func configure(with alert: NotificationAlert, viewModel: NotificationSettingsViewModel, notificationsEnabled: Bool) {
self.alert = alert
let toggleIsOn: Bool
@ -40,7 +40,13 @@ class NotificationSettingTableViewToggleCell: ToggleTableViewCell {
}
label.text = alert.title
toggle.isOn = toggleIsOn
if notificationsEnabled {
label.textColor = .label
} else {
label.textColor = .secondaryLabel
}
toggle.isOn = toggleIsOn && notificationsEnabled
toggle.isEnabled = notificationsEnabled
}
@objc

View File

@ -19,7 +19,7 @@ class NotificationSettingsViewController: UIViewController {
let sections: [NotificationSettingsSection]
var viewModel: NotificationSettingsViewModel
init(currentSetting: Setting?) {
init(currentSetting: Setting?, notificationsEnabled: Bool) {
let activeSubscription = currentSetting?.activeSubscription
let alert = activeSubscription?.alert
viewModel = NotificationSettingsViewModel(selectedPolicy: activeSubscription?.notificationPolicy ?? .noone,
@ -37,6 +37,7 @@ class NotificationSettingsViewController: UIViewController {
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(NotificationSettingTableViewCell.self, forCellReuseIdentifier: NotificationSettingTableViewCell.reuseIdentifier)
tableView.register(NotificationSettingTableViewToggleCell.self, forCellReuseIdentifier: NotificationSettingTableViewToggleCell.reuseIdentifier)
tableView.isUserInteractionEnabled = notificationsEnabled
super.init(nibName: nil, bundle: nil)
@ -45,18 +46,18 @@ class NotificationSettingsViewController: UIViewController {
let cell: UITableViewCell
switch itemIdentifier {
case .policy:
guard let self,
let notificationCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewCell else { fatalError("WTF Wrong cell!?") }
case .policy:
guard let self,
let notificationCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewCell else { fatalError("WTF Wrong cell!?") }
notificationCell.configure(with: .policy, viewModel: self.viewModel)
cell = notificationCell
notificationCell.configure(with: .policy, viewModel: self.viewModel, notificationsEnabled: notificationsEnabled)
cell = notificationCell
case .alert(let alert):
guard let self,
let toggleCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewToggleCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewToggleCell else { fatalError("WTF Wrong cell!?") }
toggleCell.configure(with: alert, viewModel: self.viewModel)
case .alert(let alert):
guard let self,
let toggleCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewToggleCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewToggleCell else { fatalError("WTF Wrong cell!?") }
toggleCell.configure(with: alert, viewModel: self.viewModel, notificationsEnabled: notificationsEnabled)
toggleCell.delegate = self
cell = toggleCell
}

View File

@ -61,7 +61,8 @@ extension SettingsCoordinator: SettingsViewControllerDelegate {
case .notifications:
let currentSetting = appContext.settingService.currentSetting.value
let notificationViewController = NotificationSettingsViewController(currentSetting: currentSetting)
let notificationsEnabled = appContext.notificationService.isNotificationPermissionGranted.value
let notificationViewController = NotificationSettingsViewController(currentSetting: currentSetting, notificationsEnabled: notificationsEnabled)
notificationViewController.delegate = self
self.navigationController.pushViewController(notificationViewController, animated: true)