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

MLB:1856: changed copy on backingfragment whe plot selected #2181

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/src/main/java/com/kickstarter/models/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Project private constructor(
private val goal: Double,
private val id: Long, // in the Kickstarter app, this is project.pid not project.id
private val isBacking: Boolean,
private val isPledgeOverTimeAllowed: Boolean?,
private val isStarred: Boolean,
private val lastUpdatePublishedAt: DateTime?,
private val launchedAt: DateTime?,
Expand Down Expand Up @@ -90,6 +91,7 @@ class Project private constructor(
fun goal() = this.goal
override fun id() = this.id
fun isBacking() = this.isBacking
fun isPledgeOverTimeAllowed() = this.isPledgeOverTimeAllowed
fun isStarred() = this.isStarred
fun lastUpdatePublishedAt() = this.lastUpdatePublishedAt
fun launchedAt() = this.launchedAt
Expand Down Expand Up @@ -149,6 +151,7 @@ class Project private constructor(
private var goal: Double = 0.0,
private var id: Long = 0L,
private var isBacking: Boolean = false,
private var isPledgeOverTimeAllowed: Boolean? = null,
private var isStarred: Boolean = false,
private var lastUpdatePublishedAt: DateTime? = null,
private var launchedAt: DateTime? = null,
Expand Down Expand Up @@ -209,6 +212,7 @@ class Project private constructor(
fun goal(goal: Double?) = apply { this.goal = goal ?: 0.0 }
fun id(id: Long?) = apply { this.id = id ?: 0L }
fun isBacking(isBacking: Boolean?) = apply { this.isBacking = isBacking ?: false }
fun isPledgeOverTimeAllowed(isPledgeOverTimeAllowed: Boolean?) = apply { this.isPledgeOverTimeAllowed = isPledgeOverTimeAllowed }
fun isStarred(isStarred: Boolean?) = apply { this.isStarred = isStarred ?: false }
fun lastUpdatePublishedAt(lastUpdatePublishedAt: DateTime?) = apply { this.lastUpdatePublishedAt = lastUpdatePublishedAt }
fun launchedAt(launchedAt: DateTime?) = apply { this.launchedAt = launchedAt }
Expand Down Expand Up @@ -264,6 +268,7 @@ class Project private constructor(
goal = goal,
id = id,
isBacking = isBacking,
isPledgeOverTimeAllowed = isPledgeOverTimeAllowed,
isStarred = isStarred,
lastUpdatePublishedAt = lastUpdatePublishedAt,
launchedAt = launchedAt,
Expand Down Expand Up @@ -324,6 +329,7 @@ class Project private constructor(
goal = goal,
id = id,
isBacking = isBacking,
isPledgeOverTimeAllowed = isPledgeOverTimeAllowed,
isStarred = isStarred,
lastUpdatePublishedAt = lastUpdatePublishedAt,
launchedAt = launchedAt,
Expand Down Expand Up @@ -497,6 +503,7 @@ class Project private constructor(
goal() == other.goal() &&
id() == other.id() &&
isBacking() == other.isBacking() &&
isPledgeOverTimeAllowed() == other.isPledgeOverTimeAllowed() &&
isStarred() == other.isStarred() &&
lastUpdatePublishedAt() == other.lastUpdatePublishedAt() &&
launchedAt() == other.launchedAt() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.kickstarter.R
import com.kickstarter.libs.Either
import com.kickstarter.libs.Environment
import com.kickstarter.libs.KSString
import com.kickstarter.libs.featureflag.FlagKey
import com.kickstarter.libs.rx.transformers.Transformers.combineLatestPair
import com.kickstarter.libs.rx.transformers.Transformers.neverErrorV2
import com.kickstarter.libs.rx.transformers.Transformers.takePairWhenV2
Expand Down Expand Up @@ -240,7 +241,10 @@ interface BackingFragmentViewModel {
val reward = Observable.merge(rewardA, rewardB)
.distinctUntilChanged()

val isCreator = Observable.combineLatest(this.currentUser.observable(), backedProject) { user, project ->
val isCreator = Observable.combineLatest(
this.currentUser.observable(),
backedProject
) { user, project ->
Pair(user, project)
}
.map { it.second.userIsCreator(it.first.getValue()) }
Expand Down Expand Up @@ -295,7 +299,11 @@ interface BackingFragmentViewModel {
this.pledgeSummaryIsGone.onNext(it)
}.addToDisposable(disposables)

Observable.combineLatest(backedProject, backing, this.currentUser.loggedInUser()) { p, b, user -> Triple(p, b, user) }
Observable.combineLatest(
backedProject,
backing,
this.currentUser.loggedInUser()
) { p, b, user -> Triple(p, b, user) }
.map { pledgeStatusData(it.first, it.second, it.third) }
.distinctUntilChanged()
.subscribe { this.pledgeStatusData.onNext(it) }
Expand All @@ -305,7 +313,13 @@ interface BackingFragmentViewModel {
.filter { it.shippingAmount().isNotNull() }
.map { requireNotNull(it.shippingAmount()) }
.compose<Pair<Float, Project>>(combineLatestPair(backedProject))
.map { ProjectViewUtils.styleCurrency(it.first.toDouble(), it.second, this.ksCurrency) }
.map {
ProjectViewUtils.styleCurrency(
it.first.toDouble(),
it.second,
this.ksCurrency
)
}
.distinctUntilChanged()
.subscribe { this.shippingAmount.onNext(it) }
.addToDisposable(disposables)
Expand Down Expand Up @@ -393,7 +407,10 @@ interface BackingFragmentViewModel {
backing
.compose<Pair<Backing, Project>>(combineLatestPair(backedProject))
.compose(takePairWhenV2(this.receivedCheckboxToggled))
.switchMap { this.apiClient.postBacking(it.first.second, it.first.first, it.second).compose(neverErrorV2()) }
.switchMap {
this.apiClient.postBacking(it.first.second, it.first.first, it.second)
.compose(neverErrorV2())
}
.share()
.subscribe()

Expand Down Expand Up @@ -507,7 +524,14 @@ interface BackingFragmentViewModel {
return when (CreditCardPaymentType.safeValueOf(paymentSource.paymentType())) {
CreditCardPaymentType.ANDROID_PAY -> Either.Right(R.string.googlepay_button_content_description)
CreditCardPaymentType.APPLE_PAY -> Either.Right(R.string.apple_pay_content_description)
CreditCardPaymentType.CREDIT_CARD -> Either.Left(StoredCard.issuer(CreditCardTypes.safeValueOf(paymentSource.type())))
CreditCardPaymentType.CREDIT_CARD -> Either.Left(
StoredCard.issuer(
CreditCardTypes.safeValueOf(
paymentSource.type()
)
)
)

else -> Either.Left(CardBrand.Unknown.code)
}
}
Expand All @@ -521,7 +545,11 @@ interface BackingFragmentViewModel {
}
}

private fun pledgeStatusData(project: Project, backing: Backing, user: User): PledgeStatusData {
private fun pledgeStatusData(
project: Project,
backing: Backing,
user: User
): PledgeStatusData {

var statusStringRes: Int?

Expand All @@ -534,13 +562,22 @@ interface BackingFragmentViewModel {
Backing.STATUS_COLLECTED -> R.string.We_collected_your_pledge_for_this_project
Backing.STATUS_DROPPED -> R.string.Your_pledge_was_dropped_because_of_payment_errors
Backing.STATUS_ERRORED -> R.string.We_cant_process_your_pledge_Please_update_your_payment_method
Backing.STATUS_PLEDGED -> R.string.If_your_project_reaches_its_funding_goal_the_backer_will_be_charged_total_on_project_deadline
Backing.STATUS_PLEDGED -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

@jlplks add tests for the new string, take a look here to see an example -> @Test fun testFixPaymentMethodButtonIsGone_whenBackingIsErrored() at BackingFragmentViewModelTest.kt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added the test

if (project.isPledgeOverTimeAllowed() == true &&
environment.featureFlagClient()
?.getBoolean(FlagKey.ANDROID_PLEDGE_OVER_TIME) == true
) {
R.string.fpo_you_have_selected_pledge_over_time_if_the_project_reaches_its_funding_goal_the_first_charge_of
} else {
R.string.If_your_project_reaches_its_funding_goal_the_backer_will_be_charged_total_on_project_deadline
}
}

Backing.STATUS_PREAUTH -> R.string.We_re_processing_your_pledge_pull_to_refresh
else -> null
}
}
} else {

statusStringRes = when (project.state()) {
Project.STATE_CANCELED -> R.string.You_canceled_this_project_so_the_backers_payment_method_was_never_charged
Project.STATE_FAILED -> R.string.Your_project_didnt_reach_its_funding_goal_so_the_backers_payment_method_was_never_charged
Expand Down Expand Up @@ -603,13 +640,17 @@ interface BackingFragmentViewModel {

override fun cardLogo(): Observable<Int> = this.cardLogo

override fun fixPaymentMethodButtonIsGone(): Observable<Boolean> = this.fixPaymentMethodButtonIsGone
override fun fixPaymentMethodButtonIsGone(): Observable<Boolean> =
this.fixPaymentMethodButtonIsGone

override fun fixPaymentMethodMessageIsGone(): Observable<Boolean> = this.fixPaymentMethodMessageIsGone
override fun fixPaymentMethodMessageIsGone(): Observable<Boolean> =
this.fixPaymentMethodMessageIsGone

override fun notifyDelegateToRefreshProject(): Observable<Unit> = this.notifyDelegateToRefreshProject
override fun notifyDelegateToRefreshProject(): Observable<Unit> =
this.notifyDelegateToRefreshProject

override fun notifyDelegateToShowFixPledge(): Observable<Unit> = this.notifyDelegateToShowFixPledge
override fun notifyDelegateToShowFixPledge(): Observable<Unit> =
this.notifyDelegateToShowFixPledge

override fun paymentMethodIsGone(): Observable<Boolean> = this.paymentMethodIsGone

Expand All @@ -621,15 +662,18 @@ interface BackingFragmentViewModel {

override fun pledgeSummaryIsGone(): Observable<Boolean> = this.pledgeSummaryIsGone

override fun projectDataAndReward(): Observable<Pair<ProjectData, Reward>> = this.projectDataAndReward
override fun projectDataAndReward(): Observable<Pair<ProjectData, Reward>> =
this.projectDataAndReward

override fun projectDataAndAddOns(): Observable<Pair<ProjectData, List<Reward>>> = this.addOnsList
override fun projectDataAndAddOns(): Observable<Pair<ProjectData, List<Reward>>> =
this.addOnsList

override fun receivedCheckboxChecked(): Observable<Boolean> = this.receivedCheckboxChecked

override fun receivedSectionIsGone(): Observable<Boolean> = this.receivedSectionIsGone

override fun receivedSectionCreatorIsGone(): Observable<Boolean> = this.receivedSectionCreatorIsGone
override fun receivedSectionCreatorIsGone(): Observable<Boolean> =
this.receivedSectionCreatorIsGone

override fun shippingAmount(): Observable<CharSequence> = this.shippingAmount

Expand All @@ -639,15 +683,17 @@ interface BackingFragmentViewModel {

override fun showUpdatePledgeSuccess(): Observable<Unit> = this.showUpdatePledgeSuccess

override fun swipeRefresherProgressIsVisible(): Observable<Boolean> = this.swipeRefresherProgressIsVisible
override fun swipeRefresherProgressIsVisible(): Observable<Boolean> =
this.swipeRefresherProgressIsVisible

override fun totalAmount(): Observable<CharSequence> = this.totalAmount

override fun bonusSupport(): Observable<CharSequence> = this.bonusSupport

override fun estimatedDelivery(): Observable<String> = this.estimatedDelivery

override fun deliveryDisclaimerSectionIsGone(): Observable<Boolean> = this.deliveryDisclaimerSectionIsGone
override fun deliveryDisclaimerSectionIsGone(): Observable<Boolean> =
this.deliveryDisclaimerSectionIsGone

override fun onCleared() {
disposables.clear()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@
<string name="fpo_collected">Collected</string>
<string name="fpo_unattempted">Unattempted</string>
<string name="fpo_payment_schedule">Payment schedule</string>
<string name="fpo_you_have_selected_pledge_over_time_if_the_project_reaches_its_funding_goal_the_first_charge_of">You have selected Pledge Over Time. If the project reaches its funding goal, the first charge of $20 will be collected on March 15, 2024.</string>

</resources>