This file contains hidden or 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 listAwsRepos(services: List<RetroService>): List<AwsRepo>? { | |
| Log.v(TAG, "Attempting to get awsRepos from \$services") | |
| services.filterIsInstance<AwsCodeCommitService>() | |
| .forEach { service -> | |
| val result = service.listAwsRepos() | |
| Log.i(TAG, "Returned result $result") | |
| return result | |
| } |
This file contains hidden or 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
| implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" // In your gradle | |
| import kotlin.reflect.KFunction1 // You have to import this manually | |
| // The IDE generates this automatically | |
| fun doAwsApiCall( | |
| services: List<RetroService>, | |
| apiCall: KFunction1<AwsCodeCommitService, List<AwsRepo>> | |
| ): List<AwsRepo>? { | |
| TODO("Not implemented yet") |
This file contains hidden or 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 doAwsApiCall( | |
| services: List<RetroService>, | |
| apiCall: KFunction1<AwsCodeCommitService, List<AwsRepo>> | |
| ): List<AwsRepo>? { | |
| Log.v(TAG, "Attempting to do \$apiCall on \$services") | |
| services.filterIsInstance<AwsCodeCommitService>() | |
| .forEach { service -> | |
| val result = apiCall(service) // This is the only real change | |
| Log.i(TAG, "Returned result $result") |
This file contains hidden or 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
| inline fun <reified Service: RetroService, Result> doApiCall( | |
| services: List<RetroService>, | |
| apiCall: KFunction1<Service, Result> | |
| ): Result? { | |
| Log.v(TAG, "Attempting to do \$apiCall on \$services") | |
| services.filterIsInstance<Service>() | |
| .forEach { service -> | |
| val result = apiCall(service) | |
| Log.i(TAG, "Returned result $result") |
This file contains hidden or 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
| import kotlin.reflect.KFunction2 // You have to import this manually | |
| inline fun <reified Service: RetroService, Input, Result> doApiCallWithArg( | |
| services: List<RetroService>, | |
| apiCall: KFunction2<Service, Input, Result>, | |
| input: Input | |
| ): Result? { | |
| Log.v(TAG, "Attempting to do \$apiCall on \$services with argument \$input") | |
| services.filterIsInstance<Service>() |
This file contains hidden or 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
| import kotlin.reflect.KSuspendFunction1 // You have to import this manually | |
| import kotlin.reflect.KSuspendFunction2 // You have to import this manually | |
| inline suspend fun <reified Service: RetroService, Result> doSuspendedApiCall( | |
| services: List<RetroService>, | |
| apiCall: KSuspendFunction1<Service, Result> | |
| ): Result? { | |
| // identical to doApiCall | |
| } |
This file contains hidden or 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
| // Project-level build.gradle: | |
| buildscript { | |
| dependencies { | |
| classpath 'com.novoda:bintray-release:0.9' | |
| } | |
| } | |
| // Library module build.gradle: | |
| apply plugin: 'com.novoda.bintray-release' |
This file contains hidden or 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
| inline fun <reified Interface, Input, Result> callFunction( | |
| apiCall: [THE INTERCHANGEABLE BIT], | |
| input: Input //If there is an input | |
| ): Result? |
This file contains hidden or 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 saveUsername(username: String) { | |
| StorageService.getInstance().saveUsername(username) { result -> | |
| handleResult(result) | |
| } | |
| } |
This file contains hidden or 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
| suspend fun saveUsername(username: String) { | |
| val result = suspendedSaveUsername(username) | |
| handleResult(result) | |
| } | |
| suspend fun suspendedSaveUsername(username: String) = suspendCoroutine<String> { continuation -> | |
| StorageService.getInstance().saveUsername(username) { result -> | |
| continuation.resume(result) |