From c287aa3a0cc433f12ec4237754065c5fa805c918 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Mon, 9 May 2022 12:57:29 +0600 Subject: [PATCH 1/4] App lounge: show install text for purchased app --- ...hViewModel.kt => AppInfoFetchViewModel.kt} | 32 ++- .../e/apps/api/fused/data/FusedApp.kt | 1 + .../e/apps/application/ApplicationFragment.kt | 6 +- .../ApplicationListFragment.kt | 6 +- .../model/ApplicationListRVAdapter.kt | 42 ++- .../foundation/e/apps/home/HomeFragment.kt | 4 +- .../e/apps/home/model/HomeChildRVAdapter.kt | 262 ++++++++++++------ .../e/apps/home/model/HomeParentRVAdapter.kt | 12 +- .../e/apps/search/SearchFragment.kt | 6 +- .../e/apps/updates/UpdatesFragment.kt | 6 +- .../main/res/layout/application_list_item.xml | 11 + .../main/res/layout/home_child_list_item.xml | 33 ++- app/src/main/res/values/strings.xml | 1 + 13 files changed, 297 insertions(+), 125 deletions(-) rename app/src/main/java/foundation/e/apps/{FdroidFetchViewModel.kt => AppInfoFetchViewModel.kt} (63%) diff --git a/app/src/main/java/foundation/e/apps/FdroidFetchViewModel.kt b/app/src/main/java/foundation/e/apps/AppInfoFetchViewModel.kt similarity index 63% rename from app/src/main/java/foundation/e/apps/FdroidFetchViewModel.kt rename to app/src/main/java/foundation/e/apps/AppInfoFetchViewModel.kt index 8b1f24cae..b8a9c1e8d 100644 --- a/app/src/main/java/foundation/e/apps/FdroidFetchViewModel.kt +++ b/app/src/main/java/foundation/e/apps/AppInfoFetchViewModel.kt @@ -1,13 +1,19 @@ package foundation.e.apps import android.widget.TextView +import androidx.lifecycle.LiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.liveData import androidx.lifecycle.viewModelScope +import com.aurora.gplayapi.data.models.AuthData +import com.google.gson.Gson import dagger.hilt.android.lifecycle.HiltViewModel import foundation.e.apps.api.fdroid.FdroidRepository import foundation.e.apps.api.fdroid.models.FdroidEntity import foundation.e.apps.api.fused.data.FusedApp +import foundation.e.apps.api.gplay.GPlayAPIRepository import foundation.e.apps.utils.enums.Origin +import foundation.e.apps.utils.modules.DataStoreModule import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -17,8 +23,11 @@ import javax.inject.Inject * */ @HiltViewModel -class FdroidFetchViewModel @Inject constructor( - private val fdroidRepository: FdroidRepository +class AppInfoFetchViewModel @Inject constructor( + private val fdroidRepository: FdroidRepository, + private val gPlayAPIRepository: GPlayAPIRepository, + private val dataStoreModule: DataStoreModule, + private val gson: Gson ) : ViewModel() { private val fdroidEntries = mutableMapOf() @@ -55,4 +64,23 @@ class FdroidFetchViewModel @Inject constructor( } } } + + fun isAppPurchased(app: FusedApp): LiveData { + return liveData { + val authData = gson.fromJson(dataStoreModule.getAuthDataSync(), AuthData::class.java) + try { + gPlayAPIRepository.getDownloadInfo( + app.package_name, + app.latest_version_code, + app.offer_type, + authData + ) + app.isPurchased = true + emit(true) + } catch (e: Exception) { + app.isPurchased = false + emit(false) + } + } + } } diff --git a/app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt b/app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt index b4f349b63..d48829311 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt @@ -53,6 +53,7 @@ data class FusedApp( val url: String = String(), var type: Type = Type.NATIVE, var privacyScore: Int = -1, + var isPurchased: Boolean = false, /* * List of permissions from Exodus API. 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 d1031a4c1..b61052bf4 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -44,7 +44,7 @@ import com.google.android.material.button.MaterialButton import com.google.android.material.snackbar.Snackbar import com.google.android.material.textview.MaterialTextView import dagger.hilt.android.AndroidEntryPoint -import foundation.e.apps.FdroidFetchViewModel +import foundation.e.apps.AppInfoFetchViewModel import foundation.e.apps.MainActivityViewModel import foundation.e.apps.PrivacyInfoViewModel import foundation.e.apps.R @@ -81,7 +81,7 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { private val applicationViewModel: ApplicationViewModel by viewModels() private val privacyInfoViewModel: PrivacyInfoViewModel by viewModels() - private val fdroidFetchViewModel: FdroidFetchViewModel by viewModels() + private val appInfoFetchViewModel: AppInfoFetchViewModel by viewModels() private val mainActivityViewModel: MainActivityViewModel by activityViewModels() private var applicationIcon: ImageView? = null @@ -147,7 +147,7 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { applicationIcon = appIcon appName.text = it.name appAuthor.text = it.author - fdroidFetchViewModel.setAuthorNameIfNeeded(appAuthor, it) + appInfoFetchViewModel.setAuthorNameIfNeeded(appAuthor, it) categoryTitle.text = it.category if (args.origin == Origin.CLEANAPK) { appIcon.load(CleanAPKInterface.ASSET_URL + it.icon_image_path) 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 ada42adbc..834fb44ee 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt @@ -31,8 +31,8 @@ import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint +import foundation.e.apps.AppInfoFetchViewModel import foundation.e.apps.AppProgressViewModel -import foundation.e.apps.FdroidFetchViewModel import foundation.e.apps.MainActivityViewModel import foundation.e.apps.PrivacyInfoViewModel import foundation.e.apps.R @@ -62,7 +62,7 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu private val viewModel: ApplicationListViewModel by viewModels() private val privacyInfoViewModel: PrivacyInfoViewModel by viewModels() - private val fdroidFetchViewModel: FdroidFetchViewModel by viewModels() + private val appInfoFetchViewModel: AppInfoFetchViewModel by viewModels() private val mainActivityViewModel: MainActivityViewModel by activityViewModels() private val appProgressViewModel: AppProgressViewModel by viewModels() @@ -112,7 +112,7 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu ApplicationListRVAdapter( this, privacyInfoViewModel, - fdroidFetchViewModel, + appInfoFetchViewModel, it, pkgManagerModule, pwaManagerModule, 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 324f2e6b1..30f5c9f63 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 @@ -33,8 +33,9 @@ import coil.load import com.facebook.shimmer.Shimmer import com.facebook.shimmer.Shimmer.Direction.LEFT_TO_RIGHT import com.facebook.shimmer.ShimmerDrawable +import com.google.android.material.button.MaterialButton import com.google.android.material.snackbar.Snackbar -import foundation.e.apps.FdroidFetchViewModel +import foundation.e.apps.AppInfoFetchViewModel import foundation.e.apps.PrivacyInfoViewModel import foundation.e.apps.R import foundation.e.apps.api.cleanapk.CleanAPKInterface @@ -55,7 +56,7 @@ import javax.inject.Singleton class ApplicationListRVAdapter( private val fusedAPIInterface: FusedAPIInterface, private val privacyInfoViewModel: PrivacyInfoViewModel, - private val fdroidFetchViewModel: FdroidFetchViewModel, + private val appInfoFetchViewModel: AppInfoFetchViewModel, private val currentDestinationId: Int, private val pkgManagerModule: PkgManagerModule, private val pwaManagerModule: PWAManagerModule, @@ -125,7 +126,7 @@ class ApplicationListRVAdapter( } appTitle.text = searchApp.name appAuthor.text = searchApp.author - fdroidFetchViewModel.setAuthorNameIfNeeded(appAuthor, searchApp) + appInfoFetchViewModel.setAuthorNameIfNeeded(appAuthor, searchApp) if (searchApp.ratings.usageQualityScore != -1.0) { appRating.text = searchApp.ratings.usageQualityScore.toString() appRatingBar.rating = searchApp.ratings.usageQualityScore.toFloat() @@ -200,6 +201,7 @@ class ApplicationListRVAdapter( installApplication(searchApp, appIcon) } } + progressBarInstall.visibility = View.GONE } private fun ApplicationListItemBinding.handleBlocked(view: View) { @@ -216,6 +218,7 @@ class ApplicationListRVAdapter( } } } + progressBarInstall.visibility = View.GONE } private fun ApplicationListItemBinding.showCalculatedPrivacyScoreData( @@ -272,11 +275,13 @@ 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) } + progressBarInstall.visibility = View.GONE } private fun ApplicationListItemBinding.handleDownloading( @@ -293,7 +298,9 @@ class ApplicationListRVAdapter( setOnClickListener { cancelDownload(searchApp) } + progressBarInstall.visibility = View.GONE } + progressBarInstall.visibility = View.GONE } private fun ApplicationListItemBinding.handleUnavailable( @@ -301,14 +308,13 @@ class ApplicationListRVAdapter( searchApp: FusedApp, ) { installButton.apply { - isEnabled = true - text = if (searchApp.isFree) context.getString(R.string.install) else searchApp.price + updateUIByPaymentType(searchApp, this, this@handleUnavailable) 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 (searchApp.isFree) { + if (searchApp.isFree || searchApp.isPurchased) { installApplication(searchApp, appIcon) } else { paidAppHandler?.invoke(searchApp) @@ -317,6 +323,28 @@ class ApplicationListRVAdapter( } } + private fun updateUIByPaymentType( + searchApp: FusedApp, + materialButton: MaterialButton, + applicationListItemBinding: ApplicationListItemBinding + ) { + if (searchApp.isFree) { + materialButton.isEnabled = true + materialButton.text = materialButton.context.getString(R.string.install) + applicationListItemBinding.progressBarInstall.visibility = View.GONE + } else { + materialButton.isEnabled = false + materialButton.text = "" + applicationListItemBinding.progressBarInstall.visibility = View.VISIBLE + appInfoFetchViewModel.isAppPurchased(searchApp).observe(lifecycleOwner) { + materialButton.isEnabled = true + applicationListItemBinding.progressBarInstall.visibility = View.GONE + materialButton.text = + if (it) materialButton.context.getString(R.string.install) else searchApp.price + } + } + } + private fun ApplicationListItemBinding.handleUpdatable( view: View, searchApp: FusedApp @@ -331,6 +359,7 @@ class ApplicationListRVAdapter( installApplication(searchApp, appIcon) } } + progressBarInstall.visibility = View.GONE } private fun ApplicationListItemBinding.handleInstalled( @@ -351,6 +380,7 @@ class ApplicationListRVAdapter( } } } + progressBarInstall.visibility = View.GONE } fun setData(newList: List) { diff --git a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt index 8fc618938..d4f0dfb88 100644 --- a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt @@ -29,6 +29,7 @@ import androidx.navigation.findNavController import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint +import foundation.e.apps.AppInfoFetchViewModel import foundation.e.apps.AppProgressViewModel import foundation.e.apps.MainActivityViewModel import foundation.e.apps.R @@ -56,6 +57,7 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { private val homeViewModel: HomeViewModel by viewModels() private val mainActivityViewModel: MainActivityViewModel by activityViewModels() private val appProgressViewModel: AppProgressViewModel by viewModels() + private val appInfoFetchViewModel: AppInfoFetchViewModel by viewModels() @Inject lateinit var pkgManagerModule: PkgManagerModule @@ -90,7 +92,7 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { pkgManagerModule, pwaManagerModule, User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), - mainActivityViewModel, viewLifecycleOwner + mainActivityViewModel, appInfoFetchViewModel, viewLifecycleOwner ) { fusedApp -> if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { ApplicationDialogFragment( 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 42997ea63..25885d9a0 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 @@ -20,16 +20,20 @@ package foundation.e.apps.home.model import android.graphics.Color import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import android.widget.ImageView import androidx.core.content.ContextCompat +import androidx.lifecycle.LifecycleOwner import androidx.navigation.findNavController import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import coil.load import com.facebook.shimmer.Shimmer import com.facebook.shimmer.ShimmerDrawable +import com.google.android.material.button.MaterialButton import com.google.android.material.snackbar.Snackbar +import foundation.e.apps.AppInfoFetchViewModel import foundation.e.apps.R import foundation.e.apps.api.cleanapk.CleanAPKInterface import foundation.e.apps.api.fused.FusedAPIInterface @@ -46,7 +50,9 @@ class HomeChildRVAdapter( private val fusedAPIInterface: FusedAPIInterface, private val pkgManagerModule: PkgManagerModule, private val pwaManagerModule: PWAManagerModule, + private val appInfoFetchViewModel: AppInfoFetchViewModel, private val user: User, + private val lifecycleOwner: LifecycleOwner, private val paidAppHandler: ((FusedApp) -> Unit)? = null ) : ListAdapter(HomeChildFusedAppDiffUtil()) { @@ -99,115 +105,187 @@ class HomeChildRVAdapter( when (homeApp.status) { Status.INSTALLED -> { - installButton.apply { - isEnabled = true - 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) { - pwaManagerModule.launchPwa(homeApp) - } else { - context.startActivity(pkgManagerModule.getLaunchIntent(homeApp.package_name)) - } - } - } + handleInstalled(view, homeApp) } Status.UPDATABLE -> { - installButton.apply { - text = 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 { - installApplication(homeApp, appIcon) - } - } + handleUpdatable(view, homeApp) } Status.UNAVAILABLE -> { - installButton.apply { - text = - if (homeApp.isFree) context.getString(R.string.install) else homeApp.price - 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 (homeApp.isFree) { - installApplication(homeApp, appIcon) - } else { - paidAppHandler?.invoke(homeApp) - } - } - } + handleUnavailable(homeApp, holder, view) } Status.QUEUED, Status.AWAITING, Status.DOWNLOADING -> { - installButton.apply { - 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(homeApp) - } - } + handleQueued(view, homeApp) } Status.INSTALLING, Status.UNINSTALLING -> { - installButton.apply { - isEnabled = false - 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) - } + handleInstalling(view) } Status.BLOCKED -> { - installButton.setOnClickListener { - val errorMsg = when (user) { - User.ANONYMOUS, - User.UNAVAILABLE -> view.context.getString(R.string.install_blocked_anonymous) - User.GOOGLE -> view.context.getString(R.string.install_blocked_google) - } - if (errorMsg.isNotBlank()) { - Snackbar.make(view, errorMsg, Snackbar.LENGTH_SHORT).show() - } - } + handleBlocked(view) } Status.INSTALLATION_ISSUE -> { - installButton.apply { - 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) - } - } + handleInstallationIssue(view, homeApp) } } } } + private fun HomeChildListItemBinding.handleInstallationIssue( + view: View, + homeApp: FusedApp + ) { + installButton.apply { + 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) + } + } + progressBarInstall.visibility = View.GONE + } + + private fun HomeChildListItemBinding.handleBlocked(view: View) { + installButton.setOnClickListener { + val errorMsg = when (user) { + User.ANONYMOUS, + User.UNAVAILABLE -> view.context.getString(R.string.install_blocked_anonymous) + User.GOOGLE -> view.context.getString(R.string.install_blocked_google) + } + if (errorMsg.isNotBlank()) { + Snackbar.make(view, errorMsg, Snackbar.LENGTH_SHORT).show() + } + } + progressBarInstall.visibility = View.GONE + } + + 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) + } + progressBarInstall.visibility = View.GONE + } + + private fun HomeChildListItemBinding.handleQueued( + view: View, + homeApp: FusedApp + ) { + installButton.apply { + 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(homeApp) + } + } + progressBarInstall.visibility = View.GONE + } + + 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 (homeApp.isFree) { + installApplication(homeApp, appIcon) + } else { + paidAppHandler?.invoke(homeApp) + } + } + } + } + + private fun HomeChildListItemBinding.handleUpdatable( + view: View, + homeApp: FusedApp + ) { + installButton.apply { + text = 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 { + installApplication(homeApp, appIcon) + } + } + progressBarInstall.visibility = View.GONE + } + + private fun HomeChildListItemBinding.handleInstalled( + view: View, + homeApp: FusedApp + ) { + installButton.apply { + isEnabled = true + 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) { + pwaManagerModule.launchPwa(homeApp) + } else { + context.startActivity(pkgManagerModule.getLaunchIntent(homeApp.package_name)) + } + } + } + progressBarInstall.visibility = View.GONE + } + + private fun updateUIByPaymentType( + homeApp: FusedApp, + materialButton: MaterialButton, + homeChildListItemBinding: HomeChildListItemBinding + ) { + if (homeApp.isFree) { + materialButton.isEnabled = true + materialButton.text = materialButton.context.getString(R.string.install) + homeChildListItemBinding.progressBarInstall.visibility = View.GONE + } else { + materialButton.isEnabled = false + materialButton.text = "" + homeChildListItemBinding.progressBarInstall.visibility = View.VISIBLE + appInfoFetchViewModel.isAppPurchased(homeApp).observe(lifecycleOwner) { + materialButton.isEnabled = true + homeChildListItemBinding.progressBarInstall.visibility = View.GONE + materialButton.text = + if (it) materialButton.context.getString(R.string.install) else homeApp.price + } + } + } + fun setData(newList: List) { this.submitList(newList.map { it.copy() }) } diff --git a/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt b/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt index c7300994f..8564b0df4 100644 --- a/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt @@ -24,6 +24,7 @@ import androidx.lifecycle.LifecycleOwner import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView +import foundation.e.apps.AppInfoFetchViewModel import foundation.e.apps.MainActivityViewModel import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp @@ -39,6 +40,7 @@ class HomeParentRVAdapter( private val pwaManagerModule: PWAManagerModule, private val user: User, private val mainActivityViewModel: MainActivityViewModel, + private val appInfoFetchViewModel: AppInfoFetchViewModel, private val lifecycleOwner: LifecycleOwner, private val paidAppHandler: ((FusedApp) -> Unit)? = null ) : ListAdapter(FusedHomeDiffUtil()) { @@ -58,7 +60,15 @@ class HomeParentRVAdapter( override fun onBindViewHolder(holder: ViewHolder, position: Int) { val fusedHome = getItem(position) val homeChildRVAdapter = - HomeChildRVAdapter(fusedAPIInterface, pkgManagerModule, pwaManagerModule, user, paidAppHandler) + HomeChildRVAdapter( + fusedAPIInterface, + pkgManagerModule, + pwaManagerModule, + appInfoFetchViewModel, + user, + lifecycleOwner, + paidAppHandler + ) homeChildRVAdapter.setData(fusedHome.list) holder.binding.titleTV.text = fusedHome.title 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 1ef753bb1..f21890609 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -39,8 +39,8 @@ import androidx.recyclerview.widget.RecyclerView import com.aurora.gplayapi.SearchSuggestEntry import com.facebook.shimmer.ShimmerFrameLayout import dagger.hilt.android.AndroidEntryPoint +import foundation.e.apps.AppInfoFetchViewModel import foundation.e.apps.AppProgressViewModel -import foundation.e.apps.FdroidFetchViewModel import foundation.e.apps.MainActivityViewModel import foundation.e.apps.PrivacyInfoViewModel import foundation.e.apps.R @@ -74,7 +74,7 @@ class SearchFragment : private val searchViewModel: SearchViewModel by viewModels() private val privacyInfoViewModel: PrivacyInfoViewModel by viewModels() - private val fdroidFetchViewModel: FdroidFetchViewModel by viewModels() + private val appInfoFetchViewModel: AppInfoFetchViewModel by viewModels() private val mainActivityViewModel: MainActivityViewModel by activityViewModels() private val appProgressViewModel: AppProgressViewModel by viewModels() @@ -120,7 +120,7 @@ class SearchFragment : ApplicationListRVAdapter( this, privacyInfoViewModel, - fdroidFetchViewModel, + appInfoFetchViewModel, it, pkgManagerModule, pwaManagerModule, 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 5b41db085..b81c41702 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt @@ -29,8 +29,8 @@ import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint +import foundation.e.apps.AppInfoFetchViewModel import foundation.e.apps.AppProgressViewModel -import foundation.e.apps.FdroidFetchViewModel import foundation.e.apps.MainActivityViewModel import foundation.e.apps.PrivacyInfoViewModel import foundation.e.apps.R @@ -61,7 +61,7 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { private val updatesViewModel: UpdatesViewModel by viewModels() private val privacyInfoViewModel: PrivacyInfoViewModel by viewModels() - private val fdroidFetchViewModel: FdroidFetchViewModel by viewModels() + private val appInfoFetchViewModel: AppInfoFetchViewModel by viewModels() private val mainActivityViewModel: MainActivityViewModel by activityViewModels() private val appProgressViewModel: AppProgressViewModel by viewModels() @@ -91,7 +91,7 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { ApplicationListRVAdapter( this, privacyInfoViewModel, - fdroidFetchViewModel, + appInfoFetchViewModel, it, pkgManagerModule, pwaManagerModule, diff --git a/app/src/main/res/layout/application_list_item.xml b/app/src/main/res/layout/application_list_item.xml index e88d128b1..2160447f9 100644 --- a/app/src/main/res/layout/application_list_item.xml +++ b/app/src/main/res/layout/application_list_item.xml @@ -120,6 +120,17 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="@+id/app_title" /> + + - + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c7f94ead7..cc2b2491e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -74,6 +74,7 @@ Check out \"%1$s\"\n%2$s OK Install + Installing Cancel App icon N/A -- GitLab From 2fba33074b37f6e966eb050a10b86ad03d759f09 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Mon, 9 May 2022 20:41:20 +0600 Subject: [PATCH 2/4] App Lounge: fixed issues due to resolving conflicts --- .../apps/applicationlist/model/ApplicationListRVAdapter.kt | 2 +- .../java/foundation/e/apps/home/model/HomeChildRVAdapter.kt | 6 ++++-- 2 files changed, 5 insertions(+), 3 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 b96ddf502..1c7986ffd 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 @@ -332,7 +332,7 @@ class ApplicationListRVAdapter( ) { when { mainActivityViewModel.checkUnsupportedApplication(searchApp) -> { - materialButton.isEnabled = false + materialButton.isEnabled = true materialButton.text = materialButton.context.getString(R.string.not_available) } searchApp.isFree -> { 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 a3f501959..94583d893 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 @@ -230,7 +230,9 @@ class HomeChildRVAdapter( homeApp: FusedApp ) { installButton.apply { - text = context.getString(R.string.update) + 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) @@ -273,7 +275,7 @@ class HomeChildRVAdapter( ) { when { mainActivityViewModel.checkUnsupportedApplication(homeApp) -> { - materialButton.isEnabled = false + materialButton.isEnabled = true materialButton.text = materialButton.context.getString(R.string.not_available) } homeApp.isFree -> { -- GitLab From b17c25415206b1accd3bf46c32f088a742c36a7a Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Mon, 9 May 2022 21:01:43 +0600 Subject: [PATCH 3/4] App lounge: fixed install button click for unsupported apps This fix is needed because it was broked during resolving conflicts --- .../e/apps/applicationlist/model/ApplicationListRVAdapter.kt | 3 +++ .../java/foundation/e/apps/home/model/HomeChildRVAdapter.kt | 3 +++ 2 files changed, 6 insertions(+) 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 1c7986ffd..b94d70af4 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 @@ -316,6 +316,9 @@ class ApplicationListRVAdapter( 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) { installApplication(searchApp, appIcon) } else { 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 94583d893..90d61d7e3 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 @@ -216,6 +216,9 @@ class HomeChildRVAdapter( strokeColor = ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { + if (mainActivityViewModel.checkUnsupportedApplication(homeApp, context)) { + return@setOnClickListener + } if (homeApp.isFree) { installApplication(homeApp, appIcon) } else { -- GitLab From 24b8d54fde97a3e98ecc89b40ef8add97f91a497 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Mon, 9 May 2022 21:09:14 +0600 Subject: [PATCH 4/4] App lounge: fixed update button click for unsupported apps This fix is needed because it was broked during resolving conflicts --- .../java/foundation/e/apps/home/model/HomeChildRVAdapter.kt | 3 +++ 1 file changed, 3 insertions(+) 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 90d61d7e3..59fe1b908 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 @@ -242,6 +242,9 @@ class HomeChildRVAdapter( strokeColor = ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { + if (mainActivityViewModel.checkUnsupportedApplication(homeApp, context)) { + return@setOnClickListener + } installApplication(homeApp, appIcon) } } -- GitLab