Skip to content

Commit

Permalink
hint for no goal when filtering and ptr on empty list
Browse files Browse the repository at this point in the history
uses the common technique of setting the backgroundView of the CollectionView
when no items would be displayed

fixes #226
  • Loading branch information
krugerk committed Oct 28, 2024
1 parent 5be8685 commit 3da3a0d
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions BeeSwift/Gallery/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,29 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
let cellReuseIdentifier = "Cell"
var deadbeatView = UIView()
var outofdateView = UIView()
let noGoalsLabel = BSLabel()
var noGoalsLabel: BSLabel {
let label = BSLabel()
label.text = """
You have no Beeminder goals!
You'll need to create one before this app will be any use.
"""
label.textAlignment = .center
label.numberOfLines = 0

return label
}
var noGoalsMatchingFilterLabel: BSLabel {
let label = BSLabel()
label.text = """
You have Beeminder goals!
None match the current filter.
"""
label.textAlignment = .center
label.numberOfLines = 0

return label
}
let outofdateLabel = BSLabel()
let searchBar = UISearchBar()
var lastUpdated: Date?
Expand Down Expand Up @@ -150,16 +172,7 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
make.right.equalTo(self.view.safeAreaLayoutGuide.snp.rightMargin)
make.bottom.equalTo(0)
}

self.view.addSubview(self.noGoalsLabel)
self.noGoalsLabel.snp.makeConstraints { (make) in
make.top.left.right.equalTo(self.collectionView!)
}
self.noGoalsLabel.text = "You have no Beeminder goals!\n\nYou'll need to create one before this app will be any use."
self.noGoalsLabel.textAlignment = .center
self.noGoalsLabel.numberOfLines = 0
self.noGoalsLabel.isHidden = true


self.updateGoals()
self.fetchGoals()

Expand Down Expand Up @@ -431,9 +444,19 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
}

func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
switch (filteredGoals.isEmpty, goals.isEmpty) {
case (true, false):
collectionView.backgroundView = self.noGoalsMatchingFilterLabel
return 0
case (true, true):
collectionView.backgroundView = self.noGoalsLabel
return 0
default:
collectionView.backgroundView = nil
return 1
}
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let minimumWidth: CGFloat = 320

Expand Down

0 comments on commit 3da3a0d

Please sign in to comment.