mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
iOS: use actual data for checkmarks on main screen
This commit is contained in:
@@ -61,8 +61,13 @@ class MainScreenCell : UITableViewCell {
|
|||||||
fatalError()
|
fatalError()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setColor(_ color: Color) {
|
func update(name: String,
|
||||||
|
color: Color,
|
||||||
|
values: [KotlinInt]) {
|
||||||
|
|
||||||
|
label.text = name
|
||||||
label.textColor = color.uicolor
|
label.textColor = color.uicolor
|
||||||
|
|
||||||
ring.component = Ring(color: color,
|
ring.component = Ring(color: color,
|
||||||
percentage: Double.random(in: 0...1),
|
percentage: Double.random(in: 0...1),
|
||||||
thickness: 2.5,
|
thickness: 2.5,
|
||||||
@@ -70,20 +75,12 @@ class MainScreenCell : UITableViewCell {
|
|||||||
theme: theme,
|
theme: theme,
|
||||||
label: false)
|
label: false)
|
||||||
ring.setNeedsDisplay()
|
ring.setNeedsDisplay()
|
||||||
let isNumerical = Int.random(in: 1...4) == 1
|
|
||||||
for btn in buttons {
|
for i in 0..<buttons.count {
|
||||||
if isNumerical {
|
buttons[i].component = CheckmarkButton(value: Int32(truncating: values[i]),
|
||||||
btn.component = NumberButton(color: color,
|
color: color,
|
||||||
value: Double.random(in: 0...5000),
|
theme: theme)
|
||||||
threshold: 2000,
|
buttons[i].setNeedsDisplay()
|
||||||
units: "steps",
|
|
||||||
theme: theme)
|
|
||||||
} else {
|
|
||||||
btn.component = CheckmarkButton(value: Int32.random(in: 0...2),
|
|
||||||
color: color,
|
|
||||||
theme: theme)
|
|
||||||
}
|
|
||||||
btn.setNeedsDisplay()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,6 +90,7 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
|
|||||||
var dataSource: MainScreenDataSource
|
var dataSource: MainScreenDataSource
|
||||||
var data: MainScreenDataSource.Data?
|
var data: MainScreenDataSource.Data?
|
||||||
var theme: Theme
|
var theme: Theme
|
||||||
|
var nButtons = 3
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
fatalError()
|
fatalError()
|
||||||
@@ -142,14 +140,15 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
|
|||||||
let row = indexPath.row
|
let row = indexPath.row
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MainScreenCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MainScreenCell
|
||||||
let color = theme.color(paletteIndex: data!.colors[row].index)
|
let color = theme.color(paletteIndex: data!.colors[row].index)
|
||||||
cell.label.text = data!.names[row]
|
cell.update(name: data!.names[row],
|
||||||
cell.setColor(color)
|
color: color,
|
||||||
|
values: data!.checkmarks[row])
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
||||||
let component = HabitListHeader(today: LocalDate(year: 2019, month: 3, day: 24),
|
let component = HabitListHeader(today: LocalDate(year: 2019, month: 3, day: 24),
|
||||||
nButtons: 3,
|
nButtons: Int32(nButtons),
|
||||||
theme: theme,
|
theme: theme,
|
||||||
fmt: IosLocalDateFormatter())
|
fmt: IosLocalDateFormatter())
|
||||||
return ComponentView(frame: CGRect(x: 0, y: 0, width: 100, height: CGFloat(theme.checkmarkButtonSize)),
|
return ComponentView(frame: CGRect(x: 0, y: 0, width: 100, height: CGFloat(theme.checkmarkButtonSize)),
|
||||||
|
|||||||
Reference in New Issue
Block a user