Skip to content

Commit 3588ef6

Browse files
committed
Revert to single FLS system
1 parent 018ea16 commit 3588ef6

File tree

8 files changed

+47
-102
lines changed

8 files changed

+47
-102
lines changed

ForPDA/Resources/en.lproj/Localizable.strings

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@
7272
"background.dark" = "Dark";
7373
"background.black" = "Black";
7474
"advanced" = "Advanced";
75-
"fast.loading.news" = "Fast loading news";
76-
"fast.loading.news.warning" = "After activiting this option some of the last news may not load and/or show wrong amount of comments";
77-
"fast.loading.article" = "Fast loading article";
78-
"fast.loading.article.warning" = "After activiting this option you won't see likes on the comments automatically";
75+
"fast.loading.system" = "Fast loading news";
76+
"fast.loading.system.warning" = "After activiting this option latest news may not load and show wrong amount of comments, and likes may not appear in articles";
7977
"comments.show.likes" = "Show likes";
80-
"comments.show.likes.warning" = "After activiting this option and \"Fast loading article\" you may see increase of traffic usage";
78+
"comments.show.likes.warning" = "After activiting this option with \"Fast loading article\" you may see increase in traffic usage";
8179
"account" = "Account";
8280
"sign.out" = "Sign Out";
8381
"about.app" = "About App";

ForPDA/Resources/ru.lproj/Localizable.strings

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@
7272
"background.dark" = "Темный";
7373
"background.black" = "Черный";
7474
"advanced" = "Продвинутые";
75-
"fast.loading.news" = "Быстрая загрузка новостей";
76-
"fast.loading.news.warning" = "При активации этой функции последние статьи могут не отображаться, а количество лайков не соответствовать действительности";
77-
"fast.loading.article" = "Быстрая загрузка новости";
78-
"fast.loading.article.warning" = "После активации этой функции, количество лайков на комментариях не будет отображаться";
75+
"fast.loading.system" = "Быстрая загрузка новостей";
76+
"fast.loading.system.warning" = "При активации этой функции статьи могут обновляться с задержкой, отображать неверное количество комментариев, а лайки в статьях не отображаться";
7977
"comments.show.likes" = "Отображать лайки";
80-
"comments.show.likes.warning" = "При активации этой функции вместе с \"Быстрая загрузка новости\" может быть увеличенный расход трафика";
78+
"comments.show.likes.warning" = "При активации этой функции вместе с \"Быстрая загрузка новостей\" может быть увеличенный расход трафика";
8179
"account" = "Аккаунт";
8280
"sign.out" = "Выйти";
8381
"about.app" = "О приложении";

