Show title instead of "x" for clear-all-button (IOS-141)

Also: Move stuff around. It doesn't make sense for search-diffable-stuff to live in an enitrely different folder than the rest.
This commit is contained in:
Nathan Mattes 2023-09-15 11:37:33 +02:00
parent c892034093
commit e8509a063d
15 changed files with 18 additions and 128 deletions

View File

@ -661,6 +661,7 @@
"no_results": "No results"
},
"recent_search": "Recent searches",
"clear_all": "Clear all",
"clear": "Clear"
}
},

View File

@ -252,7 +252,6 @@
DB4AA6B327BA34B6009EC082 /* CellFrameCacheContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4AA6B227BA34B6009EC082 /* CellFrameCacheContainer.swift */; };
DB4F0963269ED06300D62E92 /* SearchResultViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4F0962269ED06300D62E92 /* SearchResultViewController.swift */; };
DB4F0966269ED52200D62E92 /* SearchResultViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4F0965269ED52200D62E92 /* SearchResultViewModel.swift */; };
DB4F0968269ED8AD00D62E92 /* SearchHistoryTableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4F0967269ED8AD00D62E92 /* SearchHistoryTableHeaderView.swift */; };
DB4F096A269EDAD200D62E92 /* SearchResultViewModel+State.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4F0969269EDAD200D62E92 /* SearchResultViewModel+State.swift */; };
DB4F097526A037F500D62E92 /* SearchHistoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4F097426A037F500D62E92 /* SearchHistoryViewModel.swift */; };
DB4F097B26A039FF00D62E92 /* SearchHistorySection.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4F097A26A039FF00D62E92 /* SearchHistorySection.swift */; };
@ -927,7 +926,6 @@
DB4B779626CA50BA00B087B3 /* th */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = th; path = th.lproj/Intents.stringsdict; sourceTree = "<group>"; };
DB4F0962269ED06300D62E92 /* SearchResultViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultViewController.swift; sourceTree = "<group>"; };
DB4F0965269ED52200D62E92 /* SearchResultViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultViewModel.swift; sourceTree = "<group>"; };
DB4F0967269ED8AD00D62E92 /* SearchHistoryTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHistoryTableHeaderView.swift; sourceTree = "<group>"; };
DB4F0969269EDAD200D62E92 /* SearchResultViewModel+State.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchResultViewModel+State.swift"; sourceTree = "<group>"; };
DB4F097426A037F500D62E92 /* SearchHistoryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHistoryViewModel.swift; sourceTree = "<group>"; };
DB4F097A26A039FF00D62E92 /* SearchHistorySection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHistorySection.swift; sourceTree = "<group>"; };
@ -2099,6 +2097,8 @@
DB4F0965269ED52200D62E92 /* SearchResultViewModel.swift */,
DB0FCB932797E2B0006C02E2 /* SearchResultViewModel+Diffable.swift */,
DB4F0969269EDAD200D62E92 /* SearchResultViewModel+State.swift */,
2D198648261C0B8500F0B013 /* SearchResultSection.swift */,
2D198642261BF09500F0B013 /* SearchResultItem.swift */,
);
path = SearchResult;
sourceTree = "<group>";
@ -2108,10 +2108,6 @@
children = (
DB0FCB852796BDA1006C02E2 /* SearchSection.swift */,
DB0FCB872796BDA9006C02E2 /* SearchItem.swift */,
2D198648261C0B8500F0B013 /* SearchResultSection.swift */,
2D198642261BF09500F0B013 /* SearchResultItem.swift */,
DB4F097A26A039FF00D62E92 /* SearchHistorySection.swift */,
DB4F097C26A03A5B00D62E92 /* SearchHistoryItem.swift */,
);
path = Search;
sourceTree = "<group>";
@ -2137,7 +2133,6 @@
DB4F098026A0475500D62E92 /* View */ = {
isa = PBXGroup;
children = (
DB4F0967269ED8AD00D62E92 /* SearchHistoryTableHeaderView.swift */,
);
path = View;
sourceTree = "<group>";
@ -2920,6 +2915,8 @@
DB63F76127996B6600455B82 /* SearchHistoryViewController+DataSourceProvider.swift */,
DB4F097426A037F500D62E92 /* SearchHistoryViewModel.swift */,
DB63F74E2799405600455B82 /* SearchHistoryViewModel+Diffable.swift */,
DB4F097A26A039FF00D62E92 /* SearchHistorySection.swift */,
DB4F097C26A03A5B00D62E92 /* SearchHistoryItem.swift */,
);
path = SearchHistory;
sourceTree = "<group>";
@ -3694,7 +3691,6 @@
2D84350525FF858100EECE90 /* UIScrollView.swift in Sources */,
6213AF5A28939C8400BCADB6 /* BookmarkViewModel.swift in Sources */,
5B24BBDB262DB14800A9381B /* ReportStatusViewModel+Diffable.swift in Sources */,
DB4F0968269ED8AD00D62E92 /* SearchHistoryTableHeaderView.swift in Sources */,
5DA732CC2629CEF500A92342 /* UIView+Remove.swift in Sources */,
2A506CF4292CD85800059C37 /* FollowedTagsViewController.swift in Sources */,
DB1D843026566512000346B3 /* KeyboardPreference.swift in Sources */,

