Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation #1

Merged
merged 67 commits into from
Jun 22, 2018
Merged

Initial implementation #1

merged 67 commits into from
Jun 22, 2018

Conversation

wiruzx
Copy link
Collaborator

@wiruzx wiruzx commented Jun 22, 2018

No description provided.

<string>
// The MIT License (MIT)
//
// Copyright (c) 2015-present Badoo Trading Limited.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright date needs to be fixed

// MARK: - Utility extensions

private extension String {
static let cell = "cell"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, such a nice idea

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=)


func setItem(_ item: Item) {
itemId = item.identifier
textLabel!.text = item.title

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "!"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always gonna be there, right?


override func prepareForReuse() {
super.prepareForReuse()
detailTextLabel!.text = nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change type in setItem to optional, then you can clean a view state with setItem(nil).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't think I need prepare for reuse here at all. if I replace

if let subtitle = item.subtitle {
    detailTextLabel!.text = subtitle
}

with

detailTextLabel!.text = item.subtitle


func filter(text: String) {
searchText = text
updateFilteredItems()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be called in searchText.didSet

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix, thanks

switch preferredPresentationStyle {
case .push:
guard let navigationController = viewController.navigationController else {
assertionFailure()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a descriptive message here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure


private let store: ItemStore
private let storage: FavoritesStorageProtocol
private var favorited: Set<ItemIdentifier> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "favorited" here? Everywhere else it's "favorites"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be fixed, thanks

hashValue = ItemIdentifier.hash(id: id.itemId, parents: parents)
}

private static func hash(id: String, parents: [String]) -> Int {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider to use a new Swift syntax for hash function in Swift 4.2

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's not available yet right?

Copy link
Collaborator

@radekcieciwa radekcieciwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for generating snapshot tests

Ideas:
No need for Section.
No need for ItemStore.


// MARK: - Layout

extension UICollectionViewLayout {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about file naming. UICollectionViewFlowLayout+Factory - would be more intuitive for me to find this method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

override func viewDidLoad() {
super.viewDidLoad()

collectionView = UICollectionView(frame: .zero,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's initiate it init as the rest of the views - dropping ! as well from declaration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure


override func prepareForReuse() {
super.prepareForReuse()
detailTextLabel!.text = nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's clean textLabel as well.
Maybe we should reset isFavourite to default state - if there is such.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I've already removed prepareForReuse code. I think it's not require to clean it here, because I update all the fields every time I set an item

override func viewDidLoad() {
super.viewDidLoad()

tableView = UITableView(frame: .zero, style: .grouped)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in init

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

tableView.alignAllEdgesWithSuperview()

if #available(iOS 11, *) {
addSearch()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any fallback or is it only for iOS 11 exclusively?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth it

@wiruzx wiruzx merged commit 4bd804e into master Jun 22, 2018
@wiruzx wiruzx deleted the init branch June 22, 2018 15:00
THE SOFTWARE.
*/

public protocol ElementsProviding: TestCaseNameProviding {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be reasonable to compose those protocols at client side (ElementsProviding & TestCaseNameProviding) instead of inheriting?


protocol FavoritesStorageProtocol {
func save(favorites: [ItemIdentifier])
func load() -> [ItemIdentifier]?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid optionality here and simply return [] when there's no favorites?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants