Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0075ae00 authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge branch '292-purchase_declined' into main

parents ee86e7a9 236d476f
Loading
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -208,11 +208,6 @@ class MainActivity : AppCompatActivity() {
        viewModel.isAppPurchased.observe(this) {
            if (it.isNotEmpty()) {
                startInstallationOfPurchasedApp(viewModel, it)
                ApplicationDialogFragment(
                    title = "Purchase complete!",
                    message = "Your app will automatically be downloaded in this device",
                    positiveButtonText = "OK"
                ).show(supportFragmentManager, TAG)
            }
        }

@@ -258,8 +253,17 @@ class MainActivity : AppCompatActivity() {
            val fusedDownload = viewModel.updateAwaitingForPurchasedApp(it)
            if (fusedDownload != null) {
                InstallWorkManager.enqueueWork(fusedDownload)
                ApplicationDialogFragment(
                    title = getString(R.string.purchase_complete),
                    message = getString(R.string.download_automatically_message),
                    positiveButtonText = getString(R.string.ok)
                ).show(supportFragmentManager, TAG)
            } else {
                showSnackbarMessage(getString(R.string.paid_app_anonymous_message))
                ApplicationDialogFragment(
                    title = getString(R.string.purchase_error),
                    message = getString(R.string.something_went_wrong),
                    positiveButtonText = getString(R.string.ok)
                ).show(supportFragmentManager, TAG)
            }
        }
    }
