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

Commit 12a30d2d authored by Hasib Prince's avatar Hasib Prince
Browse files

fix: install button for paidapp

parent 9e00d5b1
Loading
Loading
Loading
Loading
Loading
+37 −23
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

package foundation.e.apps.ui.application

import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.Drawable
@@ -782,6 +783,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        }
    }

    @SuppressLint("SetTextI18n")
    private fun handleUnavaiable(
        installButton: MaterialButton,
        application: Application,
@@ -789,23 +791,41 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize: MaterialTextView
    ) {
        installButton.apply {
            installButton.disableInstallButton(R.string.install)
            installButton.text = ""
            binding.downloadInclude.progressBarInstall.visibility = View.VISIBLE

            appInfoFetchViewModel.isAppPurchased(application).observe(viewLifecycleOwner) {
                binding.downloadInclude.progressBarInstall.visibility = View.GONE
                enableInstallButton(R.string.install)
                text = when {
                    mainActivityViewModel.checkUnsupportedApplication(application) ->
                        getString(R.string.not_available)

                application.isFree -> getString(R.string.install)
                    application.isFree || application.isPurchased -> getString(R.string.install)
                    else -> application.price
                }
            }

            setOnClickListener {
                if (mainActivityViewModel.checkUnsupportedApplication(application, activity)) {
                    return@setOnClickListener
                }
                applicationIcon?.let {
                    if (application.isFree) {
                    if (application.isFree || application.isPurchased) {
                        disableInstallButton(R.string.cancel)
                        installApplication(application)
                    } else {
                        handleInstallClickForPaidApp(application)
                    }
                }
            }
        }
        downloadPB.visibility = View.GONE
        appSize.visibility = View.VISIBLE
    }

    private fun handleInstallClickForPaidApp(application: Application) {
        if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(application)) {
            ApplicationDialogFragment(
                title = getString(R.string.dialog_title_paid_app, application.name),
@@ -822,12 +842,6 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
            ).show(childFragmentManager, "ApplicationFragment")
        }
    }
                }
            }
        }
        downloadPB.visibility = View.GONE
        appSize.visibility = View.VISIBLE
    }

    private fun MaterialButton.disableInstallButton(buttonStringID: Int) {
        isEnabled = false
+11 −0
Original line number Diff line number Diff line
@@ -93,4 +93,15 @@
        app:cornerRadius="4dp"
        />

    <ProgressBar
        android:id="@+id/progressBarInstall"
        style="?android:attr/progressBarStyle"
        android:layout_width="16dp"
        android:layout_height="16dp"
        android:visibility="invisible"
        app:layout_constraintBottom_toBottomOf="@+id/installButton"
        app:layout_constraintLeft_toLeftOf="@+id/installButton"
        app:layout_constraintRight_toRightOf="@+id/installButton"
        app:layout_constraintTop_toTopOf="@+id/installButton" />

</androidx.constraintlayout.widget.ConstraintLayout>
 No newline at end of file