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

Commit 17b11363 authored by Hasib Prince's avatar Hasib Prince
Browse files

instant install button feedback added for app detail page

parent 46381d43
Loading
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -468,7 +468,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize: MaterialTextView
    ) {
        installButton.apply {
            text = getString(R.string.retry)
            enableInstallButton(R.string.retry)
            setOnClickListener {
                applicationIcon?.let {
                    mainActivityViewModel.getApplication(fusedApp, it)
@@ -504,7 +504,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        downloadPB: RelativeLayout,
        appSize: MaterialTextView
    ) {
        installButton.isEnabled = false
        installButton.disableInstallButton(R.string.installing)
        downloadPB.visibility = View.GONE
        appSize.visibility = View.VISIBLE
    }
@@ -516,6 +516,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize: MaterialTextView
    ) {
        installButton.apply {
            enableInstallButton(R.string.cancel)
            text = getString(R.string.cancel)
            setOnClickListener {
                mainActivityViewModel.cancelDownload(fusedApp)
@@ -539,6 +540,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        downloadPB.visibility = View.GONE
        appSize.visibility = View.VISIBLE
        installButton.apply {
            enableInstallButton(R.string.cancel)
            text = getString(R.string.cancel)
            setOnClickListener {
                mainActivityViewModel.cancelDownload(fusedApp)
@@ -553,6 +555,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize: MaterialTextView
    ) {
        installButton.apply {
            enableInstallButton(R.string.install)
            text = when {
                mainActivityViewModel.checkUnsupportedApplication(fusedApp) ->
                    getString(R.string.not_available)
@@ -565,6 +568,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
                }
                applicationIcon?.let {
                    if (fusedApp.isFree) {
                        disableInstallButton(R.string.cancel)
                        installApplication(fusedApp, it)
                    } else {
                        if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) {
@@ -590,6 +594,24 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize.visibility = View.VISIBLE
    }

    private fun MaterialButton.disableInstallButton(buttonStringID: Int) {
        isEnabled = false
        text = context.getString(buttonStringID)
        strokeColor = ContextCompat.getColorStateList(context, R.color.light_grey)
        setTextColor(context.getColor(R.color.light_grey))
        backgroundTintList =
            ContextCompat.getColorStateList(context, android.R.color.transparent)
    }

    private fun MaterialButton.enableInstallButton(buttonStringID: Int) {
        isEnabled = true
        text = context.getString(buttonStringID)
        strokeColor = ContextCompat.getColorStateList(context, R.color.colorAccent)
        setTextColor(context.getColor(R.color.colorAccent))
        backgroundTintList =
            ContextCompat.getColorStateList(context, android.R.color.transparent)
    }

    private fun installApplication(
        fusedApp: FusedApp,
        it: ImageView
@@ -616,6 +638,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize: MaterialTextView
    ) {
        installButton.apply {
            enableInstallButton(R.string.not_available)
            text = if (mainActivityViewModel.checkUnsupportedApplication(fusedApp))
                getString(R.string.not_available)
            else getString(R.string.update)
@@ -645,8 +668,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        downloadPB.visibility = View.GONE
        appSize.visibility = View.VISIBLE
        installButton.apply {
            isEnabled = true
            text = getString(R.string.open)
            enableInstallButton(R.string.open)
            setTextColor(Color.WHITE)
            backgroundTintList =
                ContextCompat.getColorStateList(view.context, R.color.colorAccent)