Simplify data trasfer in MainScreenDataSource

This commit is contained in:
2019-03-31 17:31:40 -05:00
parent 6ac7ef7807
commit f491acdda9
2 changed files with 21 additions and 25 deletions

View File

@@ -101,7 +101,7 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
self.dataSource = backend.mainScreenDataSource
self.theme = backend.theme
super.init(nibName: nil, bundle: nil)
self.dataSource.addListener(listener: self)
self.dataSource.observable.addListener(listener: self)
self.dataSource.requestData()
}
@@ -133,16 +133,16 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data?.names.count ?? 0
return data?.habits.count ?? 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = indexPath.row
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MainScreenCell
let color = theme.color(paletteIndex: data!.colors[row].index)
cell.update(name: data!.names[row],
color: color,
values: data!.checkmarks[row])
let habit = data!.habits[row]
cell.update(name: habit.name,
color: theme.color(paletteIndex: habit.color.index),
values: data!.checkmarkValues[habit]!)
return cell
}
@@ -164,7 +164,9 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let color = theme.color(paletteIndex: data!.colors[indexPath.row].index)
self.navigationController?.pushViewController(ShowHabitController(theme: theme, color: color), animated: true)
let color = theme.color(paletteIndex: data!.habits[indexPath.row].color.index)
self.navigationController?.pushViewController(ShowHabitController(theme: theme,
color: color),
animated: true)
}
}