Skip to content

Commit f0994cc

Browse files
committed
Complete rewrite of article parse & show system
1 parent 9ea950d commit f0994cc

Some content is hidden

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

41 files changed

+1713
-90
lines changed

ForPDA.xcodeproj/project.pbxproj

Lines changed: 176 additions & 0 deletions
Large diffs are not rendered by default.

ForPDA.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ForPDA/Sources/Application/SceneDelegate.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ extension SceneDelegate {
4747
// Cold start deeplink
4848
handleDeeplinkUrl(url)
4949
} else {
50-
// Handle 'try?' later (todo)
51-
// handleDeeplinkUrl(URL(string: "forpda://article/2023/10/21/419630/")!)
52-
try? DefaultRouter().navigate(to: RouteMap.newsScreen, with: nil)
50+
// Handle all 'try?' on routers? (todo)
51+
// Wrong link is not showing anything (todo)
52+
let testLink = "" // format starts/ends with slash: /2023/../../....../
53+
if testLink.isEmpty {
54+
try? DefaultRouter().navigate(to: RouteMap.newsScreen, with: nil)
55+
} else {
56+
// Testing purposes only
57+
handleDeeplinkUrl(URL(string: "forpda://article\(testLink)")!)
58+
}
5359
}
5460
}
5561

@@ -62,7 +68,7 @@ extension SceneDelegate {
6268
let id = url.absoluteString.components(separatedBy: "article/")[1]
6369
let url = URL.fourpda.absoluteString + id
6470
let article = Article(url: url, info: nil)
65-
try? DefaultRouter().navigate(to: RouteMap.articleScreen, with: article)
71+
try? DefaultRouter().navigate(to: RouteMap.newArticleScreen, with: article)
6672
}
6773
}
6874

ForPDA/Sources/Coordinator/RouteMap.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ struct RouteMap: RouteMapProtocol {
4343
.assemble()
4444
}
4545

46+
static var newArticleScreen: DestinationStep<NewArticleVC, Article> {
47+
StepAssembly(
48+
finder: ClassFinder<NewArticleVC, Article>(),
49+
factory: NewArticleFactory())
50+
.using(UINavigationController.push())
51+
.from(newsScreen.expectingContainer())
52+
.assemble()
53+
}
54+
4655
// MARK: - [Menu]
4756

4857
static var menuScreen: DestinationStep<MenuVC, Any?> {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// UICollectionView+Ext.swift
3+
// ForPDA
4+
//
5+
// Created by Ilia Lubianoi on 04.11.2023.
6+
//
7+
8+
import UIKit
9+
10+
extension UICollectionViewCell {
11+
12+
static var reuseIdentifier: String {
13+
String(describing: self)
14+
}
15+
16+
}
17+
18+
extension UICollectionView {
19+
20+
func register<T: UICollectionViewCell>(_ type: T.Type) {
21+
register(T.self, forCellWithReuseIdentifier: T.reuseIdentifier)
22+
}
23+
24+
func reuse<T: UICollectionViewCell>(_ type: T.Type, _ indexPath: IndexPath) -> T {
25+
// swiftlint:disable force_cast
26+
dequeueReusableCell(withReuseIdentifier: T.reuseIdentifier, for: indexPath) as! T
27+
// swiftlint:enable force_cast
28+
}
29+
}

ForPDA/Sources/Models/Article.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Article {
1515
struct ArticleInfo {
1616
let title: String
1717
let description: String
18-
let imageUrl: String
18+
let imageUrl: URL
1919
let author: String
2020
let date: String
2121
let isReview: Bool

ForPDA/Sources/Modules/Article/ArticleBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class ArticleBuilder {
2121
if description.contains("Узнать подробнее") { description.removeLast(16) }
2222
return [
2323
TextElement(text: description),
24-
ButtonElement(text: R.string.localizable.learnMore(), url: url)
24+
ButtonElement(text: R.string.localizable.learnMore(), url: URL(string: url)!)
2525
]
2626
}
2727

ForPDA/Sources/Modules/Article/ArticleVC.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protocol ArticleVCProtocol: AnyObject {
2020
func showError()
2121
}
2222

23-
final class ArticleVC: PDAViewController<ArticleView> {
23+
final class ArticleVC: PDAViewControllerWithView<ArticleView> {
2424

2525
// MARK: - Properties
2626

@@ -71,7 +71,7 @@ final class ArticleVC: PDAViewController<ArticleView> {
7171
}
7272

7373
private func configureView() {
74-
NukeExtensions.loadImage(with: URL(string: presenter.article.info?.imageUrl), into: myView.articleImage) { result in
74+
NukeExtensions.loadImage(with: presenter.article.info?.imageUrl, into: myView.articleImage) { result in
7575
// Добавляем оверлей если открываем не через deeplink (?)
7676
if (try? result.get()) != nil { self.myView.articleImage.addoverlay() }
7777
}
@@ -133,16 +133,16 @@ final class ArticleVC: PDAViewController<ArticleView> {
133133
)
134134

135135
case let item as ImageElement:
136-
articleElement = ArticleBuilder.addImage(url: item.url, description: item.description)
136+
articleElement = ArticleBuilder.addImage(url: item.url.absoluteString, description: item.description)
137137

138138
case let item as VideoElement:
139139
articleElement = ArticleBuilder.addVideo(id: item.url)
140140

141141
case let item as GifElement:
142-
articleElement = ArticleBuilder.addGif(url: item.url)
142+
articleElement = ArticleBuilder.addGif(url: item.url.absoluteString)
143143

144144
case let item as ButtonElement:
145-
articleElement = ArticleBuilder.addButton(text: item.text, url: item.url) { [weak self] link in
145+
articleElement = ArticleBuilder.addButton(text: item.text, url: item.url.absoluteString) { [weak self] link in
146146
self?.externalLinkButtonTapped(link)
147147
}
148148

ForPDA/Sources/Modules/Login/LoginVC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protocol LoginVCProtocol: AnyObject {
1818
func dismissLogin()
1919
}
2020

21-
final class LoginVC: PDAViewController<LoginView> {
21+
final class LoginVC: PDAViewControllerWithView<LoginView> {
2222

2323
// MARK: - Properties
2424

ForPDA/Sources/Modules/Menu/MenuVC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protocol MenuVCProtocol: AnyObject {
1414
func reloadData()
1515
}
1616

17-
final class MenuVC: PDAViewController<MenuView> {
17+
final class MenuVC: PDAViewControllerWithView<MenuView> {
1818

1919
// MARK: - Properties
2020

0 commit comments

Comments
 (0)