kotlin

Handling file download with gRPC on Android

你说的曾经没有我的故事 提交于 2020-06-26 13:53:13
问题 I currently have a gRPC server which is sending chunks of a video file. My android application written in Kotlin uses coroutines for UI updates (on Dispatchers.MAIN) and for handling a unidirectional stream of chunks (on Dispatchers.IO). Like the following: GlobalScope.launch(Dispatchers.Main) { viewModel.downloadUpdated().accept(DOWNLOAD_STATE.DOWNLOADING) // MAKE PROGRESS BAR VISIBLE GlobalScope.launch(Dispatchers.IO) { stub.downloadVideo(request).forEach { file.appendBytes( it.data

Handling file download with gRPC on Android

安稳与你 提交于 2020-06-26 13:53:04
问题 I currently have a gRPC server which is sending chunks of a video file. My android application written in Kotlin uses coroutines for UI updates (on Dispatchers.MAIN) and for handling a unidirectional stream of chunks (on Dispatchers.IO). Like the following: GlobalScope.launch(Dispatchers.Main) { viewModel.downloadUpdated().accept(DOWNLOAD_STATE.DOWNLOADING) // MAKE PROGRESS BAR VISIBLE GlobalScope.launch(Dispatchers.IO) { stub.downloadVideo(request).forEach { file.appendBytes( it.data

Get the same instance of ViewModel in Fragment which is defined in Activity with parameter

邮差的信 提交于 2020-06-26 12:54:11
问题 So, I am using Koin for dependency injection, Here is what I did inside a activity class ModuleDetailActivity : AppCompatActivity() { private lateinit var moduleId:String private lateinit var levelModule:Level.Module private val moduleViewModel: ModuleViewModel by viewModel { parameterOf(moduleId, levelModule) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ... ... moduleId = intent.getString("module_id") levelModule = intent.getParcelable("level

How to create full text search query in mongodb with spring-data?

谁都会走 提交于 2020-06-26 06:14:22
问题 I have spring-data-mogodb application on java or kotlin, and need create text search request to mongodb by spring template. In mongo shell it look like that: db.stores.find( { $text: { $search: "java coffee shop" } }, { score: { $meta: "textScore" } } ).sort( { score: { $meta: "textScore" } } ) I already tried to do something but it is not exactly what i need: @override fun getSearchedFiles(searchQuery: String, pageNumber: Long, pageSize: Long, direction: Sort.Direction, sortColumn: String):

How to create full text search query in mongodb with spring-data?

谁都会走 提交于 2020-06-26 06:11:41
问题 I have spring-data-mogodb application on java or kotlin, and need create text search request to mongodb by spring template. In mongo shell it look like that: db.stores.find( { $text: { $search: "java coffee shop" } }, { score: { $meta: "textScore" } } ).sort( { score: { $meta: "textScore" } } ) I already tried to do something but it is not exactly what i need: @override fun getSearchedFiles(searchQuery: String, pageNumber: Long, pageSize: Long, direction: Sort.Direction, sortColumn: String):

Unresolved reference: async in Kotlin in 1.3

ε祈祈猫儿з 提交于 2020-06-25 10:50:14
问题 I have multi module kotlin gradle project in github here. One of my sub project introducing-coroutines with build file build.gradle.kts file is here The contents of build.gradle.kts is - import org.jetbrains.kotlin.gradle.dsl.Coroutines import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { java kotlin("jvm") version "1.3.11" } group = "chapter2" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { compile(kotlin("stdlib-jdk8")) compile("org.jetbrains.kotlinx

Unresolved reference: async in Kotlin in 1.3

心已入冬 提交于 2020-06-25 10:49:20
问题 I have multi module kotlin gradle project in github here. One of my sub project introducing-coroutines with build file build.gradle.kts file is here The contents of build.gradle.kts is - import org.jetbrains.kotlin.gradle.dsl.Coroutines import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { java kotlin("jvm") version "1.3.11" } group = "chapter2" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { compile(kotlin("stdlib-jdk8")) compile("org.jetbrains.kotlinx

What are the `^let` annotations in Android Studio / IntelliJ?

﹥>﹥吖頭↗ 提交于 2020-06-25 09:11:33
问题 In a let block, I sometimes see ^let annotations before my statements, and it's not clear to me what they mean or why they are there. Is it to indicate that a value will be returned as the value of the let call? Screenshot: 回答1: These do in fact show you that those values are going to be returned from the let expression. If you move to cursor to one of these hints and open intention actions (Alt + Enter), you get the option "Do not show lambda return expression hints ", which I suppose is the

Hide static Java methods from Kotlin

谁都会走 提交于 2020-06-25 06:29:26
问题 We're converting a lot of java static methods to kotlin extension functions. However, there are some methods that we need to keep around JUST FOR JAVA (We want to force kotlin code to use the extension functions). Is there a way to hide java static methods from kotlin? 回答1: You can annotate those methods with a @Deprecated annotation with deprecation level HIDDEN: @kotlin.Deprecated(message = "JUST FOR JAVA", level = DeprecationLevel.HIDDEN) public void foo() { } 回答2: There is a solution. It

How to mock and verify Lambda expression in Kotlin?

懵懂的女人 提交于 2020-06-25 05:09:25
问题 In Kotlin (and Java 8) we can use Lambda expression to remove boilerplate callback interface. For example, data class Profile(val name: String) interface ProfileCallback { fun onSuccess(profile: Profile) } class ProfileRepository(val callback: ProfileCallback) { fun getProfile() { // do calculation callback.onSuccess(Profile("name")) } } We can change remove ProfileCallback and change it into Kotlin's Lambda: class ProfileRepository(val callback: (Profile) -> Unit) { fun getProfile() { // do