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

Commit 236d476f authored by Hasib Prince's avatar Hasib Prince
Browse files

App lounge: fixed: showing wrong dialog

parent a26845ab
Loading
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -202,11 +202,6 @@ class MainActivity : AppCompatActivity() {
        viewModel.isAppPurchased.observe(this) {
            if (it.isNotEmpty()) {
                startInstallationOfPurchasedApp(viewModel, it)
                ApplicationDialogFragment(
                    title = getString(R.string.purchase_complete),
                    message = getString(R.string.download_automatically_message),
                    positiveButtonText = getString(R.string.ok)
                ).show(supportFragmentManager, TAG)
            }
        }

@@ -252,6 +247,11 @@ 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 {
                ApplicationDialogFragment(
                    title = getString(R.string.purchase_error),
+2 −2
Original line number Diff line number Diff line
@@ -297,10 +297,10 @@ class MainActivityViewModel @Inject constructor(
                        fusedDownload
                    )
                } catch (e: ApiException.AppNotPurchased) {
                    Log.e(TAG, e.stackTraceToString())
                    e.printStackTrace()
                    return null
                } catch (e: Exception) {
                    Log.e(TAG, e.stackTraceToString())
                    e.printStackTrace()
                    _errorMessage.value = e
                    return null
                }
+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 =