Loading app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +26 −4 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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 } Loading @@ -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) Loading @@ -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) Loading @@ -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) Loading @@ -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)) { Loading @@ -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 Loading @@ -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) Loading Loading @@ -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) Loading app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationDiffUtil.kt→app/src/main/java/foundation/e/apps/applicationlist/ApplicationDiffUtil.kt +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package foundation.e.apps.applicationlist.model package foundation.e.apps.applicationlist import androidx.recyclerview.widget.DiffUtil import foundation.e.apps.api.fused.data.FusedApp Loading app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +0 −1 Original line number Diff line number Diff line Loading @@ -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 Loading app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt→app/src/main/java/foundation/e/apps/applicationlist/ApplicationListRVAdapter.kt +32 −55 Original line number Diff line number Diff line /* * 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 Loading @@ -16,9 +15,8 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ 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 Loading @@ -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 Loading Loading @@ -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) Loading Loading @@ -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 { Loading Loading @@ -401,29 +398,20 @@ class ApplicationListRVAdapter( appPrivacyScore.visibility = View.VISIBLE } private fun ApplicationListItemBinding.handleInstalling(view: View, holder: ViewHolder) { private fun ApplicationListItemBinding.handleInstalling() { 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() 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) } Loading @@ -433,21 +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() text = context.getText(R.string.cancel) installApplication(searchApp, appIcon) } else { paidAppHandler?.invoke(searchApp) Loading @@ -464,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) Loading @@ -482,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 Loading @@ -492,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 Loading @@ -514,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) Loading app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt +17 −42 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading Loading @@ -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) Loading @@ -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) } Loading @@ -147,6 +142,7 @@ class HomeChildRVAdapter( } private fun HomeChildListItemBinding.handleBlocked(view: View) { installButton.enableInstallButton() installButton.setOnClickListener { val errorMsg = when (mainActivityViewModel.getUser()) { User.ANONYMOUS, Loading @@ -160,17 +156,10 @@ class HomeChildRVAdapter( progressBarInstall.visibility = View.GONE } private fun HomeChildListItemBinding.handleInstalling(view: View) { private fun HomeChildListItemBinding.handleInstalling() { installButton.apply { isEnabled = false setTextColor(context.getColor(R.color.light_grey)) disableInstallButton() text = context.getString(R.string.installing) backgroundTintList = ContextCompat.getColorStateList( view.context, android.R.color.transparent ) strokeColor = ContextCompat.getColorStateList(view.context, R.color.light_grey) } progressBarInstall.visibility = View.GONE } Loading @@ -180,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( Loading @@ -199,22 +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() text = context.getString(R.string.cancel) installApplication(homeApp, appIcon) } else { paidAppHandler?.invoke(homeApp) Loading @@ -228,14 +212,10 @@ class HomeChildRVAdapter( 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 Loading @@ -251,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) Loading @@ -276,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 } Loading Loading
app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +26 −4 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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 } Loading @@ -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) Loading @@ -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) Loading @@ -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) Loading @@ -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)) { Loading @@ -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 Loading @@ -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) Loading Loading @@ -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) Loading
app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationDiffUtil.kt→app/src/main/java/foundation/e/apps/applicationlist/ApplicationDiffUtil.kt +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package foundation.e.apps.applicationlist.model package foundation.e.apps.applicationlist import androidx.recyclerview.widget.DiffUtil import foundation.e.apps.api.fused.data.FusedApp Loading
app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +0 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt→app/src/main/java/foundation/e/apps/applicationlist/ApplicationListRVAdapter.kt +32 −55 Original line number Diff line number Diff line /* * 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 Loading @@ -16,9 +15,8 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ 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 Loading @@ -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 Loading Loading @@ -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) Loading Loading @@ -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 { Loading Loading @@ -401,29 +398,20 @@ class ApplicationListRVAdapter( appPrivacyScore.visibility = View.VISIBLE } private fun ApplicationListItemBinding.handleInstalling(view: View, holder: ViewHolder) { private fun ApplicationListItemBinding.handleInstalling() { 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() 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) } Loading @@ -433,21 +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() text = context.getText(R.string.cancel) installApplication(searchApp, appIcon) } else { paidAppHandler?.invoke(searchApp) Loading @@ -464,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) Loading @@ -482,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 Loading @@ -492,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 Loading @@ -514,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) Loading
app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt +17 −42 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading Loading @@ -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) Loading @@ -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) } Loading @@ -147,6 +142,7 @@ class HomeChildRVAdapter( } private fun HomeChildListItemBinding.handleBlocked(view: View) { installButton.enableInstallButton() installButton.setOnClickListener { val errorMsg = when (mainActivityViewModel.getUser()) { User.ANONYMOUS, Loading @@ -160,17 +156,10 @@ class HomeChildRVAdapter( progressBarInstall.visibility = View.GONE } private fun HomeChildListItemBinding.handleInstalling(view: View) { private fun HomeChildListItemBinding.handleInstalling() { installButton.apply { isEnabled = false setTextColor(context.getColor(R.color.light_grey)) disableInstallButton() text = context.getString(R.string.installing) backgroundTintList = ContextCompat.getColorStateList( view.context, android.R.color.transparent ) strokeColor = ContextCompat.getColorStateList(view.context, R.color.light_grey) } progressBarInstall.visibility = View.GONE } Loading @@ -180,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( Loading @@ -199,22 +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() text = context.getString(R.string.cancel) installApplication(homeApp, appIcon) } else { paidAppHandler?.invoke(homeApp) Loading @@ -228,14 +212,10 @@ class HomeChildRVAdapter( 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 Loading @@ -251,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) Loading @@ -276,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 } Loading