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

Commit 71b4fedb authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Use EventBus class to pass network errors via AppEvent.DataLoadError

parent 9ee9c3e2
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.aurora.gplayapi.data.models.AuthData
import com.aurora.gplayapi.exceptions.ApiException
import dagger.hilt.android.lifecycle.HiltViewModel
import foundation.e.apps.R
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.enums.Origin
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.enums.Status
@@ -34,6 +35,8 @@ import foundation.e.apps.data.fusedDownload.FusedManagerRepository
import foundation.e.apps.data.fusedDownload.models.FusedDownload
import foundation.e.apps.install.download.data.DownloadProgress
import foundation.e.apps.install.download.data.DownloadProgressLD
import foundation.e.apps.utils.eventBus.AppEvent
import foundation.e.apps.utils.eventBus.EventBus
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject
@@ -77,6 +80,16 @@ class ApplicationViewModel @Inject constructor(
                        origin
                    )
                fusedApp.postValue(appData)

                val status = appData.second

                if (status != ResultStatus.OK) {
                    EventBus.invokeEvent(
                        AppEvent.DataLoadError(
                            ResultSupreme.create(status, appData.first)
                        )
                    )
                }
            } catch (e: ApiException.AppNotFound) {
                _errorMessageLiveData.postValue(R.string.app_not_found)
            } catch (e: Exception) {
+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.fused.FusedAPIRepository
import foundation.e.apps.data.fused.data.FusedApp
import foundation.e.apps.utils.eventBus.AppEvent
import foundation.e.apps.utils.eventBus.EventBus
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject
@@ -71,6 +73,8 @@ class ApplicationListViewModel @Inject constructor(
                appListLiveData.postValue(ResultSupreme.create(ResultStatus.OK, it.first))
                updateNextPageUrl(it.second)
            }

            if (!result.isSuccess()) EventBus.invokeEvent(AppEvent.DataLoadError(result))
        }
    }

+13 −0
Original line number Diff line number Diff line
@@ -22,10 +22,13 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.fused.FusedAPIRepository
import foundation.e.apps.data.fused.data.FusedCategory
import foundation.e.apps.data.fused.utils.CategoryType
import foundation.e.apps.utils.eventBus.AppEvent
import foundation.e.apps.utils.eventBus.EventBus
import kotlinx.coroutines.launch
import javax.inject.Inject

@@ -47,6 +50,16 @@ class CategoriesViewModel @Inject constructor(
        viewModelScope.launch {
            val categoriesData = fusedAPIRepository.getCategoriesList(type)
            categoriesList.postValue(categoriesData)

            val status = categoriesData.third

            if (status != ResultStatus.OK) {
                EventBus.invokeEvent(
                    AppEvent.DataLoadError(
                        ResultSupreme.create(status, categoriesData.second)
                    )
                )
            }
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.fused.FusedAPIRepository
import foundation.e.apps.data.fused.data.FusedApp
import foundation.e.apps.data.fused.data.FusedHome
import foundation.e.apps.utils.eventBus.AppEvent
import foundation.e.apps.utils.eventBus.EventBus
import kotlinx.coroutines.launch
import javax.inject.Inject

@@ -52,6 +54,10 @@ class HomeViewModel @Inject constructor(
        viewModelScope.launch {
            fusedAPIRepository.getHomeScreenData(authData).observe(lifecycleOwner) {
                homeScreenData.postValue(it)

                if (!it.isSuccess()) viewModelScope.launch {
                    EventBus.invokeEvent(AppEvent.DataLoadError(it))
                }
            }
        }
    }
+3 −14
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import foundation.e.apps.data.fused.data.FusedApp
import foundation.e.apps.data.login.AuthObject
import foundation.e.apps.data.login.exceptions.CleanApkException
import foundation.e.apps.data.login.exceptions.GPlayException
import foundation.e.apps.utils.eventBus.AppEvent
import foundation.e.apps.utils.eventBus.EventBus
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -98,20 +100,7 @@ class SearchViewModel @Inject constructor(
            searchResult.postValue(searchResultSupreme)

            if (!searchResultSupreme.isSuccess()) {
                val exception =
                    if (authData.aasToken.isNotBlank() || authData.authToken.isNotBlank()) {
                        GPlayException(
                            searchResultSupreme.isTimeout(),
                            searchResultSupreme.message.ifBlank { DATA_LOAD_ERROR }
                        )
                    } else {
                        CleanApkException(
                            searchResultSupreme.isTimeout(),
                            searchResultSupreme.message.ifBlank { DATA_LOAD_ERROR }
                        )
                    }

//                handleException(exception)
                EventBus.invokeEvent(AppEvent.DataLoadError(searchResultSupreme))
            }

            nextSubBundle = null
Loading