mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-06-04 19:43:31 +08:00
* nified cell standardized cell style * Made swipe delete action generic * Fixed clear all button behavior * Added attributed string * Cleanup * Resolved merge conflicts
69 lines
1.6 KiB
Swift
69 lines
1.6 KiB
Swift
//
|
|
// SearchRecentViewModel.swift
|
|
// Freetime
|
|
//
|
|
// Created by Hesham Salman on 10/21/17.
|
|
// Copyright © 2017 Ryan Nystrom. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import IGListKit
|
|
|
|
private enum Keys {
|
|
static let search = "search"
|
|
static let viewed = "viewed"
|
|
}
|
|
|
|
final class SearchRecentViewModel: NSObject, ListDiffable {
|
|
|
|
let query: SearchQuery
|
|
|
|
init(query: SearchQuery) {
|
|
self.query = query
|
|
}
|
|
|
|
var displayText: NSAttributedString {
|
|
switch query {
|
|
case .search(let text):
|
|
return NSAttributedString(string: text, attributes: standardAttributes)
|
|
case .recentlyViewed(let repoDetails):
|
|
return RepositoryAttributedString(owner: repoDetails.owner, name: repoDetails.name)
|
|
}
|
|
}
|
|
|
|
var icon: UIImage {
|
|
switch query {
|
|
case .search:
|
|
return #imageLiteral(resourceName: "search")
|
|
case .recentlyViewed:
|
|
return #imageLiteral(resourceName: "repo")
|
|
}
|
|
}
|
|
|
|
// MARK: ListDiffable
|
|
|
|
func diffIdentifier() -> NSObjectProtocol {
|
|
var identifier: String
|
|
switch query {
|
|
case .recentlyViewed:
|
|
identifier = Keys.viewed
|
|
case .search:
|
|
identifier = Keys.search
|
|
}
|
|
return (identifier + displayText.string) as NSObjectProtocol
|
|
}
|
|
|
|
func isEqual(toDiffableObject object: ListDiffable?) -> Bool {
|
|
return true
|
|
}
|
|
|
|
// MARK: Private API
|
|
|
|
private var standardAttributes: [NSAttributedStringKey: Any] {
|
|
return [
|
|
.font: Styles.Fonts.body,
|
|
.foregroundColor: Styles.Colors.Gray.dark.color
|
|
]
|
|
}
|
|
}
|