Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1f29f27 authored by dev-12's avatar dev-12
Browse files

Merge branch '3776-reduce-load-on-annom-token' into 'main'

Avoid retrieving the purchase status of paid apps while in anonymous mode.

See merge request !621
parents 6edbcc49 ff4ce976
Loading
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -159,8 +159,7 @@ class PlayStoreRepository @Inject constructor(
        withContext(Dispatchers.IO) {
            var appDetails: List<GplayApp> = getAppDetailsHelper().getAppByPackageName(packageNames)

            if (!isEmulator() && appDetails.any { it.versionCode == 0L }
                && authenticatorRepository.getGPlayAuthOrThrow().isAnonymous) {
            if (!isEmulator() && appDetails.any { it.versionCode == 0L } && isAnonymousUser()) {
                // Google Play returns limited result ( i.e. version code being 0) with a stale token,
                // so we need to refresh authentication to get a new token.
                Timber.i("Version code is 0.")
@@ -182,9 +181,7 @@ class PlayStoreRepository @Inject constructor(
        withContext(Dispatchers.IO) {
            var appDetails: GplayApp = getAppDetailsHelper().getAppByPackageName(packageName)

            if (!isEmulator() && appDetails.versionCode == 0L
                && authenticatorRepository.getGPlayAuthOrThrow().isAnonymous
            ) {
            if (!isEmulator() && appDetails.versionCode == 0L && isAnonymousUser()) {
                // Google Play returns limited result ( i.e. version code being 0) with a stale token,
                // so we need to refresh authentication to get a new token.
                Timber.i("Version code is 0 for ${appDetails.packageName}.")
@@ -281,6 +278,8 @@ class PlayStoreRepository @Inject constructor(
        buildList { addAll(purchaseHelper.purchase(idOrPackageName, version, offer)) }
    }

    fun isAnonymousUser() = authenticatorRepository.getGPlayAuthOrThrow().isAnonymous

    suspend fun getOnDemandModule(
        packageName: String,
        moduleName: String,
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ class AppInfoFetchViewModel @Inject constructor(
        emit(authorName)
    }

    fun isAnonymousUser() = gPlayRepository.isAnonymousUser()

    fun isAppPurchased(app: Application): LiveData<Boolean> {
        return liveData {
            try {
+9 −1
Original line number Diff line number Diff line
@@ -86,7 +86,6 @@ import timber.log.Timber
import java.util.Locale
import javax.inject.Inject


@AndroidEntryPoint
class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {

@@ -228,6 +227,15 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
            progressBarInstall.visibility = View.VISIBLE
        }

        if (appInfoFetchViewModel.isAnonymousUser() && !application.isFree) {
            handleInstallStatus(Status.UNAVAILABLE, binding.root, application)
            binding.downloadInclude.apply {
                progressBarInstall.visibility = View.GONE
                installButton.text = application.price
            }
            return
        }

        if (!isFreeOrAlreadyPurchased(application)) {
            appInfoFetchViewModel.isAppPurchased(application).observe(viewLifecycleOwner) {
                binding.downloadInclude.progressBarInstall.visibility = View.GONE
+6 −0
Original line number Diff line number Diff line
@@ -441,6 +441,12 @@ class ApplicationListRVAdapter(
                materialButton.disableInstallButton()
                materialButton.text = ""
                applicationListItemBinding.progressBarInstall.visibility = View.VISIBLE
                if (appInfoFetchViewModel.isAnonymousUser()) {
                    materialButton.enableInstallButton()
                    applicationListItemBinding.progressBarInstall.visibility = View.GONE
                    materialButton.text = searchApp.price
                    return
                }
                holder.isPurchasedLiveData = appInfoFetchViewModel.isAppPurchased(searchApp)
                if (lifecycleOwner == null) {
                    return