Skip to content

Commit

Permalink
Item caching to help queries, and cleanup everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
VeritasDev committed Oct 25, 2019
1 parent 61181a0 commit 7b0be24
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 422 deletions.
232 changes: 116 additions & 116 deletions iOS/BattleBuddy/Misc/Localization/de.lproj/Localizable.strings

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ protocol HttpRequestor {
func sendGetRequest(url: String, headers: [String: String], completion: @escaping (_ : [String: Any]?) -> Void)
}

// MARK:- Session

// MARK:- Account
enum AccountProperty: String {
case lastLogin = "lastLogin"
case loyalty = "loyalty"
Expand All @@ -59,7 +58,6 @@ protocol AccountManager {
}

// MARK: - Database

protocol DatabaseManager {
func getCharacters(handler: @escaping (_: [Character]) -> Void)

Expand Down Expand Up @@ -93,12 +91,6 @@ protocol DatabaseManager {
func getAllHelmetsWithMaterial(material: ArmorMaterial, handler: @escaping ([Armor]) -> Void)
func getAllHelmetArmorOfClass(armorClass: ArmorClass, handler: @escaping ([Armor]) -> Void)
func getAllHelmetArmorWithMaterial(material: ArmorMaterial, handler: @escaping ([Armor]) -> Void)

func getAllMods(handler: @escaping (_: [Modification]) -> Void)
func getAllModsByType(handler: @escaping ([ModType: [Modification]]) -> Void)
func getAllModsOfType(_ type: ModType, handler: @escaping ([Modification]) -> Void)

func getCompatibleItemsForFirearm(_ firearm: Firearm, handler: @escaping (FirearmBuildConfig) -> Void)
}

// MARK:- Ads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ struct ModificationComparison: ItemComparison {
possibleOptions = []
}

// TODO: Implement
func getPercentValue(item: Comparable, property: ComparableProperty, traitCollection: UITraitCollection) -> Float {
guard let throwable = item as? Throwable else { fatalError() }
let range = getComparedItemsSummaryMap()[property]!

switch property {
default: fatalError()
}
// guard let throwable = item as? Throwable else { fatalError() }
// let range = getComparedItemsSummaryMap()[property]!
//
// switch property {
// default: fatalError()
// }
return 1.0
}

func getComparedItemsSummaryMap() -> [ComparableProperty: PropertyRange] {

for case let mod as Modification in allItems {
}
//
// for case let mod as Modification in allItems {
// }

return [:]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class FirearmDetailsConfiguration: NSObject, ItemDetailsConfiguration, UITableVi
let exploreHeaderView = SectionHeaderView(headerText: "explore".local())
lazy var exploreTableView = { BaseTableView(dataSource: self, delegate: self) }()
let compareCell = BaseTableViewCell(text: "compare_performance".local())
let customBuildCell = BaseTableViewCell(text: "gun_build_custom".local())
let combatSimCell = BaseTableViewCell(text: "main_menu_combat_sim".local())
lazy var exploreCells: [BaseTableViewCell] = { return [compareCell, combatSimCell] }()

Expand Down Expand Up @@ -146,16 +145,6 @@ class FirearmDetailsConfiguration: NSObject, ItemDetailsConfiguration, UITableVi
let comparisonVC = ComparisonOptionsViewController(FirearmComparison(self.firearm, allFirearms: firearms))
self.delegate?.showViewController(viewController: comparisonVC)
}
case customBuildCell:
self.delegate?.showLoading(show: true)

dbManager.getCompatibleItemsForFirearm(firearm) { config in
self.delegate?.showLoading(show: false)

let buildController = FirearmBuildController(config)
let buildVC = FirearmBuildViewController(buildController)
self.delegate?.showViewController(viewController: buildVC)
}
case combatSimCell:
self.delegate?.showLoading(show: true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,5 @@ class ModificationDetailsConfiguration: NSObject, ItemDetailsConfiguration, UITa

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

let cell = tableView.cellForRow(at: indexPath)

let dbManager = DependencyManagerImpl.shared.databaseManager()

switch cell {
case compareCell:
self.delegate?.showLoading(show: true)

dbManager.getAllMods { mods in
self.delegate?.showLoading(show: false)
self.delegate?.showViewController(viewController: ComparisonOptionsViewController(ModificationComparison(mods)))
}
default: fatalError()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SortableTableViewCell: BaseTableViewCell {
let stackView = BaseStackView(axis: .horizontal)
var labels: [UILabel] = []

var isSelectedOption: Bool { didSet { labels.forEach { $0.textColor = isSelected ? UIColor.Theme.primary : .white } } }
var isSelectedOption: Bool { didSet { labels.forEach { $0.textColor = isSelectedOption ? UIColor.Theme.primary : .white } } }

required init?(coder aDecoder: NSCoder) { fatalError() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ class SortableHeaderView: UIView {
delegate.toggleSort(param: params[index])

for button in buttons {
let weight = (button == sender) ? UIFont.Weight.bold : UIFont.Weight.thin
let selected = (button == sender)
let weight = selected ? UIFont.Weight.black : UIFont.Weight.thin
let color = selected ? UIColor(white: 1.0, alpha: 1.0) : UIColor(white: 0.8, alpha: 1.0)
button.titleLabel?.font = UIFont.systemFont(ofSize: 14.0, weight: weight)
button.setTitleColor(color, for: .normal)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,41 +109,33 @@ class CombatSimSubjectEditViewController: StaticGroupedTableViewController {
}

func showFirearmOptions() {
// TODO: Show type / caliber


if let options = firearmOptions {
let selectFirearmVC = SortableTableViewController(selectionDelegate: self, config: FirearmSortConfig(options: options), currentSelection: nil)
selectFirearmVC.currentSelection = character.firearm
let selectFirearmVC = SortableTableViewController(selectionDelegate: self, config: FirearmSortConfig(options: options), currentSelection: character.firearm)
selectFirearmVC.presentedModally = false
navigationController?.pushViewController(selectFirearmVC, animated: true)
} else {
showLoading()

dbManager.getAllFirearms { allFirearms in
self.hideLoading()

self.firearmOptions = allFirearms.compactMap { SimulationFirearm(json: $0.json) }
self.showFirearmOptions()
}
}
}

func showArmorOptions(armorTypes: [ArmorType]) {
// TODO: Show type / caliber

if let options = armorOptions {
let filteredOptions = options.filter { armorTypes.contains($0.armorType) }
let selectArmorVC = SortableTableViewController(selectionDelegate: self, config: ArmorSortConfig(options: filteredOptions), currentSelection: nil)
selectArmorVC.currentSelection = armorTypes.contains(.body) ? character.bodyArmor : character.headArmor
let currentSelection = armorTypes.contains(.body) ? character.bodyArmor : character.headArmor
let selectArmorVC = SortableTableViewController(selectionDelegate: self, config: ArmorSortConfig(options: filteredOptions), currentSelection: currentSelection)
selectArmorVC.presentedModally = false
navigationController?.pushViewController(selectArmorVC, animated: true)
} else {
showLoading()

dbManager.getAllArmor { allArmor in
self.hideLoading()

self.armorOptions = allArmor.compactMap { SimulationArmor(json: $0.json) }
self.showArmorOptions(armorTypes: armorTypes)
}
Expand All @@ -155,16 +147,14 @@ class CombatSimSubjectEditViewController: StaticGroupedTableViewController {

if let options = ammoOptions {
let filteredOptions = options.filter{ $0.caliber == character.firearm?.caliber }
let selectAmmoVC = SortableTableViewController(selectionDelegate: self, config: AmmoSortConfig(options: filteredOptions), currentSelection: nil)
selectAmmoVC.currentSelection = character.ammo
let selectAmmoVC = SortableTableViewController(selectionDelegate: self, config: AmmoSortConfig(options: filteredOptions), currentSelection: character.ammo)
selectAmmoVC.presentedModally = false
navigationController?.pushViewController(selectAmmoVC, animated: true)
} else {
showLoading()

dbManager.getAllAmmo { allAmmo in
self.hideLoading()

self.ammoOptions = allAmmo.compactMap { SimulationAmmo(json: $0.json) }
self.showAmmoOptions()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,6 @@ class ItemListViewController: BaseStackViewController {
self?.config.sections = medicalSections
self?.buildStackFromConfig()
}
case .modification:
self.dbManager.getAllModsByType { [weak self] modMap in
hud.dismiss(animated: false)
var modSections: [ItemSection] = []
for type in ModType.allCases {
if let items = modMap[type], items.count > 0 {
modSections.append(ItemSection(title: type.local(), items: items))
}
}
self?.config.sections = modSections
self?.buildStackFromConfig()
}
default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class MoreMenuViewController: BaseTableViewController {
super.viewWillAppear(animated)

globalMetadata = globalMetadataManager.getGlobalMetadata()
currentUserMetadata = accountManager.currentUserMetadata()
updateCells()
}

Expand All @@ -204,9 +203,10 @@ class MoreMenuViewController: BaseTableViewController {

func updateCells() {
sections = []
currentUserMetadata = accountManager.currentUserMetadata()

versionCell.detailTextLabel?.text = DependencyManagerImpl.shared.deviceManager().appVersionString()
let aboutCells = [settingsCell, versionCell, bsgTwitterCell]
let aboutCells = [settingsCell, versionCell, veritasCell]
let aboutSection = GroupedTableViewSection(headerTitle: "about".local(), cells: aboutCells)
sections.append(aboutSection)

Expand Down Expand Up @@ -234,7 +234,7 @@ class MoreMenuViewController: BaseTableViewController {

rewardCell.detailTextLabel?.text = String(nextAvailableReward.points)

let statsCells = [userCountCell, budScoreCell, leaderboardCell, rewardCell, watchAdCell, daysSinceWipeCell]
let statsCells = [userCountCell, budScoreCell, leaderboardCell, rewardCell, watchAdCell, daysSinceWipeCell, bsgTwitterCell]
let globalStatsSection = GroupedTableViewSection(headerTitle: "global_stats".local(), cells: statsCells)
sections.append(globalStatsSection)
}
Expand All @@ -245,7 +245,7 @@ class MoreMenuViewController: BaseTableViewController {

watchAdCell.videoAdState = adManager.currentVideoAdState

let supportCells = feedbackManager.canAskForReview() ? [veritasCell, rateCell, feedbackCell, githubCell, theTeamCell, attributionsCell] : [veritasCell, feedbackCell, githubCell, theTeamCell, attributionsCell]
let supportCells = feedbackManager.canAskForReview() ? [rateCell, feedbackCell, githubCell, theTeamCell, attributionsCell] : [feedbackCell, githubCell, theTeamCell, attributionsCell]
let supportSection = GroupedTableViewSection(headerTitle: "dev_support".local(), cells: supportCells)
sections.append(supportSection)
tableView.reloadData()
Expand All @@ -256,8 +256,8 @@ class MoreMenuViewController: BaseTableViewController {

accountManager.redeemBudPoints {
self.hideLoading()
self.showAlert(title: "bud_reward_title".local(), message: "bud_reward_message".local())
self.updateCells()
self.showAlert(title: "bud_reward_title".local(), message: "bud_reward_message".local())
}
}
}
Expand Down
Loading

0 comments on commit 7b0be24

Please sign in to comment.