Display informational footer on empty favorites

This commit is contained in:
Davide De Rosa 2019-11-21 15:41:27 +01:00
parent 7865f6a697
commit d43acb8593
3 changed files with 27 additions and 0 deletions

View File

@ -76,6 +76,12 @@ internal enum L10n {
/// Unfavorite /// Unfavorite
internal static let unfavorite = L10n.tr("App", "provider.pool.actions.unfavorite") internal static let unfavorite = L10n.tr("App", "provider.pool.actions.unfavorite")
} }
internal enum Sections {
internal enum EmptyFavorites {
/// Swipe left on a location to add or remove it from Favorites.
internal static let footer = L10n.tr("App", "provider.pool.sections.empty_favorites.footer")
}
}
} }
internal enum Preset { internal enum Preset {
internal enum Cells { internal enum Cells {

View File

@ -50,6 +50,7 @@
"provider.pool.actions.favorite" = "Favorite"; "provider.pool.actions.favorite" = "Favorite";
"provider.pool.actions.unfavorite" = "Unfavorite"; "provider.pool.actions.unfavorite" = "Unfavorite";
"provider.pool.sections.empty_favorites.footer" = "Swipe left on a location to add or remove it from Favorites.";
"provider.preset.cells.tech_details.caption" = "Technical details"; "provider.preset.cells.tech_details.caption" = "Technical details";

View File

@ -153,10 +153,16 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
} }
func numberOfSections(in tableView: UITableView) -> Int { func numberOfSections(in tableView: UITableView) -> Int {
if isShowingEmptyFavorites {
return 1
}
return categories.count return categories.count
} }
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if isShowingEmptyFavorites {
return nil
}
if categories.count == 1 && categories.first?.name == "" { if categories.count == 1 && categories.first?.name == "" {
return nil return nil
} }
@ -164,7 +170,17 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
return model.name return model.name
} }
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if isShowingEmptyFavorites {
return L10n.App.Provider.Pool.Sections.EmptyFavorites.footer
}
return nil
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if isShowingEmptyFavorites {
return 0
}
let model = categories[section] let model = categories[section]
return model.groups.count return model.groups.count
} }
@ -267,4 +283,8 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
private var categories: [PoolCategory] { private var categories: [PoolCategory] {
return isShowingFavorites ? favoriteCategories : allCategories return isShowingFavorites ? favoriteCategories : allCategories
} }
private var isShowingEmptyFavorites: Bool {
return isShowingFavorites && favoriteGroupIds.isEmpty
}
} }