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

Commit 06046ac7 authored by dev-12's avatar dev-12
Browse files

Merge branch '2807-handle-restricted-apps-correctly' into 'main'

prevent purchase screen trigger for restricted apps

See merge request !623
parents ad981196 0d1a62ac
Loading
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -23,16 +23,16 @@ import com.aurora.gplayapi.exceptions.InternalException
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.enums.Status
import foundation.e.apps.data.enums.Type
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.application.UpdatesDao
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.enums.Status
import foundation.e.apps.data.enums.Type
import foundation.e.apps.data.enums.User
import foundation.e.apps.data.install.AppManager
import foundation.e.apps.data.install.models.AppInstall
import foundation.e.apps.data.login.AuthObject
import foundation.e.apps.data.playstore.utils.GplayHttpRequestException
import foundation.e.apps.data.preference.AppLoungeDataStore
import foundation.e.apps.domain.ValidateAppAgeLimitUseCase
@@ -67,6 +67,9 @@ class AppInstallProcessor @Inject constructor(
    @Inject
    lateinit var downloadManager: DownloadManagerUtils

    @Inject
    lateinit var appManager: AppManager

    private var isItUpdateWork = false

    companion object {
@@ -202,6 +205,10 @@ class AppInstallProcessor @Inject constructor(
        try {
            updateFusedDownloadWithAppDownloadLink(appInstall)
        } catch (e: InternalException.AppNotPurchased) {
            if (appInstall.isFree) {
                handleAppRestricted(appInstall)
                return false
            }
            appInstallComponents.appManagerWrapper.addFusedDownloadPurchaseNeeded(appInstall)
            EventBus.invokeEvent(AppEvent.AppPurchaseEvent(appInstall))
            return false
@@ -225,6 +232,12 @@ class AppInstallProcessor @Inject constructor(
        return true
    }

    private suspend fun handleAppRestricted(appInstall: AppInstall) {
        EventBus.invokeEvent(AppEvent.AppRestrictedOrUnavailable(appInstall))
        appManager.addDownload(appInstall)
        appManager.updateUnavailable(appInstall)
    }

    private suspend fun handleUpdateDownloadError(
        appInstall: AppInstall,
        message: String,
+14 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import foundation.e.apps.data.login.exceptions.GPlayValidationException
import foundation.e.apps.databinding.ActivityMainBinding
import foundation.e.apps.install.updates.UpdatesNotifier
import foundation.e.apps.ui.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.ui.error.AppUnavailableDialogDirections
import foundation.e.apps.ui.purchase.AppPurchaseFragmentDirections
import foundation.e.apps.ui.settings.SettingsFragment
import foundation.e.apps.ui.setup.signin.SignInViewModel
@@ -227,6 +228,10 @@ class MainActivity : AppCompatActivity() {
                    observeInvalidAuth()
                }

                launch {
                    observeAppUnavailable()
                }

                launch {
                    observeTooManyRequests()
                }
@@ -508,6 +513,15 @@ class MainActivity : AppCompatActivity() {
        }
    }

    private suspend fun observeAppUnavailable() {
        EventBus.events.filterIsInstance<AppEvent.AppRestrictedOrUnavailable>()
            .collectLatest { event ->
                val appName = event.appInstall.name
                val action = AppUnavailableDialogDirections.actionGlobalAppUnavailable(appName)
                findNavController(R.id.fragment).navigate(action)
            }
    }

    private fun validatedAuthObject(appEvent: AppEvent) {
        val data = appEvent.data as String
        if (data.isNotBlank()) {
+24 −0
Original line number Diff line number Diff line
package foundation.e.apps.ui.error

import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import foundation.e.apps.R

class AppUnavailableDialog : DialogFragment() {

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        return MaterialAlertDialogBuilder(requireContext())
            .setTitle(R.string.app_unavailable_title)
            .setMessage(R.string.app_unavailable_description)
            .setCancelable(false)
            .setPositiveButton(
                android.R.string.ok,
                { dialog, _ ->
                    dialog.dismiss()
                }
            )
            .create()
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ sealed class AppEvent(val data: Any) {
    class ErrorMessageEvent(stringResourceId: Int) : AppEvent(stringResourceId)
    class ErrorMessageDialogEvent(stringResourceId: Int) : AppEvent(stringResourceId)
    class AppPurchaseEvent(appInstall: AppInstall) : AppEvent(appInstall)
    class AppRestrictedOrUnavailable(val appInstall: AppInstall) : AppEvent(appInstall)
    class NoInternetEvent(isInternetAvailable: Boolean) : AppEvent(isInternetAvailable)
    class TooManyRequests : AppEvent(Unit)
    class AgeLimitRestrictionEvent(
+12 −0
Original line number Diff line number Diff line
@@ -252,4 +252,16 @@
        android:id="@+id/action_global_appPurchaseFragment"
        app:destination="@id/appPurchaseFragment" />

    <dialog
        android:id="@+id/appUnavailable"
        android:name="foundation.e.apps.ui.error.AppUnavailableDialog"
        tools:label="app_unavailable">
        <argument
            android:name="app_name"
            app:argType="string" />
    </dialog>
    <action
        android:id="@+id/action_global_app_unavailable"
        app:destination="@id/appUnavailable" />

</navigation>
Loading