Skip to content

Commit

Permalink
Armoire fix
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed May 22, 2024
1 parent a16ca46 commit 343d913
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class AvatarGearDetailViewDataSource: BaseReactiveCollectionViewDataSource<GearP
override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

if let gear = item(at: indexPath) {
if !owns(gear: gear) {
if !owns(gear: gear) && !newCustomizationLayout {
return CGSize(width: 80, height: 108)
} else {
return CGSize(width: 80, height: 108)
return CGSize(width: 80, height: 80)
}
}
return CGSize.zero
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
if let itemCell = cell as? InAppRewardCell {
itemCell.configure(reward: item, user: user)
if let ownedItem = ownedItems["\(item.key ?? "")-\(item.type ?? item.purchaseType ?? "")"] {
itemCell.itemsLeft = ownedItem.numberOwned
itemCell.itemCount = ownedItem.numberOwned
}
itemCell.isPinned = pinnedItems.contains(item.key)
if item.type == "quests" || item.pinType == "quests" {
Expand Down
12 changes: 7 additions & 5 deletions HabitRPG/TableviewCells/InAppRewardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ class InAppRewardCell: UICollectionViewCell {

private var itemName = ""

var itemsLeft = 0 {
var itemCount = 0 {
didSet {
if itemsLeft > 0 {
if itemCount > 0 {
infoLabel.isHidden = false
infoLabel.text = String(describing: itemsLeft)
infoLabel.backgroundColor = ThemeService.shared.theme.offsetBackgroundColor
infoLabel.textColor = ThemeService.shared.theme.ternaryTextColor
infoLabel.text = String(describing: itemCount)
infoImageView.isHidden = true
} else {
infoImageView.isHidden = true
Expand Down Expand Up @@ -123,8 +121,12 @@ class InAppRewardCell: UICollectionViewCell {

if let date = reward.availableUntil() {
availableUntil = date
infoLabel.backgroundColor = ThemeService.shared.theme.backgroundTintColor
infoLabel.textColor = .white
} else {
availableUntil = nil
infoLabel.backgroundColor = ThemeService.shared.theme.offsetBackgroundColor
infoLabel.textColor = ThemeService.shared.theme.quadTextColor
}
applyAccessibility()

Expand Down
10 changes: 6 additions & 4 deletions HabitRPG/UI/General/ArmoireViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import SwiftUI
import Kingfisher
import ConfettiSwiftUI
import ReactiveSwift

struct AnimatableNumberModifier: AnimatableModifier {
var number: Double
Expand Down Expand Up @@ -72,6 +73,7 @@ private struct ArmoirePlus: View {
}

private class ViewModel: ObservableObject {
private let disposable = ScopedDisposable(CompositeDisposable())
let userRepository = UserRepository()
let inventoryRepository = InventoryRepository()

Expand All @@ -97,17 +99,17 @@ private class ViewModel: ObservableObject {
self.gold = gold
self.initialGold = gold
} else {
userRepository.getUser().on(value: { user in
disposable.inner.add(userRepository.getUser().on(value: { user in
self.isSubscribed = user.isSubscribed
if self.gold == 0 {
self.initialGold = Double(user.stats?.gold ?? 0) + 100
self.gold = Double(user.stats?.gold ?? 0) + 100
}
}).start()
}).start())

inventoryRepository.getArmoireRemainingCount().on(value: {gear in
disposable.inner.add(inventoryRepository.getArmoireRemainingCount().on(value: {gear in
self.remainingCount = gear.value.count
}).start()
}).start())
}
}

Expand Down
6 changes: 6 additions & 0 deletions HabitRPG/UI/Inventory/AvatarOverviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ class AvatarOverviewViewController: BaseUIViewController, UIScrollViewDelegate {
@IBOutlet weak var animalEarsView: AvatarOverviewItemView!
@IBOutlet weak var backgroundView: AvatarOverviewItemView!

private let headerView = AvatarHeaderView()

override func viewDidLoad() {
topHeaderCoordinator?.hideNavBar = false
super.viewDidLoad()
topHeaderCoordinator?.alternativeHeader = headerView
topHeaderCoordinator?.followScrollView = false
if let topHeaderNavigationController = navigationController as? TopHeaderViewController {
topHeaderCoordinator = TopHeaderCoordinator(topHeaderNavigationController: topHeaderNavigationController, scrollView: scrollView)
}
Expand All @@ -60,6 +65,7 @@ class AvatarOverviewViewController: BaseUIViewController, UIScrollViewDelegate {
} else {
containerview.backgroundColor = theme.offsetBackgroundColor
}
topHeaderCoordinator?.navbarVisibleColor = theme.windowBackgroundColor
}

override func populateText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public class APIGear: GearProtocol, Codable {
intelligence = (try? values.decode(Int.self, forKey: .intelligence)) ?? 0
constitution = (try? values.decode(Int.self, forKey: .constitution)) ?? 0
perception = (try? values.decode(Int.self, forKey: .perception)) ?? 0
released = (try? values.decode(Bool.self, forKey: .released)) ?? false
released = (try? values.decode(Bool.self, forKey: .released)) ?? true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public class InventoryLocalRepository: ContentLocalRepository {
}
}
.flatMap(.latest) { keys in
return RealmGear.findBy(predicate: NSPredicate(format: "habitClass == 'armoire' && released == true && NOT key IN %@", keys)).reactive()
return RealmGear.findBy(predicate: NSPredicate(format: "habitClass == 'armoire' && released != false && NOT key IN %@", keys)).reactive()
}.map({ (value, changeset) -> ReactiveResults<[GearProtocol]> in
return (value.map({ (item) -> GearProtocol in return item }), changeset)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public extension CustomizationProtocol {
case "beard":
return "hair_beard_\(key)_\(hairColor)"
case "color":
return "hair_bangs_\(preferences?.hair?.bangs ?? 1)_\(key)"
let bangs = preferences?.hair?.bangs ?? 1
return "hair_bangs_\(bangs > 0 ? bangs : 1)_\(key)"
case "flower":
return "hair_flower_\(key)"
default:
Expand Down
Loading

0 comments on commit 343d913

Please sign in to comment.