ForPDA/Sources/Modules/Article/ArticlePresenter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ final class ArticlePresenter: ArticlePresenterProtocol {
7272
// MARK: - Private Functions
7373

7474
private func showLikesIfNeeded() async {
75-
let articleUsesFLS = settingsService.getArticleFLS()
75+
let isFLSEnabled = settingsService.getFastLoadingSystem()
7676
let showLikes = settingsService.getShowLikesInComments()
7777

78-
if articleUsesFLS && showLikes {
78+
if isFLSEnabled && showLikes {
7979
await updateComments()
8080
}
8181
}

ForPDA/Sources/Modules/Comments/CommentsVC.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ final class CommentsVC: CommentsViewController {
5959
tableView.isUserInteractionEnabled = false
6060
_currentlyDisplayed.removeAll()
6161

62-
DispatchQueue.global().async {
62+
Task(priority: .background) {
6363
let newComments = self.parsingService.parseComments(from: document)
64-
self.allComments = newComments
65-
self.currentlyDisplayed = self.allComments
64+
allComments = newComments
65+
currentlyDisplayed = self.allComments
6666

67-
DispatchQueue.main.async {
68-
self.updateDelegate?.updateFinished(true)
69-
self.tableView.reloadData()
70-
self.tableView.isUserInteractionEnabled = true
67+
Task(priority: .userInitiated) {
68+
updateDelegate?.updateFinished(true)
69+
tableView.reloadData()
70+
tableView.isUserInteractionEnabled = true
7171
}
7272
}
7373
}

ForPDA/Sources/Modules/Settings/SettingsPresenter.swift

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protocol SettingsPresenterProtocol {
1313

1414
func changeTheme(to theme: AppTheme)
1515
func changeDarkThemeBackgroundColor(to color: AppDarkThemeBackgroundColor)
16-
func showNewsFLSSwitchTapped(isOn: Bool)
16+
func fastLoadingSystemSwitchTapped(isOn: Bool)
1717
func showArticleFLSSwitchTapped(isOn: Bool)
1818
func showLikesInCommentsSwitchTapped(isOn: Bool)
1919
}
@@ -48,16 +48,12 @@ final class SettingsPresenter: SettingsPresenterProtocol {
4848
}
4949
}
5050

51-
private var currentShowLikesInComments: Bool {
52-
settingsService.getShowLikesInComments()
51+
private var isFLSEnabled: Bool {
52+
settingsService.getFastLoadingSystem()
5353
}
5454

55-
private var newsUsesFLS: Bool {
56-
settingsService.getNewsFLS()
57-
}
58-
59-
private var articleUsesFLS: Bool {
60-
settingsService.getArticleFLS()
55+
private var currentShowLikesInComments: Bool {
56+
settingsService.getShowLikesInComments()
6157
}
6258

6359
private let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0"
@@ -86,12 +82,8 @@ final class SettingsPresenter: SettingsPresenterProtocol {
8682
title: R.string.localizable.advanced(),
8783
options: [
8884
.switchCell(model: SwitchOption(
89-
title: R.string.localizable.fastLoadingNews(),
90-
isOn: newsUsesFLS, handler: {})
91-
),
92-
.switchCell(model: SwitchOption(
93-
title: R.string.localizable.fastLoadingArticle(),
94-
isOn: articleUsesFLS, handler: {})
85+
title: R.string.localizable.fastLoadingSystem(),
86+
isOn: isFLSEnabled, handler: {})
9587
),
9688
.switchCell(model: SwitchOption(
9789
title: R.string.localizable.commentsShowLikes(),
@@ -125,13 +117,13 @@ final class SettingsPresenter: SettingsPresenterProtocol {
125117
reloadData()
126118
}
127119

128-
func showNewsFLSSwitchTapped(isOn: Bool) {
129-
settingsService.setNewsFLS(to: isOn)
120+
func fastLoadingSystemSwitchTapped(isOn: Bool) {
121+
settingsService.setFastLoadingSystem(to: isOn)
130122
reloadData(forceUpdate: false)
131123
}
132124

133125
func showArticleFLSSwitchTapped(isOn: Bool) {
134-
settingsService.setArticleFLS(to: isOn)
126+
settingsService.setFastLoadingSystem(to: isOn)
135127
reloadData(forceUpdate: false)
136128
}
137129

@@ -180,22 +172,16 @@ final class SettingsPresenter: SettingsPresenterProtocol {
180172
sections[1].options[1] = .descriptionCell(model: model2)
181173

182174
let model3 = SwitchOption(
183-
title: R.string.localizable.fastLoadingNews(),
184-
isOn: settingsService.getNewsFLS(),
175+
title: R.string.localizable.fastLoadingSystem(),
176+
isOn: settingsService.getFastLoadingSystem(),
185177
handler: {})
186178
sections[2].options[0] = .switchCell(model: model3)
187179

188-
let model4 = SwitchOption(
189-
title: R.string.localizable.fastLoadingArticle(),
190-
isOn: settingsService.getArticleFLS(),
191-
handler: {})
192-
sections[2].options[1] = .switchCell(model: model4)
193-
194180
let model5 = SwitchOption(
195181
title: R.string.localizable.commentsShowLikes(),
196182
isOn: settingsService.getShowLikesInComments(),
197183
handler: {})
198-
sections[2].options[2] = .switchCell(model: model5)
184+
sections[2].options[1] = .switchCell(model: model5)
199185

200186
if forceUpdate {
201187
view?.reloadData()

ForPDA/Sources/Modules/Settings/SettingsVC.swift

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,18 @@ extension SettingsVC: UITableViewDelegate, UITableViewDataSource {
9595
if !isOn {
9696
switch indexPath.row {
9797
case 0:
98-
presenter.showNewsFLSSwitchTapped(isOn: isOn)
98+
presenter.fastLoadingSystemSwitchTapped(isOn: isOn)
9999
case 1:
100-
presenter.showArticleFLSSwitchTapped(isOn: isOn)
101-
// Workaround for always working comments on article sls
102-
if let cell = tableView.cellForRow(at: IndexPath(row: 2, section: 2)) as? SettingsSwitchCell {
103-
cell.forceSwitch(to: true)
104-
presenter.showLikesInCommentsSwitchTapped(isOn: true)
105-
}
106-
default:
107100
presenter.showLikesInCommentsSwitchTapped(isOn: isOn)
101+
default:
102+
break
108103
}
109104
return
110105
}
111106

112107
var message = ""
113-
if model.title.contains("новостей") {
114-
message = R.string.localizable.fastLoadingNewsWarning()
115-
} else if model.title.contains("новости") {
116-
message = R.string.localizable.fastLoadingArticleWarning()
108+
if model.title.contains("новостей") || model.title.contains("news") {
109+
message = R.string.localizable.fastLoadingSystemWarning()
117110
} else {
118111
message = R.string.localizable.commentsShowLikesWarning()
119112
}
@@ -126,24 +119,18 @@ extension SettingsVC: UITableViewDelegate, UITableViewDataSource {
126119

127120
let okAction = UIAlertAction(title: R.string.localizable.ok(), style: .default) { [weak self] _ in
128121
guard let self else { return }
129-
switch indexPath.row {
130-
case 0:
131-
presenter.showNewsFLSSwitchTapped(isOn: isOn)
132-
case 1:
133-
presenter.showArticleFLSSwitchTapped(isOn: isOn)
134-
default:
122+
if indexPath.row == 0 {
123+
presenter.fastLoadingSystemSwitchTapped(isOn: isOn)
124+
} else {
135125
presenter.showLikesInCommentsSwitchTapped(isOn: isOn)
136126
}
137127
}
138128
let cancelAction = UIAlertAction(title: R.string.localizable.cancel(), style: .default) { [weak self] _ in
139129
guard let self else { return }
140130
cell.set(with: model)
141-
switch indexPath.row {
142-
case 0:
143-
presenter.showNewsFLSSwitchTapped(isOn: !isOn)
144-
case 1:
145-
presenter.showArticleFLSSwitchTapped(isOn: !isOn)
146-
default:
131+
if indexPath.row == 0 {
132+
presenter.fastLoadingSystemSwitchTapped(isOn: !isOn)
133+
} else {
147134
presenter.showLikesInCommentsSwitchTapped(isOn: !isOn)
148135
}
149136
}

ForPDA/Sources/Services/Network/Base/HTTPClient.swift

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ import UIKit
99
import WebKit
1010
import Factory
1111

12-
enum LoadingSystem {
13-
case fast // aka FLS
14-
case slow // aka SLS
15-
}
16-
1712
protocol HTTPClientProtocol {
1813
func request(endpoint: Endpoint) async throws -> String
1914
}
@@ -55,14 +50,8 @@ extension HTTPClient {
5550
switch endpoint {
5651
case let newsEndpoint as NewsEndpoint:
5752
switch newsEndpoint {
58-
case .news:
59-
if settingsService.getNewsFLS() {
60-
return try await fastRequest(endpoint: endpoint)
61-
} else {
62-
return try await slowRequest(endpoint: endpoint)
63-
}
64-
case .article:
65-
if settingsService.getArticleFLS() {
53+
case .news, .article:
54+
if settingsService.getFastLoadingSystem() {
6655
return try await fastRequest(endpoint: endpoint)
6756
} else {
6857
return try await slowRequest(endpoint: endpoint)
@@ -117,7 +106,7 @@ extension HTTPClient {
117106
return try await withCheckedThrowingContinuation { continuation in
118107
if self.continuation != nil {
119108
// Workaround for case when previous article is still loading,
120-
// so continuation doesn't leak, object for testing
109+
// so continuation doesn't leak, need testing
121110
self.continuation?.resume(returning: "")
122111
}
123112
self.continuation = continuation

ForPDA/Sources/Services/Settings/SettingsService.swift

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ final class SettingsService {
1818
static let userId = "userId"
1919
static let appTheme = "appTheme"
2020
static let appDarkThemeBackgroundColor = "appDarkThemeBackgroundColor"
21-
static let newsFLS = "newsFLS"
22-
static let articleFLS = "articleFLS"
21+
static let fastLoadingSystem = "fastLoadingSystem"
2322
static let showLikesInComments = "showLikesInComments"
2423
static let isDeeplinking = "isDeeplinking"
2524
}
@@ -120,24 +119,12 @@ final class SettingsService {
120119

121120
// MARK: - Loading System
122121

123-
func setNewsFLS(to state: Bool) {
124-
defaults.set(state, forKey: Keys.newsFLS)
122+
func setFastLoadingSystem(to state: Bool) {
123+
defaults.set(state, forKey: Keys.fastLoadingSystem)
125124
}
126125

127-
func getNewsFLS() -> Bool {
128-
if let show = defaults.value(forKey: Keys.newsFLS) as? Bool {
129-
return show
130-
} else {
131-
return true // Enabled by default
132-
}
133-
}
134-
135-
func setArticleFLS(to state: Bool) {
136-
defaults.set(state, forKey: Keys.articleFLS)
137-
}
138-
139-
func getArticleFLS() -> Bool {
140-
if let show = defaults.value(forKey: Keys.articleFLS) as? Bool {
126+
func getFastLoadingSystem() -> Bool {
127+
if let show = defaults.value(forKey: Keys.fastLoadingSystem) as? Bool {
141128
return show
142129
} else {
143130
return true // Enabled by default

0 commit comments

Comments
 (0)