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

Commit f8abfc17 authored by Nishith  Khanna's avatar Nishith Khanna
Browse files

Make button color and states consistent in xml and compose

parent 71fc0879
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ package foundation.e.apps.ui.application

import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.text.Html
@@ -85,6 +84,7 @@ import kotlinx.coroutines.withContext
import timber.log.Timber
import java.util.Locale
import javax.inject.Inject
import foundation.e.elib.R as eR

@AndroidEntryPoint
class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
@@ -868,8 +868,8 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
    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))
        strokeColor = ContextCompat.getColorStateList(context, eR.color.e_disabled_color)
        setTextColor(context.getColor(eR.color.e_disabled_color))
        backgroundTintList =
            ContextCompat.getColorStateList(context, android.R.color.transparent)
    }
@@ -877,8 +877,8 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
    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))
        strokeColor = ContextCompat.getColorStateList(context, eR.color.e_accent)
        setTextColor(context.getColor(eR.color.e_accent))
        backgroundTintList =
            ContextCompat.getColorStateList(context, android.R.color.transparent)
    }
@@ -914,9 +914,9 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
            } else {
                getString(R.string.update)
            }
            setTextColor(Color.WHITE)
            setTextColor(ContextCompat.getColor(view.context, eR.color.e_background))
            backgroundTintList =
                ContextCompat.getColorStateList(view.context, R.color.colorAccent)
                ContextCompat.getColorStateList(view.context, eR.color.e_accent)
            setOnClickListener {
                if (mainActivityViewModel.checkUnsupportedApplication(application, activity)) {
                    return@setOnClickListener
@@ -941,9 +941,9 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize.visibility = View.VISIBLE
        installButton.apply {
            enableInstallButton(R.string.open)
            setTextColor(Color.WHITE)
            setTextColor(ContextCompat.getColor(view.context, eR.color.e_background))
            backgroundTintList =
                ContextCompat.getColorStateList(view.context, R.color.colorAccent)
                ContextCompat.getColorStateList(view.context, eR.color.e_accent)
            setOnClickListener {
                if (application.is_pwa) {
                    pwaManager.launchPwa(application)
+2 −1
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import foundation.e.apps.utils.disableInstallButton
import foundation.e.apps.utils.enableInstallButton
import timber.log.Timber
import javax.inject.Singleton
import foundation.e.elib.R as eR
@Singleton
class ApplicationListRVAdapter(
    private val applicationInstaller: ApplicationInstaller,
@@ -433,7 +434,7 @@ class ApplicationListRVAdapter(
                materialButton.enableInstallButton()
                materialButton.text = materialButton.context.getString(R.string.install)
                materialButton.strokeColor =
                    ContextCompat.getColorStateList(holder.itemView.context, R.color.light_grey)
                    ContextCompat.getColorStateList(holder.itemView.context, eR.color.e_disabled_color)
                applicationListItemBinding.progressBarInstall.visibility = View.GONE
            }
            else -> {
+1 −1
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ private fun PrimaryActionArea(
    ) {
        val accentColor = MaterialTheme.colorScheme.tertiary
        val labelTextColor = when {
            uiState.isFilledStyle -> Color.White
            uiState.isFilledStyle -> colorResource(eR.color.e_background)
            uiState.isDisabledStyle -> colorResource(eR.color.e_disabled_color)
            else -> accentColor
        }
+1 −1
Original line number Diff line number Diff line
@@ -223,7 +223,7 @@ private fun buildDefaultBlockedLabel(app: Application): ButtonLabel {

private fun buildStyleFor(status: Status, enabled: Boolean): InstallButtonStyle {
    return when {
        status == Status.QUEUED -> InstallButtonStyle.Disabled
        status == Status.QUEUED || status == Status.INSTALLING -> InstallButtonStyle.Disabled
        status == Status.INSTALLED || status == Status.UPDATABLE -> {
            if (enabled) InstallButtonStyle.AccentFill else InstallButtonStyle.Disabled
        }
+6 −6
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@

package foundation.e.apps.utils

import android.graphics.Color
import androidx.core.content.ContextCompat
import com.google.android.material.button.MaterialButton
import foundation.e.apps.R
import foundation.e.apps.data.enums.Status
import foundation.e.elib.R as eR

fun MaterialButton.disableInstallButton(status: Status? = null) {
    toggleEnableMaterialButton(false, status)
@@ -49,16 +49,16 @@ private fun MaterialButton.getBackgroundTintList(status: Status?) =
private fun MaterialButton.getStrokeColor(
    isEnabled: Boolean,
) = if (isEnabled) {
    ContextCompat.getColorStateList(this.context, R.color.colorAccent)
    ContextCompat.getColorStateList(this.context, eR.color.e_accent)
} else {
    ContextCompat.getColorStateList(this.context, R.color.light_grey)
    ContextCompat.getColorStateList(this.context, eR.color.e_disabled_color)
}

private fun MaterialButton.setButtonTextColor(isEnabled: Boolean, status: Status?) =
    if (isEnabled && (status == Status.INSTALLED || status == Status.UPDATABLE)) {
        setTextColor(Color.WHITE)
        setTextColor(context.getColor(eR.color.e_background))
    } else if (isEnabled) {
        setTextColor(context.getColor(R.color.colorAccent))
        setTextColor(context.getColor(eR.color.e_accent))
    } else {
        setTextColor(context.getColor(R.color.light_grey))
        setTextColor(context.getColor(eR.color.e_disabled_color))
    }