Skip to content

Commit

Permalink
fixed a preview bug (which is not exactly a bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu Youyou committed Dec 30, 2020
1 parent ca2e77b commit be1f6b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ class BudgetViewController: UIViewController, UITextFieldDelegate {
for i in (self.budgetItemsDict[category]!){
tSpending += Double(i.cost)
}
let randomChoice = self.budgetItemsDict[category]?.randomElement()

let foodAttributedTitle = NSAttributedString(string: "\(category): $\(tSpending)", attributes: [NSAttributedString.Key.foregroundColor : UIColor.white, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 25, weight: UIFont.Weight(0.5))])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ protocol BudgetDataDelegate {
class TripOverviewViewController: UIViewController, ItinDataDelegate, PackingListDataDelegate, BudgetDataDelegate{

func calculateBudget(string1: String, string2: String) {
budgetOverviewLabel.text = "\(string1)\n\(string2)"
print("delegate working")
// budgetOverviewLabel.text = "\(string1)\n\(string2)"
}


Expand Down Expand Up @@ -115,19 +114,19 @@ class TripOverviewViewController: UIViewController, ItinDataDelegate, PackingLis


func printItinEvent(titleDict: Dictionary<Int, Any>) {
print("delegate titleDict:", titleDict)
for (_, value) in titleDict{
print("value", value)
if (value as! Array<DayEvent>).isEmpty == false{
switch (value as! Array<DayEvent>)[0] {
case nil:
itinOverviewLabel.text = "You have no trip at the moment! Create some"
itinOverviewLabel2.text = ""
default:
itinOverviewLabel.text = (value as!Array<DayEvent>)[0].destination
}
}
}
// print("delegate titleDict:", titleDict)
// for (_, value) in titleDict{
// print("value", value)
// if (value as! Array<DayEvent>).isEmpty == false{
// switch (value as! Array<DayEvent>)[0] {
// case nil:
// itinOverviewLabel.text = "You have no trip at the moment! Create some"
// itinOverviewLabel2.text = ""
// default:
// itinOverviewLabel.text = (value as!Array<DayEvent>)[0].destination
// }
// }
// }
}

//MARK: general overview variables
Expand Down Expand Up @@ -202,7 +201,7 @@ class TripOverviewViewController: UIViewController, ItinDataDelegate, PackingLis
trips[tripNo] = trip
Trip.saveToFile(trips: trips)

//MARK: ***************************
//MARK: *********************************************************************
var tempArray: Array<PackingItem> = []
let titleArray = PackingItem.loadFromFile()
packingItemsStorateList = titleArray ?? []
Expand Down Expand Up @@ -232,7 +231,34 @@ class TripOverviewViewController: UIViewController, ItinDataDelegate, PackingLis
}
packingItemsStorateList = titleArray ?? []
PackingItem.saveToFile(packingItems: titleArray ?? [])
//MARK: *********************
//MARK: **********************************************************************

if let tempText = itinEventsDict.values.randomElement()?.randomElement()?.destination{
itinOverviewLabel.text = tempText
}
else{itinOverviewLabel.text = "You have no trips, create some!"
}

//MARK: **********************************************************************

var spendingAddedUp: Double = 0.0
for i in self.budgetItemsStorageDict.values{
spendingAddedUp += Double(i.reduce(0,{x,y in x + y.cost}))
}
let string1 = "spent $\(spendingAddedUp) of $\(self.budgetTotal), $\((self.budgetTotal) - (spendingAddedUp)) left"
print("this is string1:", string1)

var string2 = ""
for (key,value) in self.budgetItemsStorageDict{
let tempCategorizedSpending = Double(value.reduce(0, {x,y in x + y.cost}))
let percentage = ((tempCategorizedSpending/spendingAddedUp) * 100)
let rounded = round(percentage)
let tempString = "\(rounded)% of spendings (\(key))\n"
string2.append(tempString)
print("this is string2:", string2)
}
self.budgetOverviewLabel.text = "\(string1)\n\(string2)"



}
Expand Down

0 comments on commit be1f6b3

Please sign in to comment.