kotlin

Access main project from module in Android Studio?

匆匆过客 提交于 2020-08-27 06:15:39
问题 I am using this library which I have installed locally as a module. I'm able to access it via my main project, but I'm not able to do the opposite. For example, access a variable in my main project from this library... I tried adding this line in the library's build.gradle : implementation project(':app') But I get this weird error: Circular dependency between the following tasks: :placepicker:generateDebugRFile \--- :placepicker:generateDebugRFile (*) (*) - details omitted (listed previously

How to set default value in BehaviourSubject

馋奶兔 提交于 2020-08-25 07:43:43
问题 Probably a noob question. How do I set a default value to a BehaviourSubject. I have an enum with 2 different values enum class WidgetState { HIDDEN, VISIBLE } And a behaviour subject which emits the states val widgetStateEmitter: BehaviorSubject<WidgetState> = BehaviorSubject.create() My emitter starts emitting when the view logic is written. However it's HIDDEN by default. How do I set the default value as WidgetState.HIDDEN to my emitter widgetStateEmitter ? 回答1: There's a static

Error creating bean named `conversionServicePostProcessor` when using spring-boot-admin-server

蹲街弑〆低调 提交于 2020-08-24 07:44:20
问题 I was trying to enable Spring boot admin server for my application. The default settings work perfectly fine but when I attempt to enable security, I am getting following error: APPLICATION FAILED TO START Description: The bean 'conversionServicePostProcessor', defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org

Create Custom Dagger 2 Scope with Kotlin

删除回忆录丶 提交于 2020-08-24 06:10:19
问题 I'm trying to convert a Java code into Kotlin for custom dagger scope creation. Here is Java code: @Documented @Scope @Retention(RetentionPolicy.RUNTIME) public @interface CustomScope { } Once converted into kotlin here is the result @Scope @Documented @Retention(RetentionPolicy.RUNTIME) annotation class CustomScope I have a type mismatch with @Retention(RetentionPolicy.RUNTIME) .I have the following error message :Required Type is AnnotationRetention but RetentionPolicy type was found. Also

We have to cover all branches with all Control-Flow expressions in Kotlin?

那年仲夏 提交于 2020-08-22 19:14:51
问题 I looked at the docs from Kotlin website, there are only two Control-Flow expressions: if and when . For if : the expression is required to have an else branch For when : The else branch is evaluated if none of the other branch conditions are satisfied. If when is used as an expression, the else branch is mandatory, unless the compiler can prove that all possible cases are covered with branch conditions. Question So it seems that there is no way to make a Control-Flow expression without

Firebase messaging-handle background message in kotlin

邮差的信 提交于 2020-08-22 11:44:34
问题 I'm using firebase_messaging in my flutter application. To handle background messages with firebase messaging in pub they suggested to create new Application.java file and replace java file name in AndroidManifest file. In my application i'm using kotlin and i already implemented some native code in MainActivity.kt So how to write this code in kotlin. package io.flutter.plugins.firebasemessagingexample; import io.flutter.app.FlutterApplication; import io.flutter.plugin.common.PluginRegistry;

Kotlin - Most idiomatic way to convert a List to a MutableList

痴心易碎 提交于 2020-08-22 07:09:36
问题 I have a method ( getContacts ) that returns a List<Contact> and I need to convert this result to a MutableList<Contact> . Currently the best way I can think of doing it is like this: val contacts: MutableList<Contact> = ArrayList(presenter.getContacts()) Is there a more idiomatic/"less Java" way to do that? 回答1: Consider using the toMutableList() function: presenter.getContacts().toMutableList() There are toMutableList() extensions for the stdlib types that one might want to convert to a

Why kotlin allows to declare variable with the same name as parameter inside the method?

末鹿安然 提交于 2020-08-22 04:23:27
问题 Why kotlin allows to declare variable with the same name as parameter inside the method? And is there any way to access 'hidden' parameter then? Example: fun main(args: Array<String>) { val args = Any() } 回答1: This is called shadowing and it is useful for decoupling your code from other parts of the system. It is possible because names are bound to the current scope. Consider this: You subclass a class Foo from someone else, let's say an API. In your code you introduce a variable bar . The

Custom “navigate up” behavior for certain fragment using Navigation component

南笙酒味 提交于 2020-08-21 05:14:13
问题 I want to add custom up navigation from fragment using Navigation component In my build.gradle(app) I use androidx.appcompat:appcompat:1.1.0-alpha04 dependency to have access to onBackPressedDispatcher from activity. So I implemented OnBackPressedCallback in my fragment and registered callback to dispatcher: requireActivity().onBackPressedDispatcher.addCallback(this) I expected that pressing navigate up in toolbar will call it, but it doesn't. Pressing device's back button calls it as

Custom “navigate up” behavior for certain fragment using Navigation component

馋奶兔 提交于 2020-08-21 05:13:46
问题 I want to add custom up navigation from fragment using Navigation component In my build.gradle(app) I use androidx.appcompat:appcompat:1.1.0-alpha04 dependency to have access to onBackPressedDispatcher from activity. So I implemented OnBackPressedCallback in my fragment and registered callback to dispatcher: requireActivity().onBackPressedDispatcher.addCallback(this) I expected that pressing navigate up in toolbar will call it, but it doesn't. Pressing device's back button calls it as