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

Commit 6826e7b1 authored by Hasib Prince's avatar Hasib Prince
Browse files

improvement for ui updating

parent fd5b61a2
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Timber.d("### oncreate 125")

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

+13 −4
Original line number Diff line number Diff line
@@ -208,14 +208,18 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        if (appInfoFetchViewModel.isAppInBlockedList(it)) {
            binding.snackbarLayout.visibility = View.VISIBLE
        }

        fetchAppTracker(it)
        observeDownloadList()
        observeDownloadStatus(binding.root)
        stopLoadingUI()
    }

    private fun observeDownloadList() {
        mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner)
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            applicationViewModel.updateApplicationStatus(list)
        }

        observeDownloadStatus(binding.root)
        stopLoadingUI()
    }

    private fun updateAppDescriptionText(it: FusedApp) {
@@ -706,7 +710,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        downloadProgress: DownloadProgress,
    ) {
        val progressResult = applicationViewModel.calculateProgress(downloadProgress)
        if (progressResult.first < 1) {
        if (view == null || progressResult.first < 1) {
            return
        }
        val downloadedSize = "${
@@ -780,6 +784,11 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        binding.ratingsInclude.appPrivacyScore.visibility = visibility
    }

    override fun onResume() {
        super.onResume()
        observeDownloadList()
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding?.recyclerView?.adapter = null
+1 −7
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import foundation.e.apps.utils.exceptions.GPlayLoginException
import foundation.e.apps.utils.modules.PWAManagerModule
import foundation.e.apps.utils.parentFragment.TimeoutFragment
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@AndroidEntryPoint
@@ -123,7 +122,6 @@ class ApplicationListFragment :
    ) {
        mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner)
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            Timber.d("### downloadlist observer responded: ${list.firstOrNull()?.name + ": " + list.firstOrNull()?.status}")
            val appList = viewModel.appListLiveData.value?.data?.toMutableList() ?: emptyList()

            appList.let {
@@ -144,16 +142,13 @@ class ApplicationListFragment :
    override fun onResume() {
        super.onResume()
        addDownloadProgressObserver()

        if (listAdapter.currentList.isNotEmpty() && viewModel.hasAnyAppInstallStatusChanged(
                listAdapter.currentList
            )
        ) {
            /*mainActivityViewModel.authData.value?.let {
                refreshData(it)
            }*/
            repostAuthObjects()
        }

    }

    private fun addDownloadProgressObserver() {
@@ -339,7 +334,6 @@ class ApplicationListFragment :

    override fun onPause() {
        binding.shimmerLayout.stopShimmer()
//        mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner)
        super.onPause()
    }

+0 −2
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ import foundation.e.apps.OpenForTesting
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.manager.database.fusedDownload.FusedDownloadDAO
import kotlinx.coroutines.flow.Flow
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton

@@ -29,7 +28,6 @@ class DatabaseRepository @Inject constructor(
    }

    suspend fun updateDownload(fusedDownload: FusedDownload) {
        Timber.d("### fusedownload updated: ${fusedDownload.name + ": " + fusedDownload.status}")
        fusedDownloadDAO.updateDownload(fusedDownload)
    }

+20 −13
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import androidx.cursoradapter.widget.CursorAdapter
import androidx.cursoradapter.widget.SimpleCursorAdapter
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.distinctUntilChanged
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
@@ -54,6 +53,7 @@ import foundation.e.apps.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.applicationlist.ApplicationListRVAdapter
import foundation.e.apps.databinding.FragmentSearchBinding
import foundation.e.apps.login.AuthObject
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.manager.download.data.DownloadProgress
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Status
@@ -61,7 +61,6 @@ import foundation.e.apps.utils.exceptions.GPlayLoginException
import foundation.e.apps.utils.modules.PWAManagerModule
import foundation.e.apps.utils.parentFragment.TimeoutFragment
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@AndroidEntryPoint
@@ -251,14 +250,21 @@ class SearchFragment :

    private fun observeDownloadList(applicationListRVAdapter: ApplicationListRVAdapter) {
        mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner)
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            val searchList =
                searchViewModel.searchResult.value?.data?.first?.toMutableList() ?: emptyList()
            searchList.let {
                mainActivityViewModel.updateStatusOfFusedApps(searchList, list)
                updateSearchResult(applicationListRVAdapter, ResultSupreme.Success(Pair(it, true)))
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { fusedDownloadList ->
            refreshUI(fusedDownloadList, applicationListRVAdapter)
        }
    }

    private fun refreshUI(
        fusedDownloadList: List<FusedDownload>,
        applicationListRVAdapter: ApplicationListRVAdapter
    ) {
        val searchList =
            searchViewModel.searchResult.value?.data?.first?.toMutableList() ?: emptyList()

        val hasMoreDataToLoad = searchViewModel.searchResult.value?.data?.second == true
        mainActivityViewModel.updateStatusOfFusedApps(searchList, fusedDownloadList)
        updateSearchResult(applicationListRVAdapter, ResultSupreme.Success(Pair(searchList, hasMoreDataToLoad)))
    }

    override fun onTimeout(
@@ -330,7 +336,10 @@ class SearchFragment :
        addDownloadProgressObservers()

        if (shouldRefreshData()) {
            repostAuthObjects()
            if (binding.recyclerView.adapter is ApplicationListRVAdapter) {
                val searchAdapter = binding.recyclerView.adapter as ApplicationListRVAdapter
                observeDownloadList(searchAdapter)
            }
        }

        if (searchText.isEmpty() && (recyclerView?.adapter as ApplicationListRVAdapter).currentList.isEmpty()) {
@@ -347,9 +356,7 @@ class SearchFragment :
    }

    private fun shouldRefreshData() =
        searchText.isNotEmpty() && recyclerView?.adapter != null && searchViewModel.hasAnyAppInstallStatusChanged(
            (recyclerView?.adapter as ApplicationListRVAdapter).currentList
        )
        searchText.isNotEmpty() && recyclerView?.adapter != null

    override fun onPause() {
        binding.shimmerLayout.stopShimmer()
Loading