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

[NT-203] (1/2) Pledge summary section #845

Merged
merged 25 commits into from
Sep 24, 2019
Merged

Conversation

Scollaco
Copy link
Contributor

@Scollaco Scollaco commented Sep 17, 2019

📲 What

  • Adds the Summary View section to the ManageViewPledgeViewController.

Note:

  • This PR doesn't contain the final strings. They will be added on the 2/2 part of this work.

JIRA ticket

🤔 Why

  • This is the first part of the ManagePledge feature. More to come.

🛠 How

  • Created a new ManagePledgeSummaryView class
  • Created viewModel to handle the views outputs
  • Created viewModel tests
  • Added the new view to ManageViewPledgeViewController

👀 See

Before 🐛 After 🦋
Simulator Screen Shot - iPhone 8 - 2019-09-17 at 14 50 41 Simulator Screen Shot - iPhone 8 - 2019-09-17 at 14 48 59

♿️ Accessibility

  • Supports Dynamic Type

✅ Acceptance criteria

With NativeCheckoutPledgeView feature enabled:

  • Go to Profile and choose a backed project.
  • The Backer number should match the real value
  • The Baking date number should match the real date the user backed the project
  • The Pledge amount should match the real pledged value
  • The Shipping cost should match the real shipping cost
  • If backing has non-shippable reward, no reward or no location available, the Shipping location should be hidden
  • The Total amount should match the real total amount value

@ksr-ci-bot
Copy link

ksr-ci-bot commented Sep 17, 2019

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

