I am using MVP pattern on a Kotlin Project. I have a Presenter class:
import com.google.gson.Gson
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.async
import org.jetbrains.anko.coroutines.experimental.bg
class TeamsPresenter(private val view: TeamsView,
private val apiRepository: ApiRepository,
private val gson: Gson
) {
fun getTeamList(league: String?) {
view.showLoading()
async(UI){
val data = bg {
gson.fromJson(apiRepository
.doRequest(TheSportDBApi.getTeams(league)),
TeamResponse::class.java
)
}
view.showTeamList(data.await().teams)
view.hideLoading()
}
}
}
this presenter class working fine on Kotlin 1.2.71, but I can't get it working on Kotlin 1.3.0.
I updated Kotlin version in project's build.gradle, removed "experimental coroutines" and added kotlin coroutine core dependency:
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
and this is my current code:
import com.google.gson.Gson
class TeamsPresenter(private val view: TeamsView,
private val apiRepository: ApiRepository,
private val gson: Gson
) {
fun getTeamList(league: String?) {
view.showLoading()
async(UI){
val data = bg {
gson.fromJson(apiRepository
.doRequest(TheSportDBApi.getTeams(league)),
TeamResponse::class.java
)
}
view.showTeamList(data.await().teams)
view.hideLoading()
}
}
}
Error mainly on async, UI, and bg function:
unresolved reference: async
unresolved reference: UI
unresolved reference: bg
How can I get this to work on Kotlin 1.3.0? for any help, thanks in advance.
Learn more about types of Kotlin releases and their compatiblity. IntelliJ IDEA and Android Studio suggest updating to a new release once it is out. When you accept the suggestion, it automatically updates the Kotlin plugin to the new version. You can check the Kotlin version in Tools | Kotlin | Configure Kotlin Plugin Updates.
Kotlin/Native: KDoc export to Objective-C headers and faster Array.copyInto () inside one array Gradle: caching of annotation processors' classloaders and support for the --parallel Gradle property What's new in Kotlin 1.5.20
Having the kotlin.code.style option set may modify the code style scheme during a project import and may change the code style settings. After updating your code style settings, activate Reformat Code in the project view on the desired scope.
kotlinx.html version: 0.7.2 The versions of libraries from kotlin-wrappers (such as kotlin-react) can be found in the corresponding repository. A bug fix release for Kotlin 1.5.30.
you must use GlobalScope.launch instead of launch ,GlobalScope.async instead of async Dispatcher.main instead of UI
coroutineBasics
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With