Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit ea8b64a

Browse files
committed
Fixed crash
1 parent 1128d67 commit ea8b64a

5 files changed

+37
-17
lines changed

Slide for Apple Watch Extension/InterfaceController.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class InterfaceController: WKInterfaceController {
2626
var page = 1
2727
var last = 0
2828
var currentSub = ""
29+
var isPro = false
2930

3031
override func willActivate() {
3132
// This method is called when watch view controller is about to be visible to user
@@ -105,7 +106,6 @@ class InterfaceController: WKInterfaceController {
105106
extension InterfaceController: WCSessionDelegate {
106107

107108
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String: Any]) {
108-
print("Doing links")
109109
DispatchQueue.main.async {
110110
self.setTitle(applicationContext["title"] as? String)
111111
self.beginLoadingTable()
@@ -120,6 +120,7 @@ extension InterfaceController: WCSessionDelegate {
120120
session.sendMessage(["sublist": true], replyHandler: { (message) in
121121
self.subs = message["subs"] as? [String: String] ?? [String: String]()
122122
self.subsOrdered = message["orderedsubs"] as? [String] ?? [String]()
123+
self.isPro = message["pro"] as? Bool ?? false
123124
if self.subsOrdered.count > 0 {
124125
self.getSubmissions(self.subsOrdered[0], reset: true)
125126
}

Slide for Reddit/ContentListingViewController.swift

+24-8
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ class ContentListingViewController: MediaViewController, UICollectionViewDelegat
137137

138138
func collectionView(_ tableView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
139139
if baseData.content.count == 0 {
140-
return tableView.dequeueReusableCell(withReuseIdentifier: "nocontent", for: indexPath)
140+
let cell = tableView.dequeueReusableCell(withReuseIdentifier: "nocontent", for: indexPath) as! NoContentCell
141+
cell.doText(controller: self)
142+
return cell
141143
}
142144
let thing = baseData.content[indexPath.row]
143145
var cell: UICollectionViewCell?
@@ -498,10 +500,15 @@ extension ContentListingViewController: LinkCellViewDelegate {
498500
ReadLater.removeReadLater(id: cell.link!.getId())
499501
let savedIndex = tableView.indexPath(for: cell)?.row ?? 0
500502
self.baseData.content.remove(at: savedIndex)
501-
self.tableView.reloadData()
503+
if self.baseData.content.count == 0 {
504+
self.tableView.reloadData()
505+
} else {
506+
self.tableView.deleteItems(at: [IndexPath.init(row: savedIndex, section: 0)])
507+
}
502508
BannerUtil.makeBanner(text: "Removed from Read Later", color: GMColor.red500Color(), seconds: 3, context: self, top: false) {
503509
ReadLater.addReadLater(id: cell.link!.getId(), subreddit: cell.link!.subreddit)
504510
self.baseData.content.insert(cell.link!, at: savedIndex)
511+
self.tableView.insertItems(at: [IndexPath.init(row: savedIndex, section: 0)])
505512
}
506513
}
507514
}
@@ -516,17 +523,19 @@ public class NoContentCell: UICollectionViewCell {
516523
super.init(frame: frame)
517524
setupView()
518525
}
526+
var title = UILabel()
519527

520528
required public init?(coder aDecoder: NSCoder) {
521529
fatalError("init(coder:) has not been implemented")
522530
}
523531

524-
func setupView() {
525-
let title = UILabel()
526-
title.backgroundColor = ColorUtil.foregroundColor
527-
title.textAlignment = .center
528-
529-
let text = "Nothing to see here!\nNo content was found"
532+
func doText(controller: ContentListingViewController){
533+
let text: String
534+
if controller is ReadLaterViewController {
535+
text = "Nothing to see here!\nNo more posts to Read Later"
536+
} else {
537+
text = "Nothing to see here!\nNo content was found"
538+
}
530539
let textParts = text.components(separatedBy: "\n")
531540

532541
let finalText: NSMutableAttributedString!
@@ -539,6 +548,13 @@ public class NoContentCell: UICollectionViewCell {
539548
finalText = NSMutableAttributedString.init(string: text, attributes: [NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14)])
540549
}
541550
title.attributedText = finalText
551+
}
552+
553+
func setupView() {
554+
title = UILabel()
555+
title.backgroundColor = ColorUtil.foregroundColor
556+
title.textAlignment = .center
557+
542558
title.numberOfLines = 0
543559
title.layer.cornerRadius = 15
544560
title.clipsToBounds = true

Slide for Reddit/LinkCellView.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,9 @@ class LinkCellView: UICollectionViewCell, UIViewControllerPreviewingDelegate, TT
921921
overView.layer.cornerRadius = 15
922922
overView.clipsToBounds = true
923923
}
924+
if #available(iOS 10.0, *) {
925+
HapticUtility.hapticActionStrong()
926+
}
924927
typeImage.image = UIImage(named: SettingValues.submissionActionDoubleTap.getPhoto())?.getCopy(withSize: CGSize.square(size: 30), withColor: .white)
925928
typeImage.backgroundColor = SettingValues.submissionActionDoubleTap.getColor()
926929
contentView.addSubviews(typeImage, overView)
@@ -931,7 +934,7 @@ class LinkCellView: UICollectionViewCell, UIViewControllerPreviewingDelegate, TT
931934
typeImage.centerAnchors == self.contentView.centerAnchors
932935
typeImage.heightAnchor == 45
933936
typeImage.widthAnchor == 45
934-
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseInOut, animations: {
937+
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseInOut, animations: {
935938
self.typeImage.alpha = 0
936939
overView.alpha = 0
937940
self.typeImage.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)

Slide for Reddit/SingleSubredditViewController.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ extension SingleSubredditViewController: UICollectionViewDelegate {
20162016
}
20172017

20182018
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
2019-
if indexPath.row == 0 && readLaterArticles > 0 && !loading && loaded {
2019+
if indexPath.row == 0 && readLaterArticles > 0 && loaded {
20202020
VCPresenter.showVC(viewController: ReadLaterViewController(subreddit: sub) , popupIfPossible: false, parentNavigationController: self.navigationController, parentViewController: self)
20212021
}
20222022
}
@@ -2026,17 +2026,17 @@ extension SingleSubredditViewController: UICollectionViewDelegate {
20262026
extension SingleSubredditViewController: UICollectionViewDataSource {
20272027

20282028
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
2029-
return links.count + ((links.count != 0 && loaded) ? 1 : 0) + (readLaterArticles > 0 && !loading && loaded ? 1 : 0)
2029+
return links.count + ((links.count != 0 && loaded) ? 1 : 0) + (readLaterArticles > 0 && loaded ? 1 : 0)
20302030
}
20312031

20322032
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
2033-
if indexPath.row == 0 && readLaterArticles > 0 && !loading && loaded {
2033+
if indexPath.row == 0 && readLaterArticles > 0 && loaded {
20342034
let cell = tableView.dequeueReusableCell(withReuseIdentifier: "readlater", for: indexPath) as! ReadLaterCell
20352035
cell.setArticles(articles: self.readLaterArticles)
20362036
return cell
20372037
}
20382038

2039-
let row = indexPath.row - (readLaterArticles > 0 && !loading && loaded ? 1 : 0)
2039+
let row = indexPath.row - (readLaterArticles > 0 && loaded ? 1 : 0)
20402040
if row >= self.links.count {
20412041
let cell = tableView.dequeueReusableCell(withReuseIdentifier: "loading", for: indexPath) as! LoadingCell
20422042
cell.loader.color = ColorUtil.fontColor
@@ -2165,10 +2165,10 @@ extension SingleSubredditViewController: ColorPickerViewDelegate {
21652165
// MARK: - Wrapping Flow Layout Delegate
21662166
extension SingleSubredditViewController: WrappingFlowLayoutDelegate {
21672167
func collectionView(_ collectionView: UICollectionView, width: CGFloat, indexPath: IndexPath) -> CGSize {
2168-
if indexPath.row == 0 && readLaterArticles > 0 && !loading && loaded {
2168+
if indexPath.row == 0 && readLaterArticles > 0 && loaded {
21692169
return CGSize(width: width, height: 60)
21702170
}
2171-
let row = indexPath.row - (readLaterArticles > 0 && !loading && loaded ? 1 : 0)
2171+
let row = indexPath.row - (readLaterArticles > 0 && loaded ? 1 : 0)
21722172
if row < links.count {
21732173
let submission = links[row]
21742174
if submission.author == "PAGE_SEPARATOR" {

Slide for Reddit/WatchSessionManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class WatchSessionManager: NSObject, WCSessionDelegate {
4949
for sub in Subscriptions.subreddits {
5050
colorDict[sub] = ColorUtil.getColorForSub(sub: sub).hexString
5151
}
52-
replyHandler(["subs": colorDict, "orderedsubs": sublist])
52+
replyHandler(["subs": colorDict, "orderedsubs": sublist, "pro": SettingValues.isPro])
5353
} else if message["links"] != nil {
5454
if message["reset"] as? Bool ?? true {
5555
paginator = Paginator()

0 commit comments

Comments
 (0)