Loading app/src/main/java/foundation/e/apps/MainActivity.kt +20 −26 Original line number Original line Diff line number Diff line Loading @@ -67,8 +67,6 @@ class MainActivity : AppCompatActivity() { private val TAG = MainActivity::class.java.simpleName private val TAG = MainActivity::class.java.simpleName private lateinit var viewModel: MainActivityViewModel private lateinit var viewModel: MainActivityViewModel private var isShowingDialog = false @Inject @Inject lateinit var preferenceManagerModule: PreferenceManagerModule lateinit var preferenceManagerModule: PreferenceManagerModule Loading Loading @@ -137,6 +135,12 @@ class MainActivity : AppCompatActivity() { email, email, SystemInfoProvider.getAppBuildInfo() SystemInfoProvider.getAppBuildInfo() ) ) } else if (exception != null) { ApplicationDialogFragment( title = getString(R.string.sign_in_failed_title), message = getString(R.string.sign_in_failed_desc), positiveButtonText = getString(R.string.ok) ).show(supportFragmentManager, TAG) } } } } } } Loading Loading @@ -288,36 +292,26 @@ class MainActivity : AppCompatActivity() { }.distinctUntilChanged { old, new -> }.distinctUntilChanged { old, new -> ((old.data is String) && (new.data is String) && old.data == new.data) ((old.data is String) && (new.data is String) && old.data == new.data) }.collectLatest { }.collectLatest { val data = it.data as String validatedAuthObject(it) } } private fun validatedAuthObject(appEvent: AppEvent) { val data = appEvent.data as String if (data.isNotBlank()) { if (data.isNotBlank()) { loginViewModel.markInvalidAuthObject(data) loginViewModel.markInvalidAuthObject(data) } } } } } private suspend fun observeTooManyRequests() { private suspend fun observeTooManyRequests() { EventBus.events.filter { appEvent -> EventBus.events.filter { appEvent -> appEvent is AppEvent.TooManyRequests appEvent is AppEvent.TooManyRequests }.collectLatest { }.collectLatest { appEvent -> if (isShowingDialog) return@collectLatest binding.sessionErrorLayout.visibility = View.VISIBLE ApplicationDialogFragment( binding.retrySessionButton.setOnClickListener { title = getString(R.string.too_many_requests), binding.sessionErrorLayout.visibility = View.GONE message = getString(R.string.too_many_requests_desc), validatedAuthObject(appEvent = appEvent) positiveButtonText = getString(R.string.ok), } positiveButtonAction = { preferenceManagerModule.disableGplay() loginViewModel.startLoginFlow() }, cancelButtonText = getString(R.string.logout), cancelButtonAction = { loginViewModel.logout() }, cancellable = false, onDismissListener = { isShowingDialog = false }, ).show(supportFragmentManager, TAG) isShowingDialog = true } } } } Loading app/src/main/java/foundation/e/apps/data/fused/FusedApiImpl.kt +1 −2 Original line number Original line Diff line number Diff line Loading @@ -280,7 +280,6 @@ class FusedApiImpl @Inject constructor( packageSpecificResults packageSpecificResults ) ) } } return finalSearchResult return finalSearchResult } } Loading Loading @@ -427,7 +426,7 @@ class FusedApiImpl @Inject constructor( ): FusedApp? { ): FusedApp? { try { try { getApplicationDetails(query, query, authData, Origin.GPLAY).let { getApplicationDetails(query, query, authData, Origin.GPLAY).let { if (it.second == ResultStatus.OK) { if (it.second == ResultStatus.OK && it.first.package_name.isNotEmpty()) { return it.first return it.first } } } } Loading app/src/main/java/foundation/e/apps/data/gplay/utils/GPlayHttpClient.kt +6 −2 Original line number Original line Diff line number Diff line Loading @@ -155,9 +155,11 @@ class GPlayHttpClient @Inject constructor( } } private fun processRequest(request: Request): PlayResponse { private fun processRequest(request: Request): PlayResponse { var response: Response? = null return try { return try { val call = okHttpClient.newCall(request) val call = okHttpClient.newCall(request) buildPlayResponse(call.execute()) response = call.execute() buildPlayResponse(response) } catch (e: Exception) { } catch (e: Exception) { // TODO: exception will be thrown for all apis when all gplay api implementation // TODO: exception will be thrown for all apis when all gplay api implementation // will handle the exceptions. this will be done in following issue. // will handle the exceptions. this will be done in following issue. Loading @@ -171,6 +173,8 @@ class GPlayHttpClient @Inject constructor( is SocketTimeoutException -> handleExceptionOnGooglePlayRequest(e) is SocketTimeoutException -> handleExceptionOnGooglePlayRequest(e) else -> handleExceptionOnGooglePlayRequest(e) else -> handleExceptionOnGooglePlayRequest(e) } } } finally { response?.close() } } } } Loading Loading @@ -204,7 +208,7 @@ class GPlayHttpClient @Inject constructor( 429 -> MainScope().launch { 429 -> MainScope().launch { EventBus.invokeEvent( EventBus.invokeEvent( AppEvent.TooManyRequests() AppEvent.TooManyRequests(AuthObject.GPlayAuth::class.java.simpleName) ) ) } } } } Loading app/src/main/java/foundation/e/apps/data/login/LoginViewModel.kt +3 −0 Original line number Original line Diff line number Diff line Loading @@ -17,10 +17,12 @@ package foundation.e.apps.data.login package foundation.e.apps.data.login import android.content.Context import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.data.enums.User import foundation.e.apps.data.enums.User import foundation.e.apps.ui.parentFragment.LoadingViewModel import foundation.e.apps.ui.parentFragment.LoadingViewModel import kotlinx.coroutines.launch import kotlinx.coroutines.launch Loading Loading @@ -122,6 +124,7 @@ class LoginViewModel @Inject constructor( } } authObjects.postValue(authObjectsLocal) authObjects.postValue(authObjectsLocal) cache.evictAll() } } /** /** Loading app/src/main/java/foundation/e/apps/ui/parentFragment/LoadingViewModel.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,7 @@ abstract class LoadingViewModel : ViewModel() { it is GPlayValidationException it is GPlayValidationException }?.run { }?.run { if (!autoRetried && retryBlock(failedAuthList)) { if (!autoRetried && retryBlock(failedAuthList)) { autoRetried = true autoRetried = false exceptionsList.clear() exceptionsList.clear() return return } } Loading Loading
app/src/main/java/foundation/e/apps/MainActivity.kt +20 −26 Original line number Original line Diff line number Diff line Loading @@ -67,8 +67,6 @@ class MainActivity : AppCompatActivity() { private val TAG = MainActivity::class.java.simpleName private val TAG = MainActivity::class.java.simpleName private lateinit var viewModel: MainActivityViewModel private lateinit var viewModel: MainActivityViewModel private var isShowingDialog = false @Inject @Inject lateinit var preferenceManagerModule: PreferenceManagerModule lateinit var preferenceManagerModule: PreferenceManagerModule Loading Loading @@ -137,6 +135,12 @@ class MainActivity : AppCompatActivity() { email, email, SystemInfoProvider.getAppBuildInfo() SystemInfoProvider.getAppBuildInfo() ) ) } else if (exception != null) { ApplicationDialogFragment( title = getString(R.string.sign_in_failed_title), message = getString(R.string.sign_in_failed_desc), positiveButtonText = getString(R.string.ok) ).show(supportFragmentManager, TAG) } } } } } } Loading Loading @@ -288,36 +292,26 @@ class MainActivity : AppCompatActivity() { }.distinctUntilChanged { old, new -> }.distinctUntilChanged { old, new -> ((old.data is String) && (new.data is String) && old.data == new.data) ((old.data is String) && (new.data is String) && old.data == new.data) }.collectLatest { }.collectLatest { val data = it.data as String validatedAuthObject(it) } } private fun validatedAuthObject(appEvent: AppEvent) { val data = appEvent.data as String if (data.isNotBlank()) { if (data.isNotBlank()) { loginViewModel.markInvalidAuthObject(data) loginViewModel.markInvalidAuthObject(data) } } } } } private suspend fun observeTooManyRequests() { private suspend fun observeTooManyRequests() { EventBus.events.filter { appEvent -> EventBus.events.filter { appEvent -> appEvent is AppEvent.TooManyRequests appEvent is AppEvent.TooManyRequests }.collectLatest { }.collectLatest { appEvent -> if (isShowingDialog) return@collectLatest binding.sessionErrorLayout.visibility = View.VISIBLE ApplicationDialogFragment( binding.retrySessionButton.setOnClickListener { title = getString(R.string.too_many_requests), binding.sessionErrorLayout.visibility = View.GONE message = getString(R.string.too_many_requests_desc), validatedAuthObject(appEvent = appEvent) positiveButtonText = getString(R.string.ok), } positiveButtonAction = { preferenceManagerModule.disableGplay() loginViewModel.startLoginFlow() }, cancelButtonText = getString(R.string.logout), cancelButtonAction = { loginViewModel.logout() }, cancellable = false, onDismissListener = { isShowingDialog = false }, ).show(supportFragmentManager, TAG) isShowingDialog = true } } } } Loading
app/src/main/java/foundation/e/apps/data/fused/FusedApiImpl.kt +1 −2 Original line number Original line Diff line number Diff line Loading @@ -280,7 +280,6 @@ class FusedApiImpl @Inject constructor( packageSpecificResults packageSpecificResults ) ) } } return finalSearchResult return finalSearchResult } } Loading Loading @@ -427,7 +426,7 @@ class FusedApiImpl @Inject constructor( ): FusedApp? { ): FusedApp? { try { try { getApplicationDetails(query, query, authData, Origin.GPLAY).let { getApplicationDetails(query, query, authData, Origin.GPLAY).let { if (it.second == ResultStatus.OK) { if (it.second == ResultStatus.OK && it.first.package_name.isNotEmpty()) { return it.first return it.first } } } } Loading
app/src/main/java/foundation/e/apps/data/gplay/utils/GPlayHttpClient.kt +6 −2 Original line number Original line Diff line number Diff line Loading @@ -155,9 +155,11 @@ class GPlayHttpClient @Inject constructor( } } private fun processRequest(request: Request): PlayResponse { private fun processRequest(request: Request): PlayResponse { var response: Response? = null return try { return try { val call = okHttpClient.newCall(request) val call = okHttpClient.newCall(request) buildPlayResponse(call.execute()) response = call.execute() buildPlayResponse(response) } catch (e: Exception) { } catch (e: Exception) { // TODO: exception will be thrown for all apis when all gplay api implementation // TODO: exception will be thrown for all apis when all gplay api implementation // will handle the exceptions. this will be done in following issue. // will handle the exceptions. this will be done in following issue. Loading @@ -171,6 +173,8 @@ class GPlayHttpClient @Inject constructor( is SocketTimeoutException -> handleExceptionOnGooglePlayRequest(e) is SocketTimeoutException -> handleExceptionOnGooglePlayRequest(e) else -> handleExceptionOnGooglePlayRequest(e) else -> handleExceptionOnGooglePlayRequest(e) } } } finally { response?.close() } } } } Loading Loading @@ -204,7 +208,7 @@ class GPlayHttpClient @Inject constructor( 429 -> MainScope().launch { 429 -> MainScope().launch { EventBus.invokeEvent( EventBus.invokeEvent( AppEvent.TooManyRequests() AppEvent.TooManyRequests(AuthObject.GPlayAuth::class.java.simpleName) ) ) } } } } Loading
app/src/main/java/foundation/e/apps/data/login/LoginViewModel.kt +3 −0 Original line number Original line Diff line number Diff line Loading @@ -17,10 +17,12 @@ package foundation.e.apps.data.login package foundation.e.apps.data.login import android.content.Context import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.data.enums.User import foundation.e.apps.data.enums.User import foundation.e.apps.ui.parentFragment.LoadingViewModel import foundation.e.apps.ui.parentFragment.LoadingViewModel import kotlinx.coroutines.launch import kotlinx.coroutines.launch Loading Loading @@ -122,6 +124,7 @@ class LoginViewModel @Inject constructor( } } authObjects.postValue(authObjectsLocal) authObjects.postValue(authObjectsLocal) cache.evictAll() } } /** /** Loading
app/src/main/java/foundation/e/apps/ui/parentFragment/LoadingViewModel.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,7 @@ abstract class LoadingViewModel : ViewModel() { it is GPlayValidationException it is GPlayValidationException }?.run { }?.run { if (!autoRetried && retryBlock(failedAuthList)) { if (!autoRetried && retryBlock(failedAuthList)) { autoRetried = true autoRetried = false exceptionsList.clear() exceptionsList.clear() return return } } Loading