This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> coWhenever(block: suspend CoroutineScope.() -> T): OngoingStubbing<T> = | |
runBlocking { | |
whenever(block()) | |
} | |
fun <T> coVerify(mock: T, block: suspend CoroutineScope.(T) -> Unit) { | |
runBlocking { | |
block(verify(mock)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Inject lateinit var suspendApi: SuspendApi | |
... | |
view!!.showTransparentLoading() | |
shownScope.launch { | |
val assetCategoriesResultDeferred = async{suspendApi.getAssetCategories()} | |
val categorizedAssetDeferred = async{suspendApi.getCategorizedAssets()} | |
val assetCategoriesResult = assetCategoriesResultDeferred.await() | |
val categorizedAssetsResult = categorizedAssetDeferred.await() | |
if (assetCategoriesResult is ApiResult.Success && categorizedAssetsResult is ApiResult.Success) { | |
assetCategoryList = assetCategoriesResult.data.assetCategories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Inject lateinit var suspendApi: SuspendApi | |
shownScope.launch { | |
view.showSearchLoading() | |
val result = suspendApi.getCategorizedAssetsSearch(searchStr, assetCategory?.categoryIdentifier) | |
view.hideSearchLoading() | |
when (result) { | |
is ApiResult.Success -> { | |
view.replaceListItems(getAssetListItem(result.data.categorizedAssets)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class ApiResult<out T> { | |
// HTTP 200 | |
data class Success<T>(val data: T) : ApiResult<T>() | |
// HTTP 400..500 | |
data class Failure(val code: Int, val message: String): ApiResult<Nothing>() | |
// Socket timeout, write in Demo, IO, , JSON parsing, NPE etc | |
data class NetworkError(val throwable: Throwable, val message: String, val networkErrorExceptions: ClassifiedNetworkErrorExceptions) : ApiResult<Nothing>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RolesAllowed(Role.READONLY, Role.PRIVILEGED) | |
@GET("v1/instruments/categorized-assets/search") | |
suspend fun getCategorizedAssetsSearch( | |
@Query("search_term") searchTerm: String?, | |
@Query("category_identifier") categoryIdentifier: Int? | |
): ApiResult<CategorizedAssetsResponse> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun fetchAccounts() { | |
val externalAccountLinkStatusObservable = linkCoordinator.linkStatusObservable | |
val wealthFrontAccountObservable = accountRepository.wealthfrontAccountObservable | |
val wealthFrontAccountRequestsObservable = accountRequestsRepository.wealthfrontAccountRequestObservable | |
val calloutObservable = calloutsRepository.getCalloutsObservable(AccountListSection::class.java) | |
autoDisposer.autoDispose( | |
combineLatest( | |
externalAccountLinkStatusObservable, | |
wealthFrontAccountObservable, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
autoDispose( | |
api.getCategorizedAssetsSearch(searchStr, assetCategory?.categoryIdentifier) | |
.observeOn(mainThread()) | |
.doOnSubscribe { view.showSearchLoading() } | |
.doOnTerminate { view.hideSearchLoading() } | |
.subscribe( | |
{ | |
view.replaceListItems(getAssetListItem(it.categorizedAssets)) | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GET("v1/instruments/categorized-assets/search") | |
Observable<CategorizedAssetsResponse> getCategorizedAssetsSearch( | |
@Nonnull @Query("search_term") String searchTerm, | |
@Nullable @Query("category_identifier") Integer categoryIdentifier | |
); |