Skip to content

Commit

Permalink
allow to open notification system settings
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Dec 9, 2024
1 parent 09fd61b commit de8019c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal final class NotificationsViewController: UITableViewController {
}

private enum CellTags: Int {
case notifications
case systemSettings
}

private var dcContext: DcContext
Expand Down Expand Up @@ -49,13 +49,26 @@ internal final class NotificationsViewController: UITableViewController {
})
}()

private lazy var systemSettingsCell: UITableViewCell = {
let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
cell.tag = CellTags.systemSettings.rawValue
cell.textLabel?.text = String.localized("system_settings")
cell.accessoryType = .disclosureIndicator
return cell
}()

private lazy var sections: [SectionConfigs] = {
let preferencesSection = SectionConfigs(
headerTitle: nil,
footerTitle: String.localized("pref_mention_notifications_explain"),
cells: [notificationsCell, mentionsCell]
)
return [preferencesSection]
let systemSettingsSection = SectionConfigs(
headerTitle: nil,
footerTitle: String.localized("system_settings_notify_explain_ios"),
cells: [systemSettingsCell]
)
return [preferencesSection, systemSettingsSection]
}()

init(dcAccounts: DcAccounts) {
Expand Down Expand Up @@ -102,8 +115,32 @@ internal final class NotificationsViewController: UITableViewController {
return sections[section].footerTitle
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let cell = tableView.cellForRow(at: indexPath), let cellTag = CellTags(rawValue: cell.tag) else { safe_fatalError(); return }
tableView.deselectRow(at: indexPath, animated: false)

switch cellTag {
case .systemSettings:
if let url = URL(string: notificationSettingsURLString()), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
}

private func updateCells() {
mentionsCell.uiSwitch.isEnabled = !dcContext.isMuted()
mentionsCell.uiSwitch.isOn = !dcContext.isMuted() && dcContext.isMentionsEnabled()
}

private func notificationSettingsURLString() -> String {
if #available(iOS 16, *) {
return UIApplication.openNotificationSettingsURLString
}

if #available(iOS 15.4, *) {
return UIApplicationOpenNotificationSettingsURLString
}

return UIApplication.openSettingsURLString
}
}
2 changes: 2 additions & 0 deletions deltachat-ios/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1063,3 +1063,5 @@
"backup_successful_explain_ios" = "You can find the backup in the \"Delta Chat\" folder using the \"Files\" app.\n\nMove the backup out of this folder to keep it when deleting Delta Chat.";
"location_denied" = "Location access denied";
"location_denied_explain_ios" = "In the system settings, enable \"Privacy/Location Services\" and set \"Delta Chat/Location\" to \"Always\" and \"Precise\".";
"system_settings" = "System Settings";
"system_settings_notify_explain_ios" = "Edit sound, type, badges and more";
2 changes: 2 additions & 0 deletions scripts/untranslated.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
<string name="backup_successful_explain_ios">You can find the backup in the \"Delta Chat\" folder using the \"Files\" app.\n\nMove the backup out of this folder to keep it when deleting Delta Chat.</string>
<string name="location_denied">Location access denied</string>
<string name="location_denied_explain_ios">In the system settings, enable \"Privacy/Location Services\" and set \"Delta Chat/Location\" to \"Always\" and \"Precise\".</string>
<string name="system_settings">System Settings</string>
<string name="system_settings_notify_explain_ios">Edit sound, type, badges and more</string>
</resources>

0 comments on commit de8019c

Please sign in to comment.