Files
NetNewsWire/iOS/Settings/NotificationsTableViewCell.swift

62 lines
1.5 KiB
Swift
Raw Normal View History

2022-01-26 10:25:42 +08:00
//
// 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
2022-01-27 08:27:11 +08:00
class NotificationsTableViewCell: VibrantBasicTableViewCell {
2022-01-26 10:25:42 +08:00
@IBOutlet weak var notificationsSwitch: UISwitch!
@IBOutlet weak var notificationsLabel: UILabel!
@IBOutlet weak var notificationsImageView: UIImageView!
2022-02-09 19:49:12 +08:00
weak var feed: WebFeed?
2022-01-26 10:25:42 +08:00
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) {
2022-01-26 10:25:42 +08:00
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)
notificationsLabel.text = webFeed.nameForDisplay
notificationsImageView.image = IconImageCache.shared.imageFor(webFeed.feedID!)?.image
2022-01-26 10:25:42 +08:00
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()
}
}
}