diff --git a/android/src/main/java/com/github/mustafaozhan/ccc/android/util/Extension.kt b/android/src/main/java/com/github/mustafaozhan/ccc/android/util/Extension.kt index 28f9ac13a8..ac7ff70176 100644 --- a/android/src/main/java/com/github/mustafaozhan/ccc/android/util/Extension.kt +++ b/android/src/main/java/com/github/mustafaozhan/ccc/android/util/Extension.kt @@ -144,4 +144,4 @@ fun List.toPurchaseHistoryList(): List = RemoveAdType.getBySku(purchaseHistoryRecord.skus.firstOrNull())?.let { PurchaseHistory(purchaseHistoryRecord.purchaseTime, it) } - } \ No newline at end of file + } diff --git a/backend/src/jvmMain/kotlin/com/github/mustafaozhan/ccc/backend/controller/ApiController.kt b/backend/src/jvmMain/kotlin/com/github/mustafaozhan/ccc/backend/controller/ApiController.kt index ceda9b1618..fa6a59d212 100644 --- a/backend/src/jvmMain/kotlin/com/github/mustafaozhan/ccc/backend/controller/ApiController.kt +++ b/backend/src/jvmMain/kotlin/com/github/mustafaozhan/ccc/backend/controller/ApiController.kt @@ -16,6 +16,8 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.isActive import kotlinx.coroutines.launch +private const val NUMBER_OF_REFRESH_IN_DAY = 3 + class ApiController( private val apiRepository: ApiRepository, private val offlineRatesRepository: OfflineRatesRepository @@ -26,7 +28,7 @@ class ApiController( kermit.d { "refreshing" } updateCurrencies() - delay(DAY) + delay(DAY / NUMBER_OF_REFRESH_IN_DAY) } } diff --git a/billing/src/main/kotlin/com/github/mustafaozhan/billing/BillingManager.kt b/billing/src/main/kotlin/com/github/mustafaozhan/billing/BillingManager.kt index ff05733304..11ae2992fb 100644 --- a/billing/src/main/kotlin/com/github/mustafaozhan/billing/BillingManager.kt +++ b/billing/src/main/kotlin/com/github/mustafaozhan/billing/BillingManager.kt @@ -78,10 +78,6 @@ class BillingManager(private val context: Context) : fun acknowledgePurchase() { acknowledgePurchaseParams?.let { billingClient.acknowledgePurchase(it, this) - } ?: run { - scope.launch { - _effect.emit(BillingEffect.SuccessfulPurchase) - } } } diff --git a/client/src/commonMain/kotlin/com/github/mustafaozhan/ccc/client/viewmodel/adremove/AdRemoveViewModel.kt b/client/src/commonMain/kotlin/com/github/mustafaozhan/ccc/client/viewmodel/adremove/AdRemoveViewModel.kt index ce1c096c65..b909df071c 100644 --- a/client/src/commonMain/kotlin/com/github/mustafaozhan/ccc/client/viewmodel/adremove/AdRemoveViewModel.kt +++ b/client/src/commonMain/kotlin/com/github/mustafaozhan/ccc/client/viewmodel/adremove/AdRemoveViewModel.kt @@ -10,11 +10,13 @@ import com.github.mustafaozhan.ccc.client.model.PurchaseHistory import com.github.mustafaozhan.ccc.client.model.RemoveAdData import com.github.mustafaozhan.ccc.client.model.RemoveAdType import com.github.mustafaozhan.ccc.client.util.calculateAdRewardEnd +import com.github.mustafaozhan.ccc.client.util.isRewardExpired import com.github.mustafaozhan.ccc.client.util.launchIgnored import com.github.mustafaozhan.ccc.common.settings.SettingsRepository import com.github.mustafaozhan.ccc.common.util.nowAsLong import com.github.mustafaozhan.logmob.kermit import com.github.mustafaozhan.scopemob.whether +import com.github.mustafaozhan.scopemob.whetherNot import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asSharedFlow @@ -50,16 +52,18 @@ class AdRemoveViewModel( } } - fun restorePurchase(purchaseHistoryList: List) = purchaseHistoryList .maxByOrNull { it.purchaseType.calculateAdRewardEnd(it.purchaseDate) - }?.whether { historyRecord -> - RemoveAdType.getSkuList().any { it == historyRecord.purchaseType.data.skuId } - }?.whether { it.purchaseDate > settingsRepository.adFreeEndDate } - ?.apply { - updateAddFreeDate(RemoveAdType.getBySku(purchaseType.data.skuId), this.purchaseDate) + }?.whether { purchaseHistory -> + RemoveAdType.getSkuList().any { it == purchaseHistory.purchaseType.data.skuId } + }?.whether { + purchaseDate > settingsRepository.adFreeEndDate + }?.whetherNot { + purchaseType.calculateAdRewardEnd(purchaseDate).isRewardExpired() + }?.apply { clientScope.launch { _effect.emit(AdRemoveEffect.AlreadyAdFree) } + updateAddFreeDate(RemoveAdType.getBySku(purchaseType.data.skuId), this.purchaseDate) } fun showLoadingView(shouldShow: Boolean) {