diff --git a/HabitRPG/Extensions/String-Extensions.swift b/HabitRPG/Extensions/String-Extensions.swift index d9384f96a..a8c5d4f7b 100644 --- a/HabitRPG/Extensions/String-Extensions.swift +++ b/HabitRPG/Extensions/String-Extensions.swift @@ -174,7 +174,21 @@ extension String { return L10n.Classes.warriors } } +} +extension HabiticaClass { + var translatedName: String { + switch self { + case .warrior: + return L10n.Classes.warrior + case .mage: + return L10n.Classes.mage + case .healer: + return L10n.Classes.healer + case .rogue: + return L10n.Classes.rogue + } + } } // swiftlint:enable all diff --git a/HabitRPG/Generated/Strings.swift b/HabitRPG/Generated/Strings.swift index f8df3fb57..304eaa92e 100644 --- a/HabitRPG/Generated/Strings.swift +++ b/HabitRPG/Generated/Strings.swift @@ -142,10 +142,20 @@ public enum L10n { public static var checkinYesterdaysDalies: String { return L10n.tr("Mainstrings", "checkin_yesterdays_dalies") } /// Choose Task public static var chooseTask: String { return L10n.tr("Mainstrings", "choose_task") } - /// Are you sure you want to change your class to %@? This will cost 3 gems. - public static func classChangeConfirm(_ p1: String) -> String { + /// Change class to %s for 3 Gems? + public static func classChangeConfirm(_ p1: UnsafePointer) -> String { return L10n.tr("Mainstrings", "class_change_confirm", p1) } + /// This will switch which gear is unlocked in the shops, change your available skills, and reset your stat points. + public static var classChangeConfirmDescription: String { return L10n.tr("Mainstrings", "class_change_confirm_description") } + /// You can now use %@ skills and purchase gear from shops. Gain levels to earn stat points you can use to power up your skills. + public static func classChangeSuccessDescription(_ p1: String) -> String { + return L10n.tr("Mainstrings", "class_change_success_description", p1) + } + /// You're a %@! + public static func classChangeSuccessTitle(_ p1: String) -> String { + return L10n.tr("Mainstrings", "class_change_success_title", p1) + } /// This item is only available to %s.\nOpen Settings to change class. public static func classEquipmentShopDialog(_ p1: UnsafePointer) -> String { return L10n.tr("Mainstrings", "class_equipment_shop_dialog", p1) @@ -478,6 +488,8 @@ public enum L10n { public static var gold: String { return L10n.tr("Mainstrings", "gold") } /// Gold is the **main form of currency** within Habitica and allows you to buy certain gear, quests, items, or even custom rewards you make for yourself.\n\n**Earn Gold** through completing tasks or quests, or through some Class skills. Higher **Perception stats** raise the amount of Gold you earn.\n\nIf you subscribe to Habitica, you can even use Gold to purchase a number of Gems determined by the length of time you’ve been subscribed. public static var goldDescription: String { return L10n.tr("Mainstrings", "gold_description") } + /// Got it! + public static var gotIt: String { return L10n.tr("Mainstrings", "got_it") } /// Great public static var great: String { return L10n.tr("Mainstrings", "great") } /// Group By @@ -780,6 +792,8 @@ public enum L10n { public static var openMysteryItem: String { return L10n.tr("Mainstrings", "open_mystery_item") } /// Open Profile public static var openProfile: String { return L10n.tr("Mainstrings", "open_profile") } + /// Open Stats + public static var openStats: String { return L10n.tr("Mainstrings", "open_stats") } /// Open Website public static var openWebsite: String { return L10n.tr("Mainstrings", "open_website") } /// Organize By diff --git a/HabitRPG/GuidelinesViewController.swift b/HabitRPG/GuidelinesViewController.swift index ae0e106da..bb5066862 100644 --- a/HabitRPG/GuidelinesViewController.swift +++ b/HabitRPG/GuidelinesViewController.swift @@ -8,24 +8,40 @@ import UIKit import Down +import SwiftUIX class GuidelinesViewController: UIViewController { @IBOutlet weak var textView: UITextView! - + let activityIndicator = UIHostingView(rootView: HabiticaProgressView()) + override func viewDidLoad() { super.viewDidLoad() + view.addSubview(activityIndicator) + navigationItem.title = L10n.Titles.guidelines let urlString = "https://s3.amazonaws.com/habitica-assets/mobileApp/endpoint/community-guidelines.md" guard let url = URL(string: urlString) else { return } - if let text = try? String(contentsOf: url) { - textView.attributedText = try? Down(markdownString: text).toHabiticaAttributedString() + DispatchQueue.global(qos: .background).async { [weak self] in + if let text = try? String(contentsOf: url) { + let attributed = try? Down(markdownString: text).toHabiticaAttributedString() + DispatchQueue.main.async { + self?.textView.attributedText = attributed + self?.textView.isHidden = false + self?.activityIndicator.isHidden = true + } + } } } + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + activityIndicator.pin.center().size(44) + } + @IBAction func doneButtonTapped(_ sender: Any) { dismiss(animated: true, completion: nil) } diff --git a/HabitRPG/HRPGShopSectionHeaderCollectionReusableView.swift b/HabitRPG/HRPGShopSectionHeaderCollectionReusableView.swift index 4053cca9c..c729a9296 100644 --- a/HabitRPG/HRPGShopSectionHeaderCollectionReusableView.swift +++ b/HabitRPG/HRPGShopSectionHeaderCollectionReusableView.swift @@ -53,13 +53,13 @@ class HRPGShopSectionHeaderCollectionReusableView: UICollectionReusableView { @objc private func changeClassTapped() { - let dialog = HabiticaAlertController(title: L10n.classChangeConfirm(newClassName ?? "")) - dialog.addAction(title: L10n.yes, isMainAction: true) { _ in + let dialog = HabiticaAlertController(title: L10n.classChangeConfirm(newClassName ?? ""), message: L10n.classChangeConfirmDescription) + dialog.addAction(title: L10n.Settings.changeClass, style: .destructive, isMainAction: true) { _ in if let action = self.onClassChange { action() } } - dialog.addAction(title: L10n.no) + dialog.addCloseAction() dialog.show() } diff --git a/HabitRPG/Repositories/Implementations/UserRepository.swift b/HabitRPG/Repositories/Implementations/UserRepository.swift index 31029788d..0a500e9cc 100644 --- a/HabitRPG/Repositories/Implementations/UserRepository.swift +++ b/HabitRPG/Repositories/Implementations/UserRepository.swift @@ -392,10 +392,23 @@ class UserRepository: BaseRepository { return Signal.empty } lastClassSelection = Date() - return SelectClassCall(class: habiticaClass).responseSignal - .flatMap(.latest, {[weak self] _ in - return self?.retrieveUser(withTasks: false, forced: true) ?? .empty + return SelectClassCall(class: habiticaClass).httpResponseSignal + .on(value: { response in + if response.statusCode == 200 { + let alert = HabiticaAlertController( + title: L10n.classChangeSuccessTitle(habiticaClass?.translatedName ?? ""), + message: L10n.classChangeSuccessDescription(habiticaClass?.translatedName ?? "")) + alert.addAction(title: L10n.gotIt, isMainAction: true) + alert.addAction(title: L10n.openStats) { _ in + RouterHandler.shared.handle(urlString: "/user/stats") + } + alert.show() + } + }) + .flatMap(.latest, { _ in + return self.retrieveUser(withTasks: false, forced: true) }) + .take(first: 1) .on(value: handleUserUpdate()) } diff --git a/HabitRPG/Storyboards/Base.lproj/Social.storyboard b/HabitRPG/Storyboards/Base.lproj/Social.storyboard index 88a2fda8b..0455f313e 100644 --- a/HabitRPG/Storyboards/Base.lproj/Social.storyboard +++ b/HabitRPG/Storyboards/Base.lproj/Social.storyboard @@ -1,9 +1,9 @@ - + - + @@ -2709,7 +2709,7 @@ - + diff --git a/HabitRPG/Strings/Base.lproj/Mainstrings.strings b/HabitRPG/Strings/Base.lproj/Mainstrings.strings index 7b338e014..7cee6d7ec 100644 --- a/HabitRPG/Strings/Base.lproj/Mainstrings.strings +++ b/HabitRPG/Strings/Base.lproj/Mainstrings.strings @@ -1386,4 +1386,9 @@ "change_class_to" = "Change class to %@"; "unlock_x_gear_and_skills" = "Unlock %@ gear and skills"; -"class_change_confirm" = "Are you sure you want to change your class to %@? This will cost 3 gems."; +"class_change_confirm" = "Change class to %s for 3 Gems?"; +"class_change_confirm_description" = "This will switch which gear is unlocked in the shops, change your available skills, and reset your stat points."; +"class_change_success_title" = "You're a %@!"; +"class_change_success_description" = "You can now use %@ skills and purchase gear from shops. Gain levels to earn stat points you can use to power up your skills."; +"got_it" = "Got it!"; +"open_stats" = "Open Stats"; diff --git a/HabitRPG/TableViewDataSources/ShopCollectionViewDataSource.swift b/HabitRPG/TableViewDataSources/ShopCollectionViewDataSource.swift index a23c4f34c..d62ccb4a8 100644 --- a/HabitRPG/TableViewDataSources/ShopCollectionViewDataSource.swift +++ b/HabitRPG/TableViewDataSources/ShopCollectionViewDataSource.swift @@ -226,8 +226,11 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource