Skip to content

Commit 5164edc

Browse files
committed
Fix deeplink breaking news loading
1 parent 0dba973 commit 5164edc

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

ForPDA/Sources/Application/SceneDelegate.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
4242
// todo обработать нормально
4343
try? DefaultRouter().navigate(to: RouteMap.newsScreen, with: nil)
4444
} else {
45+
settingsService.setIsDeeplinking(to: true)
4546
let id = url.absoluteString.components(separatedBy: "article/")[1]
46-
let url = "https://4pda.to/\(id)"
47+
let url = URL.fourpda.absoluteString + id
4748
let article = Article(url: url, info: nil)
4849
try? DefaultRouter().navigate(to: RouteMap.articleScreen, with: article)
4950
}

ForPDA/Sources/Modules/News/NewsPresenter.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ final class NewsPresenter: NSObject, NewsPresenterProtocol {
5151
func loadArticles() {
5252
page += 1
5353

54-
switch fastLoadingSystem {
55-
case true:
54+
// Если происходит диплинк не на быстрой загрузке, то используем быструю загрузку
55+
// todo переделать
56+
let isDeeplinking = settingsService.getIsDeeplinking()
57+
58+
switch (fastLoadingSystem, isDeeplinking) {
59+
case (true, _), (_, true):
5660
networkService.getNews(page: page) { [weak self] result in
5761
guard let self else { return }
5862
switch result {
@@ -68,8 +72,9 @@ final class NewsPresenter: NSObject, NewsPresenterProtocol {
6872
}
6973
}
7074
}
75+
settingsService.setIsDeeplinking(to: false)
7176

72-
case false:
77+
case (false, _):
7378
slowLoad(url: URL.fourpda(page: page))
7479
}
7580
}

ForPDA/Sources/Services/Storage/SettingsService.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ final class SettingsService {
2020
static let appDarkThemeBackgroundColor = "appDarkThemeBackgroundColor"
2121
static let fastLoadingSystem = "fastLoadingSystem"
2222
static let showLikesInComments = "showLikesInComments"
23+
static let isDeeplinking = "isDeeplinking"
2324
}
2425

2526
// MARK: - Cookies
@@ -135,4 +136,18 @@ final class SettingsService {
135136
return true
136137
}
137138
}
139+
140+
// MARK: - Is Deeplinking
141+
142+
func setIsDeeplinking(to state: Bool) {
143+
defaults.set(state, forKey: Keys.isDeeplinking)
144+
}
145+
146+
func getIsDeeplinking() -> Bool {
147+
if let isDeeplinking = defaults.value(forKey: Keys.isDeeplinking) as? Bool {
148+
return isDeeplinking
149+
} else {
150+
return false
151+
}
152+
}
138153
}

0 commit comments

Comments
 (0)