Skip to content

Commit 3710e5c

Browse files
committed
Рефактор + смена языка в настройках телефона (#261)
- Обновил нейминг всех экранов - названия экранов заканчиваются на "Screen" - Вынес в `Environment` некоторые ключи, чтобы меньше обращаться к `defaults` во вьюхах - Теперь язык меняется в настройках телефона
1 parent f74f6f8 commit 3710e5c

40 files changed

+409
-348
lines changed

SwiftUI-WorkoutApp.xcodeproj/project.pbxproj

Lines changed: 93 additions & 89 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import SwiftUI
22

33
/// Ключ для получения состояния подключения к интернету
4-
struct NetworkConnectedEnvironmentKey: EnvironmentKey {
4+
struct NetworkStatusEnvironmentKey: EnvironmentKey {
55
static let defaultValue = false
66
}
77

88
extension EnvironmentValues {
99
/// `true` - есть подключение, `false` - нет подключения
10-
var networkConnected: Bool {
11-
get { self[NetworkConnectedEnvironmentKey.self] }
12-
set { self[NetworkConnectedEnvironmentKey.self] = newValue }
10+
var isNetworkConnected: Bool {
11+
get { self[NetworkStatusEnvironmentKey.self] }
12+
set { self[NetworkStatusEnvironmentKey.self] = newValue }
1313
}
1414
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import SwiftUI
2+
import SWModels
3+
4+
/// Ключ для получения "флагов" пользователя
5+
struct UserFlagsEnvironmentKey: EnvironmentKey {
6+
static let defaultValue = UserFlags.defaultValue
7+
}
8+
9+
extension EnvironmentValues {
10+
/// Флаги пользователя
11+
var userFlags: UserFlags {
12+
get { self[UserFlagsEnvironmentKey.self] }
13+
set { self[UserFlagsEnvironmentKey.self] = newValue }
14+
}
15+
}

SwiftUI-WorkoutApp/Libraries/SWModels/Sources/SWModels/AppLanguage.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

SwiftUI-WorkoutApp/Libraries/SWModels/Sources/SWModels/DefaultsProtocol.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Foundation
22

33
@MainActor
44
public protocol DefaultsProtocol: AnyObject, Sendable {
5-
var appLanguage: AppLanguage { get }
65
var appTheme: AppColorTheme { get }
76
var mainUserInfo: UserResponse? { get }
87
var mainUserCountryID: Int { get }
@@ -15,7 +14,6 @@ public protocol DefaultsProtocol: AnyObject, Sendable {
1514
var unreadMessagesCount: Int { get }
1615
/// Дефолтная дата - предыдущее ручное обновление файла `countries.json`
1716
var lastCountriesUpdateDate: Date { get }
18-
func setAppLanguage(_ language: AppLanguage)
1917
func setAppTheme(_ theme: AppColorTheme)
2018
func saveAuthData(_ info: AuthData) throws
2119
func basicAuthInfo() throws -> AuthData
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Foundation
2+
3+
/// Содержит флаги пользователя для `Environment`
4+
public struct UserFlags: Sendable {
5+
public let isAuthorized: Bool
6+
public let needUpdate: Bool
7+
public let hasParks: Bool
8+
public let hasFriends: Bool
9+
public let hasJournals: Bool
10+
11+
public init(
12+
isAuthorized: Bool,
13+
needUpdate: Bool,
14+
hasParks: Bool,
15+
hasFriends: Bool,
16+
hasJournals: Bool
17+
) {
18+
self.isAuthorized = isAuthorized
19+
self.needUpdate = needUpdate
20+
self.hasParks = hasParks
21+
self.hasFriends = hasFriends
22+
self.hasJournals = hasJournals
23+
}
24+
25+
public static let defaultValue = Self(
26+
isAuthorized: false,
27+
needUpdate: false,
28+
hasParks: false,
29+
hasFriends: false,
30+
hasJournals: false
31+
)
32+
}

SwiftUI-WorkoutApp/Resources/Localizable.xcstrings

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,6 +2717,22 @@
27172717
}
27182718
}
27192719
},
2720+
"Отмена" : {
2721+
"localizations" : {
2722+
"en" : {
2723+
"stringUnit" : {
2724+
"state" : "translated",
2725+
"value" : "Cancel"
2726+
}
2727+
},
2728+
"ru" : {
2729+
"stringUnit" : {
2730+
"state" : "translated",
2731+
"value" : "Отмена"
2732+
}
2733+
}
2734+
}
2735+
},
27202736
"Отправить" : {
27212737
"localizations" : {
27222738
"en" : {
@@ -2835,6 +2851,16 @@
28352851
}
28362852
}
28372853
},
2854+
"Перейти" : {
2855+
"localizations" : {
2856+
"en" : {
2857+
"stringUnit" : {
2858+
"state" : "translated",
2859+
"value" : "Go to settings"
2860+
}
2861+
}
2862+
}
2863+
},
28382864
"Перейти на карту" : {
28392865
"localizations" : {
28402866
"en" : {
@@ -4147,19 +4173,35 @@
41474173
}
41484174
}
41494175
},
4150-
"Язык" : {
4176+
"Язык можно поменять в настройках телефона" : {
4177+
"localizations" : {
4178+
"en" : {
4179+
"stringUnit" : {
4180+
"state" : "translated",
4181+
"value" : "The language can be changed in the phone settings"
4182+
}
4183+
},
4184+
"ru" : {
4185+
"stringUnit" : {
4186+
"state" : "translated",
4187+
"value" : "Язык можно поменять в настройках телефона"
4188+
}
4189+
}
4190+
}
4191+
},
4192+
"Язык приложения" : {
41514193
"extractionState" : "manual",
41524194
"localizations" : {
41534195
"en" : {
41544196
"stringUnit" : {
41554197
"state" : "translated",
4156-
"value" : "Language"
4198+
"value" : "App language"
41574199
}
41584200
},
41594201
"ru" : {
41604202
"stringUnit" : {
41614203
"state" : "translated",
4162-
"value" : "Язык"
4204+
"value" : "Язык приложения"
41634205
}
41644206
}
41654207
}

SwiftUI-WorkoutApp/Screens/Common/CommentsView.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import SWModels
44

55
/// Список комментариев
66
struct CommentsView: View {
7-
@Environment(\.networkConnected) private var isNetworkConnected
8-
@EnvironmentObject private var defaults: DefaultsService
7+
@Environment(\.userFlags) private var userFlags
8+
@Environment(\.isNetworkConnected) private var isNetworkConnected
9+
let mainUserId: Int?
910
let items: [CommentResponse]
1011
let reportClbk: (CommentResponse) -> Void
1112
let deleteClbk: (Int) -> Void
@@ -23,7 +24,7 @@ struct CommentsView: View {
2324
userName: comment.user?.userName ?? "",
2425
dateText: comment.formattedDateString,
2526
bodyText: comment.formattedBody,
26-
isCommentByMainUser: comment.user?.id == defaults.mainUserInfo?.id,
27+
isCommentByMainUser: comment.user?.id == mainUserId,
2728
isNetworkConnected: isNetworkConnected,
2829
reportAction: { reportClbk(comment) },
2930
editAction: { editClbk(comment) },
@@ -34,7 +35,7 @@ struct CommentsView: View {
3435
}
3536
}
3637
}
37-
if defaults.isAuthorized {
38+
if userFlags.isAuthorized {
3839
Button("Добавить комментарий", action: createCommentClbk)
3940
.buttonStyle(SWButtonStyle(mode: .filled, size: .large))
4041
}
@@ -45,25 +46,25 @@ struct CommentsView: View {
4546
#if DEBUG
4647
#Preview("Single") {
4748
CommentsView(
49+
mainUserId: nil,
4850
items: [.preview],
4951
reportClbk: { _ in },
5052
deleteClbk: { _ in },
5153
editClbk: { _ in },
5254
createCommentClbk: {}
5355
)
5456
.padding(.horizontal)
55-
.environmentObject(DefaultsService())
5657
}
5758

5859
#Preview("Multiple") {
5960
CommentsView(
61+
mainUserId: nil,
6062
items: [.preview, .preview, .preview],
6163
reportClbk: { _ in },
6264
deleteClbk: { _ in },
6365
editClbk: { _ in },
6466
createCommentClbk: {}
6567
)
6668
.padding(.horizontal)
67-
.environmentObject(DefaultsService())
6869
}
6970
#endif

SwiftUI-WorkoutApp/Screens/Common/EmptyContentView.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ import SWModels
44

55
/// Заглушка на случай, когда нет контента
66
struct EmptyContentView: View {
7+
@Environment(\.isNetworkConnected) private var isNetworkConnected
8+
@Environment(\.userFlags) private var userFlags
79
let mode: Mode
8-
let isAuthorized: Bool
9-
let hasFriends: Bool
10-
let hasParks: Bool
11-
let isNetworkConnected: Bool
1210
let action: () -> Void
1311

1412
var body: some View {
1513
VStack(spacing: 16) {
1614
if isNetworkConnected {
1715
titleText(mode.message)
18-
if isAuthorized {
16+
if userFlags.isAuthorized {
1917
Button(actionButtonTitle, action: action)
2018
.buttonStyle(SWButtonStyle(mode: .filled, size: .large))
2119
}
@@ -55,17 +53,17 @@ private extension EmptyContentView {
5553
var actionButtonTitle: LocalizedStringKey {
5654
switch mode {
5755
case .events:
58-
hasParks && isAuthorized
56+
userFlags.hasParks && userFlags.isAuthorized
5957
? "Создать мероприятие"
6058
: "Выбрать площадку"
6159
case .dialogs:
62-
hasFriends ? "Открыть список друзей" : "Найти пользователя"
60+
userFlags.hasFriends ? "Открыть список друзей" : "Найти пользователя"
6361
case .journals: "Создать дневник"
6462
}
6563
}
6664

6765
var isHintAvailable: Bool {
68-
mode == .events && isAuthorized && !hasParks
66+
mode == .events && userFlags.isAuthorized && !userFlags.hasParks
6967
}
7068
}
7169

@@ -94,20 +92,13 @@ private extension EmptyContentView.Mode {
9492
ForEach(EmptyContentView.Mode.allCases, id: \.self) { mode in
9593
EmptyContentView(
9694
mode: mode,
97-
isAuthorized: true,
98-
hasFriends: true,
99-
hasParks: true,
100-
isNetworkConnected: true,
10195
action: {}
10296
)
10397
Divider()
10498
}
99+
.environment(\.isNetworkConnected, true)
105100
EmptyContentView(
106101
mode: .dialogs,
107-
isAuthorized: true,
108-
hasFriends: true,
109-
hasParks: true,
110-
isNetworkConnected: false,
111102
action: {}
112103
)
113104
}

SwiftUI-WorkoutApp/Screens/Common/IncognitoProfileView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct IncognitoProfileView: View {
1717
.background(Color.swBackground)
1818
.sheet(isPresented: $showAuthScreen) {
1919
ContentInSheet(title: "Авторизация") {
20-
LoginView()
20+
LoginScreen()
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)