View File

@ -171,7 +171,6 @@ extension SearchViewController {
// MARK: - UISearchBarDelegate
extension SearchViewController: UISearchBarDelegate {
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
os_log("%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
searchBarTapPublisher.send("")
return false
}

View File

@ -315,8 +315,6 @@ extension SearchDetailViewController: UISearchBarDelegate {
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
logger.debug("\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
// dismiss or pop
if isModal {
dismiss(animated: true, completion: nil)

View File

@ -30,8 +30,9 @@ final class SearchHistorySectionHeaderCollectionReusableView: UICollectionReusab
let clearButton: UIButton = {
let button = UIButton(type: .system)
button.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal)
button.tintColor = Asset.Colors.Label.secondary.color
button.setTitle(L10n.Scene.Search.Searching.clearAll, for: .normal)
button.tintColor = Asset.Colors.Brand.blurple.color
button.accessibilityLabel = L10n.Scene.Search.Searching.clear
return button
@ -47,9 +48,6 @@ final class SearchHistorySectionHeaderCollectionReusableView: UICollectionReusab
_init()
}
}
extension SearchHistorySectionHeaderCollectionReusableView {
private func _init() {
primaryLabel.translatesAutoresizingMaskIntoConstraints = false
addSubview(primaryLabel)
@ -72,9 +70,7 @@ extension SearchHistorySectionHeaderCollectionReusableView {
clearButton.addTarget(self, action: #selector(SearchHistorySectionHeaderCollectionReusableView.clearButtonDidPressed(_:)), for: .touchUpInside)
}
}
extension SearchHistorySectionHeaderCollectionReusableView {
@objc private func clearButtonDidPressed(_ sender: UIButton) {
delegate?.searchHistorySectionHeaderCollectionReusableView(self, clearButtonDidPressed: sender)
}

View File

@ -31,7 +31,7 @@ extension SearchHistoryUserCollectionViewCell {
func configure(
me: MastodonUser?,
viewModel: ViewModel,
delegate: UserViewDelegate?
delegate: SearchHistorySectionHeaderCollectionReusableViewDelegate?
) {
let user = viewModel.value

View File

@ -78,13 +78,8 @@ extension SearchHistorySection {
}
}
let trendHeaderRegister = UICollectionView.SupplementaryRegistration<SearchHistorySectionHeaderCollectionReusableView>(elementKind: UICollectionView.elementKindSectionHeader) { [weak dataSource] supplementaryView, elementKind, indexPath in
let trendHeaderRegister = UICollectionView.SupplementaryRegistration<SearchHistorySectionHeaderCollectionReusableView>(elementKind: UICollectionView.elementKindSectionHeader) { supplementaryView, elementKind, indexPath in
supplementaryView.delegate = configuration.searchHistorySectionHeaderCollectionReusableViewDelegate
guard let _ = dataSource else { return }
// let sections = dataSource.snapshot().sectionIdentifiers
// guard indexPath.section < sections.count else { return }
// let section = sections[indexPath.section]
}
dataSource.supplementaryViewProvider = { (collectionView: UICollectionView, elementKind: String, indexPath: IndexPath) in

View File

@ -118,6 +118,10 @@ extension SearchHistoryViewController: SearchHistorySectionHeaderCollectionReusa
try await DataSourceFacade.responseToDeleteSearchHistory(
provider: self
)
await MainActor.run {
button.isEnabled = false
}
}
}
}

View File

@ -1,100 +0,0 @@
//
// SearchHistoryTableHeaderView.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-7-14.
//
import os.log
import UIKit
import Combine
import MastodonAsset
import MastodonCore
import MastodonLocalization
import MastodonUI
protocol SearchHistoryTableHeaderViewDelegate: AnyObject {
func searchHistoryTableHeaderView(_ searchHistoryTableHeaderView: SearchHistoryTableHeaderView, clearSearchHistoryButtonDidPressed button: UIButton)
}
final class SearchHistoryTableHeaderView: UIView {
let logger = Logger(subsystem: "SearchHistory", category: "UI")
weak var delegate: SearchHistoryTableHeaderViewDelegate?
var disposeBag = Set<AnyCancellable>()
let recentSearchesLabel: UILabel = {
let label = UILabel()
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 20, weight: .semibold))
label.textColor = Asset.Colors.Label.primary.color
label.text = L10n.Scene.Search.Searching.recentSearch
return label
}()
let clearSearchHistoryButton: HighlightDimmableButton = {
let button = HighlightDimmableButton(type: .custom)
button.expandEdgeInsets = UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10)
button.setTitleColor(Asset.Colors.Brand.blurple.color, for: .normal)
button.setTitle(L10n.Scene.Search.Searching.clear, for: .normal)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
_init()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
_init()
}
}
extension SearchHistoryTableHeaderView {
private func _init() {
preservesSuperviewLayoutMargins = true
recentSearchesLabel.translatesAutoresizingMaskIntoConstraints = false
addSubview(recentSearchesLabel)
NSLayoutConstraint.activate([
recentSearchesLabel.topAnchor.constraint(equalTo: topAnchor, constant: 16),
recentSearchesLabel.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
bottomAnchor.constraint(equalTo: recentSearchesLabel.bottomAnchor, constant: 16),
])
clearSearchHistoryButton.translatesAutoresizingMaskIntoConstraints = false
addSubview(clearSearchHistoryButton)
NSLayoutConstraint.activate([
clearSearchHistoryButton.centerYAnchor.constraint(equalTo: recentSearchesLabel.centerYAnchor),
clearSearchHistoryButton.leadingAnchor.constraint(equalTo: recentSearchesLabel.trailingAnchor),
clearSearchHistoryButton.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
])
clearSearchHistoryButton.setContentHuggingPriority(.defaultHigh + 10, for: .horizontal)
clearSearchHistoryButton.addTarget(self, action: #selector(SearchHistoryTableHeaderView.clearSearchHistoryButtonDidPressed(_:)), for: .touchUpInside)
setupBackgroundColor(theme: ThemeService.shared.currentTheme.value)
ThemeService.shared.currentTheme
.receive(on: RunLoop.main)
.sink { [weak self] theme in
guard let self = self else { return }
self.setupBackgroundColor(theme: theme)
}
.store(in: &disposeBag)
}
}
extension SearchHistoryTableHeaderView {
@objc private func clearSearchHistoryButtonDidPressed(_ sender: UIButton) {
logger.debug("\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
delegate?.searchHistoryTableHeaderView(self, clearSearchHistoryButtonDidPressed: sender)
}
}
extension SearchHistoryTableHeaderView {
private func setupBackgroundColor(theme: Theme) {
backgroundColor = theme.systemGroupedBackgroundColor
}
}

View File

@ -90,8 +90,6 @@ extension StatusFetchedResultsController {
// MARK: - NSFetchedResultsControllerDelegate
extension StatusFetchedResultsController: NSFetchedResultsControllerDelegate {
public func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference) {
os_log("%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
let indexes = statusIDs
let objects = fetchedResultsController.fetchedObjects ?? []

View File

@ -1277,6 +1277,8 @@ public enum L10n {
public enum Searching {
/// Clear
public static let clear = L10n.tr("Localizable", "Scene.Search.Searching.Clear", fallback: "Clear")
/// Clear all
public static let clearAll = L10n.tr("Localizable", "Scene.Search.Searching.ClearAll", fallback: "Clear all")
/// Recent searches
public static let recentSearch = L10n.tr("Localizable", "Scene.Search.Searching.RecentSearch", fallback: "Recent searches")
public enum EmptyState {

View File

@ -440,6 +440,7 @@ uploaded to Mastodon.";
"Scene.Search.SearchBar.Cancel" = "Cancel";
"Scene.Search.SearchBar.Placeholder" = "Search hashtags and users";
"Scene.Search.Searching.Clear" = "Clear";
"Scene.Search.Searching.ClearAll" = "Clear all";
"Scene.Search.Searching.EmptyState.NoResults" = "No results";
"Scene.Search.Searching.RecentSearch" = "Recent searches";
"Scene.Search.Searching.Segment.All" = "All";
@ -554,4 +555,4 @@ uploaded to Mastodon.";
"Widget.MultipleFollowers.ConfigurationDescription" = "Show number of followers for multiple accounts.";
"Widget.MultipleFollowers.ConfigurationDisplayName" = "Multiple followers";
"Widget.MultipleFollowers.MockUser.AccountName" = "another@follower.social";
"Widget.MultipleFollowers.MockUser.DisplayName" = "Another follower";
"Widget.MultipleFollowers.MockUser.DisplayName" = "Another follower";