Skip to content

Commit 303edbc

Browse files
committed
Add dark/black color change for dark theme
1 parent ef89f37 commit 303edbc

File tree

12 files changed

+160
-2
lines changed

12 files changed

+160
-2
lines changed

ForPDA.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
B87EB9D4293D50DB0025C2A0 /* PDAResizingImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B87EB9D3293D50DB0025C2A0 /* PDAResizingImageView.swift */; };
5757
B884AFF829FD9D6F00BC1AA1 /* YouTubePlayerKit in Frameworks */ = {isa = PBXBuildFile; productRef = B884AFF729FD9D6F00BC1AA1 /* YouTubePlayerKit */; };
5858
B887245F2A1E9A0900DFB47F /* ArticleBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B887245E2A1E9A0900DFB47F /* ArticleBuilder.swift */; };
59+
B88724632A1EB1B100DFB47F /* AppBackgroundColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B88724622A1EB1B100DFB47F /* AppBackgroundColor.swift */; };
5960
B88D3F4A2A088FEF0061C6C4 /* MenuVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = B88D3F492A088FEF0061C6C4 /* MenuVM.swift */; };
6061
B88D3F4D2A08908D0061C6C4 /* MenuFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = B88D3F4C2A08908D0061C6C4 /* MenuFactory.swift */; };
6162
B88D3F522A0900630061C6C4 /* MenuAuthCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B88D3F512A0900620061C6C4 /* MenuAuthCell.swift */; };
@@ -162,6 +163,7 @@
162163
B87EB9D1293D2DB90025C2A0 /* ArticleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleView.swift; sourceTree = "<group>"; };
163164
B87EB9D3293D50DB0025C2A0 /* PDAResizingImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDAResizingImageView.swift; sourceTree = "<group>"; };
164165
B887245E2A1E9A0900DFB47F /* ArticleBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleBuilder.swift; sourceTree = "<group>"; };
166+
B88724622A1EB1B100DFB47F /* AppBackgroundColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppBackgroundColor.swift; sourceTree = "<group>"; };
165167
B88D3F492A088FEF0061C6C4 /* MenuVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuVM.swift; sourceTree = "<group>"; };
166168
B88D3F4C2A08908D0061C6C4 /* MenuFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuFactory.swift; sourceTree = "<group>"; };
167169
B88D3F512A0900620061C6C4 /* MenuAuthCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuAuthCell.swift; sourceTree = "<group>"; };
@@ -445,6 +447,7 @@
445447
B88D3F552A0900DA0061C6C4 /* SettingsCellType.swift */,
446448
B8001CB82A19529B00E7A8A8 /* AppLanguage.swift */,
447449
B8001CBA2A19529F00E7A8A8 /* AppTheme.swift */,
450+
B88724622A1EB1B100DFB47F /* AppBackgroundColor.swift */,
448451
B875D2102A1C343000F8AB6A /* LoginData.swift */,
449452
B8001CDB2A1ADD4000E7A8A8 /* Cookie.swift */,
450453
B8001CDE2A1B01D000E7A8A8 /* User.swift */,
@@ -841,6 +844,7 @@
841844
B89301262947E2BD00D14141 /* LoginView.swift in Sources */,
842845
B8DDFA20294A56E4008B0156 /* ParsingService.swift in Sources */,
843846
B87EB9D0293D2DA30025C2A0 /* ArticleVC.swift in Sources */,
847+
B88724632A1EB1B100DFB47F /* AppBackgroundColor.swift in Sources */,
844848
B87EB9CD293D21FB0025C2A0 /* NewsView.swift in Sources */,
845849
B8340352296789FE00C3CF37 /* PDABulletLabel.swift in Sources */,
846850
B8001CAE2A19433600E7A8A8 /* SettingsVC.swift in Sources */,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "1.000",
8+
"blue" : "0xFF",
9+
"green" : "0xFF",
10+
"red" : "0xFF"
11+
}
12+
},
13+
"idiom" : "universal"
14+
},
15+
{
16+
"appearances" : [
17+
{
18+
"appearance" : "luminosity",
19+
"value" : "dark"
20+
}
21+
],
22+
"color" : {
23+
"color-space" : "srgb",
24+
"components" : {
25+
"alpha" : "1.000",
26+
"blue" : "0x0F",
27+
"green" : "0x0F",
28+
"red" : "0x0F"
29+
}
30+
},
31+
"idiom" : "universal"
32+
}
33+
],
34+
"info" : {
35+
"author" : "xcode",
36+
"version" : 1
37+
}
38+
}

ForPDA/Resources/en.lproj/Localizable.strings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
"theme.choose" = "Choose Theme";
6868
"theme.light" = "Light";
6969
"theme.dark" = "Dark";
70+
"background.night" = "Night theme color";
71+
"background.choose" = "Choose night theme background color";
72+
"background.dark" = "Dark";
73+
"background.black" = "Black";
7074
"account" = "Account";
7175
"sign.out" = "Sign Out";
7276
"about.app" = "About App";

ForPDA/Resources/ru.lproj/Localizable.strings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
"theme.choose" = "Выберите тему";
6868
"theme.light" = "Светлая";
6969
"theme.dark" = "Темная";
70+
"background.night" = "Цвет ночного режима";
71+
"background.choose" = "Выберите цвет ночного фона";
72+
"background.dark" = "Темный";
73+
"background.black" = "Черный";
7074
"account" = "Аккаунт";
7175
"sign.out" = "Выйти";
7276
"about.app" = "О приложении";