let _ = backing.rewardId else {
return true
}
if let reward = backing.reward {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes a backing can have rewardId but the reward can still be nil

@@ -144,6 +144,12 @@ public enum Format {
return NSAttributedString(string: Strings.plus_shipping_cost(shipping_cost: ""), attributes: attributes)
}

public static func attributedAmount(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created this function to return the attributed amount without the + sign

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't think of a reason that we'd want to do this 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably remove this function now, right?

@Scollaco Scollaco changed the base branch from feature-pledge-summary-section to master September 18, 2019 14:48
Copy link
Contributor

@justinswart justinswart left a comment

Choose a reason for hiding this comment

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

Cool! Couple of small things.

|> \.textColor .~ UIColor.black
|> \.font .~ UIFont.ksr_subhead().bolded
|> \.adjustsFontForContentSizeCategory .~ true
|> \.text %~ { _ in "Total amount" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Best to use localizedString directly until we have the string added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually after merging master I noticed that most of the strings were already there!

var outputs: ManagePledgeSummaryViewViewModelOutputs { get }
}

public class ManagePledgeSummaryViewViewModel: ManagePledgeSummaryViewViewModelType,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure when we started calling VM's VVM's 😅. I don't think we should be naming them ViewViewModel, the fact that this VM is used for a View and not a ViewController doesn't matter, we should just call it ManagePledgeSummaryViewModel, I think we should also add an investment day task to fix these names in the codebase for other VVMs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol it makes sense. I will rename it

.zip(with: backing)

self.backerNumberText = backing
.map { "Backer #\($0.sequence)" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use localizedString until this is translated.


private func formattedPledgeDate(_ backing: Backing) -> String {
let formattedDate = Format.date(secondsInUTC: backing.pledgedAt, dateStyle: .long, timeStyle: .none)
return "As of \(formattedDate)"
Copy link
Contributor

Choose a reason for hiding this comment

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

localizedString

@@ -144,6 +144,12 @@ public enum Format {
return NSAttributedString(string: Strings.plus_shipping_cost(shipping_cost: ""), attributes: attributes)
}

public static func attributedAmount(
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't think of a reason that we'd want to do this 🤔

let combinedAttributes = defaultAttributes
.withAllValuesFrom(superscriptAttributes)

return Format.attributedAmount(attributes: combinedAttributes) + attributedCurrency
Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing as we don't need the + sign, we can just do:

private func attributedCurrency(with project: Project, amount: Double) -> NSAttributedString? {
  let defaultAttributes = checkoutCurrencyDefaultAttributes()
    .withAllValuesFrom([.foregroundColor: UIColor.ksr_green_500])
  let superscriptAttributes = checkoutCurrencySuperscriptAttributes()
  guard
    let attributedCurrency = Format.attributedCurrency(
      amount,
      country: project.country,
      omitCurrencyCode: project.stats.omitUSCurrencyCode,
      defaultAttributes: defaultAttributes,
      superscriptAttributes: superscriptAttributes
    ) else { return nil }

  return attributedCurrency
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Much nicer than my solution :)

superscriptAttributes: superscriptAttributes
) else { return nil }

let combinedAttributes = defaultAttributes.merging(superscriptAttributes) { _, new in new }
Copy link
Contributor

Choose a reason for hiding this comment

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

Using .withAllValuesFrom(superscriptAttributes) is a bit neater and does the same thing 👍

@justinswart
Copy link
Contributor

Do we want the date to truncate at these large sizes?

image

@justinswart
Copy link
Contributor

By the way, I noticed there's an autolayout warning when presenting the alert controller, it seems to be a UIKit bug: http://openradar.appspot.com/49289931

@justinswart
Copy link
Contributor

I think that we should use the RewardPledgeNavigationController to present this view, that already has the styling applies to its navigation bar.

.skipNil()

self.shippingLocationText = backing.ignoreValues()
.map { Strings.Shipping() + ": " + "Australia" }
Copy link
Contributor Author

@Scollaco Scollaco Sep 20, 2019

Choose a reason for hiding this comment

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

Here Australia is hardcoded because we will use a Backing property called locationName. This is done in another branch (for the 2/2 PR)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I think we want to add a new string here:

"Shipping: %{country_name}"

Although it seems very much like what you have, by including the : in the string we give the translator the ability to move it around if they need to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, before I implemented this, I checked out the Android codebase and that's how it was implemented. I can create a new string on the second part of this work, but I'm not sure if it would make a big difference.
cc @ginarovirosa

Copy link

@ginarovirosa ginarovirosa Sep 24, 2019

Choose a reason for hiding this comment

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

hello @Scollaco @justinswart. Indeed having the Shipping: %{country_name} format makes it easier for the translators to work around country name prefixes. Fwiw, it does seem that the Shipping: %{country_name} variable is an old one. We use %{country} now. As you can see in this string for instance: en -> pledges -> checkout_summary -> Shipping_to_country

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @ginarovirosa!

@justinswart
Copy link
Contributor

justinswart commented Sep 24, 2019

Will wait to hear back from @ginarovirosa on that string.

What about this comment? Is there a max number of lines set? I'm surprised it doesn't wrap on space.

@Scollaco
Copy link
Contributor Author

Will wait to hear back from @ginarovirosa on that string.

What about this comment? Is there a max number of lines set? I'm surprised it doesn't wrap on space.

It didn't have a number of lines set. I had set adjustsFontSizeToFitWidth = true instead. This is the result:

lines = 0 adjustsFontSizeToFitWidth = true
Simulator Screen Shot - iPhone 8 - 2019-09-24 at 10 38 52 Simulator Screen Shot - iPhone 8 - 2019-09-24 at 10 30 32

Seeing the difference I'm leaning towards the lines = 0 solution, because then it won't compromise the font size too much depending on the text.

Copy link
Contributor

@justinswart justinswart left a comment

Choose a reason for hiding this comment

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

Cool, just the string to add in the next PR 👍

@Scollaco Scollaco merged commit 360b7b6 into master Sep 24, 2019
@Scollaco Scollaco deleted the pledge-summary-section branch September 24, 2019 18:54
@Scollaco Scollaco changed the title [1/2] Pledge summary section [NT-203] (1/2) Pledge summary section Sep 24, 2019
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