Skip to content

Commit

Permalink
Shop improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Apr 29, 2024
1 parent 3da3a3c commit 4e1500e
Show file tree
Hide file tree
Showing 32 changed files with 276 additions and 114 deletions.
26 changes: 26 additions & 0 deletions HabitRPG/Extensions/Date-Extensions.swift
Expand Up @@ -37,4 +37,30 @@ func getShortRemainingString() -> String {
}
return string
}

func getImpreciseRemainingString() -> String {
let diff = Calendar.current.dateComponents([.day, .hour, .minute, .second], from: Date(), to: self)
if let days = diff.day, days > 0 {
if days == 1 {
return L10n._1Day
} else {
return L10n.xDays(days)
}
}
if let hours = diff.hour, hours > 0 {
if hours == 1 {
return L10n._1Hour
} else {
return L10n.xHours(hours)
}
}
if let minutes = diff.day, minutes > 0 {
if minutes == 1 {
return L10n._1Minute
} else {
return L10n.xMinutes(minutes)
}
}
return L10n._1Minute
}
}
24 changes: 24 additions & 0 deletions HabitRPG/Generated/Strings.swift
Expand Up @@ -8,8 +8,14 @@ public enum L10n {
/// Update bundle if you need to change app language
static var bundle: Bundle?

/// 1 Day
public static var _1Day: String { return L10n.tr("Mainstrings", "1_day") }
/// 1 Hour
public static var _1Hour: String { return L10n.tr("Mainstrings", "1_hour") }
/// 1 Hourglass
public static var _1Hourglass: String { return L10n.tr("Mainstrings", "1_hourglass") }
/// 1 Minute
public static var _1Minute: String { return L10n.tr("Mainstrings", "1_minute") }
/// Abort
public static var abort: String { return L10n.tr("Mainstrings", "abort") }
/// About
Expand Down Expand Up @@ -878,6 +884,8 @@ public enum L10n {
public static var reasonForReport: String { return L10n.tr("Mainstrings", "reason_for_report") }
/// Recipient
public static var recipient: String { return L10n.tr("Mainstrings", "recipient") }
/// Refresh for new Items
public static var refreshForItems: String { return L10n.tr("Mainstrings", "refresh_for_items") }
/// Reject
public static var reject: String { return L10n.tr("Mainstrings", "reject") }
/// Remember to check off your Dailies!
Expand Down Expand Up @@ -1080,6 +1088,10 @@ public enum L10n {
public static var summary: String { return L10n.tr("Mainstrings", "summary") }
/// Sunday
public static var sunday: String { return L10n.tr("Mainstrings", "sunday") }
/// Swaps in %@
public static func swapsInX(_ p1: String) -> String {
return L10n.tr("Mainstrings", "swaps_in_x", p1)
}
/// Tags
public static var tags: String { return L10n.tr("Mainstrings", "tags") }
/// Take me back
Expand Down Expand Up @@ -1232,6 +1244,10 @@ public enum L10n {
public static func writeTo(_ p1: String) -> String {
return L10n.tr("Mainstrings", "write_to", p1)
}
/// %d Days
public static func xDays(_ p1: Int) -> String {
return L10n.tr("Mainstrings", "x_days", p1)
}
/// %ld Filters
public static func xFilters(_ p1: Int) -> String {
return L10n.tr("Mainstrings", "x_filters", p1)
Expand All @@ -1248,10 +1264,18 @@ public enum L10n {
public static func xHourglasses(_ p1: Int) -> String {
return L10n.tr("Mainstrings", "x_hourglasses", p1)
}
/// %d Hours
public static func xHours(_ p1: Int) -> String {
return L10n.tr("Mainstrings", "x_hours", p1)
}
/// %d Items pending
public static func xItemsFound(_ p1: Int) -> String {
return L10n.tr("Mainstrings", "x_items_found", p1)
}
/// %d Minutes
public static func xMinutes(_ p1: Int) -> String {
return L10n.tr("Mainstrings", "x_minutes", p1)
}
/// %d Months
public static func xMonths(_ p1: Int) -> String {
return L10n.tr("Mainstrings", "x_months", p1)
Expand Down
1 change: 1 addition & 0 deletions HabitRPG/HRPGShopSectionHeaderCollectionReusableView.swift
Expand Up @@ -14,6 +14,7 @@ class HRPGShopSectionHeaderCollectionReusableView: UICollectionReusableView {
@IBOutlet weak var gearCategoryLabel: UILabel!
@IBOutlet weak var dropdownIconView: UIImageView!
@IBOutlet weak var otherClassDisclaimer: UILabel!
@IBOutlet weak var swapsInLabel: UILabel!

var onGearCategoryLabelTapped: (() -> Void)?

Expand Down
2 changes: 1 addition & 1 deletion HabitRPG/Habitica-Info.plist
Expand Up @@ -39,7 +39,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>954</string>
<string>957</string>
<key>CustomDomain</key>
<string>${CUSTOM_DOMAIN}</string>
<key>DisableSSL</key>
Expand Down
5 changes: 5 additions & 0 deletions HabitRPG/Repositories/ConfigRepository.swift
Expand Up @@ -304,6 +304,11 @@ class ConfigRepository: NSObject {

@objc
func bool(variable: ConfigVariable) -> Bool {
#if DEBUG
if testingLevel.isDeveloper {
return variable.defaultValue()
}
#endif
return ConfigRepository.remoteConfig.configValue(forKey: variable.name()).boolValue
}

Expand Down
43 changes: 21 additions & 22 deletions HabitRPG/Storyboards/Base.lproj/BuyModal.storyboard

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions HabitRPG/Storyboards/Base.lproj/Shop.storyboard
Expand Up @@ -77,6 +77,13 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YCg-bt-MYU">
<rect key="frame" x="359" y="25" width="0.0" height="0.0"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" horizontalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="Q9N-kS-Lun">
<rect key="frame" x="323" y="9" width="28" height="32"/>
<subviews>
Expand Down Expand Up @@ -133,7 +140,9 @@
<constraints>
<constraint firstAttribute="height" constant="50" id="3Pm-aT-jbe"/>
<constraint firstItem="Q9N-kS-Lun" firstAttribute="centerY" secondItem="5ba-rq-bH5" secondAttribute="centerY" id="BcN-ee-2nM"/>
<constraint firstItem="YCg-bt-MYU" firstAttribute="centerY" secondItem="5ba-rq-bH5" secondAttribute="centerY" id="E1I-RL-nX9"/>
<constraint firstItem="JB4-vT-m2S" firstAttribute="centerY" secondItem="5ba-rq-bH5" secondAttribute="centerY" id="I4e-Mr-ePC"/>
<constraint firstAttribute="trailing" secondItem="YCg-bt-MYU" secondAttribute="trailing" id="Sj9-kr-IfS"/>
<constraint firstItem="Q9N-kS-Lun" firstAttribute="trailing" secondItem="5ba-rq-bH5" secondAttribute="trailingMargin" id="Tc8-5f-0pI"/>
<constraint firstAttribute="leadingMargin" secondItem="JB4-vT-m2S" secondAttribute="leading" id="eCs-QZ-4nH"/>
<constraint firstItem="Q9N-kS-Lun" firstAttribute="leading" secondItem="JB4-vT-m2S" secondAttribute="trailing" constant="8" id="p7E-y6-Dkn"/>
Expand Down Expand Up @@ -164,6 +173,7 @@
<outlet property="gearCategoryButton" destination="Q9N-kS-Lun" id="X29-Mw-lkk"/>
<outlet property="gearCategoryLabel" destination="88E-6b-fM7" id="b7b-Z2-cVa"/>
<outlet property="otherClassDisclaimer" destination="jif-V8-AXN" id="qGg-MR-Rvb"/>
<outlet property="swapsInLabel" destination="YCg-bt-MYU" id="GHL-eK-2sq"/>
<outlet property="titleLabel" destination="JB4-vT-m2S" id="HIC-jy-x7H"/>
</connections>
</collectionReusableView>
Expand Down
9 changes: 9 additions & 0 deletions HabitRPG/Strings/Base.lproj/Mainstrings.strings
Expand Up @@ -1335,3 +1335,12 @@
"challenge_category.self_improvement" = "Self-Improvement";
"challenge_category.spirituality" = "Spirituality";
"challenge_category.time_management" = "Time-Management + Accountability";

"x_days" = "%d Days";
"1_day" = "1 Day";
"x_hours" = "%d Hours";
"1_hour" = "1 Hour";
"x_minutes" = "%d Minutes";
"1_minute" = "1 Minute";
"swaps_in_x" = "Switches in %@";
"refresh_for_items" = "Refresh for new Items";
1 change: 1 addition & 0 deletions HabitRPG/TableViewDataSources/BaseReactiveDataSource.swift
Expand Up @@ -23,6 +23,7 @@ class ItemSection<MODEL> {
var isHidden = false
var showIfEmpty = false
var items = [MODEL]()
var endDate: Date? = nil

var isVisible: Bool {
return !isHidden && (items.isEmpty == false || showIfEmpty)
Expand Down
13 changes: 13 additions & 0 deletions HabitRPG/TableViewDataSources/ShopCollectionViewDataSource.swift
Expand Up @@ -121,6 +121,7 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
let newSection = ItemSection<InAppRewardProtocol>(title: category.text)
newSection.items = category.items
newSection.key = category.identifier
newSection.endDate = category.endDate
sections.append(newSection)
}
collectionView?.reloadData()
Expand Down Expand Up @@ -214,6 +215,18 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
headerView.otherClassDisclaimer.isHidden = userClass == selectedInternalGearCategory || selectedInternalGearCategory == "none"
headerView.otherClassDisclaimer.text = L10n.Shops.otherClassDisclaimer
} else {
let section = visibleSections[indexPath.section]
if let endDate = section.endDate {
headerView.swapsInLabel.isHidden = false
if endDate > Date() {
headerView.swapsInLabel.text = L10n.swapsInX(endDate.getImpreciseRemainingString())
} else {
headerView.swapsInLabel.text = L10n.refreshForItems
}
headerView.swapsInLabel.textColor = ThemeService.shared.theme.tintedMainText
} else {
headerView.swapsInLabel.isHidden = true
}
headerView.titleLabel.text = titleFor(section: indexPath.section)?.localizedUppercase
}
headerView.titleLabel.textColor = ThemeService.shared.theme.ternaryTextColor
Expand Down
4 changes: 2 additions & 2 deletions HabitRPG/TableviewCells/InAppRewardCell.swift
Expand Up @@ -104,7 +104,7 @@ class InAppRewardCell: UICollectionViewCell {
var currency: Currency?
let price = reward.value
currencyView.amount = Int(reward.value)
imageName = reward.imageName ?? ""
imageName = reward.iconName
itemName = reward.text ?? ""
if let currencyString = reward.currency, let thisCurrency = Currency(rawValue: currencyString) {
currencyView.currency = thisCurrency
Expand All @@ -121,7 +121,7 @@ class InAppRewardCell: UICollectionViewCell {
showPurchaseConfirmation()
}

if let date = reward.eventEnd {
if let date = reward.availableUntil() {
availableUntil = date
} else {
availableUntil = nil
Expand Down
2 changes: 1 addition & 1 deletion HabitRPG/UI/General/MainMenuViewController.swift
Expand Up @@ -389,7 +389,7 @@ class MainMenuViewController: BaseTableViewController {
})
}

if configRepository.bool(variable: .enableCustomizationShop) {
if configRepository.bool(variable: .enableCustomizationShop) || configRepository.testingLevel.isDeveloper {
menuItem(withKey: .customizationShop).isHidden = false
tableView.reloadData()
}
Expand Down
4 changes: 2 additions & 2 deletions HabitRPG/UI/Inventory/AvatarDetailViewController.swift
Expand Up @@ -27,7 +27,7 @@ class AvatarDetailViewController: BaseCollectionViewController, UICollectionView
super.viewDidLoad()
topHeaderCoordinator?.followScrollView = false

newCustomizationLayout = configRepository.bool(variable: .enableCustomizationShop)
newCustomizationLayout = configRepository.bool(variable: .enableCustomizationShop) || configRepository.testingLevel.isDeveloper

if let type = customizationType {
if type == "eyewear" || type == "headAccessory" || type == "back" || type == "animalTails" {
Expand Down Expand Up @@ -101,7 +101,7 @@ class AvatarDetailViewController: BaseCollectionViewController, UICollectionView
}

private func showPurchaseDialog(customization: CustomizationProtocol, withSource sourceView: UIView?) {
let sheet = HostingBottomSheetController(rootView: BottomSheetMenu(Text(customization.titleText), iconName: customization.imageName(forUserPreferences: nil) ?? "", menuItems: {
let sheet = HostingBottomSheetController(rootView: BottomSheetMenu(Text(customization.titleText), iconName: customization.iconName(forUserPreferences: nil) ?? "", menuItems: {
BottomSheetMenuitem(title: HStack {
Text(L10n.purchaseForWithoutCurrency(Int(customization.price)))
Image(uiImage: HabiticaIcons.imageOfGem)
Expand Down
18 changes: 9 additions & 9 deletions HabitRPG/UI/Inventory/AvatarOverviewViewController.swift
Expand Up @@ -111,47 +111,47 @@ class AvatarOverviewViewController: BaseUIViewController, UIScrollViewDelegate {
bodySizeControl.selectedSegmentIndex = user.preferences?.size == "slim" ? 0 : 1

if let shirt = user.preferences?.shirt {
shirtView.configure("Icon_\(user.preferences?.size ?? "slim")_shirt_\(shirt)")
shirtView.configure("icon_\(user.preferences?.size ?? "slim")_shirt_\(shirt)")
}
if let skin = user.preferences?.skin {
skinView.configure("Icon_skin_\(skin)")
skinView.configure("icon_skin_\(skin)")
}
if let hairColor = user.preferences?.hair?.color {
let bangs = user.preferences?.hair?.bangs
hairColorView.configure("Icon_hair_bangs_\(bangs ?? 1)_\(hairColor)")
hairColorView.configure("icon_hair_bangs_\(bangs ?? 1)_\(hairColor)")
if bangs != 0 {
hairBangsView.configure("Icon_hair_bangs_\(bangs ?? 1)_\(hairColor)")
hairBangsView.configure("icon_hair_bangs_\(bangs ?? 1)_\(hairColor)")
} else {
hairBangsView.configure(nil)
}

if let base = user.preferences?.hair?.base, base != 0 {
hairBaseView.configure("Icon_hair_base_\(base)_\(hairColor)")
hairBaseView.configure("icon_hair_base_\(base)_\(hairColor)")
} else {
hairBaseView.configure(nil)
}

if let beard = user.preferences?.hair?.beard, beard != 0 {
hairBeardView.configure("Icon_hair_beard_\(beard)_\(hairColor)")
hairBeardView.configure("icon_hair_beard_\(beard)_\(hairColor)")
} else {
hairBeardView.configure(nil)
}

if let mustache = user.preferences?.hair?.mustache, mustache != 0 {
hairMustacheView.configure("Icon_hair_mustache_\(mustache)_\(hairColor)")
hairMustacheView.configure("icon_hair_mustache_\(mustache)_\(hairColor)")
} else {
hairMustacheView.configure(nil)
}
}

if let flower = user.preferences?.hair?.flower, flower != 0 {
hairFlowerView.configure("Icon_hair_flower_\(flower)")
hairFlowerView.configure("icon_hair_flower_\(flower)")
} else {
hairFlowerView.configure(nil)
}

if let chair = user.preferences?.chair, chair != "none" {
wheelchairView.configure("Icon_chair_\(chair)")
wheelchairView.configure("icon_chair_\(chair)")
} else {
wheelchairView.configure(nil)
}
Expand Down

0 comments on commit 4e1500e

Please sign in to comment.