Skip to content

Commit

Permalink
Bugfix/60 crash in flight mode (#61)
Browse files Browse the repository at this point in the history
#60: Add Spanish
  • Loading branch information
Entreco authored Oct 2, 2019
1 parent d73acd3 commit 068def0
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class BetaActivity : ViewModelActivity(), DonateCallback, BetaAnimator.Swapper {

private fun handleDonation(result: MakeDonationResponse) {
when (result) {
is MakeDonationResponse.Success -> { /* Yeah, also consumed */ }
is MakeDonationResponse.Success -> { /* Yeah, also acknowledged */ }
is MakeDonationResponse.Purchased -> donateViewModel.onMakeDonationSuccess(result)
is MakeDonationResponse.AlreadyOwned -> failAndToast("Donation Already Owned")
is MakeDonationResponse.Cancelled -> failAndToast("Donation Cancelled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,23 @@ class DonateViewModel @Inject constructor(
}

private fun onFetchDonationsSuccess(): (FetchDonationsResponse) -> Unit = { result ->
requiresConsumption.set(result.needToBeConsumed)
canRemoveAds.set(!result.needToBeConsumed)
donations.clear()
donations.addAll(result.donations)
when (result) {
is FetchDonationsResponse.Ok -> {
requiresConsumption.set(result.needToBeConsumed)
canRemoveAds.set(!result.needToBeConsumed)
donations.clear()
donations.addAll(result.donations)
}
is FetchDonationsResponse.Error -> {
requiresConsumption.set(result.hasPreviouslyBoughtItems)
canRemoveAds.set(!result.hasPreviouslyBoughtItems)
donations.clear()
onFetchDonationsFailed().invoke(result.error)
}
}
}

private fun onFetchDonationsFailed(): (Throwable) -> Unit = {
requiresConsumption.set(false)
analytics.trackPurchaseFailed(productId, "FetchDonations failed")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SettingsActivity : ViewModelActivity(), DonateCallback {

private fun handleDonation(result: MakeDonationResponse) {
when (result) {
is MakeDonationResponse.Success -> { /* Yeah, also consumed */ }
is MakeDonationResponse.Success -> { /* Yeah, also acknowledged */ }
is MakeDonationResponse.Purchased -> donateViewModel.onMakeDonationSuccess(result)
is MakeDonationResponse.AlreadyOwned -> failAndToast("Donation Already Owned")
is MakeDonationResponse.Cancelled -> failAndToast("Donation Cancelled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
android:layout_margin="0dp"
android:onClick="@{() -> viewModel.swapStyle()}"
android:padding="0dp"
android:lines="1"
android:text="@string/settings_theme_desc" />
</RelativeLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ class GooglePlayConnection : PurchasesUpdatedListener {
// future to complete the purchase if you detect that it is still
// pending.
updater.invoke(MakeDonationResponse.Pending)
} else {
// State is Purchase.PurchaseState.UNSPECIFIED_STATE
// TODO: determine what to do here.
// For now -> handle as Pending -> votes will be added.
updater.invoke(MakeDonationResponse.Pending)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ class PlayStoreBillingRepository(
}

@WorkerThread
override fun fetchDonationsExclAds(done: (List<Donation>) -> Unit) {
override fun fetchDonationsExclAds(done: (List<Donation>) -> Unit, fail: (Throwable)->Unit) {
val donations = FetchDonationsData()
fetchProducts(donations, done)
fetchProducts(donations, done, fail)
}

@WorkerThread
override fun fetchDonationsInclAds(done: (List<Donation>) -> Unit) {
override fun fetchDonationsInclAds(done: (List<Donation>) -> Unit, fail: (Throwable)->Unit) {
val donations = FetchDonationsInclAdsData()
fetchProducts(donations, done)
fetchProducts(donations, done, fail)
}

@WorkerThread
private fun fetchProducts(donations: InAppProducts, done: (List<Donation>) -> Unit) {
private fun fetchProducts(donations: InAppProducts, done: (List<Donation>) -> Unit, fail: (Throwable)->Unit) {
val params = SkuDetailsParams.newBuilder()
params.setSkusList(donations.listOfProducts()).setType(BillingClient.SkuType.INAPP)
val client = playConnection.getClient()
Expand All @@ -59,7 +59,7 @@ class PlayStoreBillingRepository(
}
done(items)
} else {
throw Throwable("Unable to retrieve donations, $params")
fail(Throwable("Unable to retrieve donations, $params"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ import nl.entreco.domain.beta.Donation
/**
* Created by entreco on 09/02/2018.
*/
class FetchDonationsResponse(val donations: List<Donation>, val needToBeConsumed: Boolean)
sealed class FetchDonationsResponse{
data class Ok(val donations: List<Donation>, val needToBeConsumed: Boolean):FetchDonationsResponse()
data class Error(val error: Throwable, val hasPreviouslyBoughtItems: Boolean):FetchDonationsResponse()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ class FetchDonationsUsecase @Inject constructor(private val billingRepository: B

val hasPreviouslyBoughtItems = billingRepository.fetchPurchasedItems().isNotEmpty()
if (hasPreviouslyBoughtItems) {
billingRepository.fetchDonationsExclAds { donations ->
onUi { done(FetchDonationsResponse(donations.sortedBy { it.priceMicros }, true)) }
billingRepository.fetchDonationsExclAds({ donations ->
onUi { done(FetchDonationsResponse.Ok(donations.sortedBy { it.priceMicros }, true)) }
}) {
onUi { done(FetchDonationsResponse.Error(it, true)) }
}

} else {
billingRepository.fetchDonationsInclAds { donations ->
onUi { done(FetchDonationsResponse(donations.sortedBy { it.priceMicros }, false)) }
billingRepository.fetchDonationsInclAds({ donations ->
onUi { done(FetchDonationsResponse.Ok(donations.sortedBy { it.priceMicros }, false)) }
}) {
onUi { done(FetchDonationsResponse.Error(it, false)) }
}
}
}, fail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ interface BillingRepository {
fun unbind()

@WorkerThread
fun fetchDonationsExclAds(done: (List<Donation>)->Unit)
fun fetchDonationsExclAds(done: (List<Donation>)->Unit, fail: (Throwable)->Unit)

@WorkerThread
fun fetchDonationsInclAds(done: (List<Donation>)->Unit)
fun fetchDonationsInclAds(done: (List<Donation>)->Unit, fail: (Throwable)->Unit)

@WorkerThread
fun donate(donation: Donation, update:(MakeDonationResponse)->Unit)
Expand Down
2 changes: 1 addition & 1 deletion android/DartsScorecard/scripts/android_common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
versionCode config.versionCode
versionName config.versionName

resConfigs "en", "nl", "de"
resConfigs "en", "nl", "de", "es"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down

0 comments on commit 068def0

Please sign in to comment.