Skip to content

Commit

Permalink
Merge pull request #663 from gini/lint_issues_capture_and_bank
Browse files Browse the repository at this point in the history
Lint issues capture and bank
  • Loading branch information
zladzeyka authored Sep 25, 2024
2 parents ef1e40d + 058fc17 commit 4aecf5e
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ extension GiniBankNetworkingScreenApiCoordinator: SkontoCoordinatorDelegate {
let viewModel = DocumentPagesViewModel(originalImages: pageImages,
originalSizes: originalSizes,
extractionBoundingBoxes: extractionBoundingBoxes,
amountToPay: skontoViewModel.amountToPay,
amountToPay: skontoViewModel.amountToPay,
skontoAmountToPay: skontoViewModel.skontoAmountToPay,
expiryDate: skontoViewModel.dueDate)
skontoViewModel.setDocumentPagesViewModel(viewModel)
Expand Down
71 changes: 36 additions & 35 deletions BankSDK/GiniBankSDK/Sources/GiniBankSDK/Core/GiniBankUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ public protocol GiniBankAnalysisDelegate: AnalysisDelegate {}

/**
Returns a localized string resource preferably from the client's bundle. Used in Return Assistant Screens.

- parameter key: The key to search for in the strings file.
- parameter comment: The corresponding comment.

- returns: String resource for the given key.
*/
func NSLocalizedStringPreferredGiniBankFormat(_ key: String,
fallbackKey: String = "",
comment: String,
isCustomizable: Bool = true) -> String {
if isCustomizable {
if let clientLocalizedStringMainBundle = clientLocalizedString(key,
fallbackKey: fallbackKey,
comment: comment,
bundle: .main) {
return clientLocalizedStringMainBundle

} else if let customBundle = GiniBankConfiguration.shared.customResourceBundle,
let clientLocalizedStringCustomBundle = clientLocalizedString(key,
fallbackKey: fallbackKey,
comment: comment,
bundle: customBundle) {
return clientLocalizedStringCustomBundle
}
}
return giniLocalizedString(key, fallbackKey: fallbackKey, comment: comment)
}
if isCustomizable {
if let clientLocalizedStringMainBundle = clientLocalizedString(key,
fallbackKey: fallbackKey,
comment: comment,
bundle: .main) {
return clientLocalizedStringMainBundle

} else if let customBundle = GiniBankConfiguration.shared.customResourceBundle,
let clientLocalizedStringCustomBundle = clientLocalizedString(key,
fallbackKey: fallbackKey,
comment: comment,
bundle: customBundle) {
return clientLocalizedStringCustomBundle
}
}
return giniLocalizedString(key, fallbackKey: fallbackKey, comment: comment)
}

