diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 9adb161617fe7324f17ba0362e21cb6fc0368ce7..45aad52687d01448922bbe55a7d0186ee07f36a4 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -20,6 +20,7 @@ package foundation.e.apps.api.fused import android.content.Context import android.text.format.Formatter +import android.util.Log import com.aurora.gplayapi.SearchSuggestEntry import com.aurora.gplayapi.data.models.App import com.aurora.gplayapi.data.models.Artwork @@ -638,19 +639,17 @@ class FusedAPIImpl @Inject constructor( origin = Origin.GPLAY, shareUrl = this.shareUrl, appSize = Formatter.formatFileSize(context, this.size), - isFree = this.isFree + isFree = this.isFree, + price = this.price ) app.updateStatus() return app } private fun FusedApp.updateStatus() { - this.status = if (this.isFree) { - pkgManagerModule.getPackageStatus(this.package_name, this.latest_version_code) - } else if (this.status == Status.INSTALLATION_ISSUE) { - this.status - } else { - Status.BLOCKED + if (this.status != Status.INSTALLATION_ISSUE) { + this.status = + pkgManagerModule.getPackageStatus(this.package_name, this.latest_version_code) } } 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 1429dec0543fdb2fa7877a48b9cd64478b836c43..c676eeed2b8dbe60716bfab5757833e8f3c5f43d 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 @@ -44,6 +44,7 @@ data class FusedApp( val shareUrl: String = String(), val appSize: String = String(), var source: String = String(), + val price: String = String(), val isFree: Boolean = true, val is_pwa: Boolean = false, val url: String = String(), 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 61175a9a84cfacfb52ea53657323323879cef5e6..9cfe4eeec09810b1e0585f74857926989ca358a7 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -261,7 +261,13 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { val fusedApp = applicationViewModel.fusedApp.value ?: FusedApp() when (status) { - Status.INSTALLED -> handleInstalled(installButton, view, fusedApp, downloadPB, appSize) + Status.INSTALLED -> handleInstalled( + installButton, + view, + fusedApp, + downloadPB, + appSize + ) Status.UPDATABLE -> handleUpdatable( installButton, view, @@ -270,7 +276,12 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { appSize ) Status.UNAVAILABLE -> handleUnavaiable(installButton, fusedApp, downloadPB, appSize) - Status.QUEUED, Status.AWAITING -> handleQueued(installButton, fusedApp, downloadPB, appSize) + Status.QUEUED, Status.AWAITING -> handleQueued( + installButton, + fusedApp, + downloadPB, + appSize + ) Status.DOWNLOADING -> handleDownloading( installButton, fusedApp, @@ -388,10 +399,21 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { appSize: MaterialTextView ) { installButton.apply { - text = getString(R.string.install) + text = if (fusedApp.isFree) getString(R.string.install) else fusedApp.price setOnClickListener { applicationIcon?.let { - mainActivityViewModel.getApplication(fusedApp, it) + if (fusedApp.isFree) { + mainActivityViewModel.getApplication(fusedApp, it) + } else { + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "ApplicationFragment") + } } } } diff --git a/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt b/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt index 202d3b8e6f8e1fe7811e5b5a07a59c653b4d1bee..c3e5a455afd2eaf7a13c404131797848f228aabf 100644 --- a/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt @@ -33,20 +33,33 @@ import foundation.e.apps.R @AndroidEntryPoint class ApplicationDialogFragment( - private val drawable: Int, + private val drawable: Int = -1, private val title: String, - private val message: String + private val message: String, + private val positiveButtonText: String = "", + private val positiveButtonAction: (() -> Unit)? = null, + private val cancelButtonText: String = "", + private val cancelButtonAction: (() -> Unit)? = null, ) : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - return MaterialAlertDialogBuilder(requireContext()) - .setIcon(drawable) - .setTitle(title) + val positiveButtonText = + positiveButtonText.ifEmpty { getString(R.string.ok) } + val materialAlertDialogBuilder = MaterialAlertDialogBuilder(requireContext()) + .setTitle(Html.fromHtml(title, Html.FROM_HTML_MODE_COMPACT)) .setMessage(Html.fromHtml(message, Html.FROM_HTML_MODE_COMPACT)) - .setPositiveButton(getString(R.string.ok)) { _, _ -> + .setPositiveButton(positiveButtonText) { _, _ -> + positiveButtonAction?.invoke() this.dismiss() } - .create() + .setNegativeButton(cancelButtonText) { _, _ -> + cancelButtonAction?.invoke() + this.dismiss() + } + if (drawable != -1) { + materialAlertDialogBuilder.setIcon(drawable) + } + return materialAlertDialogBuilder.create() } override fun onResume() { 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 aeb6fb05c72f16dba552ef3a087321a01c68d164..c7b02d519d5a726c11b9d05253327f71a49e29aa 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt @@ -38,6 +38,7 @@ import foundation.e.apps.PrivacyInfoViewModel import foundation.e.apps.R 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 @@ -114,7 +115,16 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu pkgManagerModule, User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), viewLifecycleOwner - ) + ) { fusedApp -> + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "HomeFragment") + } } recyclerView.apply { 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 3179ce134464c65a993237d8a5b6d071668dbb13..048d23f7f26c19113f282980f71a4f86c8239602 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 @@ -57,6 +57,7 @@ class ApplicationListRVAdapter( private val pkgManagerModule: PkgManagerModule, private val user: User, private val lifecycleOwner: LifecycleOwner, + private val paidAppHandler: ((FusedApp) -> Unit)? = null ) : ListAdapter(ApplicationDiffUtil()) { private val TAG = ApplicationListRVAdapter::class.java.simpleName @@ -295,13 +296,17 @@ class ApplicationListRVAdapter( ) { installButton.apply { isEnabled = true - text = context.getString(R.string.install) + text = if (searchApp.isFree) context.getString(R.string.install) else searchApp.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 { - installApplication(searchApp, appIcon) + if (searchApp.isFree) { + installApplication(searchApp, appIcon) + } else { + paidAppHandler?.invoke(searchApp) + } } } } 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 7773a453780a56904e2afa1770c053f79700ed6d..5c30d86c24766020d9a760eae72ced8a2051e7ed 100644 --- a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt @@ -34,6 +34,7 @@ import foundation.e.apps.MainActivityViewModel import foundation.e.apps.R 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.databinding.FragmentHomeBinding import foundation.e.apps.home.model.HomeChildRVAdapter import foundation.e.apps.home.model.HomeParentRVAdapter @@ -84,7 +85,16 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { pkgManagerModule, User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), mainActivityViewModel, viewLifecycleOwner - ) + ) { fusedApp -> + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "HomeFragment") + } binding.parentRV.apply { adapter = homeParentRVAdapter 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 a877dcd14d758a27ee0e9cc3bfb0955e681960aa..0d4b74f3260b43010ee10d212ae7c6f58fe98c05 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 @@ -44,7 +44,8 @@ import foundation.e.apps.utils.enums.User class HomeChildRVAdapter( private val fusedAPIInterface: FusedAPIInterface, private val pkgManagerModule: PkgManagerModule, - private val user: User + private val user: User, + private val paidAppHandler: ((FusedApp) -> Unit)? = null ) : ListAdapter(HomeChildFusedAppDiffUtil()) { private val shimmer = Shimmer.ColorHighlightBuilder() @@ -124,7 +125,8 @@ class HomeChildRVAdapter( } Status.UNAVAILABLE -> { installButton.apply { - text = context.getString(R.string.install) + text = + if (homeApp.isFree) context.getString(R.string.install) else homeApp.price setTextColor(context.getColor(R.color.colorAccent)) backgroundTintList = ContextCompat.getColorStateList( view.context, @@ -133,7 +135,11 @@ class HomeChildRVAdapter( strokeColor = ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { - installApplication(homeApp, appIcon) + if (homeApp.isFree) { + installApplication(homeApp, appIcon) + } else { + paidAppHandler?.invoke(homeApp) + } } } } 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 30ca74d226b553cbe757dd9191f49a4e5d8ba02d..1595866c3847fec9c8699243003d4d018e883b42 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 @@ -38,7 +38,8 @@ class HomeParentRVAdapter( private val pkgManagerModule: PkgManagerModule, private val user: User, private val mainActivityViewModel: MainActivityViewModel, - private val lifecycleOwner: LifecycleOwner + private val lifecycleOwner: LifecycleOwner, + private val paidAppHandler: ((FusedApp) -> Unit)? = null ) : ListAdapter(FusedHomeDiffUtil()) { private val viewPool = RecyclerView.RecycledViewPool() @@ -55,7 +56,7 @@ class HomeParentRVAdapter( override fun onBindViewHolder(holder: ViewHolder, position: Int) { val fusedHome = getItem(position) val homeChildRVAdapter = - HomeChildRVAdapter(fusedAPIInterface, pkgManagerModule, user) + HomeChildRVAdapter(fusedAPIInterface, pkgManagerModule, user, 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 3bc4bb727fd22fb3865f6f7c0bd8a55b286c3316..c5ea9d887d27a56921e1a1dfa1fdb2f7e8339f9f 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -46,6 +46,7 @@ import foundation.e.apps.PrivacyInfoViewModel import foundation.e.apps.R 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.FragmentSearchBinding import foundation.e.apps.manager.pkg.PkgManagerModule @@ -118,7 +119,16 @@ class SearchFragment : pkgManagerModule, User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), viewLifecycleOwner - ) + ) { fusedApp -> + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "SearchFragment") + } } recyclerView?.apply { 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 4fb3b683f9be800708c734566f64cc60eb902aa3..f9b2962e9b41728942fe36a2336a564e83ec9690 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt @@ -35,6 +35,7 @@ import foundation.e.apps.PrivacyInfoViewModel import foundation.e.apps.R 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.FragmentUpdatesBinding import foundation.e.apps.manager.download.data.DownloadProgress @@ -86,7 +87,16 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { pkgManagerModule, User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), viewLifecycleOwner, - ) + ) { fusedApp -> + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "UpdatesFragment") + } } recyclerView.apply { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e2a657ddb3da124fd63a65550632dcbb4bd3aad7..751f3ac385cd9cbcdbd48470df4b3eade3585ed8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -149,4 +149,10 @@ Can\'t connect! Please check your internet connection and try again + + %1$s]]> + When clicked confirm, it will take you to Google Play page for the app to complete the purchase using your browser. Click confirm to purchase %1$s for %2$s. + CONFIRM + CANCEL +