Disable notifications if they aren't enabled (IOS-14)
This commit is contained in:
parent
f5365a9d6e
commit
85a82cbb9b
|
@ -6,7 +6,7 @@ import MastodonLocalization
|
||||||
class NotificationSettingTableViewCell: UITableViewCell {
|
class NotificationSettingTableViewCell: UITableViewCell {
|
||||||
static let reuseIdentifier = "NotificationSettingTableViewCell"
|
static let reuseIdentifier = "NotificationSettingTableViewCell"
|
||||||
|
|
||||||
func configure(with entry: NotificationSettingEntry, viewModel: NotificationSettingsViewModel) {
|
func configure(with entry: NotificationSettingEntry, viewModel: NotificationSettingsViewModel, notificationsEnabled: Bool) {
|
||||||
|
|
||||||
switch entry {
|
switch entry {
|
||||||
case.alert(_):
|
case.alert(_):
|
||||||
|
@ -16,6 +16,13 @@ class NotificationSettingTableViewCell: UITableViewCell {
|
||||||
var content = UIListContentConfiguration.valueCell()
|
var content = UIListContentConfiguration.valueCell()
|
||||||
content.text = L10n.Scene.Settings.Notifications.Policy.title
|
content.text = L10n.Scene.Settings.Notifications.Policy.title
|
||||||
content.secondaryText = viewModel.selectedPolicy.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
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ class NotificationSettingTableViewToggleCell: ToggleTableViewCell {
|
||||||
|
|
||||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
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
|
self.alert = alert
|
||||||
|
|
||||||
let toggleIsOn: Bool
|
let toggleIsOn: Bool
|
||||||
|
@ -40,7 +40,13 @@ class NotificationSettingTableViewToggleCell: ToggleTableViewCell {
|
||||||
}
|
}
|
||||||
|
|
||||||
label.text = alert.title
|
label.text = alert.title
|
||||||
toggle.isOn = toggleIsOn
|
if notificationsEnabled {
|
||||||
|
label.textColor = .label
|
||||||
|
} else {
|
||||||
|
label.textColor = .secondaryLabel
|
||||||
|
}
|
||||||
|
toggle.isOn = toggleIsOn && notificationsEnabled
|
||||||
|
toggle.isEnabled = notificationsEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
|
|
|
@ -19,7 +19,7 @@ class NotificationSettingsViewController: UIViewController {
|
||||||
let sections: [NotificationSettingsSection]
|
let sections: [NotificationSettingsSection]
|
||||||
var viewModel: NotificationSettingsViewModel
|
var viewModel: NotificationSettingsViewModel
|
||||||
|
|
||||||
init(currentSetting: Setting?) {
|
init(currentSetting: Setting?, notificationsEnabled: Bool) {
|
||||||
let activeSubscription = currentSetting?.activeSubscription
|
let activeSubscription = currentSetting?.activeSubscription
|
||||||
let alert = activeSubscription?.alert
|
let alert = activeSubscription?.alert
|
||||||
viewModel = NotificationSettingsViewModel(selectedPolicy: activeSubscription?.notificationPolicy ?? .noone,
|
viewModel = NotificationSettingsViewModel(selectedPolicy: activeSubscription?.notificationPolicy ?? .noone,
|
||||||
|
@ -37,6 +37,7 @@ class NotificationSettingsViewController: UIViewController {
|
||||||
tableView.translatesAutoresizingMaskIntoConstraints = false
|
tableView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
tableView.register(NotificationSettingTableViewCell.self, forCellReuseIdentifier: NotificationSettingTableViewCell.reuseIdentifier)
|
tableView.register(NotificationSettingTableViewCell.self, forCellReuseIdentifier: NotificationSettingTableViewCell.reuseIdentifier)
|
||||||
tableView.register(NotificationSettingTableViewToggleCell.self, forCellReuseIdentifier: NotificationSettingTableViewToggleCell.reuseIdentifier)
|
tableView.register(NotificationSettingTableViewToggleCell.self, forCellReuseIdentifier: NotificationSettingTableViewToggleCell.reuseIdentifier)
|
||||||
|
tableView.isUserInteractionEnabled = notificationsEnabled
|
||||||
|
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
|
||||||
|
@ -49,14 +50,14 @@ class NotificationSettingsViewController: UIViewController {
|
||||||
guard let self,
|
guard let self,
|
||||||
let notificationCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewCell else { fatalError("WTF Wrong cell!?") }
|
let notificationCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewCell else { fatalError("WTF Wrong cell!?") }
|
||||||
|
|
||||||
notificationCell.configure(with: .policy, viewModel: self.viewModel)
|
notificationCell.configure(with: .policy, viewModel: self.viewModel, notificationsEnabled: notificationsEnabled)
|
||||||
cell = notificationCell
|
cell = notificationCell
|
||||||
|
|
||||||
case .alert(let alert):
|
case .alert(let alert):
|
||||||
guard let self,
|
guard let self,
|
||||||
let toggleCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewToggleCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewToggleCell else { fatalError("WTF Wrong cell!?") }
|
let toggleCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewToggleCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewToggleCell else { fatalError("WTF Wrong cell!?") }
|
||||||
|
|
||||||
toggleCell.configure(with: alert, viewModel: self.viewModel)
|
toggleCell.configure(with: alert, viewModel: self.viewModel, notificationsEnabled: notificationsEnabled)
|
||||||
toggleCell.delegate = self
|
toggleCell.delegate = self
|
||||||
cell = toggleCell
|
cell = toggleCell
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,8 @@ extension SettingsCoordinator: SettingsViewControllerDelegate {
|
||||||
case .notifications:
|
case .notifications:
|
||||||
|
|
||||||
let currentSetting = appContext.settingService.currentSetting.value
|
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
|
notificationViewController.delegate = self
|
||||||
|
|
||||||
self.navigationController.pushViewController(notificationViewController, animated: true)
|
self.navigationController.pushViewController(notificationViewController, animated: true)
|
||||||
|
|
Loading…
Reference in New Issue