private func clientLocalizedString(_ key: String,
fallbackKey: String,
Expand All @@ -50,7 +50,7 @@ private func clientLocalizedString(_ key: String,
var fallbackClientString = NSLocalizedString(fallbackKey,
bundle: bundle,
comment: comment)

if let localizedResourceName = GiniBankConfiguration.shared.localizedStringsTableName {
clientString = NSLocalizedString(key,
tableName: localizedResourceName,
Expand All @@ -61,29 +61,30 @@ private func clientLocalizedString(_ key: String,
bundle: bundle,
comment: comment)
}

guard (clientString.lowercased() != key.lowercased() || fallbackClientString.lowercased() != fallbackKey.lowercased()) else {

guard clientString.lowercased() != key.lowercased()
|| fallbackClientString.lowercased() != fallbackKey.lowercased() else {
return nil
}

return clientString
}

private func giniLocalizedString(_ key: String,
fallbackKey: String,
comment: String) -> String {
let giniBundle = giniBankBundle()

var defaultFormat = NSLocalizedString(key,
bundle: giniBundle,
comment: comment)

if defaultFormat.lowercased() == key.lowercased() {
defaultFormat = NSLocalizedString(fallbackKey,
bundle: giniBundle,
comment: comment)
}

return defaultFormat
}

Expand All @@ -93,9 +94,9 @@ func giniBankBundle() -> Bundle {

/**
Returns an optional `UIImage` instance with the given `name` preferably from the client's bundle.

- parameter name: The name of the image file without file extension.

- returns: Image if found with name.
*/
func prefferedImage(named name: String) -> UIImage? {
Expand All @@ -117,9 +118,9 @@ func prefferedImage(named name: String) -> UIImage? {
}
/**
Returns an optional `UIColor` instance with the given `name` preferably from the client's bundle.

- parameter name: The name of the UIColor from `GiniColors` asset catalog.

- returns: UIColor if found with name.
*/
func prefferedColor(named name: String) -> UIColor {
Expand Down Expand Up @@ -164,19 +165,19 @@ public func prefferedColorByProvider(named name: String) -> UIColor {
Getting the payment request id from incoming url
Should be called inside function:
func application(_ application: UIApplication,
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any] = [:] ) -> Bool
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any] = [:] ) -> Bool

- parameter url: The incoming url from the business app
- parameter completion: An action for processing asynchronous data received from the service with Result type as a paramater. Result is a value that represents either a success or a failure, including an associated value in each case.
In success case it includes payment request Id.
In case of failure error that there is no requestId in incoming url from the business app.

*/
public func receivePaymentRequestId(url: URL, completion: @escaping (Result<String, GiniBankError>) -> Void) {
// Process the URL.
guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
let params = components.queryItems else {
let params = components.queryItems else {
completion(.failure(.noRequestId))
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ extension GiniBank {
documentMetadata: Document.Metadata? = nil,
trackingDelegate: GiniCaptureTrackingDelegate? = nil,
networkingService: GiniCaptureNetworkService,
configurationService: ClientConfigurationServiceProtocol? = nil) -> UIViewController {
configurationService: ClientConfigurationServiceProtocol? = nil)
-> UIViewController {
let screenCoordinator = GiniBankNetworkingScreenApiCoordinator(resultsDelegate: resultsDelegate,
configuration: configuration,
documentMetadata: documentMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ final class DigitalInvoiceBottomNavigationBar: UIView {

NSLayoutConstraint.activate([
contentView.centerXAnchor.constraint(equalTo: centerXAnchor),
contentView.widthAnchor.constraint(equalTo: widthAnchor, multiplier: multiplier),
contentView.widthAnchor.constraint(equalTo: widthAnchor,
multiplier: multiplier),
contentView.topAnchor.constraint(equalTo: topAnchor)
])
}
Expand All @@ -201,7 +202,8 @@ final class DigitalInvoiceBottomNavigationBar: UIView {
private func setupTotalLabelConstraints() {
NSLayoutConstraint.activate([
totalLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: Constants.padding),
totalLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: Constants.padding),
totalLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor,
constant: Constants.padding),
totalLabel.trailingAnchor.constraint(lessThanOrEqualTo: skontoBadgeView.leadingAnchor,
constant: -Constants.badgeHorizontalPadding)
])
Expand All @@ -211,7 +213,8 @@ final class DigitalInvoiceBottomNavigationBar: UIView {
NSLayoutConstraint.activate([
totalValueLabel.topAnchor.constraint(equalTo: totalLabel.bottomAnchor,
constant: Constants.totalValueLabelTopPadding),
totalValueLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: Constants.padding),
totalValueLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor,
constant: Constants.padding),
totalValueLabel.trailingAnchor.constraint(lessThanOrEqualTo: contentView.trailingAnchor,
constant: -Constants.padding)
])
Expand Down Expand Up @@ -247,26 +250,32 @@ final class DigitalInvoiceBottomNavigationBar: UIView {

private func setupHelpButtonConstraints() {
NSLayoutConstraint.activate([
helpButton.buttonView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -Constants.padding),
helpButton.buttonView.trailingAnchor.constraint(equalTo: trailingAnchor,
constant: -Constants.padding),
helpButton.buttonView.centerYAnchor.constraint(equalTo: proceedButton.centerYAnchor)
])
}

private func setupProceedButtonConstraints() {
NSLayoutConstraint.activate([
proceedButton.topAnchor.constraint(equalTo: contentView.bottomAnchor, constant: Constants.proceedButtonTopPadding),
proceedButton.topAnchor.constraint(equalTo: contentView.bottomAnchor,
constant: Constants.proceedButtonTopPadding),
proceedButton.centerXAnchor.constraint(equalTo: centerXAnchor),
proceedButton.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor, constant: -Constants.verticalPadding),
proceedButton.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor,
constant: -Constants.verticalPadding),
proceedButton.heightAnchor.constraint(equalToConstant: Constants.proceedButtonHeight)
])
if UIDevice.current.isIpad {
NSLayoutConstraint.activate([
proceedButton.widthAnchor.constraint(equalTo: contentView.widthAnchor, constant: -Constants.padding * 2)
proceedButton.widthAnchor.constraint(equalTo: contentView.widthAnchor,
constant: -Constants.padding * 2)
])
} else {
NSLayoutConstraint.activate([
proceedButton.widthAnchor.constraint(lessThanOrEqualTo: contentView.widthAnchor, constant: -Constants.padding * 2),
proceedButton.trailingAnchor.constraint(equalTo: helpButton.buttonView.leadingAnchor, constant: -Constants.helpButtonHorizontalPadding)
proceedButton.widthAnchor.constraint(lessThanOrEqualTo: contentView.widthAnchor,
constant: -Constants.padding * 2),
proceedButton.trailingAnchor.constraint(equalTo: helpButton.buttonView.leadingAnchor,
constant: -Constants.helpButtonHorizontalPadding)
])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ class DigitalInvoiceProceedView: UIView {

private let configuration = GiniBankConfiguration.shared

private let skontoPercentageText = NSLocalizedStringPreferredGiniBankFormat("ginibank.skonto.total.skontopercentage",
comment: "%@ Skonto discount")

init() {
super.init(frame: .zero)
setupView()
Expand Down Expand Up @@ -139,7 +136,8 @@ class DigitalInvoiceProceedView: UIView {

NSLayoutConstraint.activate([
contentView.centerXAnchor.constraint(equalTo: centerXAnchor),
contentView.widthAnchor.constraint(equalTo: widthAnchor, multiplier: multiplier),
contentView.widthAnchor.constraint(equalTo: widthAnchor,
multiplier: multiplier),
contentView.topAnchor.constraint(equalTo: topAnchor),
contentView.bottomAnchor.constraint(equalTo: bottomAnchor)
])
Expand All @@ -157,7 +155,8 @@ class DigitalInvoiceProceedView: UIView {
private func setupTotalStringLabelConstraints() {
NSLayoutConstraint.activate([
totalStringLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: Constants.padding),
totalStringLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor,constant: Constants.padding),
totalStringLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor,
constant: Constants.padding),
totalStringLabel.trailingAnchor.constraint(lessThanOrEqualTo: skontoBadgeView.leadingAnchor,
constant: -Constants.badgeHorizontalPadding)
])
Expand Down Expand Up @@ -228,8 +227,11 @@ class DigitalInvoiceProceedView: UIView {
if let skontoViewModel = viewModel.skontoViewModel {
let isSkontoApplied = skontoViewModel.isSkontoApplied
skontoBadgeView.isHidden = !isSkontoApplied
let skontoPercentageLabelText = String.localizedStringWithFormat(skontoPercentageText,
skontoViewModel.formattedPercentageDiscounted)
let formattedPercentageDiscounted = skontoViewModel.formattedPercentageDiscounted
let percentageText = NSLocalizedStringPreferredGiniBankFormat("ginibank.skonto.total.skontopercentage",
comment: "%@ Skonto discount")
let skontoPercentageLabelText = String.localizedStringWithFormat(percentageText,
formattedPercentageDiscounted)
skontoPercentageLabel.text = skontoPercentageLabelText
skontoPercentageLabel.accessibilityValue = skontoPercentageLabelText
savingsAmountLabel.isHidden = !isSkontoApplied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ final class DigitalInvoiceViewController: UIViewController {
forCellReuseIdentifier: DigitalLineItemTableViewCell.reuseIdentifier)
tableView.register(DigitalInvoiceAddOnListCell.self,
forCellReuseIdentifier: DigitalInvoiceAddOnListCell.reuseIdentifier)
tableView.register(DigitalInvoiceSkontoTableViewCell.self, forCellReuseIdentifier: "DigitalInvoiceSkontoTableViewCell")
tableView.register(DigitalInvoiceSkontoTableViewCell.self,
forCellReuseIdentifier: "DigitalInvoiceSkontoTableViewCell")
tableView.separatorStyle = .none
tableView.backgroundColor = .clear
tableView.showsVerticalScrollIndicator = false
Expand Down Expand Up @@ -229,15 +230,15 @@ extension DigitalInvoiceViewController: UITableViewDelegate, UITableViewDataSour
}
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch Section(rawValue: indexPath.section) {
case .titleCell:
if let cell = tableView.dequeueReusableCell(
withIdentifier: DigitalInvoiceTableViewTitleCell.reuseIdentifier,
for: indexPath) as? DigitalInvoiceTableViewTitleCell {
let cellIdentifier = DigitalInvoiceTableViewTitleCell.reuseIdentifier
if let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier,
for: indexPath) as? DigitalInvoiceTableViewTitleCell {
return cell
}
assertionFailure("DigitalInvoiceTableViewTitleCell could not been reused")
return UITableViewCell()
case .lineItems:

Expand Down Expand Up @@ -268,7 +269,8 @@ extension DigitalInvoiceViewController: UITableViewDelegate, UITableViewDataSour
return UITableViewCell()
case .skonto:
guard let skontoViewModel = viewModel.skontoViewModel else { return UITableViewCell() }
let cell = tableView.dequeueReusableCell(withIdentifier: "DigitalInvoiceSkontoTableViewCell",for: indexPath)
let cell = tableView.dequeueReusableCell(withIdentifier: "DigitalInvoiceSkontoTableViewCell",
for: indexPath)
if let cell = cell as? DigitalInvoiceSkontoTableViewCell {
cell.delegate = self
cell.configure(with: skontoViewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ final class QuantityView: UIView {
button.addTarget(self, action: #selector(decreaseQuantity), for: .touchUpInside)
button.isExclusiveTouch = true
button.translatesAutoresizingMaskIntoConstraints = false
let descriptor = NSLocalizedStringPreferredGiniBankFormat("ginibank.digitalinvoice.edit.minus.button.accessibility",
let minusButtonAccessibilityKey = "ginibank.digitalinvoice.edit.minus.button.accessibility"
let descriptor = NSLocalizedStringPreferredGiniBankFormat(minusButtonAccessibilityKey,
comment: "Decrease quantity")
button.accessibilityValue = descriptor
return button
Expand All @@ -58,7 +59,9 @@ final class QuantityView: UIView {
button.addTarget(self, action: #selector(increaseQuantity), for: .touchUpInside)
button.isExclusiveTouch = true
button.translatesAutoresizingMaskIntoConstraints = false
let descriptor = NSLocalizedStringPreferredGiniBankFormat("ginibank.digitalinvoice.edit.plus.button.accessibility",
let plusButtonAccessibilityKey = "ginibank.digitalinvoice.edit.plus.button.accessibility"

let descriptor = NSLocalizedStringPreferredGiniBankFormat(plusButtonAccessibilityKey,
comment: "Increase quantity")
button.accessibilityValue = descriptor
return button
Expand Down
Loading

0 comments on commit 4aecf5e

Please sign in to comment.