Skip to content

Commit 6096b03

Browse files
authored
Merge pull request #5486 from selanthiraiyan/issue/5369-install-jetpack-row-in-settings
Add Install Jetpack row in Settings
2 parents dc1a7a2 + 63b5716 commit 6096b03

File tree

3 files changed

+204
-45
lines changed

3 files changed

+204
-45
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/Settings/Settings/SettingsViewController.swift

Lines changed: 158 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class SettingsViewController: UIViewController {
5656
private extension SettingsViewController {
5757

5858
func configureNavigation() {
59-
title = NSLocalizedString("Settings", comment: "Settings navigation title")
59+
title = Localization.navigationTitle
6060
}
6161

6262
func configureMainView() {
@@ -106,18 +106,22 @@ private extension SettingsViewController {
106106
configureSwitchStore(cell: cell)
107107
case let cell as BasicTableViewCell where row == .plugins:
108108
configurePlugins(cell: cell)
109-
case let cell as BasicTableViewCell where row == .support:
110-
configureSupport(cell: cell)
111109
case let cell as BasicTableViewCell where row == .inPersonPayments:
112110
configureInPersonPayments(cell: cell)
113-
case let cell as BasicTableViewCell where row == .privacy:
114-
configurePrivacy(cell: cell)
111+
case let cell as BasicTableViewCell where row == .installJetpack:
112+
configureInstallJetpack(cell: cell)
113+
case let cell as BasicTableViewCell where row == .support:
114+
configureSupport(cell: cell)
115115
case let cell as BasicTableViewCell where row == .betaFeatures:
116116
configureBetaFeatures(cell: cell)
117117
case let cell as BasicTableViewCell where row == .sendFeedback:
118118
configureSendFeedback(cell: cell)
119+
case let cell as BasicTableViewCell where row == .privacy:
120+
configurePrivacy(cell: cell)
119121
case let cell as BasicTableViewCell where row == .about:
120122
configureAbout(cell: cell)
123+
case let cell as BasicTableViewCell where row == .whatsNew:
124+
configureWhatsNew(cell: cell)
121125
case let cell as BasicTableViewCell where row == .licenses:
122126
configureLicenses(cell: cell)
123127
case let cell as BasicTableViewCell where row == .deviceSettings:
@@ -126,8 +130,6 @@ private extension SettingsViewController {
126130
configureWormholy(cell: cell)
127131
case let cell as BasicTableViewCell where row == .logout:
128132
configureLogout(cell: cell)
129-
case let cell as BasicTableViewCell where row == .whatsNew:
130-
configureWhatsNew(cell: cell)
131133
default:
132134
fatalError()
133135
}
@@ -140,85 +142,87 @@ private extension SettingsViewController {
140142

141143
func configureSwitchStore(cell: BasicTableViewCell) {
142144
cell.selectionStyle = .default
143-
cell.textLabel?.text = NSLocalizedString(
144-
"Switch Store",
145-
comment: "This action allows the user to change stores without logging out and logging back in again."
146-
)
145+
cell.textLabel?.text = Localization.switchStore
147146
}
148147

149148
func configurePlugins(cell: BasicTableViewCell) {
150149
cell.selectionStyle = .default
151150
cell.accessoryType = .disclosureIndicator
152-
cell.textLabel?.text = NSLocalizedString("Plugins", comment: "Navigates to Plugins screen.")
151+
cell.textLabel?.text = Localization.plugins
153152
}
154153

155154
func configureSupport(cell: BasicTableViewCell) {
156155
cell.accessoryType = .disclosureIndicator
157156
cell.selectionStyle = .default
158-
cell.textLabel?.text = NSLocalizedString("Help & Support", comment: "Contact Support Action")
157+
cell.textLabel?.text = Localization.helpAndSupport
159158
}
160159

161160
func configureInPersonPayments(cell: BasicTableViewCell) {
162161
cell.accessoryType = .disclosureIndicator
163162
cell.selectionStyle = .default
164-
cell.textLabel?.text = NSLocalizedString("In-Person Payments", comment: "Navigates to In-Person Payments screen")
163+
cell.textLabel?.text = Localization.inPersonPayments
164+
}
165+
166+
func configureInstallJetpack(cell: BasicTableViewCell) {
167+
cell.accessoryType = .disclosureIndicator
168+
cell.selectionStyle = .default
169+
cell.textLabel?.text = Localization.installJetpack
165170
}
166171

167172
func configurePrivacy(cell: BasicTableViewCell) {
168173
cell.accessoryType = .disclosureIndicator
169174
cell.selectionStyle = .default
170-
cell.textLabel?.text = NSLocalizedString("Privacy Settings", comment: "Navigates to Privacy Settings screen")
175+
cell.textLabel?.text = Localization.privacySettings
171176
}
172177

173178
func configureBetaFeatures(cell: BasicTableViewCell) {
174179
cell.accessoryType = .disclosureIndicator
175180
cell.selectionStyle = .default
176-
cell.textLabel?.text = NSLocalizedString("Experimental Features", comment: "Navigates to experimental features screen")
181+
cell.textLabel?.text = Localization.experimentalFeatures
177182
cell.accessibilityIdentifier = "settings-beta-features-button"
178183
}
179184

180185
func configureSendFeedback(cell: BasicTableViewCell) {
181186
cell.accessoryType = .disclosureIndicator
182187
cell.selectionStyle = .default
183-
cell.textLabel?.text = NSLocalizedString("Send Feedback", comment: "Presents a survey to gather feedback from the user.")
188+
cell.textLabel?.text = Localization.sendFeedback
184189
}
185190

186191
func configureAbout(cell: BasicTableViewCell) {
187192
cell.accessoryType = .disclosureIndicator
188193
cell.selectionStyle = .default
189-
cell.textLabel?.text = NSLocalizedString("WooCommerce", comment: "Navigates to about WooCommerce app screen")
194+
cell.textLabel?.text = Localization.wooCommerce
190195
}
191196

192197
func configureLicenses(cell: BasicTableViewCell) {
193198
cell.accessoryType = .disclosureIndicator
194199
cell.selectionStyle = .default
195-
cell.textLabel?.text = NSLocalizedString("Third Party Licenses", comment: "Navigates to screen with third party software licenses")
200+
cell.textLabel?.text = Localization.thirdPartyLicenses
196201
}
197202

198203
func configureAppSettings(cell: BasicTableViewCell) {
199204
cell.accessoryType = .disclosureIndicator
200205
cell.selectionStyle = .default
201-
cell.textLabel?.text = NSLocalizedString("Open Device Settings", comment: "Opens iOS's Device Settings for the app")
206+
cell.textLabel?.text = Localization.openDeviceSettings
202207
}
203208

204209
func configureWormholy(cell: BasicTableViewCell) {
205210
cell.accessoryType = .disclosureIndicator
206211
cell.selectionStyle = .default
207-
cell.textLabel?.text = NSLocalizedString("Launch Wormholy Debug",
208-
comment: "Opens an internal library called Wormholy. Not visible to users.")
212+
cell.textLabel?.text = Localization.launchWormHolyDebug
209213
}
210214

211215
func configureWhatsNew(cell: BasicTableViewCell) {
212216
cell.accessoryType = .disclosureIndicator
213217
cell.selectionStyle = .default
214-
cell.textLabel?.text = NSLocalizedString("What's New in WooCommerce", comment: "Navigates to screen containing the latest WooCommerce Features")
218+
cell.textLabel?.text = Localization.whatsNew
215219
}
216220

217221
func configureLogout(cell: BasicTableViewCell) {
218222
cell.selectionStyle = .default
219223
cell.textLabel?.textAlignment = .center
220224
cell.textLabel?.textColor = .error
221-
cell.textLabel?.text = NSLocalizedString("Log Out", comment: "Log out button title")
225+
cell.textLabel?.text = Localization.logout
222226
cell.accessibilityIdentifier = "settings-log-out-button"
223227
}
224228
}
@@ -240,22 +244,16 @@ private extension SettingsViewController {
240244

241245
func logoutWasPressed() {
242246
ServiceLocator.analytics.track(.settingsLogoutTapped)
243-
let messageUnformatted = NSLocalizedString(
244-
"Are you sure you want to log out of the account %@?",
245-
comment: "Alert message to confirm a user meant to log out."
246-
)
247-
let messageFormatted = String(format: messageUnformatted, viewModel.accountName)
247+
let messageFormatted = String(format: Localization.LogoutAlert.alertMessage, viewModel.accountName)
248248
let alertController = UIAlertController(title: "", message: messageFormatted, preferredStyle: .alert)
249249

250-
let cancelText = NSLocalizedString("Back", comment: "Alert button title - dismisses alert, which cancels the log out attempt")
251-
alertController.addActionWithTitle(cancelText, style: .cancel) { _ in
250+
alertController.addActionWithTitle(Localization.LogoutAlert.cancelButtonTitle, style: .cancel) { _ in
252251
ServiceLocator.analytics.track(.settingsLogoutConfirmation, withProperties: ["result": "negative"])
253252
}
254253

255-
let logoutText = NSLocalizedString("Log Out", comment: "Alert button title - confirms and logs out the user")
256-
alertController.addDefaultActionWithTitle(logoutText) { _ in
254+
alertController.addDefaultActionWithTitle(Localization.LogoutAlert.logoutButtonTitle) { [weak self] _ in
257255
ServiceLocator.analytics.track(.settingsLogoutConfirmation, withProperties: ["result": "positive"])
258-
self.logOutUser()
256+
self?.logOutUser()
259257
}
260258

261259
present(alertController, animated: true)
@@ -483,9 +481,7 @@ private extension SettingsViewController {
483481
/// (which contains a link to the "Work with us" URL)
484482
///
485483
var hiringAttributedText: NSAttributedString {
486-
let hiringText = NSLocalizedString("Made with love by Automattic. <a href=\"https://automattic.com/work-with-us/\">We’re hiring!</a>",
487-
comment: "It reads 'Made with love by Automattic. We’re hiring!'. Place \'We’re hiring!' between `<a>` and `</a>`"
488-
)
484+
let hiringText = Localization.hiring
489485
let hiringAttributes: [NSAttributedString.Key: Any] = [
490486
.font: StyleManager.footerLabelFont,
491487
.foregroundColor: UIColor.textSubtle
@@ -509,20 +505,37 @@ extension SettingsViewController {
509505
}
510506

511507
enum Row: CaseIterable {
508+
// Selected Store
512509
case selectedStore
513510
case switchStore
511+
512+
// Plugins
514513
case plugins
515-
case support
514+
515+
// Store settings
516516
case inPersonPayments
517-
case logout
518-
case privacy
517+
case installJetpack
518+
519+
// Help & Feedback
520+
case support
519521
case betaFeatures
520522
case sendFeedback
523+
524+
// App Settings
525+
case privacy
526+
527+
// About the App
521528
case about
529+
case whatsNew
522530
case licenses
531+
532+
// Other
523533
case deviceSettings
524534
case wormholy
525-
case whatsNew
535+
536+
// Logout
537+
case logout
538+
526539

527540
fileprivate var type: UITableViewCell.Type {
528541
switch self {
@@ -536,6 +549,8 @@ extension SettingsViewController {
536549
return BasicTableViewCell.self
537550
case .inPersonPayments:
538551
return BasicTableViewCell.self
552+
case .installJetpack:
553+
return BasicTableViewCell.self
539554
case .logout:
540555
return BasicTableViewCell.self
541556
case .privacy:
@@ -571,3 +586,105 @@ extension SettingsViewController: SettingsViewPresenter {
571586
tableView.reloadData()
572587
}
573588
}
589+
590+
// MARK: - Localizations
591+
//
592+
private extension SettingsViewController {
593+
enum Localization {
594+
static let navigationTitle = NSLocalizedString(
595+
"Settings",
596+
comment: "Settings navigation title"
597+
)
598+
599+
static let switchStore = NSLocalizedString(
600+
"Switch Store",
601+
comment: "This action allows the user to change stores without logging out and logging back in again."
602+
)
603+
604+
static let plugins = NSLocalizedString(
605+
"Plugins",
606+
comment: "Navigates to Plugins screen."
607+
)
608+
609+
static let helpAndSupport = NSLocalizedString(
610+
"Help & Support",
611+
comment: "Contact Support Action"
612+
)
613+
614+
static let inPersonPayments = NSLocalizedString(
615+
"In-Person Payments",
616+
comment: "Navigates to In-Person Payments screen"
617+
)
618+
619+
static let installJetpack = NSLocalizedString(
620+
"Install Jetpack",
621+
comment: "Navigates to Install Jetpack screen."
622+
)
623+
624+
static let privacySettings = NSLocalizedString(
625+
"Privacy Settings",
626+
comment: "Navigates to Privacy Settings screen"
627+
)
628+
629+
static let experimentalFeatures = NSLocalizedString(
630+
"Experimental Features",
631+
comment: "Navigates to experimental features screen"
632+
)
633+
634+
static let sendFeedback = NSLocalizedString(
635+
"Send Feedback",
636+
comment: "Presents a survey to gather feedback from the user."
637+
)
638+
639+
static let wooCommerce = NSLocalizedString(
640+
"WooCommerce",
641+
comment: "Navigates to about WooCommerce app screen"
642+
)
643+
644+
static let thirdPartyLicenses = NSLocalizedString(
645+
"Third Party Licenses",
646+
comment: "Navigates to screen with third party software licenses"
647+
)
648+
649+
static let openDeviceSettings = NSLocalizedString(
650+
"Open Device Settings",
651+
comment: "Opens iOS's Device Settings for the app"
652+
)
653+
654+
static let launchWormHolyDebug = NSLocalizedString(
655+
"Launch Wormholy Debug",
656+
comment: "Opens an internal library called Wormholy. Not visible to users."
657+
)
658+
659+
static let whatsNew = NSLocalizedString(
660+
"What's New in WooCommerce",
661+
comment: "Navigates to screen containing the latest WooCommerce Features"
662+
)
663+
664+
static let logout = NSLocalizedString(
665+
"Log Out",
666+
comment: "Log out button title"
667+
)
668+
669+
static let hiring = NSLocalizedString(
670+
"Made with love by Automattic. <a href=\"https://automattic.com/work-with-us/\">We’re hiring!</a>",
671+
comment: "It reads 'Made with love by Automattic. We’re hiring!'. Place \'We’re hiring!' between `<a>` and `</a>`"
672+
)
673+
674+
enum LogoutAlert {
675+
static let alertMessage = NSLocalizedString(
676+
"Are you sure you want to log out of the account %@?",
677+
comment: "Alert message to confirm a user meant to log out."
678+
)
679+
static let cancelButtonTitle = NSLocalizedString(
680+
"Back",
681+
comment: "Alert button title - dismisses alert, which cancels the log out attempt"
682+
)
683+
684+
static let logoutButtonTitle = NSLocalizedString(
685+
"Log Out",
686+
comment: "Alert button title - confirms and logs out the user"
687+
)
688+
}
689+
}
690+
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/Settings/SettingsViewModel.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import UIKit
22
import Yosemite
33
import Storage
44
import class Networking.UserAgent
5+
import Experiments
56

67
protocol SettingsViewModelOutput {
78
typealias Section = SettingsViewController.Section
@@ -91,11 +92,14 @@ final class SettingsViewModel: SettingsViewModelOutput, SettingsViewModelActions
9192

9293
private let stores: StoresManager
9394
private let storageManager: StorageManagerType
95+
private let featureFlagService: FeatureFlagService
9496

9597
init(stores: StoresManager = ServiceLocator.stores,
96-
storageManager: StorageManagerType = ServiceLocator.storageManager) {
98+
storageManager: StorageManagerType = ServiceLocator.storageManager,
99+
featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService) {
97100
self.stores = stores
98101
self.storageManager = storageManager
102+
self.featureFlagService = featureFlagService
99103

100104
/// Initialize Sites Results Controller
101105
///
@@ -187,9 +191,17 @@ private extension SettingsViewModel {
187191
}()
188192

189193
// Store settings
190-
let storeSettingsSection = Section(title: Localization.storeSettingsTitle,
191-
rows: [.inPersonPayments],
192-
footerHeight: UITableView.automaticDimension)
194+
let storeSettingsSection: Section = {
195+
let rows: [Row]
196+
if featureFlagService.isFeatureFlagEnabled(.jetpackConnectionPackageSupport) {
197+
rows = [.inPersonPayments, .installJetpack]
198+
} else {
199+
rows = [.inPersonPayments]
200+
}
201+
return Section(title: Localization.storeSettingsTitle,
202+
rows: rows,
203+
footerHeight: UITableView.automaticDimension)
204+
}()
193205

194206
// Help & Feedback
195207
let helpAndFeedbackSection: Section = {

0 commit comments

Comments
 (0)