Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit b489e8d

Browse files
authored
Local push notifications (#2145)
* add fmdb * add local notification cache mechanism * rewiring to update local db when fetching notifications * local pushes working * building for xcode 10
1 parent f131dc6 commit b489e8d

File tree

54 files changed

+12716
-5957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+12716
-5957
lines changed

Classes/Issues/IssueStatus+ButtonState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
extension IssueStatus {
12-
var buttonState: UIButton.State {
12+
var buttonState: UIButton.IssueState {
1313
switch self {
1414
case .closed: return .closed
1515
case .open: return .open

Classes/Issues/Referenced/IssueReferencedCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class IssueReferencedCell: StyledTextViewCell {
4242
func configure(_ model: IssueReferencedModel) {
4343
set(renderer: model.string)
4444

45-
let buttonState: UIButton.State
45+
let buttonState: UIButton.IssueState
4646
switch model.state {
4747
case .closed: buttonState = .closed
4848
case .merged: buttonState = .merged

Classes/Issues/StatusEvent/IssueStatusEvent+ButtonState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
extension IssueStatusEvent {
12-
var buttonState: UIButton.State {
12+
var buttonState: UIButton.IssueState {
1313
switch self {
1414
case .closed: return .closed
1515
case .reopened: return .open

Classes/Notifications/NotificationModelController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ final class NotificationModelController {
5151
width: CGFloat,
5252
completion: @escaping (Result<([NotificationViewModel], Int?)>) -> Void
5353
) {
54+
let badge = githubClient.badge
5455
let contentSizeCategory = UIContentSizeCategory.preferred
5556
// TODO move handling + parsing to a single method?
5657
if let repo = repo {
5758
githubClient.client.send(V3RepositoryNotificationRequest(all: all, owner: repo.owner, repo: repo.name)) { result in
5859
switch result {
5960
case .success(let response):
61+
badge.updateLocalNotificationCache(notifications: response.data, showAlert: false)
62+
6063
CreateNotificationViewModels(
6164
width: width,
6265
contentSizeCategory: contentSizeCategory,
@@ -72,6 +75,8 @@ final class NotificationModelController {
7275
githubClient.client.send(V3NotificationRequest(all: all, page: page)) { result in
7376
switch result {
7477
case .success(let response):
78+
badge.updateLocalNotificationCache(notifications: response.data, showAlert: false)
79+
7580
CreateNotificationViewModels(
7681
width: width,
7782
contentSizeCategory: contentSizeCategory,

Classes/Notifications/NotificationsViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ BaseListViewController2EmptyDataSource {
129129
let hasUnread = unread > 0
130130
navigationItem.rightBarButtonItem?.isEnabled = hasUnread
131131
navigationController?.tabBarItem.badgeValue = hasUnread ? "\(unread)" : nil
132-
BadgeNotifications.update(count: unread)
132+
BadgeNotifications.updateBadge(count: unread)
133133
}
134134

135135
@objc func onMore(sender: UIBarButtonItem) {
@@ -227,7 +227,7 @@ BaseListViewController2EmptyDataSource {
227227
generator.notificationOccurred(.success)
228228

229229
// clear all badges
230-
BadgeNotifications.update(count: 0)
230+
BadgeNotifications.updateBadge(count: 0)
231231

232232
// change the spinner to the mark all item
233233
// don't update state here; it is managed by `fetch`

Classes/Settings/Settings.storyboard

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<color key="separatorColor" red="0.73725490196078436" green="0.73333333333333328" blue="0.75686274509803919" alpha="1" colorSpace="calibratedRGB"/>
2121
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
2222
<view key="tableFooterView" contentMode="scaleToFill" id="jkq-3p-p02">
23-
<rect key="frame" x="0.0" y="649.5" width="375" height="44"/>
23+
<rect key="frame" x="0.0" y="693.5" width="375" height="44"/>
2424
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2525
<subviews>
2626
<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" customClass="SettingsLabel" customModule="Freetime" customModuleProvider="target">
@@ -205,7 +205,7 @@
205205
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FvK-93-raA" customClass="StyledSwitch" customModule="Freetime" customModuleProvider="target">
206206
<rect key="frame" x="311" y="6" width="51" height="31"/>
207207
<connections>
208-
<action selector="onBackgroundFetchChanged" destination="NnB-TU-bkW" eventType="valueChanged" id="gPu-bQ-K9r"/>
208+
<action selector="onBadgeChanged" destination="NnB-TU-bkW" eventType="valueChanged" id="l51-6Q-vcD"/>
209209
</connections>
210210
</switch>
211211
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="36B-Ge-m5V">
@@ -230,9 +230,50 @@
230230
</tableViewCellContentView>
231231
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
232232
</tableViewCell>
233-
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="U6l-Zw-17s" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
233+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="pbF-qp-TdT" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
234234
<rect key="frame" x="0.0" y="419.5" width="375" height="44"/>
235235
<autoresizingMask key="autoresizingMask"/>
236+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="pbF-qp-TdT" id="nUN-Hd-0xp">
237+
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
238+
<autoresizingMask key="autoresizingMask"/>
239+
<subviews>
240+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Push Notifications" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vNL-qr-bAj" customClass="SettingsLabel" customModule="Freetime" customModuleProvider="target">
241+
<rect key="frame" x="16" y="12" width="132" height="20"/>
242+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
243+
<color key="textColor" red="0.14117647059999999" green="0.16078431369999999" blue="0.18039215689999999" alpha="1" colorSpace="calibratedRGB"/>
244+
<nil key="highlightedColor"/>
245+
</label>
246+
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="T30-uT-48L" customClass="StyledSwitch" customModule="Freetime" customModuleProvider="target">
247+
<rect key="frame" x="311" y="6" width="51" height="31"/>
248+
<connections>
249+
<action selector="onPushChanged" destination="NnB-TU-bkW" eventType="valueChanged" id="3Sx-fq-g7U"/>
250+
</connections>
251+
</switch>
252+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HFk-Cc-92g">
253+
<rect key="frame" x="315" y="5" width="60" height="32"/>
254+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
255+
<state key="normal" title="Settings">
256+
<color key="titleColor" red="0.63921568630000003" green="0.66666666669999997" blue="0.69411764710000001" alpha="1" colorSpace="calibratedRGB"/>
257+
</state>
258+
<connections>
259+
<action selector="onSettings:" destination="NnB-TU-bkW" eventType="touchUpInside" id="eCr-BP-8PS"/>
260+
</connections>
261+
</button>
262+
</subviews>
263+
<constraints>
264+
<constraint firstAttribute="trailing" secondItem="T30-uT-48L" secondAttribute="trailing" constant="15" id="6RB-2m-fYA"/>
265+
<constraint firstItem="HFk-Cc-92g" firstAttribute="centerY" secondItem="nUN-Hd-0xp" secondAttribute="centerY" id="Ind-0b-it6"/>
266+
<constraint firstItem="vNL-qr-bAj" firstAttribute="centerY" secondItem="nUN-Hd-0xp" secondAttribute="centerY" id="TTt-u4-ANE"/>
267+
<constraint firstAttribute="trailing" secondItem="HFk-Cc-92g" secondAttribute="trailing" id="ZLK-Ic-qgC"/>
268+
<constraint firstItem="vNL-qr-bAj" firstAttribute="leading" secondItem="nUN-Hd-0xp" secondAttribute="leading" constant="16" id="o6O-Rl-PO6"/>
269+
<constraint firstItem="T30-uT-48L" firstAttribute="centerY" secondItem="nUN-Hd-0xp" secondAttribute="centerY" id="wgd-mx-RqK"/>
270+
</constraints>
271+
</tableViewCellContentView>
272+
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
273+
</tableViewCell>
274+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="U6l-Zw-17s" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
275+
<rect key="frame" x="0.0" y="463.5" width="375" height="44"/>
276+
<autoresizingMask key="autoresizingMask"/>
236277
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="U6l-Zw-17s" id="cMZ-jh-esi">
237278
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
238279
<autoresizingMask key="autoresizingMask"/>
@@ -260,7 +301,7 @@
260301
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
261302
</tableViewCell>
262303
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="0eH-mW-WpD" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
263-
<rect key="frame" x="0.0" y="463.5" width="375" height="44"/>
304+
<rect key="frame" x="0.0" y="507.5" width="375" height="44"/>
264305
<autoresizingMask key="autoresizingMask"/>
265306
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="0eH-mW-WpD" id="dAx-L4-nLX">
266307
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
@@ -289,7 +330,7 @@
289330
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
290331
</tableViewCell>
291332
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="Z8j-JQ-qiy" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
292-
<rect key="frame" x="0.0" y="507.5" width="375" height="44"/>
333+
<rect key="frame" x="0.0" y="551.5" width="375" height="44"/>
293334
<autoresizingMask key="autoresizingMask"/>
294335
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Z8j-JQ-qiy" id="uAb-lB-GZA">
295336
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
@@ -320,7 +361,7 @@
320361
<tableViewSection id="GTg-1u-cvV">
321362
<cells>
322363
<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">
323-
<rect key="frame" x="0.0" y="587.5" width="375" height="44"/>
364+
<rect key="frame" x="0.0" y="631.5" width="375" height="44"/>
324365
<autoresizingMask key="autoresizingMask"/>
325366
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Y2k-Zq-AUW" id="XiT-sq-B22">
326367
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
@@ -350,12 +391,15 @@
350391
<outlet property="accountsCell" destination="64O-sw-wTx" id="UPX-Wa-mYM"/>
351392
<outlet property="apiStatusLabel" destination="rIC-a2-0GF" id="ceC-Ij-CrY"/>
352393
<outlet property="apiStatusView" destination="1mP-Dr-7rt" id="f66-HG-AkG"/>
353-
<outlet property="backgroundFetchSwitch" destination="FvK-93-raA" id="Huy-vc-MoM"/>
354394
<outlet property="badgeCell" destination="pnm-5p-yC5" id="hdC-aO-QSy"/>
395+
<outlet property="badgeSettingsButton" destination="36B-Ge-m5V" id="7Sw-oi-5Ra"/>
396+
<outlet property="badgeSwitch" destination="FvK-93-raA" id="twy-bl-O1q"/>
355397
<outlet property="defaultReactionLabel" destination="UHH-lU-DUe" id="ew2-Hr-5UH"/>
356398
<outlet property="githubStatusCell" destination="x9n-2O-buf" id="xc3-W3-bZW"/>
357399
<outlet property="markReadSwitch" destination="8dQ-YU-Yuw" id="5jz-5d-osk"/>
358-
<outlet property="openSettingsButton" destination="36B-Ge-m5V" id="tsc-wS-3vb"/>
400+
<outlet property="pushCell" destination="pbF-qp-TdT" id="zVp-UJ-bIl"/>
401+
<outlet property="pushSettingsButton" destination="HFk-Cc-92g" id="1fa-Sc-SQ1"/>
402+
<outlet property="pushSwitch" destination="T30-uT-48L" id="mNm-JM-Q97"/>
359403
<outlet property="reportBugCell" destination="WwO-m1-s3q" id="nCb-BL-DRJ"/>
360404
<outlet property="reviewAccessCell" destination="TXs-sw-hO1" id="10W-u8-ofC"/>
361405
<outlet property="reviewOnAppStoreCell" destination="Z8j-JQ-qiy" id="QRZ-5e-WQi"/>

0 commit comments

Comments
 (0)