forked from Dimillian/ACHNBrowserUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Dimillian#171 show entered turnips price values instead of min …
…max and average (Dimillian#175) * feat(Turnips): use entered prices instead of min-max or average ones * Fix Dimillian#171 * fix(Turnips): select another tab change the values between average and min max * fix(Turnips): remove the visual glitch while switching from tab to tab * feat(Turnips): use acText color for entered price values
- Loading branch information
1 parent
ceba2fd
commit 4af12fb
Showing
9 changed files
with
245 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
ACHNBrowserUI/ACHNBrowserUI/views/turnips/rows/TurnipsMinMaxPriceRow.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// TurnipsMinMaxPriceRow.swift | ||
// ACHNBrowserUI | ||
// | ||
// Created by Renaud JENNY on 22/05/2020. | ||
// Copyright © 2020 Thomas Ricouard. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct TurnipsMinMaxPriceRow: View { | ||
let label: String | ||
let prices: [[Int]] | ||
let averagePrices: [Int] | ||
|
||
typealias Meridian = TurnipsAveragePriceRow.Meridian | ||
|
||
var body: some View { | ||
HStack { | ||
Text(LocalizedStringKey(label)) | ||
.font(.body) | ||
.foregroundColor(.acText) | ||
Spacer() | ||
Text(amMinMaxPrices) | ||
.font(.headline) | ||
.fontWeight(.bold) | ||
.foregroundColor(color(meridian: .am)) | ||
Spacer() | ||
Text(pmMinMaxPrices) | ||
.font(.headline) | ||
.fontWeight(.bold) | ||
.foregroundColor(color(meridian: .pm)) | ||
} | ||
} | ||
} | ||
|
||
extension TurnipsMinMaxPriceRow: TurnipsPriceRow { | ||
var minMaxPrices: [[Int]] { prices } | ||
|
||
private func color(meridian: Meridian) -> Color { | ||
let amAveragedPrices = prices.first?.average | ||
let pmAveragedPrices = prices.last?.average | ||
guard let averagedPrice = meridian == .am ? amAveragedPrices : pmAveragedPrices else { | ||
return .clear | ||
} | ||
return isEntered(meridian: meridian) ? .acText : color(price: Int(averagedPrice)) | ||
} | ||
|
||
private var amMinMaxPrices: String { | ||
guard let min = prices.first?.first, | ||
let max = prices.first?.last else { | ||
return "" | ||
} | ||
if isEntered(meridian: .am) { | ||
return "\(min)" | ||
} else { | ||
return "\(min) - \(max)" | ||
} | ||
} | ||
|
||
private var pmMinMaxPrices: String { | ||
guard let min = prices.last?.first, | ||
let max = prices.last?.last else { | ||
return "" | ||
} | ||
if isEntered(meridian: .pm) { | ||
return "\(min)" | ||
} else { | ||
return "\(min) - \(max)" | ||
} | ||
} | ||
} | ||
|
||
struct TurnipsMinMaxPriceRow_Previews: PreviewProvider { | ||
static var previews: some View { | ||
NavigationView { | ||
List { | ||
TurnipsMinMaxPriceRow(label: "Mon", prices: [[90, 90], [81, 141]], averagePrices: [90, 95]) | ||
TurnipsMinMaxPriceRow(label: "Mon", prices: [[60, 90], [81, 81]], averagePrices: [70, 81]) | ||
TurnipsMinMaxPriceRow(label: "Mon", prices: [[40, 81], [250, 600]], averagePrices: [40, 600]) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.