+20 −5
Original line number Diff line number Diff line
@@ -325,12 +325,20 @@ class MainActivityViewModel @Inject constructor(
     *
     * Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/178
     */
    fun checkUnsupportedApplication(fusedApp: FusedApp, alertDialogContext: Context? = null): Boolean {
    fun checkUnsupportedApplication(
        fusedApp: FusedApp,
        alertDialogContext: Context? = null
    ): Boolean {
        if (!fusedApp.isFree && fusedApp.price.isBlank()) {
            alertDialogContext?.let { context ->
                AlertDialog.Builder(context).apply {
                    setTitle(R.string.unsupported_app_title)
                    setMessage(context.getString(R.string.unsupported_app_unreleased, fusedApp.name))
                    setMessage(
                        context.getString(
                            R.string.unsupported_app_unreleased,
                            fusedApp.name
                        )
                    )
                    setPositiveButton(android.R.string.ok, null)
                }.show()
            }
@@ -425,8 +433,11 @@ class MainActivityViewModel @Inject constructor(
                        Origin.GPLAY,
                        fusedDownload
                    )
                } catch (e: ApiException.AppNotPurchased) {
                    e.printStackTrace()
                    return null
                } catch (e: Exception) {
                    Log.e(TAG, e.stackTraceToString())
                    e.printStackTrace()
                    _errorMessage.value = e
                    return null
                }
@@ -481,12 +492,16 @@ class MainActivityViewModel @Inject constructor(
        emitSource(ReactiveNetwork().observeInternetConnectivity().asLiveData(Dispatchers.Default))
    }

    fun updateStatusOfFusedApps(fusedAppList: List<FusedApp>, fusedDownloadList: List<FusedDownload>) {
    fun updateStatusOfFusedApps(
        fusedAppList: List<FusedApp>,
        fusedDownloadList: List<FusedDownload>
    ) {
        fusedAppList.forEach {
            val downloadingItem = fusedDownloadList.find { fusedDownload ->
                fusedDownload.origin == it.origin && (fusedDownload.packageName == it.package_name || fusedDownload.id == it._id)
            }
            it.status = downloadingItem?.status ?: fusedAPIRepository.getFusedAppInstallationStatus(it)
            it.status =
                downloadingItem?.status ?: fusedAPIRepository.getFusedAppInstallationStatus(it)
        }
    }
}
+17 −5
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.content.ContextCompat
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.navigation.findNavController
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
@@ -78,7 +80,9 @@ class ApplicationListRVAdapter(
        .build()

    inner class ViewHolder(val binding: ApplicationListItemBinding) :
        RecyclerView.ViewHolder(binding.root)
        RecyclerView.ViewHolder(binding.root) {
        var isPurchasedLiveData: LiveData<Boolean> = MutableLiveData()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
@@ -160,6 +164,7 @@ class ApplicationListRVAdapter(
                }
                else -> Log.wtf(TAG, "${searchApp.package_name} is from an unknown origin")
            }
            removeIsPurchasedObserver(holder)
            when (searchApp.status) {
                Status.INSTALLED -> {
                    handleInstalled(view, searchApp)
@@ -168,7 +173,7 @@ class ApplicationListRVAdapter(
                    handleUpdatable(view, searchApp)
                }
                Status.UNAVAILABLE -> {
                    handleUnavailable(view, searchApp)
                    handleUnavailable(view, searchApp, holder)
                }
                Status.QUEUED, Status.AWAITING, Status.DOWNLOADING -> {
                    handleDownloading(view, searchApp)
@@ -188,6 +193,10 @@ class ApplicationListRVAdapter(
        }
    }

    private fun removeIsPurchasedObserver(holder: ViewHolder) {
        holder.isPurchasedLiveData.removeObservers(lifecycleOwner)
    }

    private fun ApplicationListItemBinding.handleInstallationIssue(
        view: View,
        searchApp: FusedApp,
@@ -308,9 +317,10 @@ class ApplicationListRVAdapter(
    private fun ApplicationListItemBinding.handleUnavailable(
        view: View,
        searchApp: FusedApp,
        holder: ViewHolder,
    ) {
        installButton.apply {
            updateUIByPaymentType(searchApp, this, this@handleUnavailable)
            updateUIByPaymentType(searchApp, this, this@handleUnavailable, holder)
            setTextColor(context.getColor(R.color.colorAccent))
            backgroundTintList =
                ContextCompat.getColorStateList(view.context, android.R.color.transparent)
@@ -331,7 +341,8 @@ class ApplicationListRVAdapter(
    private fun updateUIByPaymentType(
        searchApp: FusedApp,
        materialButton: MaterialButton,
        applicationListItemBinding: ApplicationListItemBinding
        applicationListItemBinding: ApplicationListItemBinding,
        holder: ViewHolder
    ) {
        when {
            mainActivityViewModel.checkUnsupportedApplication(searchApp) -> {
@@ -347,7 +358,8 @@ class ApplicationListRVAdapter(
                materialButton.isEnabled = false
                materialButton.text = ""
                applicationListItemBinding.progressBarInstall.visibility = View.VISIBLE
                appInfoFetchViewModel.isAppPurchased(searchApp).observe(lifecycleOwner) {
                holder.isPurchasedLiveData = appInfoFetchViewModel.isAppPurchased(searchApp)
                holder.isPurchasedLiveData.observe(lifecycleOwner) {
                    materialButton.isEnabled = true
                    applicationListItemBinding.progressBarInstall.visibility = View.GONE
                    materialButton.text =
+6 −1
Original line number Diff line number Diff line
@@ -105,6 +105,8 @@
    <string name="unknown_error">Unknown Error!</string>
    <string name="not_enough_storage">There is not enough space available to download this application!</string>
    <string name="app_not_found">Your application was not found.</string>
    <string name="something_went_wrong">Something went wrong!</string>


    <!-- Updates Fragment -->
    <string name="update_all">Update All</string>
@@ -168,6 +170,9 @@
    <string name="dialog_confirm">CONFIRM</string>
    <string name="dialog_cancel">CANCEL</string>
    <string name="paid_app_anonymous_message">Paid apps cannot be installed in anonymous mode. Please log into your Google account to install paid apps.</string>
    <string name="purchase_complete">Purchase complete!</string>
    <string name="download_automatically_message">Your app will automatically be downloaded in this device</string>
    <string name="purchase_error">Purchase error!</string>

    <!--Unsupported app-->
    <string name="unsupported_app_title">Unsupported app!</string>