-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add shop configs #179
Merged
Merged
Add shop configs #179
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
442f26d
Modify gateway
radyslavkrechet 872de6d
Modify magento api
radyslavkrechet 0d7d4e3
Modify data and domain layers
radyslavkrechet b6f217c
Modify account module with customer settings config
radyslavkrechet 43e0680
Modify account module with customer order list config
radyslavkrechet 3c28ddb
Replace config use case with dependency injection
radyslavkrechet f2c8af8
Rename config field
radyslavkrechet 7316567
Modify main module with home screen config
radyslavkrechet 1415375
Fix errors in tests target
radyslavkrechet 7e89b3f
Modify tests
radyslavkrechet 180b6f7
Make changes by request
radyslavkrechet 7eeac42
Fix tests
radyslavkrechet 086e852
Make changes by request
radyslavkrechet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,26 +10,57 @@ import UIKit | |
|
||
import ShopApp_Gateway | ||
|
||
private enum AccountSection: Int { | ||
case customer | ||
case policy | ||
|
||
static let allValues = [customer, policy] | ||
} | ||
|
||
enum AccountCustomerSection: Int { | ||
case orders | ||
case info | ||
case addresses | ||
|
||
static let allValues = [orders, info, addresses] | ||
} | ||
|
||
protocol AccountTableProviderDelegate: class { | ||
func provider(_ provider: AccountTableProvider, didSelect type: AccountCustomerSection) | ||
func provider(_ provider: AccountTableProvider, didSelect policy: Policy) | ||
} | ||
|
||
class AccountTableProvider: NSObject, UITableViewDataSource, UITableViewDelegate { | ||
private let kSpaceBetweenSections: CGFloat = 10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private let properties inside class should not have prefix 'k' |
||
|
||
var policies: [Policy] = [] | ||
var customer: Customer? | ||
var isOrdersEnabled = false | ||
|
||
weak var delegate: (AccountTableProviderDelegate & AccountNotLoggedHeaderDelegate & AccountLoggedHeaderDelegate & AccountFooterDelegate)? | ||
weak var delegate: (AccountTableProviderDelegate & AccountNotLoggedHeaderDelegate & AccountFooterDelegate)? | ||
|
||
// MARK: - UITableViewDataSource | ||
|
||
func numberOfSections(in tableView: UITableView) -> Int { | ||
return AccountSection.allValues.count | ||
} | ||
|
||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return policies.count | ||
return section == AccountSection.customer.rawValue ? numberOfRowsInHeaderSection() : policies.count | ||
} | ||
|
||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell: AccountTableViewCell = tableView.dequeueReusableCellForIndexPath(indexPath) | ||
let policy = policies[indexPath.row] | ||
cell.configure(with: policy) | ||
|
||
switch indexPath.section { | ||
case AccountSection.customer.rawValue: | ||
let type = typeOfIndexPath(indexPath) | ||
cell.configure(with: type) | ||
default: | ||
let policy = policies[indexPath.row] | ||
cell.configure(with: policy) | ||
} | ||
|
||
return cell | ||
} | ||
|
||
|
@@ -39,36 +70,76 @@ class AccountTableProvider: NSObject, UITableViewDataSource, UITableViewDelegate | |
guard let delegate = delegate else { | ||
return | ||
} | ||
let policy = policies[indexPath.row] | ||
delegate.provider(self, didSelect: policy) | ||
|
||
switch indexPath.section { | ||
case AccountSection.customer.rawValue: | ||
let type = typeOfIndexPath(indexPath) | ||
delegate.provider(self, didSelect: type) | ||
default: | ||
let policy = policies[indexPath.row] | ||
delegate.provider(self, didSelect: policy) | ||
} | ||
} | ||
|
||
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { | ||
return customer != nil ? kAccountLoggedHeaderViewHeight : kAccountNotLoggedHeaderViewHeight | ||
switch section { | ||
case AccountSection.customer.rawValue: | ||
return customer != nil ? kAccountLoggedHeaderViewHeight : kAccountNotLoggedHeaderViewHeight | ||
default: | ||
return kSpaceBetweenSections | ||
} | ||
} | ||
|
||
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { | ||
return customer != nil ? kAccountFooterViewHeight : TableView.headerFooterMinHeight | ||
switch section { | ||
case AccountSection.customer.rawValue: | ||
return TableView.headerFooterMinHeight | ||
default: | ||
return customer != nil ? kAccountFooterViewHeight : TableView.headerFooterMinHeight | ||
} | ||
} | ||
|
||
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { | ||
guard section == AccountSection.customer.rawValue else { | ||
return UIView() | ||
} | ||
|
||
if let customer = customer { | ||
let view = AccountLoggedHeaderView(frame: CGRect.zero, customer: customer) | ||
view.delegate = delegate | ||
return view | ||
} else { | ||
let view = AccountNotLoggedHeaderView(frame: CGRect.zero) | ||
view.delegate = delegate | ||
return view | ||
} | ||
} | ||
|
||
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { | ||
guard customer != nil else { | ||
guard section == AccountSection.policy.rawValue, customer != nil else { | ||
return UIView() | ||
} | ||
let view: AccountFooterView = tableView.dequeueReusableHeaderFooterView() | ||
view.delegate = delegate | ||
return view | ||
} | ||
|
||
private func numberOfRowsInHeaderSection() -> Int { | ||
guard customer != nil else { | ||
return 0 | ||
} | ||
|
||
var numberOfRows = AccountCustomerSection.allValues.count | ||
|
||
if !isOrdersEnabled { | ||
numberOfRows -= 1 | ||
} | ||
|
||
return numberOfRows | ||
} | ||
|
||
private func typeOfIndexPath(_ indexPath: IndexPath) -> AccountCustomerSection { | ||
let index = isOrdersEnabled ? indexPath.row : indexPath.row + 1 | ||
|
||
return AccountCustomerSection(rawValue: index)! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You inject this value to view controller and then pass it to the provider, but you can inject it directly to a provider