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

Commit 5e1c1b52 authored by Nishant Dande's avatar Nishant Dande
Browse files

Merge branch '1346-connect-anonymous-api-with-ui' of...

Merge branch '1346-connect-anonymous-api-with-ui' of gitlab.e.foundation:e/os/apps into 1346-connect-anonymous-api-with-ui
parents 8a3e50a7 3841ddd2
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.aurora.gplayapi.exceptions.ApiException
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.fusedDownload.models.FusedDownload
import foundation.e.apps.data.login.LoginSourceGPlay
import foundation.e.apps.data.preference.PreferenceManagerModule
@@ -221,6 +222,10 @@ class MainActivity : AppCompatActivity() {
                launch {
                    observeNoInternetEvent()
                }

                launch {
                    observeDataLoadError()
                }
            }
        }
    }
@@ -292,6 +297,23 @@ class MainActivity : AppCompatActivity() {
        }
    }

    private suspend fun observeDataLoadError() {
        EventBus.events.filter { appEvent ->
            appEvent is AppEvent.DataLoadError<*>
        }.collectLatest {
            retryMechanism.wrapWithRetry(
                { loginViewModel.checkLogin() },
                {
                    ceh.getDialogForDataLoadError(
                        context = this@MainActivity,
                        result = it.data as ResultSupreme<*>,
                        retryAction = { loginViewModel.checkLogin() },
                    )?.run { ceh.dismissAllAndShow(this) }
                }
            )
        }
    }

    private fun validatedAuthObject(appEvent: AppEvent) {
        val data = appEvent.data as String
        if (data.isNotBlank()) {
+6 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import timber.log.Timber
import java.io.IOException
import java.io.InterruptedIOException
import java.net.SocketTimeoutException
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@@ -169,7 +170,11 @@ class GPlayHttpClient @Inject constructor(
        } catch (e: GplayHttpRequestException) {
            throw e
        } catch (e: Exception) {
            val status = if (e is SocketTimeoutException) STATUS_CODE_TIMEOUT else -1
            val status = when {
                e is SocketTimeoutException -> STATUS_CODE_TIMEOUT
                e is InterruptedIOException && e.message == "timeout" -> STATUS_CODE_TIMEOUT
                else -> -1
            }
            throw GplayHttpRequestException(status, e.localizedMessage ?: "")
        } finally {
            response?.close()
+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)
                    )
                )
            }
        }
    }
}
Loading