Skip to content

Commit 5347472

Browse files
committed
Added logic to profiling. Clean localisations.
1 parent 882212e commit 5347472

File tree

8 files changed

+106
-109
lines changed

8 files changed

+106
-109
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let package = Package(
1616
],
1717
dependencies: [
1818
.package(url: "https://github.com/ivanvorobei/SPAlert", .upToNextMajor(from: "4.2.0")),
19-
.package(url: "https://github.com/ivanvorobei/NativeUIKit", .upToNextMajor(from: "1.4.4")),
19+
.package(url: "https://github.com/ivanvorobei/NativeUIKit", .upToNextMajor(from: "1.4.5")),
2020
.package(url: "https://github.com/ivanvorobei/SPFirebase", .upToNextMajor(from: "1.0.8")),
2121
.package(url: "https://github.com/sparrowcode/SPSafeSymbols", .upToNextMajor(from: "1.0.5")),
2222
.package(url: "https://github.com/kean/Nuke", .upToNextMajor(from: "10.7.1"))

Sources/SPProfiling/Data/Texts.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ enum Texts {
6666

6767
enum Profile {
6868

69+
static var name_title: String { NSLocalizedString("profile name title", bundle: .module, comment: "") }
70+
static var email_title: String { NSLocalizedString("profile email title", bundle: .module, comment: "") }
6971
static var placeholder_name: String { NSLocalizedString("profile placeholder name", bundle: .module, comment: "") }
7072

73+
static var public_data_header: String { NSLocalizedString("profile public data header", bundle: .module, comment: "") }
74+
static var public_data_footer: String { NSLocalizedString("profile public data footer", bundle: .module, comment: "") }
75+
7176
enum Devices {
7277

7378
static var title: String { NSLocalizedString("profile devices title", bundle: .module, comment: "") }
@@ -84,18 +89,6 @@ enum Texts {
8489

8590
enum Actions {
8691

87-
static var email_copied: String { NSLocalizedString("profile actions email copied", bundle: .module, comment: "") }
88-
89-
enum Rename {
90-
91-
static var title: String { NSLocalizedString("profile actions rename title", bundle: .module, comment: "") }
92-
static var description: String { NSLocalizedString("profile actions rename description", bundle: .module, comment: "") }
93-
94-
static var alert_title: String { NSLocalizedString("profile rename alert title", bundle: .module, comment: "") }
95-
static var alert_description: String { NSLocalizedString("profile rename alert description", bundle: .module, comment: "") }
96-
static var alert_placeholder: String { NSLocalizedString("profile rename alert placeholder", bundle: .module, comment: "") }
97-
}
98-
9992
enum SignOut {
10093

10194
static var title: String { NSLocalizedString("profile actions sign out title", bundle: .module, comment: "") }

Sources/SPProfiling/Interface/Devices/DeviceTableCell.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DeviceTableCell: SPTableViewCell {
3737

3838
override func commonInit() {
3939
super.commonInit()
40-
textLabel?.font = UIFont.preferredFont(forTextStyle: .title3, weight: .medium)
40+
textLabel?.font = UIFont.preferredFont(forTextStyle: .body, weight: .medium)
4141
textLabel?.textColor = .label
4242
textLabel?.numberOfLines = .zero
4343
detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .footnote)
@@ -66,4 +66,11 @@ class DeviceTableCell: SPTableViewCell {
6666

6767
imageView?.tintColor = .tint
6868
}
69+
70+
// MARK: - Layout
71+
72+
open override func sizeThatFits(_ size: CGSize) -> CGSize {
73+
let superSize = super.sizeThatFits(size)
74+
return .init(width: superSize.width, height: superSize.height + 2)
75+
}
6976
}

Sources/SPProfiling/Interface/Profile/ProfileController+Actions.swift

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2022 Ivan Vorobei ([email protected])
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
import UIKit
23+
import NativeUIKit
24+
import SparrowKit
25+
import SPDiffable
26+
import SPSafeSymbols
27+
import SPAlert
28+
29+
extension ProfileController: UITextFieldDelegate {
30+
31+
func textFieldDidEndEditing(_ textField: UITextField) {
32+
33+
let nameTextField: UITextField? = {
34+
guard let indexPath = diffableDataSource?.getIndexPath(id: Item.name.id) else { return nil }
35+
guard let cell = tableView.cellForRow(at: indexPath) as? SPDiffableTextFieldTitleTableViewCell else { return nil }
36+
return cell.textField
37+
}()
38+
39+
switch textField {
40+
case nameTextField:
41+
let text = textField.text ?? .empty
42+
self.profileModel.setName(text, completion: { error in
43+
if let error = error {
44+
SPAlert.present(message: error.localizedDescription, haptic: .error)
45+
}
46+
nameTextField?.text = self.profileModel.name
47+
})
48+
default:
49+
break
50+
}
51+
}
52+
53+
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
54+
textField.resignFirstResponder()
55+
return true
56+
}
57+
}

Sources/SPProfiling/Interface/Profile/ProfileController.swift

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,62 +77,72 @@ class ProfileController: NativeProfileController {
7777
guard let self = self else { return }
7878
if let profileModel = ProfileModel.currentProfile {
7979
self.profileModel = profileModel
80-
self.configureHeader()
81-
self.diffableDataSource?.updateLayout(animated: true)
80+
self.diffableDataSource?.set(self.content, animated: true)
8281
}
8382
}
8483

8584
configureHeader()
85+
dismissKeyboardWhenTappedAround()
8686
}
8787

8888
// MARK: - Diffable
8989

90-
internal enum Item: String, CaseIterable {
90+
internal enum Section: String, CaseIterable {
9191

92-
case change_name
92+
case pulibc_info
9393
case devices
9494
case sign_out
9595
case delete_account
9696

97-
var section_id: String { rawValue + "_section" }
98-
var item_id: String { rawValue + "_row" }
97+
var id: String { rawValue }
98+
}
99+
100+
internal enum Item: String, CaseIterable {
101+
102+
case name
103+
case email
104+
case sign_out
105+
case delete_account
106+
107+
var id: String { rawValue }
99108
}
100109

101110
private var content: [SPDiffableSection] {
102111
return [
103112
.init(
104-
id: Item.change_name.section_id,
105-
header: nil,
106-
footer: SPDiffableTextHeaderFooter(text: Texts.Profile.Actions.Rename.description),
113+
id: Section.pulibc_info.id,
114+
header: SPDiffableTextHeaderFooter(text: Texts.Profile.public_data_header),
115+
footer: SPDiffableTextHeaderFooter(text: Texts.Profile.public_data_footer),
107116
items: [
108117
SPDiffableTableRowTextFieldTitle(
109-
id: Item.change_name.item_id,
118+
id: Item.name.id,
110119
icon: nil,
111-
title: "Name",
120+
title: Texts.Profile.name_title,
112121
text: profileModel.name,
113-
placeholder: "Your name",
122+
placeholder: Texts.Profile.placeholder_name,
114123
autocorrectionType: .no,
115124
keyboardType: .default,
116125
autocapitalizationType: .words,
117126
clearButtonMode: .never,
118-
delegate: nil
127+
delegate: self
119128
),
120129
SPDiffableTableRowTextFieldTitle(
121-
id: Item.change_name.item_id + "email",
130+
id: Item.email.id,
122131
icon: nil,
123-
title: "Email",
132+
title: Texts.Profile.email_title,
124133
text: profileModel.email,
125-
placeholder: "Your email",
134+
placeholder: .empty,
126135
autocorrectionType: .no,
127136
keyboardType: .emailAddress,
128137
autocapitalizationType: .words,
129138
clearButtonMode: .never,
130-
delegate: nil
139+
delegate: nil,
140+
editable: false
131141
)
132142
]
133143
),
134144
.init(
135-
id: Item.devices.section_id,
145+
id: Section.devices.id,
136146
header: SPDiffableTextHeaderFooter(text: Texts.Profile.Devices.header),
137147
footer: SPDiffableTextHeaderFooter(text: Texts.Profile.Devices.footer),
138148
items: profileModel.devices.prefix(3).map({ SPDiffableWrapperItem(id: $0.id, model: $0) }) + [
@@ -151,12 +161,12 @@ class ProfileController: NativeProfileController {
151161
]
152162
),
153163
.init(
154-
id: Item.sign_out.section_id,
155-
header: nil,
164+
id: Section.sign_out.id,
165+
header: SPDiffableTextHeaderFooter(text: Texts.Profile.Actions.SignOut.title),
156166
footer: SPDiffableTextHeaderFooter(text: Texts.Profile.Actions.SignOut.description),
157167
items: [
158168
NativeDiffableLeftButton(
159-
id: Item.sign_out.item_id,
169+
id: Item.sign_out.id,
160170
text: Texts.Profile.Actions.SignOut.title,
161171
icon: .init(.xmark.squareFill),
162172
action: { [weak self] _, indexPath in
@@ -194,12 +204,12 @@ class ProfileController: NativeProfileController {
194204
]
195205
),
196206
.init(
197-
id: Item.delete_account.section_id,
207+
id: Section.delete_account.id,
198208
header: SPDiffableTextHeaderFooter(text: Texts.Profile.Actions.Delete.header),
199209
footer: SPDiffableTextHeaderFooter(text: Texts.Profile.Actions.Delete.description),
200210
items: [
201211
NativeDiffableLeftButton(
202-
id: Item.delete_account.item_id,
212+
id: Item.delete_account.id,
203213
text: Texts.Profile.Actions.Delete.title,
204214
textColor: .destructiveColor,
205215
icon: .init(.trash.fill).withTintColor(.destructiveColor, renderingMode: .alwaysOriginal),

Sources/SPProfiling/Resources/Localization/en.lproj/Localizable.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"profile devices footer" = "You can disable access to a profile by deleting it.";
105105

106106
/* No comment provided by engineer. */
107-
"profile devices header" = "Connected Devices";
107+
"profile devices header" = "Devices";
108108

109109
/* No comment provided by engineer. */
110110
"profile devices manage devices" = "Manage Devices";

Sources/SPProfiling/Resources/Localization/ru.lproj/Localizable.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"profile devices footer" = "Вы можете запретить доступ к профилю, удалив его.";
105105

106106
/* No comment provided by engineer. */
107-
"profile devices header" = "Подключенные устройства";
107+
"profile devices header" = "Устройства";
108108

109109
/* No comment provided by engineer. */
110110
"profile devices manage devices" = "Управление устройствами";

0 commit comments

Comments
 (0)