forked from zelo72/mastodon-ios
chore: add backgroud.navigation.color. update colors in searching page
This commit is contained in:
parent
c7eea5d8e6
commit
27b698a97a
|
@ -42,6 +42,7 @@ internal enum Asset {
|
|||
internal static let dangerBorder = ColorAsset(name: "Colors/Background/danger.border")
|
||||
internal static let danger = ColorAsset(name: "Colors/Background/danger")
|
||||
internal static let mediaTypeIndicotor = ColorAsset(name: "Colors/Background/media.type.indicotor")
|
||||
internal static let navigationBar = ColorAsset(name: "Colors/Background/navigationBar")
|
||||
internal static let onboardingBackground = ColorAsset(name: "Colors/Background/onboarding.background")
|
||||
internal static let secondaryGroupedSystemBackground = ColorAsset(name: "Colors/Background/secondary.grouped.system.background")
|
||||
internal static let secondarySystemBackground = ColorAsset(name: "Colors/Background/secondary.system.background")
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "0.940",
|
||||
"blue" : "249",
|
||||
"green" : "249",
|
||||
"red" : "249"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "0.940",
|
||||
"blue" : "29",
|
||||
"green" : "29",
|
||||
"red" : "29"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ final class SearchViewController: UIViewController, NeedsDependency {
|
|||
searchBar.showsBookmarkButton = true
|
||||
searchBar.showsScopeBar = false
|
||||
searchBar.scopeButtonTitles = [L10n.Scene.Search.Searching.Segment.all, L10n.Scene.Search.Searching.Segment.people, L10n.Scene.Search.Searching.Segment.hashtags]
|
||||
searchBar.barTintColor = Asset.Colors.Background.navigationBar.color
|
||||
return searchBar
|
||||
}()
|
||||
|
||||
|
@ -76,9 +77,10 @@ final class SearchViewController: UIViewController, NeedsDependency {
|
|||
// searching
|
||||
let searchingTableView: UITableView = {
|
||||
let tableView = UITableView()
|
||||
tableView.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color
|
||||
tableView.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color
|
||||
tableView.rowHeight = UITableView.automaticDimension
|
||||
tableView.separatorStyle = .singleLine
|
||||
tableView.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
|
||||
return tableView
|
||||
}()
|
||||
|
||||
|
@ -99,7 +101,7 @@ final class SearchViewController: UIViewController, NeedsDependency {
|
|||
|
||||
let clearSearchHistoryButton: UIButton = {
|
||||
let button = UIButton(type: .custom)
|
||||
button.setTitleColor(Asset.Colors.buttonDefault.color, for: .normal)
|
||||
button.setTitleColor(Asset.Colors.brandBlue.color, for: .normal)
|
||||
button.setTitle(L10n.Scene.Search.Searching.clear, for: .normal)
|
||||
return button
|
||||
}()
|
||||
|
@ -109,6 +111,12 @@ extension SearchViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color
|
||||
let barAppearance = UINavigationBarAppearance()
|
||||
barAppearance.configureWithTransparentBackground()
|
||||
barAppearance.backgroundColor = Asset.Colors.Background.navigationBar.color
|
||||
navigationItem.standardAppearance = barAppearance
|
||||
navigationItem.compactAppearance = barAppearance
|
||||
navigationItem.scrollEdgeAppearance = barAppearance
|
||||
searchBar.delegate = self
|
||||
navigationItem.titleView = searchBar
|
||||
navigationItem.hidesBackButton = true
|
||||
|
@ -183,11 +191,11 @@ extension SearchViewController: UISearchBarDelegate {
|
|||
func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
|
||||
switch selectedScope {
|
||||
case 0:
|
||||
viewModel.searchScope.value = ""
|
||||
viewModel.searchScope.value = Mastodon.API.Search.SearchType.default
|
||||
case 1:
|
||||
viewModel.searchScope.value = Mastodon.API.Search.Scope.accounts.rawValue
|
||||
viewModel.searchScope.value = Mastodon.API.Search.SearchType.accounts
|
||||
case 2:
|
||||
viewModel.searchScope.value = Mastodon.API.Search.Scope.hashtags.rawValue
|
||||
viewModel.searchScope.value = Mastodon.API.Search.SearchType.hashtags
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
|
@ -53,23 +53,24 @@ extension SearchViewModel.LoadOldestState {
|
|||
}
|
||||
var offset = 0
|
||||
switch viewModel.searchScope.value {
|
||||
case Mastodon.API.Search.Scope.accounts.rawValue:
|
||||
case Mastodon.API.Search.SearchType.accounts:
|
||||
offset = oldSearchResult.accounts.count
|
||||
case Mastodon.API.Search.Scope.hashtags.rawValue:
|
||||
case Mastodon.API.Search.SearchType.hashtags:
|
||||
offset = oldSearchResult.hashtags.count
|
||||
default:
|
||||
return
|
||||
}
|
||||
let query = Mastodon.API.Search.Query(accountID: nil,
|
||||
let query = Mastodon.API.Search.Query(q: viewModel.searchText.value,
|
||||
type: viewModel.searchScope.value,
|
||||
accountID: nil,
|
||||
maxID: nil,
|
||||
minID: nil,
|
||||
type: viewModel.searchScope.value,
|
||||
excludeUnreviewed: nil,
|
||||
q: viewModel.searchText.value,
|
||||
resolve: nil,
|
||||
limit: nil,
|
||||
offset: offset,
|
||||
following: nil)
|
||||
|
||||
viewModel.context.apiService.search(domain: activeMastodonAuthenticationBox.domain, query: query, mastodonAuthenticationBox: activeMastodonAuthenticationBox)
|
||||
.sink { completion in
|
||||
switch completion {
|
||||
|
@ -81,7 +82,7 @@ extension SearchViewModel.LoadOldestState {
|
|||
}
|
||||
} receiveValue: { result in
|
||||
switch viewModel.searchScope.value {
|
||||
case Mastodon.API.Search.Scope.accounts.rawValue:
|
||||
case Mastodon.API.Search.SearchType.accounts:
|
||||
if result.value.accounts.isEmpty {
|
||||
stateMachine.enter(NoMore.self)
|
||||
} else {
|
||||
|
@ -91,7 +92,7 @@ extension SearchViewModel.LoadOldestState {
|
|||
viewModel.searchResult.value = Mastodon.Entity.SearchResult(accounts: newAccounts.removeDuplicate(), statuses: oldSearchResult.statuses, hashtags: oldSearchResult.hashtags)
|
||||
stateMachine.enter(Idle.self)
|
||||
}
|
||||
case Mastodon.API.Search.Scope.hashtags.rawValue:
|
||||
case Mastodon.API.Search.SearchType.hashtags:
|
||||
if result.value.hashtags.isEmpty {
|
||||
stateMachine.enter(NoMore.self)
|
||||
} else {
|
||||
|
|
|
@ -22,7 +22,7 @@ final class SearchViewModel: NSObject {
|
|||
|
||||
// output
|
||||
let searchText = CurrentValueSubject<String, Never>("")
|
||||
let searchScope = CurrentValueSubject<String, Never>("")
|
||||
let searchScope = CurrentValueSubject<Mastodon.API.Search.SearchType, Never>(Mastodon.API.Search.SearchType.default)
|
||||
|
||||
let isSearching = CurrentValueSubject<Bool, Never>(false)
|
||||
|
||||
|
@ -68,12 +68,12 @@ final class SearchViewModel: NSObject {
|
|||
}
|
||||
.flatMap { (text, scope) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.SearchResult>, Error> in
|
||||
|
||||
let query = Mastodon.API.Search.Query(accountID: nil,
|
||||
let query = Mastodon.API.Search.Query(q: text,
|
||||
type: scope,
|
||||
accountID: nil,
|
||||
maxID: nil,
|
||||
minID: nil,
|
||||
type: scope,
|
||||
excludeUnreviewed: nil,
|
||||
q: text,
|
||||
resolve: nil,
|
||||
limit: nil,
|
||||
offset: nil,
|
||||
|
@ -101,25 +101,27 @@ final class SearchViewModel: NSObject {
|
|||
searchScope
|
||||
)
|
||||
.filter { isSearching, text, _ in
|
||||
isSearching && text.isEmpty
|
||||
isSearching
|
||||
}
|
||||
.sink { [weak self] _, _, scope in
|
||||
.sink { [weak self] _, text, scope in
|
||||
guard let self = self else { return }
|
||||
guard let searchHistories = self.fetchSearchHistory() else { return }
|
||||
guard let dataSource = self.searchResultDiffableDataSource else { return }
|
||||
var snapshot = NSDiffableDataSourceSnapshot<SearchResultSection, SearchResultItem>()
|
||||
snapshot.appendSections([.mixed])
|
||||
|
||||
searchHistories.forEach { searchHistory in
|
||||
let containsAccount = scope == Mastodon.API.Search.Scope.accounts.rawValue || scope == ""
|
||||
let containsHashTag = scope == Mastodon.API.Search.Scope.hashtags.rawValue || scope == ""
|
||||
if let mastodonUser = searchHistory.account, containsAccount {
|
||||
let item = SearchResultItem.accountObjectID(accountObjectID: mastodonUser.objectID)
|
||||
snapshot.appendItems([item], toSection: .mixed)
|
||||
}
|
||||
if let tag = searchHistory.hashtag, containsHashTag {
|
||||
let item = SearchResultItem.hashtagObjectID(hashtagObjectID: tag.objectID)
|
||||
snapshot.appendItems([item], toSection: .mixed)
|
||||
if text.isEmpty {
|
||||
snapshot.appendSections([.mixed])
|
||||
|
||||
searchHistories.forEach { searchHistory in
|
||||
let containsAccount = scope == Mastodon.API.Search.SearchType.accounts || scope == Mastodon.API.Search.SearchType.default
|
||||
let containsHashTag = scope == Mastodon.API.Search.SearchType.hashtags || scope == Mastodon.API.Search.SearchType.default
|
||||
if let mastodonUser = searchHistory.account, containsAccount {
|
||||
let item = SearchResultItem.accountObjectID(accountObjectID: mastodonUser.objectID)
|
||||
snapshot.appendItems([item], toSection: .mixed)
|
||||
}
|
||||
if let tag = searchHistory.hashtag, containsHashTag {
|
||||
let item = SearchResultItem.hashtagObjectID(hashtagObjectID: tag.objectID)
|
||||
snapshot.appendItems([item], toSection: .mixed)
|
||||
}
|
||||
}
|
||||
}
|
||||
dataSource.apply(snapshot, animatingDifferences: false, completion: nil)
|
||||
|
@ -166,7 +168,7 @@ final class SearchViewModel: NSObject {
|
|||
snapshot.appendSections([.account])
|
||||
let items = accounts.compactMap { SearchResultItem.account(account: $0) }
|
||||
snapshot.appendItems(items, toSection: .account)
|
||||
if self.searchScope.value == Mastodon.API.Search.Scope.accounts.rawValue && !items.isEmpty {
|
||||
if self.searchScope.value == Mastodon.API.Search.SearchType.accounts && !items.isEmpty {
|
||||
snapshot.appendItems([.bottomLoader], toSection: .account)
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +176,7 @@ final class SearchViewModel: NSObject {
|
|||
snapshot.appendSections([.hashtag])
|
||||
let items = tags.compactMap { SearchResultItem.hashtag(tag: $0) }
|
||||
snapshot.appendItems(items, toSection: .hashtag)
|
||||
if self.searchScope.value == Mastodon.API.Search.Scope.hashtags.rawValue && !items.isEmpty {
|
||||
if self.searchScope.value == Mastodon.API.Search.SearchType.hashtags && !items.isEmpty {
|
||||
snapshot.appendItems([.bottomLoader], toSection: .hashtag)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ final class SearchBottomLoader: UITableViewCell {
|
|||
|
||||
func _init() {
|
||||
selectionStyle = .none
|
||||
backgroundColor = Asset.Colors.lightWhite.color
|
||||
backgroundColor = Asset.Colors.Background.systemGroupedBackground.color
|
||||
contentView.addSubview(activityIndicatorView)
|
||||
activityIndicatorView.constrainToCenter()
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ final class SearchingTableViewCell: UITableViewCell {
|
|||
|
||||
let _titleLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.textColor = Asset.Colors.buttonDefault.color
|
||||
label.textColor = Asset.Colors.brandBlue.color
|
||||
label.font = .systemFont(ofSize: 17, weight: .semibold)
|
||||
label.lineBreakMode = .byTruncatingTail
|
||||
return label
|
||||
|
|
|
@ -28,7 +28,7 @@ class SearchRecommendCollectionHeader: UIView {
|
|||
let seeAllButton: UIButton = {
|
||||
let button = UIButton(type: .custom)
|
||||
button.setTitleColor(Asset.Colors.brandBlue.color, for: .normal)
|
||||
button.setTitle(L10n.Scene.Search.Recommend.buttontext, for: .normal)
|
||||
button.setTitle(L10n.Scene.Search.Recommend.buttonText, for: .normal)
|
||||
return button
|
||||
}()
|
||||
|
||||
|
|
|
@ -50,9 +50,6 @@ extension Mastodon.API.Search {
|
|||
}
|
||||
|
||||
extension Mastodon.API.Search {
|
||||
public enum SearchType: String, Codable {
|
||||
case ccounts, hashtags, statuses
|
||||
}
|
||||
|
||||
public struct Query: Codable, GetQuery {
|
||||
public init(q: String,
|
||||
|
@ -109,9 +106,11 @@ extension Mastodon.API.Search {
|
|||
}
|
||||
|
||||
public extension Mastodon.API.Search {
|
||||
enum Scope: String {
|
||||
enum SearchType: String, Codable {
|
||||
case accounts
|
||||
case hashtags
|
||||
case statuses
|
||||
case `default`
|
||||
|
||||
public var rawValue: String {
|
||||
switch self {
|
||||
|
@ -119,6 +118,10 @@ public extension Mastodon.API.Search {
|
|||
return "accounts"
|
||||
case .hashtags:
|
||||
return "hashtags"
|
||||
case .statuses:
|
||||
return "statuses"
|
||||
case .default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue