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

Commit aece2990 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Issue 178: Show alert dialog for unsupported apps

parent 73054f19
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

package foundation.e.apps

import android.app.AlertDialog
import android.content.Context
import android.graphics.Bitmap
import android.os.Build
import android.util.Base64
@@ -176,6 +178,29 @@ class MainActivityViewModel @Inject constructor(
        return false
    }

    /**
     * Handle various cases of unsupported apps here.
     * Returns true if the [fusedApp] is not supported by App Lounge.
     *
     * Pass [alertDialogContext] as null to prevent an alert dialog from being shown to the user.
     * In that case, this method simply works as a validation.
     *
     * Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/178
     */
    fun checkUnsupportedApplication(fusedApp: FusedApp, alertDialogContext: Context? = null): Boolean {
        if (!fusedApp.isFree && fusedApp.price.isBlank()) {
            alertDialogContext?.let { context ->
                AlertDialog.Builder(context).apply {
                    setTitle(R.string.unsupported_app_title)
                    setMessage(context.getString(R.string.unsupported_app_unreleased, fusedApp.name))
                    setPositiveButton(android.R.string.ok, null)
                }.show()
            }
            return true
        }
        return false
    }

    fun getApplication(app: FusedApp, imageView: ImageView?) {
        if (shouldShowPaidAppsSnackBar(app)) {
            return
+15 −2
Original line number Diff line number Diff line
@@ -406,8 +406,16 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
        appSize: MaterialTextView
    ) {
        installButton.apply {
            text = if (fusedApp.isFree) getString(R.string.install) else fusedApp.price
            text = when {
                mainActivityViewModel.checkUnsupportedApplication(fusedApp) ->
                    getString(R.string.not_available)
                fusedApp.isFree -> getString(R.string.install)
                else -> fusedApp.price
            }
            setOnClickListener {
                if (mainActivityViewModel.checkUnsupportedApplication(fusedApp, activity)) {
                    return@setOnClickListener
                }
                applicationIcon?.let {
                    if (fusedApp.isFree) {
                        mainActivityViewModel.getApplication(fusedApp, it)
@@ -439,11 +447,16 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
        appSize: MaterialTextView
    ) {
        installButton.apply {
            text = getString(R.string.update)
            text = if (mainActivityViewModel.checkUnsupportedApplication(fusedApp))
                getString(R.string.not_available)
            else getString(R.string.update)
            setTextColor(Color.WHITE)
            backgroundTintList =
                ContextCompat.getColorStateList(view.context, R.color.colorAccent)
            setOnClickListener {
                if (mainActivityViewModel.checkUnsupportedApplication(fusedApp, activity)) {
                    return@setOnClickListener
                }
                applicationIcon?.let {
                    mainActivityViewModel.getApplication(fusedApp, it)
                }
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu
                    this,
                    privacyInfoViewModel,
                    fdroidFetchViewModel,
                    mainActivityViewModel,
                    it,
                    pkgManagerModule,
                    pwaManagerModule,
+17 −2
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.facebook.shimmer.Shimmer.Direction.LEFT_TO_RIGHT
import com.facebook.shimmer.ShimmerDrawable
import com.google.android.material.snackbar.Snackbar
import foundation.e.apps.FdroidFetchViewModel
import foundation.e.apps.MainActivityViewModel
import foundation.e.apps.PrivacyInfoViewModel
import foundation.e.apps.R
import foundation.e.apps.api.cleanapk.CleanAPKInterface
@@ -56,6 +57,7 @@ class ApplicationListRVAdapter(
    private val fusedAPIInterface: FusedAPIInterface,
    private val privacyInfoViewModel: PrivacyInfoViewModel,
    private val fdroidFetchViewModel: FdroidFetchViewModel,
    private val mainActivityViewModel: MainActivityViewModel,
    private val currentDestinationId: Int,
    private val pkgManagerModule: PkgManagerModule,
    private val pwaManagerModule: PWAManagerModule,
@@ -302,12 +304,20 @@ class ApplicationListRVAdapter(
    ) {
        installButton.apply {
            isEnabled = true
            text = if (searchApp.isFree) context.getString(R.string.install) else searchApp.price
            text = when {
                mainActivityViewModel.checkUnsupportedApplication(searchApp) ->
                    context.getString(R.string.not_available)
                searchApp.isFree -> context.getString(R.string.install)
                else -> searchApp.price
            }
            setTextColor(context.getColor(R.color.colorAccent))
            backgroundTintList =
                ContextCompat.getColorStateList(view.context, android.R.color.transparent)
            strokeColor = ContextCompat.getColorStateList(view.context, R.color.colorAccent)
            setOnClickListener {
                if (mainActivityViewModel.checkUnsupportedApplication(searchApp, context)) {
                    return@setOnClickListener
                }
                if (searchApp.isFree) {
                    installApplication(searchApp, appIcon)
                } else {
@@ -323,11 +333,16 @@ class ApplicationListRVAdapter(
    ) {
        installButton.apply {
            isEnabled = true
            text = context.getString(R.string.update)
            text = if (mainActivityViewModel.checkUnsupportedApplication(searchApp))
                context.getString(R.string.not_available)
            else context.getString(R.string.update)
            setTextColor(Color.WHITE)
            backgroundTintList = ContextCompat.getColorStateList(view.context, R.color.colorAccent)
            strokeColor = ContextCompat.getColorStateList(view.context, R.color.colorAccent)
            setOnClickListener {
                if (mainActivityViewModel.checkUnsupportedApplication(searchApp, context)) {
                    return@setOnClickListener
                }
                installApplication(searchApp, appIcon)
            }
        }
+17 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import coil.load
import com.facebook.shimmer.Shimmer
import com.facebook.shimmer.ShimmerDrawable
import com.google.android.material.snackbar.Snackbar
import foundation.e.apps.MainActivityViewModel
import foundation.e.apps.R
import foundation.e.apps.api.cleanapk.CleanAPKInterface
import foundation.e.apps.api.fused.FusedAPIInterface
@@ -46,6 +47,7 @@ class HomeChildRVAdapter(
    private val fusedAPIInterface: FusedAPIInterface,
    private val pkgManagerModule: PkgManagerModule,
    private val pwaManagerModule: PWAManagerModule,
    private val mainActivityViewModel: MainActivityViewModel,
    private val user: User,
    private val paidAppHandler: ((FusedApp) -> Unit)? = null
) : ListAdapter<FusedApp, HomeChildRVAdapter.ViewHolder>(HomeChildFusedAppDiffUtil()) {
@@ -118,21 +120,30 @@ class HomeChildRVAdapter(
                }
                Status.UPDATABLE -> {
                    installButton.apply {
                        text = context.getString(R.string.update)
                        text = if (mainActivityViewModel.checkUnsupportedApplication(homeApp))
                            context.getString(R.string.not_available)
                        else context.getString(R.string.update)
                        setTextColor(Color.WHITE)
                        backgroundTintList =
                            ContextCompat.getColorStateList(view.context, R.color.colorAccent)
                        strokeColor =
                            ContextCompat.getColorStateList(view.context, R.color.colorAccent)
                        setOnClickListener {
                            if (mainActivityViewModel.checkUnsupportedApplication(homeApp, context)) {
                                return@setOnClickListener
                            }
                            installApplication(homeApp, appIcon)
                        }
                    }
                }
                Status.UNAVAILABLE -> {
                    installButton.apply {
                        text =
                            if (homeApp.isFree) context.getString(R.string.install) else homeApp.price
                        text = when {
                            mainActivityViewModel.checkUnsupportedApplication(homeApp) ->
                                context.getString(R.string.not_available)
                            homeApp.isFree -> context.getString(R.string.install)
                            else -> homeApp.price
                        }
                        setTextColor(context.getColor(R.color.colorAccent))
                        backgroundTintList = ContextCompat.getColorStateList(
                            view.context,
@@ -141,6 +152,9 @@ class HomeChildRVAdapter(
                        strokeColor =
                            ContextCompat.getColorStateList(view.context, R.color.colorAccent)
                        setOnClickListener {
                            if (mainActivityViewModel.checkUnsupportedApplication(homeApp, context)) {
                                return@setOnClickListener
                            }
                            if (homeApp.isFree) {
                                installApplication(homeApp, appIcon)
                            } else {
Loading