Loading app/src/main/java/foundation/e/apps/MainActivity.kt +3 −2 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.data.fusedDownload.models.FusedDownload import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.login.LoginSourceGPlay import foundation.e.apps.data.login.LoginViewModel import foundation.e.apps.data.login.exceptions.GPlayValidationException import foundation.e.apps.data.preference.PreferenceManagerModule Loading Loading @@ -308,11 +309,11 @@ class MainActivity : AppCompatActivity() { private suspend fun observeTooManyRequests() { EventBus.events.filter { appEvent -> appEvent is AppEvent.TooManyRequests }.collectLatest { appEvent -> }.collectLatest { binding.sessionErrorLayout.visibility = View.VISIBLE binding.retrySessionButton.setOnClickListener { binding.sessionErrorLayout.visibility = View.GONE validatedAuthObject(appEvent = appEvent) loginViewModel.startLoginFlow(listOf(LoginSourceGPlay::class.java.simpleName)) } } } Loading app/src/main/java/foundation/e/apps/data/gplay/utils/GPlayHttpClient.kt +12 −4 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ import java.util.concurrent.TimeUnit import javax.inject.Inject class GPlayHttpClient @Inject constructor( cache: Cache, private val cache: Cache, ) : IHttpClient { private val POST = "POST" Loading @@ -55,6 +55,9 @@ class GPlayHttpClient @Inject constructor( private const val TAG = "GPlayHttpClient" private const val HTTP_TIMEOUT_IN_SECOND = 10L private const val SEARCH = "search" private const val SEARCH_SUGGEST = "searchSuggest" private const val STATUS_CODE_UNAUTHORIZED = 401 private const val STATUS_CODE_TOO_MANY_REQUESTS = 429 } private val okHttpClient = OkHttpClient().newBuilder() Loading Loading @@ -200,15 +203,20 @@ class GPlayHttpClient @Inject constructor( Timber.d("$TAG: Url: ${response.request.url}\nStatus: $code") when (code) { 401 -> MainScope().launch { STATUS_CODE_UNAUTHORIZED -> MainScope().launch { EventBus.invokeEvent( AppEvent.InvalidAuthEvent(AuthObject.GPlayAuth::class.java.simpleName) ) } 429 -> MainScope().launch { STATUS_CODE_TOO_MANY_REQUESTS -> MainScope().launch { cache.evictAll() if (response.request.url.toString().contains(SEARCH_SUGGEST)) { return@launch } EventBus.invokeEvent( AppEvent.TooManyRequests(AuthObject.GPlayAuth::class.java.simpleName) AppEvent.TooManyRequests() ) } } Loading app/src/main/java/foundation/e/apps/data/login/LoginViewModel.kt +0 −2 Original line number Diff line number Diff line Loading @@ -17,12 +17,10 @@ package foundation.e.apps.data.login import android.content.Context import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.data.enums.User import foundation.e.apps.ui.parentFragment.LoadingViewModel import kotlinx.coroutines.launch Loading app/src/main/java/foundation/e/apps/ui/parentFragment/LoadingViewModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ abstract class LoadingViewModel : ViewModel() { it is GPlayValidationException }?.run { if (!autoRetried && retryBlock(failedAuthList)) { autoRetried = false autoRetried = true exceptionsList.clear() return } Loading app/src/main/java/foundation/e/apps/ui/parentFragment/TimeoutFragment.kt +8 −1 Original line number Diff line number Diff line Loading @@ -54,6 +54,10 @@ import timber.log.Timber */ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { companion object { private const val STATUS_TOO_MANY_REQUESTS = "Status: 429" } val loginViewModel: LoginViewModel by lazy { ViewModelProvider(requireActivity())[LoginViewModel::class.java] } Loading Loading @@ -353,7 +357,6 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { * is shown to the user. */ fun showDataLoadError(exception: Exception) { val dialogView = DialogErrorLogBinding.inflate(requireActivity().layoutInflater) dialogView.apply { moreInfo.setOnClickListener { Loading Loading @@ -406,6 +409,10 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { } val unknownSourceException = exceptions.find { it is UnknownSourceException } if (gPlayException?.message?.contains(STATUS_TOO_MANY_REQUESTS) == true) { return } /* * Take caution altering the cases. * Cases to be defined from most restrictive to least restrictive. Loading Loading
app/src/main/java/foundation/e/apps/MainActivity.kt +3 −2 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.data.fusedDownload.models.FusedDownload import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.login.LoginSourceGPlay import foundation.e.apps.data.login.LoginViewModel import foundation.e.apps.data.login.exceptions.GPlayValidationException import foundation.e.apps.data.preference.PreferenceManagerModule Loading Loading @@ -308,11 +309,11 @@ class MainActivity : AppCompatActivity() { private suspend fun observeTooManyRequests() { EventBus.events.filter { appEvent -> appEvent is AppEvent.TooManyRequests }.collectLatest { appEvent -> }.collectLatest { binding.sessionErrorLayout.visibility = View.VISIBLE binding.retrySessionButton.setOnClickListener { binding.sessionErrorLayout.visibility = View.GONE validatedAuthObject(appEvent = appEvent) loginViewModel.startLoginFlow(listOf(LoginSourceGPlay::class.java.simpleName)) } } } Loading
app/src/main/java/foundation/e/apps/data/gplay/utils/GPlayHttpClient.kt +12 −4 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ import java.util.concurrent.TimeUnit import javax.inject.Inject class GPlayHttpClient @Inject constructor( cache: Cache, private val cache: Cache, ) : IHttpClient { private val POST = "POST" Loading @@ -55,6 +55,9 @@ class GPlayHttpClient @Inject constructor( private const val TAG = "GPlayHttpClient" private const val HTTP_TIMEOUT_IN_SECOND = 10L private const val SEARCH = "search" private const val SEARCH_SUGGEST = "searchSuggest" private const val STATUS_CODE_UNAUTHORIZED = 401 private const val STATUS_CODE_TOO_MANY_REQUESTS = 429 } private val okHttpClient = OkHttpClient().newBuilder() Loading Loading @@ -200,15 +203,20 @@ class GPlayHttpClient @Inject constructor( Timber.d("$TAG: Url: ${response.request.url}\nStatus: $code") when (code) { 401 -> MainScope().launch { STATUS_CODE_UNAUTHORIZED -> MainScope().launch { EventBus.invokeEvent( AppEvent.InvalidAuthEvent(AuthObject.GPlayAuth::class.java.simpleName) ) } 429 -> MainScope().launch { STATUS_CODE_TOO_MANY_REQUESTS -> MainScope().launch { cache.evictAll() if (response.request.url.toString().contains(SEARCH_SUGGEST)) { return@launch } EventBus.invokeEvent( AppEvent.TooManyRequests(AuthObject.GPlayAuth::class.java.simpleName) AppEvent.TooManyRequests() ) } } Loading
app/src/main/java/foundation/e/apps/data/login/LoginViewModel.kt +0 −2 Original line number Diff line number Diff line Loading @@ -17,12 +17,10 @@ package foundation.e.apps.data.login import android.content.Context import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.data.enums.User import foundation.e.apps.ui.parentFragment.LoadingViewModel import kotlinx.coroutines.launch Loading
app/src/main/java/foundation/e/apps/ui/parentFragment/LoadingViewModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ abstract class LoadingViewModel : ViewModel() { it is GPlayValidationException }?.run { if (!autoRetried && retryBlock(failedAuthList)) { autoRetried = false autoRetried = true exceptionsList.clear() return } Loading
app/src/main/java/foundation/e/apps/ui/parentFragment/TimeoutFragment.kt +8 −1 Original line number Diff line number Diff line Loading @@ -54,6 +54,10 @@ import timber.log.Timber */ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { companion object { private const val STATUS_TOO_MANY_REQUESTS = "Status: 429" } val loginViewModel: LoginViewModel by lazy { ViewModelProvider(requireActivity())[LoginViewModel::class.java] } Loading Loading @@ -353,7 +357,6 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { * is shown to the user. */ fun showDataLoadError(exception: Exception) { val dialogView = DialogErrorLogBinding.inflate(requireActivity().layoutInflater) dialogView.apply { moreInfo.setOnClickListener { Loading Loading @@ -406,6 +409,10 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { } val unknownSourceException = exceptions.find { it is UnknownSourceException } if (gPlayException?.message?.contains(STATUS_TOO_MANY_REQUESTS) == true) { return } /* * Take caution altering the cases. * Cases to be defined from most restrictive to least restrictive. Loading