mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
work on notification manager
This commit is contained in:
70
iOS/Settings/NotificationsTableViewCell.swift
Normal file
70
iOS/Settings/NotificationsTableViewCell.swift
Normal file
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// NotificationsTableViewCell.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 26/01/2022.
|
||||
// Copyright © 2022 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Account
|
||||
import UserNotifications
|
||||
|
||||
class NotificationsTableViewCell: UITableViewCell {
|
||||
|
||||
@IBOutlet weak var notificationsSwitch: UISwitch!
|
||||
@IBOutlet weak var notificationsLabel: UILabel!
|
||||
@IBOutlet weak var notificationsImageView: UIImageView!
|
||||
var feed: WebFeed?
|
||||
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
// Initialization code
|
||||
}
|
||||
|
||||
override func setSelected(_ selected: Bool, animated: Bool) {
|
||||
super.setSelected(selected, animated: animated)
|
||||
|
||||
// Configure the view for the selected state
|
||||
}
|
||||
|
||||
func configure(_ webFeed: WebFeed, _ status: UNAuthorizationStatus) {
|
||||
self.feed = webFeed
|
||||
var isOn = false
|
||||
if webFeed.isNotifyAboutNewArticles == nil {
|
||||
isOn = false
|
||||
} else {
|
||||
isOn = webFeed.isNotifyAboutNewArticles!
|
||||
}
|
||||
notificationsSwitch.isOn = isOn
|
||||
notificationsSwitch.addTarget(self, action: #selector(toggleWebFeedNotification(_:)), for: .touchUpInside)
|
||||
if status == .denied { notificationsSwitch.isEnabled = false }
|
||||
notificationsLabel.text = webFeed.nameForDisplay
|
||||
notificationsImageView.image = webFeed.smallIcon?.image
|
||||
notificationsImageView.layer.cornerRadius = 4
|
||||
}
|
||||
|
||||
func configure(_ status: UNAuthorizationStatus) {
|
||||
notificationsSwitch.isOn = (status == .authorized) ? true : false
|
||||
if status == .denied { notificationsSwitch.isEnabled = false }
|
||||
notificationsLabel.text = NSLocalizedString("Enable Notifications", comment: "")
|
||||
notificationsImageView.image = UIImage(systemName: "bell")
|
||||
notificationsImageView.layer.cornerRadius = 4
|
||||
}
|
||||
|
||||
@objc
|
||||
private func toggleWebFeedNotification(_ sender: Any) {
|
||||
guard let feed = feed else {
|
||||
return
|
||||
}
|
||||
if feed.isNotifyAboutNewArticles == nil {
|
||||
feed.isNotifyAboutNewArticles = true
|
||||
}
|
||||
else {
|
||||
feed.isNotifyAboutNewArticles!.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user