From a725c6b317b04c5318e9cd368505f1e89841e555 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Sat, 17 Sep 2022 10:36:18 +0600 Subject: [PATCH 1/4] space for title is increased in app item layout --- app/src/main/res/layout/application_list_item.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/layout/application_list_item.xml b/app/src/main/res/layout/application_list_item.xml index 0984cf0a6..2205bd5b3 100644 --- a/app/src/main/res/layout/application_list_item.xml +++ b/app/src/main/res/layout/application_list_item.xml @@ -68,7 +68,6 @@ android:textColor="?android:textColorPrimary" android:textSize="16sp" app:layout_constraintLeft_toRightOf="@+id/app_icon_card" - app:layout_constraintRight_toLeftOf="@+id/installButton" app:layout_constraintTop_toTopOf="@+id/app_icon_card" tools:text="Google Chrome - Fast and Secured" /> @@ -96,7 +95,7 @@ android:progressBackgroundTint="@color/colorAccent" android:progressTint="@color/colorAccent" android:stepSize="0.1" - app:layout_constraintBottom_toBottomOf="@id/app_icon_card" + app:layout_constraintTop_toBottomOf="@+id/installButton" app:layout_constraintLeft_toLeftOf="@+id/app_title" /> + app:layout_constraintTop_toBottomOf="@+id/app_title" /> Date: Sun, 18 Sep 2022 10:22:05 +0600 Subject: [PATCH 2/4] instant visual feedback added for install button --- .../model/ApplicationListRVAdapter.kt | 17 +++++++++----- .../e/apps/home/model/HomeChildRVAdapter.kt | 23 +++++++++++-------- .../e/apps/util/LiveDataTestUtil.kt | 2 -- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt b/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt index ecc072724..f47cbd67b 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt @@ -403,12 +403,7 @@ class ApplicationListRVAdapter( private fun ApplicationListItemBinding.handleInstalling(view: View, holder: ViewHolder) { installButton.apply { - isEnabled = false - text = context.getString(R.string.installing) - setTextColor(context.getColor(R.color.light_grey)) - backgroundTintList = - ContextCompat.getColorStateList(view.context, android.R.color.transparent) - strokeColor = ContextCompat.getColorStateList(view.context, R.color.light_grey) + disableInstallButton(this, R.string.installing) } progressBarInstall.visibility = View.GONE } @@ -448,6 +443,7 @@ class ApplicationListRVAdapter( return@setOnClickListener } if (searchApp.isFree || searchApp.isPurchased) { + disableInstallButton(view, R.string.cancel) installApplication(searchApp, appIcon) } else { paidAppHandler?.invoke(searchApp) @@ -456,6 +452,15 @@ class ApplicationListRVAdapter( } } + private fun MaterialButton.disableInstallButton(view: View, buttonString: Int) { + isEnabled = false + text = context.getString(buttonString) + strokeColor = getStrokeColor(isEnabled, view) + setButtonTextColor(isEnabled) + backgroundTintList = + ContextCompat.getColorStateList(view.context, android.R.color.transparent) + } + private fun updateUIByPaymentType( searchApp: FusedApp, materialButton: MaterialButton, diff --git a/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt b/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt index a7de334ff..640fe9439 100644 --- a/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt @@ -162,15 +162,7 @@ class HomeChildRVAdapter( private fun HomeChildListItemBinding.handleInstalling(view: View) { installButton.apply { - isEnabled = false - setTextColor(context.getColor(R.color.light_grey)) - text = context.getString(R.string.installing) - backgroundTintList = ContextCompat.getColorStateList( - view.context, - android.R.color.transparent - ) - strokeColor = - ContextCompat.getColorStateList(view.context, R.color.light_grey) + disableInstallButton(this, R.string.installing) } progressBarInstall.visibility = View.GONE } @@ -215,6 +207,7 @@ class HomeChildRVAdapter( return@setOnClickListener } if (homeApp.isFree) { + disableInstallButton(view, R.string.cancel) installApplication(homeApp, appIcon) } else { paidAppHandler?.invoke(homeApp) @@ -223,6 +216,18 @@ class HomeChildRVAdapter( } } + private fun MaterialButton.disableInstallButton(view: View, buttonString: Int) { + isEnabled = false + text = context.getString(buttonString) + setTextColor(context.getColor(R.color.light_grey)) + backgroundTintList = ContextCompat.getColorStateList( + view.context, + android.R.color.transparent + ) + strokeColor = + ContextCompat.getColorStateList(view.context, R.color.light_grey) + } + private fun HomeChildListItemBinding.handleUpdatable( view: View, homeApp: FusedApp diff --git a/app/src/test/java/foundation/e/apps/util/LiveDataTestUtil.kt b/app/src/test/java/foundation/e/apps/util/LiveDataTestUtil.kt index 679cc04e2..58e478c34 100644 --- a/app/src/test/java/foundation/e/apps/util/LiveDataTestUtil.kt +++ b/app/src/test/java/foundation/e/apps/util/LiveDataTestUtil.kt @@ -20,8 +20,6 @@ package foundation.e.apps.util import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import kotlinx.coroutines.delay -import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit /** * Gets the value of a [LiveData] or waits for it to have one, with a timeout. -- GitLab From 17b1136350baa8d595eb6ed2ceb50f5f627a7f47 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Mon, 19 Sep 2022 10:34:31 +0600 Subject: [PATCH 3/4] instant install button feedback added for app detail page --- .../e/apps/application/ApplicationFragment.kt | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt index 365a5473e..9dac14ef5 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -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) -- GitLab From c196bb302a1cf522d754a1d88c842d89562b24de Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Tue, 20 Sep 2022 17:43:02 +0600 Subject: [PATCH 4/4] Refactored state handling of install button --- .../{model => }/ApplicationDiffUtil.kt | 2 +- .../ApplicationListFragment.kt | 1 - .../{model => }/ApplicationListRVAdapter.kt | 92 +++++++------------ .../e/apps/home/model/HomeChildRVAdapter.kt | 66 ++++--------- .../e/apps/search/SearchFragment.kt | 2 +- .../e/apps/updates/UpdatesFragment.kt | 2 +- .../e/apps/utils/MaterialButtonUtils.kt | 63 +++++++++++++ 7 files changed, 116 insertions(+), 112 deletions(-) rename app/src/main/java/foundation/e/apps/applicationlist/{model => }/ApplicationDiffUtil.kt (98%) rename app/src/main/java/foundation/e/apps/applicationlist/{model => }/ApplicationListRVAdapter.kt (82%) create mode 100644 app/src/main/java/foundation/e/apps/utils/MaterialButtonUtils.kt diff --git a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationDiffUtil.kt b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationDiffUtil.kt similarity index 98% rename from app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationDiffUtil.kt rename to app/src/main/java/foundation/e/apps/applicationlist/ApplicationDiffUtil.kt index 69e4b7935..e1c2c3a65 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationDiffUtil.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationDiffUtil.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package foundation.e.apps.applicationlist.model +package foundation.e.apps.applicationlist import androidx.recyclerview.widget.DiffUtil import foundation.e.apps.api.fused.data.FusedApp diff --git a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt index 0158c66ea..371808ea5 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt @@ -40,7 +40,6 @@ import foundation.e.apps.api.ResultSupreme import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.application.subFrags.ApplicationDialogFragment -import foundation.e.apps.applicationlist.model.ApplicationListRVAdapter import foundation.e.apps.databinding.FragmentApplicationListBinding import foundation.e.apps.manager.download.data.DownloadProgress import foundation.e.apps.manager.pkg.PkgManagerModule diff --git a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListRVAdapter.kt similarity index 82% rename from app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt rename to app/src/main/java/foundation/e/apps/applicationlist/ApplicationListRVAdapter.kt index f47cbd67b..e1897ab3c 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListRVAdapter.kt @@ -1,24 +1,22 @@ /* - * Apps Quickly and easily install Android apps onto your device! - * Copyright (C) 2021 E FOUNDATION + * Copyright (C) 2022 ECORP * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -package foundation.e.apps.applicationlist.model +package foundation.e.apps.applicationlist -import android.graphics.Color import android.util.Log import android.view.LayoutInflater import android.view.View @@ -45,11 +43,12 @@ import foundation.e.apps.R import foundation.e.apps.api.cleanapk.CleanAPKInterface import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp -import foundation.e.apps.applicationlist.ApplicationListFragmentDirections import foundation.e.apps.databinding.ApplicationListItemBinding import foundation.e.apps.manager.pkg.InstallerService import foundation.e.apps.search.SearchFragmentDirections import foundation.e.apps.updates.UpdatesFragmentDirections +import foundation.e.apps.utils.disableInstallButton +import foundation.e.apps.utils.enableInstallButton import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User @@ -244,19 +243,19 @@ class ApplicationListRVAdapter( showMore.visibility = View.INVISIBLE when (searchApp.status) { Status.INSTALLED -> { - handleInstalled(view, searchApp) + handleInstalled(searchApp) } Status.UPDATABLE -> { - handleUpdatable(view, searchApp) + handleUpdatable(searchApp) } Status.UNAVAILABLE -> { - handleUnavailable(view, searchApp, holder) + handleUnavailable(searchApp, holder) } Status.QUEUED, Status.AWAITING, Status.DOWNLOADING, Status.DOWNLOADED -> { - handleDownloading(view, searchApp) + handleDownloading(searchApp) } Status.INSTALLING, Status.UNINSTALLING -> { - handleInstalling(view, holder) + handleInstalling() } Status.BLOCKED -> { handleBlocked(view) @@ -293,10 +292,8 @@ class ApplicationListRVAdapter( searchApp: FusedApp ) { installButton.apply { - isEnabled = !faultyAppResult.first + if (faultyAppResult.first) disableInstallButton() else enableInstallButton() text = getInstallationIssueText(faultyAppResult, view) - strokeColor = getStrokeColor(isEnabled, view) - setButtonTextColor(isEnabled) backgroundTintList = ContextCompat.getColorStateList(view.context, android.R.color.transparent) setOnClickListener { @@ -401,24 +398,20 @@ class ApplicationListRVAdapter( appPrivacyScore.visibility = View.VISIBLE } - private fun ApplicationListItemBinding.handleInstalling(view: View, holder: ViewHolder) { + private fun ApplicationListItemBinding.handleInstalling() { installButton.apply { - disableInstallButton(this, R.string.installing) + disableInstallButton() + text = context.getText(R.string.installing) } progressBarInstall.visibility = View.GONE } private fun ApplicationListItemBinding.handleDownloading( - view: View, searchApp: FusedApp, ) { installButton.apply { - isEnabled = true + enableInstallButton() text = context.getString(R.string.cancel) - setTextColor(context.getColor(R.color.colorAccent)) - backgroundTintList = - ContextCompat.getColorStateList(view.context, android.R.color.transparent) - strokeColor = ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { cancelDownload(searchApp) } @@ -428,22 +421,18 @@ class ApplicationListRVAdapter( } private fun ApplicationListItemBinding.handleUnavailable( - view: View, searchApp: FusedApp, holder: ViewHolder, ) { installButton.apply { updateUIByPaymentType(searchApp, this, this@handleUnavailable, holder) - 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 || searchApp.isPurchased) { - disableInstallButton(view, R.string.cancel) + disableInstallButton() + text = context.getText(R.string.cancel) installApplication(searchApp, appIcon) } else { paidAppHandler?.invoke(searchApp) @@ -452,15 +441,6 @@ class ApplicationListRVAdapter( } } - private fun MaterialButton.disableInstallButton(view: View, buttonString: Int) { - isEnabled = false - text = context.getString(buttonString) - strokeColor = getStrokeColor(isEnabled, view) - setButtonTextColor(isEnabled) - backgroundTintList = - ContextCompat.getColorStateList(view.context, android.R.color.transparent) - } - private fun updateUIByPaymentType( searchApp: FusedApp, materialButton: MaterialButton, @@ -469,17 +449,17 @@ class ApplicationListRVAdapter( ) { when { mainActivityViewModel.checkUnsupportedApplication(searchApp) -> { - materialButton.isEnabled = true + materialButton.enableInstallButton() materialButton.text = materialButton.context.getString(R.string.not_available) applicationListItemBinding.progressBarInstall.visibility = View.GONE } searchApp.isFree -> { - materialButton.isEnabled = true + materialButton.enableInstallButton() materialButton.text = materialButton.context.getString(R.string.install) applicationListItemBinding.progressBarInstall.visibility = View.GONE } else -> { - materialButton.isEnabled = false + materialButton.disableInstallButton() materialButton.text = "" applicationListItemBinding.progressBarInstall.visibility = View.VISIBLE holder.isPurchasedLiveData = appInfoFetchViewModel.isAppPurchased(searchApp) @@ -487,7 +467,7 @@ class ApplicationListRVAdapter( return } holder.isPurchasedLiveData.observe(lifecycleOwner!!) { - materialButton.isEnabled = true + materialButton.enableInstallButton() applicationListItemBinding.progressBarInstall.visibility = View.GONE materialButton.text = if (it) materialButton.context.getString(R.string.install) else searchApp.price @@ -497,17 +477,13 @@ class ApplicationListRVAdapter( } private fun ApplicationListItemBinding.handleUpdatable( - view: View, searchApp: FusedApp ) { installButton.apply { - isEnabled = true + enableInstallButton(Status.UPDATABLE) 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 @@ -519,15 +495,11 @@ class ApplicationListRVAdapter( } private fun ApplicationListItemBinding.handleInstalled( - view: View, searchApp: FusedApp, ) { installButton.apply { - isEnabled = true + enableInstallButton(Status.INSTALLED) text = context.getString(R.string.open) - setTextColor(Color.WHITE) - backgroundTintList = ContextCompat.getColorStateList(view.context, R.color.colorAccent) - strokeColor = ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { if (searchApp.is_pwa) { mainActivityViewModel.launchPwa(searchApp) diff --git a/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt b/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt index 640fe9439..3309c595b 100644 --- a/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt @@ -18,7 +18,6 @@ package foundation.e.apps.home.model -import android.graphics.Color import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -41,6 +40,8 @@ import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.databinding.HomeChildListItemBinding import foundation.e.apps.home.HomeFragmentDirections +import foundation.e.apps.utils.disableInstallButton +import foundation.e.apps.utils.enableInstallButton import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User @@ -108,13 +109,13 @@ class HomeChildRVAdapter( handleUpdatable(view, homeApp) } Status.UNAVAILABLE -> { - handleUnavailable(homeApp, holder, view) + handleUnavailable(homeApp, holder) } Status.QUEUED, Status.AWAITING, Status.DOWNLOADING, Status.DOWNLOADED -> { handleQueued(view, homeApp) } Status.INSTALLING, Status.UNINSTALLING -> { - handleInstalling(view) + handleInstalling() } Status.BLOCKED -> { handleBlocked(view) @@ -131,14 +132,8 @@ class HomeChildRVAdapter( homeApp: FusedApp ) { installButton.apply { + enableInstallButton() text = view.context.getString(R.string.retry) - setTextColor(context.getColor(R.color.colorAccent)) - backgroundTintList = ContextCompat.getColorStateList( - view.context, - android.R.color.transparent - ) - strokeColor = - ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { installApplication(homeApp, appIcon) } @@ -147,6 +142,7 @@ class HomeChildRVAdapter( } private fun HomeChildListItemBinding.handleBlocked(view: View) { + installButton.enableInstallButton() installButton.setOnClickListener { val errorMsg = when (mainActivityViewModel.getUser()) { User.ANONYMOUS, @@ -160,9 +156,10 @@ class HomeChildRVAdapter( progressBarInstall.visibility = View.GONE } - private fun HomeChildListItemBinding.handleInstalling(view: View) { + private fun HomeChildListItemBinding.handleInstalling() { installButton.apply { - disableInstallButton(this, R.string.installing) + disableInstallButton() + text = context.getString(R.string.installing) } progressBarInstall.visibility = View.GONE } @@ -172,6 +169,7 @@ class HomeChildRVAdapter( homeApp: FusedApp ) { installButton.apply { + enableInstallButton() text = context.getString(R.string.cancel) setTextColor(context.getColor(R.color.colorAccent)) backgroundTintList = ContextCompat.getColorStateList( @@ -191,23 +189,16 @@ class HomeChildRVAdapter( private fun HomeChildListItemBinding.handleUnavailable( homeApp: FusedApp, holder: ViewHolder, - view: View ) { installButton.apply { updateUIByPaymentType(homeApp, this, holder.binding) - 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(homeApp, context)) { return@setOnClickListener } if (homeApp.isFree) { - disableInstallButton(view, R.string.cancel) + disableInstallButton() + text = context.getString(R.string.cancel) installApplication(homeApp, appIcon) } else { paidAppHandler?.invoke(homeApp) @@ -216,31 +207,15 @@ class HomeChildRVAdapter( } } - private fun MaterialButton.disableInstallButton(view: View, buttonString: Int) { - isEnabled = false - text = context.getString(buttonString) - setTextColor(context.getColor(R.color.light_grey)) - backgroundTintList = ContextCompat.getColorStateList( - view.context, - android.R.color.transparent - ) - strokeColor = - ContextCompat.getColorStateList(view.context, R.color.light_grey) - } - private fun HomeChildListItemBinding.handleUpdatable( view: View, homeApp: FusedApp ) { installButton.apply { + enableInstallButton(Status.UPDATABLE) 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 @@ -256,13 +231,8 @@ class HomeChildRVAdapter( homeApp: FusedApp ) { installButton.apply { - isEnabled = true + enableInstallButton(Status.INSTALLED) text = context.getString(R.string.open) - setTextColor(Color.WHITE) - backgroundTintList = - ContextCompat.getColorStateList(view.context, R.color.colorAccent) - strokeColor = - ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { if (homeApp.is_pwa) { mainActivityViewModel.launchPwa(homeApp) @@ -281,22 +251,22 @@ class HomeChildRVAdapter( ) { when { mainActivityViewModel.checkUnsupportedApplication(homeApp) -> { - materialButton.isEnabled = true + materialButton.enableInstallButton() materialButton.text = materialButton.context.getString(R.string.not_available) } homeApp.isFree -> { - materialButton.isEnabled = true + materialButton.enableInstallButton() materialButton.text = materialButton.context.getString(R.string.install) homeChildListItemBinding.progressBarInstall.visibility = View.GONE } else -> { - materialButton.isEnabled = false + materialButton.disableInstallButton() materialButton.text = "" homeChildListItemBinding.progressBarInstall.visibility = View.VISIBLE lifecycleOwner?.let { appInfoFetchViewModel.isAppPurchased(homeApp).observe(it) { - materialButton.isEnabled = true homeChildListItemBinding.progressBarInstall.visibility = View.GONE + materialButton.enableInstallButton() materialButton.text = if (it) materialButton.context.getString(R.string.install) else homeApp.price } diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 545c13f67..35de693ce 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -50,7 +50,7 @@ import foundation.e.apps.api.ResultSupreme import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.application.subFrags.ApplicationDialogFragment -import foundation.e.apps.applicationlist.model.ApplicationListRVAdapter +import foundation.e.apps.applicationlist.ApplicationListRVAdapter import foundation.e.apps.databinding.FragmentSearchBinding import foundation.e.apps.manager.download.data.DownloadProgress import foundation.e.apps.manager.pkg.PkgManagerModule diff --git a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt index 5e8d1a100..a192c48a1 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt @@ -40,7 +40,7 @@ import foundation.e.apps.api.fused.FusedAPIImpl import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.application.subFrags.ApplicationDialogFragment -import foundation.e.apps.applicationlist.model.ApplicationListRVAdapter +import foundation.e.apps.applicationlist.ApplicationListRVAdapter import foundation.e.apps.databinding.FragmentUpdatesBinding import foundation.e.apps.manager.download.data.DownloadProgress import foundation.e.apps.manager.pkg.PkgManagerModule diff --git a/app/src/main/java/foundation/e/apps/utils/MaterialButtonUtils.kt b/app/src/main/java/foundation/e/apps/utils/MaterialButtonUtils.kt new file mode 100644 index 000000000..1d6b29825 --- /dev/null +++ b/app/src/main/java/foundation/e/apps/utils/MaterialButtonUtils.kt @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2022 ECORP + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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.utils.enums.Status + +fun MaterialButton.disableInstallButton(status: Status? = null) { + toggleEnableMaterialButton(false, status) +} + +fun MaterialButton.enableInstallButton(status: Status? = null) { + toggleEnableMaterialButton(true, status) +} + +private fun MaterialButton.toggleEnableMaterialButton(isEnabled: Boolean, status: Status?) { + this.isEnabled = isEnabled + strokeColor = getStrokeColor(isEnabled) + setButtonTextColor(isEnabled, status) + backgroundTintList = + getBackgroundTintList(status) +} + +private fun MaterialButton.getBackgroundTintList(status: Status?) = + if (status == Status.INSTALLED || status == Status.UPDATABLE) { + ContextCompat.getColorStateList(this.context, R.color.colorAccent) + } else + ContextCompat.getColorStateList(this.context, android.R.color.transparent) + +private fun MaterialButton.getStrokeColor( + isEnabled: Boolean, +) = if (isEnabled) { + ContextCompat.getColorStateList(this.context, R.color.colorAccent) +} else { + ContextCompat.getColorStateList(this.context, R.color.light_grey) +} + +private fun MaterialButton.setButtonTextColor(isEnabled: Boolean, status: Status?) = + if (isEnabled && (status == Status.INSTALLED || status == Status.UPDATABLE)) { + setTextColor(Color.WHITE) + } else if (isEnabled) { + setTextColor(context.getColor(R.color.colorAccent)) + } else { + setTextColor(context.getColor(R.color.light_grey)) + } -- GitLab