mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-05-20 22:30:45 +08:00
option to mark read on open
This commit is contained in:
@@ -9,8 +9,8 @@
|
||||
import Foundation
|
||||
|
||||
protocol NotificationClientListener: class {
|
||||
func willMarkRead(client: NotificationClient, id: String)
|
||||
func didFailToMarkRead(client: NotificationClient, id: String)
|
||||
func willMarkRead(client: NotificationClient, id: String, isOpen: Bool)
|
||||
func didFailToMarkRead(client: NotificationClient, id: String, isOpen: Bool)
|
||||
}
|
||||
|
||||
final class NotificationClient {
|
||||
@@ -33,6 +33,16 @@ final class NotificationClient {
|
||||
|
||||
// Public API
|
||||
|
||||
static private let openOnReadKey = "com.freetime.NotificationClient.read-on-open"
|
||||
|
||||
static func readOnOpen() -> Bool {
|
||||
return UserDefaults.standard.bool(forKey: openOnReadKey)
|
||||
}
|
||||
|
||||
static func setReadOnOpen(open: Bool) {
|
||||
UserDefaults.standard.set(open, forKey: openOnReadKey)
|
||||
}
|
||||
|
||||
func add(listener: NotificationClientListener) {
|
||||
let wrapper = ListenerWrapper()
|
||||
wrapper.listener = listener
|
||||
@@ -100,10 +110,10 @@ final class NotificationClient {
|
||||
})
|
||||
}
|
||||
|
||||
func markNotificationRead(id: String) {
|
||||
func markNotificationRead(id: String, isOpen: Bool) {
|
||||
for wrapper in listeners {
|
||||
if let listener = wrapper.listener {
|
||||
listener.willMarkRead(client: self, id: id)
|
||||
listener.willMarkRead(client: self, id: id, isOpen: isOpen)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +125,7 @@ final class NotificationClient {
|
||||
if !success {
|
||||
for wrapper in self.listeners {
|
||||
if let listener = wrapper.listener {
|
||||
listener.didFailToMarkRead(client: self, id: id)
|
||||
listener.didFailToMarkRead(client: self, id: id, isOpen: isOpen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,14 @@ SwipeCollectionViewCellDelegate {
|
||||
}
|
||||
|
||||
override func didSelectItem(at index: Int) {
|
||||
guard let object = self.object else { fatalError("Should have an object") }
|
||||
guard let object = self.object,
|
||||
let cell = collectionContext?.cellForItem(at: index, sectionController: self) as? NotificationCell
|
||||
else { fatalError("Missing object, cell missing, or incorrect type") }
|
||||
|
||||
if NotificationClient.readOnOpen() {
|
||||
cell.isRead = true
|
||||
client.markNotificationRead(id: object.id, isOpen: true)
|
||||
}
|
||||
|
||||
let controller = NavigateToNotificationContent(object: object, client: client.githubClient)
|
||||
viewController?.showDetailViewController(controller, sender: nil)
|
||||
@@ -51,7 +58,7 @@ SwipeCollectionViewCellDelegate {
|
||||
|
||||
func markRead() {
|
||||
guard let object = object else { fatalError("Should have an object") }
|
||||
client.markNotificationRead(id: object.id)
|
||||
client.markNotificationRead(id: object.id, isOpen: false)
|
||||
collectionContext?.performBatch(animated: true, updates: { context in
|
||||
context.reload(self)
|
||||
})
|
||||
|
||||
@@ -236,15 +236,21 @@ ForegroundHandlerDelegate {
|
||||
|
||||
// MARK: NotificationClientListener
|
||||
|
||||
func willMarkRead(client: NotificationClient, id: String) {
|
||||
func willMarkRead(client: NotificationClient, id: String, isOpen: Bool) {
|
||||
dataSource.setOptimisticRead(id: id)
|
||||
update(dismissRefresh: false, animated: true)
|
||||
|
||||
if !isOpen {
|
||||
update(dismissRefresh: false, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
func didFailToMarkRead(client: NotificationClient, id: String) {
|
||||
func didFailToMarkRead(client: NotificationClient, id: String, isOpen: Bool) {
|
||||
dataSource.removeOptimisticRead(id: id)
|
||||
StatusBar.showGenericError()
|
||||
update(dismissRefresh: false, animated: true)
|
||||
|
||||
if !isOpen {
|
||||
update(dismissRefresh: false, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: NotificationNextPageSectionControllerDelegate
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<color key="separatorColor" red="0.73725490196078436" green="0.73333333333333328" blue="0.75686274509803919" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<inset key="separatorInset" minX="15" minY="0.0" maxX="0.0" maxY="0.0"/>
|
||||
<view key="tableFooterView" contentMode="scaleToFill" id="jkq-3p-p02">
|
||||
<rect key="frame" x="0.0" y="385.5" width="375" height="44"/>
|
||||
<rect key="frame" x="0.0" y="429.5" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Version 1.4.0 (1207)" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2bb-Lj-p2k">
|
||||
@@ -138,12 +138,42 @@
|
||||
</tableViewCellContentView>
|
||||
<inset key="separatorInset" minX="15" minY="0.0" maxX="0.0" maxY="0.0"/>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="U6l-Zw-17s" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="287.5" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="U6l-Zw-17s" id="cMZ-jh-esi">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="View Marks Read" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vFz-nF-pf2">
|
||||
<rect key="frame" x="15" y="12" width="125" height="20"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="16"/>
|
||||
<color key="textColor" red="0.14117647059999999" green="0.16078431369999999" blue="0.18039215689999999" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8dQ-YU-Yuw">
|
||||
<rect key="frame" x="311" y="6" width="51" height="31"/>
|
||||
<connections>
|
||||
<action selector="onBackgroundFetchChanged" destination="NnB-TU-bkW" eventType="valueChanged" id="ePm-x8-F16"/>
|
||||
<action selector="onMarkRead:" destination="NnB-TU-bkW" eventType="valueChanged" id="QPk-DK-Ufx"/>
|
||||
</connections>
|
||||
</switch>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="vFz-nF-pf2" firstAttribute="centerY" secondItem="cMZ-jh-esi" secondAttribute="centerY" id="BNn-oJ-HMH"/>
|
||||
<constraint firstItem="8dQ-YU-Yuw" firstAttribute="centerY" secondItem="cMZ-jh-esi" secondAttribute="centerY" id="C0M-rY-Ybl"/>
|
||||
<constraint firstAttribute="trailing" secondItem="8dQ-YU-Yuw" secondAttribute="trailing" constant="15" id="d02-AH-Owk"/>
|
||||
<constraint firstItem="vFz-nF-pf2" firstAttribute="leading" secondItem="cMZ-jh-esi" secondAttribute="leading" constant="15" id="gBJ-QS-bCQ"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<inset key="separatorInset" minX="15" minY="0.0" maxX="0.0" maxY="0.0"/>
|
||||
</tableViewCell>
|
||||
</cells>
|
||||
</tableViewSection>
|
||||
<tableViewSection id="GTg-1u-cvV">
|
||||
<cells>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="ku5-ZI-OG9" style="IBUITableViewCellStyleDefault" id="Y2k-Zq-AUW" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="323.5" width="375" height="44"/>
|
||||
<rect key="frame" x="0.0" y="367.5" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Y2k-Zq-AUW" id="XiT-sq-B22">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
|
||||
@@ -178,6 +208,7 @@
|
||||
<connections>
|
||||
<outlet property="backgroundFetchSwitch" destination="FvK-93-raA" id="Huy-vc-MoM"/>
|
||||
<outlet property="badgeCell" destination="pnm-5p-yC5" id="hdC-aO-QSy"/>
|
||||
<outlet property="markReadSwitch" destination="8dQ-YU-Yuw" id="5jz-5d-osk"/>
|
||||
<outlet property="openSettingsButton" destination="36B-Ge-m5V" id="tsc-wS-3vb"/>
|
||||
<outlet property="reportBugCell" destination="WwO-m1-s3q" id="nCb-BL-DRJ"/>
|
||||
<outlet property="reviewAccessCell" destination="TXs-sw-hO1" id="10W-u8-ofC"/>
|
||||
|
||||
@@ -22,11 +22,13 @@ final class SettingsViewController: UITableViewController {
|
||||
@IBOutlet weak var backgroundFetchSwitch: UISwitch!
|
||||
@IBOutlet weak var openSettingsButton: UIButton!
|
||||
@IBOutlet weak var badgeCell: UITableViewCell!
|
||||
@IBOutlet weak var markReadSwitch: UISwitch!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
versionLabel.text = Bundle.main.prettyVersionString
|
||||
markReadSwitch.isOn = NotificationClient.readOnOpen()
|
||||
|
||||
updateBadge()
|
||||
|
||||
@@ -148,4 +150,7 @@ final class SettingsViewController: UITableViewController {
|
||||
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
||||
}
|
||||
|
||||
@IBAction func onMarkRead(_ sender: Any) {
|
||||
NotificationClient.setReadOnOpen(open: markReadSwitch.isOn)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1446</string>
|
||||
<string>1448</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
|
||||
Reference in New Issue
Block a user