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 Original line Diff line number Diff line
@@ -468,7 +468,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize: MaterialTextView
        appSize: MaterialTextView
    ) {
    ) {
        installButton.apply {
        installButton.apply {
            text = getString(R.string.retry)
            enableInstallButton(R.string.retry)
            setOnClickListener {
            setOnClickListener {
                applicationIcon?.let {
                applicationIcon?.let {
                    mainActivityViewModel.getApplication(fusedApp, it)
                    mainActivityViewModel.getApplication(fusedApp, it)
@@ -504,7 +504,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        downloadPB: RelativeLayout,
        downloadPB: RelativeLayout,
        appSize: MaterialTextView
        appSize: MaterialTextView
    ) {
    ) {
        installButton.isEnabled = false
        installButton.disableInstallButton(R.string.installing)
        downloadPB.visibility = View.GONE
        downloadPB.visibility = View.GONE
        appSize.visibility = View.VISIBLE
        appSize.visibility = View.VISIBLE
    }
    }
@@ -516,6 +516,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize: MaterialTextView
        appSize: MaterialTextView
    ) {
    ) {
        installButton.apply {
        installButton.apply {
            enableInstallButton(R.string.cancel)
            text = getString(R.string.cancel)
            text = getString(R.string.cancel)
            setOnClickListener {
            setOnClickListener {
                mainActivityViewModel.cancelDownload(fusedApp)
                mainActivityViewModel.cancelDownload(fusedApp)
@@ -539,6 +540,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        downloadPB.visibility = View.GONE
        downloadPB.visibility = View.GONE
        appSize.visibility = View.VISIBLE
        appSize.visibility = View.VISIBLE
        installButton.apply {
        installButton.apply {
            enableInstallButton(R.string.cancel)
            text = getString(R.string.cancel)
            text = getString(R.string.cancel)
            setOnClickListener {
            setOnClickListener {
                mainActivityViewModel.cancelDownload(fusedApp)
                mainActivityViewModel.cancelDownload(fusedApp)
@@ -553,6 +555,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize: MaterialTextView
        appSize: MaterialTextView
    ) {
    ) {
        installButton.apply {
        installButton.apply {
            enableInstallButton(R.string.install)
            text = when {
            text = when {
                mainActivityViewModel.checkUnsupportedApplication(fusedApp) ->
                mainActivityViewModel.checkUnsupportedApplication(fusedApp) ->
                    getString(R.string.not_available)
                    getString(R.string.not_available)
@@ -565,6 +568,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
                }
                }
                applicationIcon?.let {
                applicationIcon?.let {
                    if (fusedApp.isFree) {
                    if (fusedApp.isFree) {
                        disableInstallButton(R.string.cancel)
                        installApplication(fusedApp, it)
                        installApplication(fusedApp, it)
                    } else {
                    } else {
                        if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) {
                        if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) {
@@ -590,6 +594,24 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize.visibility = View.VISIBLE
        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(
    private fun installApplication(
        fusedApp: FusedApp,
        fusedApp: FusedApp,
        it: ImageView
        it: ImageView
@@ -616,6 +638,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        appSize: MaterialTextView
        appSize: MaterialTextView
    ) {
    ) {
        installButton.apply {
        installButton.apply {
            enableInstallButton(R.string.not_available)
            text = if (mainActivityViewModel.checkUnsupportedApplication(fusedApp))
            text = if (mainActivityViewModel.checkUnsupportedApplication(fusedApp))
                getString(R.string.not_available)
                getString(R.string.not_available)
            else getString(R.string.update)
            else getString(R.string.update)
@@ -645,8 +668,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        downloadPB.visibility = View.GONE
        downloadPB.visibility = View.GONE
        appSize.visibility = View.VISIBLE
        appSize.visibility = View.VISIBLE
        installButton.apply {
        installButton.apply {
            isEnabled = true
            enableInstallButton(R.string.open)
            text = getString(R.string.open)
            setTextColor(Color.WHITE)
            setTextColor(Color.WHITE)
            backgroundTintList =
            backgroundTintList =
                ContextCompat.getColorStateList(view.context, R.color.colorAccent)
                ContextCompat.getColorStateList(view.context, R.color.colorAccent)