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

Commit 3d299a6a authored by Hasib Prince's avatar Hasib Prince
Browse files

boradcasted change of app status

parent 0347130f
Loading
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -26,10 +26,9 @@ import dagger.hilt.android.AndroidEntryPoint
import foundation.e.apps.api.faultyApps.FaultyAppRepository
import foundation.e.apps.manager.fused.FusedManagerRepository
import foundation.e.apps.utils.enums.Status
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import foundation.e.apps.utils.eventBus.AppEvent
import foundation.e.apps.utils.eventBus.EventBus
import kotlinx.coroutines.*
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Named
@@ -68,10 +67,16 @@ open class PkgManagerBR : BroadcastReceiver() {
                        Intent.ACTION_PACKAGE_ADDED -> {
                            updateDownloadStatus(pkgName)
                            removeFaultyAppByPackageName(pkgName)
                            MainScope().launch {
                                EventBus.invokeEvent(AppEvent.AppStatusUpdated())
                            }
                        }
                        Intent.ACTION_PACKAGE_REMOVED -> {
                            if (!isUpdating) deleteDownload(pkgName)
                            removeFaultyAppByPackageName(pkgName)
                            MainScope().launch {
                                EventBus.invokeEvent(AppEvent.AppStatusUpdated())
                            }
                        }
                        PkgManagerModule.ERROR_PACKAGE_INSTALL -> {
                            Timber.e("Installation failed due to error: $extra")
+1 −0
Original line number Diff line number Diff line
@@ -22,4 +22,5 @@ package foundation.e.apps.utils.eventBus

sealed class AppEvent(val data: Any) {
    class SignatureMissMatchError(packageName: String) : AppEvent(packageName)
    class AppStatusUpdated: AppEvent("")
}
+22 −2
Original line number Diff line number Diff line
@@ -18,13 +18,21 @@
package foundation.e.apps.utils.parentFragment

import android.app.Activity
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.aurora.gplayapi.data.models.AuthData
import foundation.e.apps.MainActivityViewModel
import foundation.e.apps.R
import foundation.e.apps.utils.eventBus.AppEvent
import foundation.e.apps.utils.eventBus.EventBus
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.filter
import timber.log.Timber

/*
 * Parent class (extending fragment) for fragments which can display a timeout dialog
@@ -40,6 +48,16 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) {
     */
    private var timeoutAlertDialog: AlertDialog? = null

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        lifecycleScope.launchWhenResumed {
            EventBus.events.filter { appEvent -> appEvent is AppEvent.AppStatusUpdated }
                .collectLatest {
                    Timber.d("@@@ app status updated")
                }
        }
    }

    abstract fun onTimeout()

    /*
@@ -182,7 +200,8 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) {
         */
        try {
            timeoutAlertDialog?.dismiss()
        } catch (_: Exception) {}
        } catch (_: Exception) {
        }

        timeoutAlertDialog = timeoutAlertDialogBuilder.create()
        timeoutAlertDialog?.show()
@@ -210,7 +229,8 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) {
        if (isTimeoutDialogDisplayed()) {
            try {
                timeoutAlertDialog?.dismiss()
            } catch (_: Exception) {}
            } catch (_: Exception) {
            }
        }
    }
}