ForPDA/Sources/Extensions/NSNotificationName+Ext.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ import Foundation
99

1010
extension NSNotification.Name {
1111
static let userDidChange = Self(rawValue: "userDidChange")
12+
static let darkThemeBackgroundColorDidChange = Self(rawValue: "darkThemeBackgroundColorDidChange")
1213
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// AppDarkThemeBackgroundColor.swift
3+
// ForPDA
4+
//
5+
// Created by Subvert on 25.05.2023.
6+
//
7+
8+
import Foundation
9+
10+
enum AppDarkThemeBackgroundColor: String {
11+
case dark
12+
case black
13+
}

ForPDA/Sources/Modules/News/Cells/ArticleCell.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ final class ArticleCell: UITableViewCell {
9898
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
9999
super.init(style: style, reuseIdentifier: reuseIdentifier)
100100
separatorInset = .zero
101+
backgroundColor = .clear
101102
isSkeletonable = true
102103

103104
addSubviews()

ForPDA/Sources/Modules/Settings/SettingsVC.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Factory
1111
protocol SettingsVCProtocol: AnyObject {
1212
func showChangeLanguageSheet()
1313
func showChangeThemeSheet()
14+
func showChangeDarkThemeBackgroundColorSheet()
1415
func showReloadingAlert()
1516
func reloadData()
1617

@@ -166,8 +167,27 @@ extension SettingsVC: SettingsVCProtocol {
166167
present(alert, animated: true)
167168
}
168169

170+
func showChangeDarkThemeBackgroundColorSheet() {
171+
let alert = UIAlertController(title: R.string.localizable.backgroundChoose(), message: nil, preferredStyle: .actionSheet)
172+
173+
let darkAction = UIAlertAction(title: R.string.localizable.backgroundDark(), style: .default) { _ in
174+
guard self.settingsService.getAppBackgroundColor() != AppDarkThemeBackgroundColor.dark else { return }
175+
self.viewModel.changeDarkThemeBackgroundColor(to: .dark)
176+
}
177+
let blackAction = UIAlertAction(title: R.string.localizable.backgroundBlack(), style: .default) { _ in
178+
guard self.settingsService.getAppBackgroundColor() != AppDarkThemeBackgroundColor.black else { return }
179+
self.viewModel.changeDarkThemeBackgroundColor(to: .black)
180+
}
181+
let cancelAction = UIAlertAction(title: R.string.localizable.cancel(), style: .cancel)
182+
183+
alert.addAction(darkAction)
184+
alert.addAction(blackAction)
185+
alert.addAction(cancelAction)
186+
187+
present(alert, animated: true)
188+
}
189+
169190
func showReloadingAlert() {
170-
print(#function)
171191
let alert = UIAlertController(title: R.string.localizable.warning(),
172192
message: R.string.localizable.warningRestartApp(),
173193
preferredStyle: .alert)

ForPDA/Sources/Modules/Settings/SettingsVM.swift

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ protocol SettingsVMProtocol {
1313

1414
func changeLanguage(to language: AppLanguage)
1515
func changeTheme(to theme: AppTheme)
16+
func changeDarkThemeBackgroundColor(to color: AppDarkThemeBackgroundColor)
1617
}
1718

1819
final class SettingsVM: SettingsVMProtocol {
@@ -39,6 +40,13 @@ final class SettingsVM: SettingsVMProtocol {
3940
}
4041
}
4142

43+
private var currentAppDarkThemeBackgroundColor: String {
44+
switch settingsService.getAppBackgroundColor() {
45+
case .dark: return R.string.localizable.backgroundDark()
46+
case .black: return R.string.localizable.backgroundBlack()
47+
}
48+
}
49+
4250
private let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0"
4351
private let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "0"
4452

@@ -52,7 +60,10 @@ final class SettingsVM: SettingsVMProtocol {
5260
MenuSection(title: R.string.localizable.appearance(), options: [
5361
.descriptionCell(model: DescriptionOption(title: R.string.localizable.theme(),
5462
description: currentTheme,
55-
handler: changeTheme))
63+
handler: changeTheme)),
64+
.descriptionCell(model: DescriptionOption(title: R.string.localizable.backgroundNight(),
65+
description: currentAppDarkThemeBackgroundColor,
66+
handler: changeDarkThemeBackgroundColor))
5667
]),
5768

5869
//MenuSection(title: "Просмотр тем", options: []),
@@ -97,6 +108,17 @@ final class SettingsVM: SettingsVMProtocol {
97108
view?.reloadData()
98109
}
99110

111+
func changeDarkThemeBackgroundColor(to color: AppDarkThemeBackgroundColor) {
112+
settingsService.setAppBackgroundColor(to: color)
113+
114+
let model = DescriptionOption(title: R.string.localizable.backgroundNight(),
115+
description: currentAppDarkThemeBackgroundColor,
116+
handler: changeDarkThemeBackgroundColor)
117+
sections[1].options[1] = .descriptionCell(model: model)
118+
119+
view?.reloadData()
120+
}
121+
100122
// MARK: - Private Actions
101123

102124
private func changeLanguage() {
@@ -107,6 +129,10 @@ final class SettingsVM: SettingsVMProtocol {
107129
view?.showChangeThemeSheet()
108130
}
109131

132+
private func changeDarkThemeBackgroundColor() {
133+
view?.showChangeDarkThemeBackgroundColorSheet()
134+
}
135+
110136
private func showDefaultError() {
111137
view?.showDefaultError()
112138
}

0 commit comments

Comments
 (0)