Android databinding with Kotlin map - android

This is a basic question that for some reason Google doesn't seem to have the answer. I'm trying to use a Kotlin map object with databinding for xml. How the heck do I import the Map object in the xml?
Using
name="formIds"
type="kotlin.collections.MapsKt" />
doesn't import the map object. I get a Failed to resolve Bracked Expr formIds["Submit"], target: kotlin.collections.MapsKt when I try to use the object.
I create formIds as follows:
val _formIds =
mapOf<FormType, Map<String, Int>>(...
Anyone know?

type="kotlin.collections.MapsKt" is not enought for databinding. Declare it explictly with types and provide import if required. For example type="java.util.HashMap<String, Integer>"

Related

kotlin- PaymentSessionConfiguration

Hello I am trying to update stripe but when I have to call PaymentSessionConfig my code blocks because the companion of the PaymentSessionConfig class is in private, I cannot modify the class because it is in read only, here is the line :
mPaymentSession = PaymentSession (activity = summaryActivity, config = PaymentSessionConfig)
and the error message I have :
Cannot access 'Companion': it is private in 'PaymentSessionConfig'
Type mismatch.
Required:
PaymentSessionConfig
Found:
PaymentSessionConfig.Companion
Can you share the details of what versions of the SDK you're updating from and to? The migration docs cover a lot of details changes for various versions.
Is it possible you mean to reference some paymentSessionConfig, or what is your config here?
See this example implementation using the PaymentSessionConfig.Builder() (github)

CoordinatorLayout.DefaultBehaviour deprecated, no other option

So according to android documentation, defaultBehaviour is deprecated and AttachedBehaviour should be used instead.
However:
does not "exist" in android. I always receive the Annotation type expected error.
My import is:
import androidx.coordinatorlayout.widget.CoordinatorLayout;
Am I using the wrong import?
AttachedBehavior is an interface, not an annotation.
Therefore your CustomLinearLayout must implement AttachedBehavior and override the getBehavior() method to return an instance of your MoveUpwardBehavior class.

kotlin missing methods for GoogleMap

I'm converting part of an app to kotlin and I've a problem caused by the intellisense of Android Studio (3.5.3) not showing all methods of googleMaps
this is an example:
override fun onMapReady(googleMap: GoogleMap) {
map = googleMap
map.setBuildingsEnabled(true)
map.setTrafficEnabled(true)
map.setOnMapLoadedCallback(OnMapLoadedCallback {
if (currentMission != null) {
drawMission()
} else {
drawNoMission()
}
})
}
for instance I can't see map.setBuildingsEnabled in intellisense, see image
but if I force to call that hidden method, the app still builds, so it's something caused by kotlin or intellisense
It may be related to the gray suggestion I got regarding property access maybe (but this isn't a property because on google maps there isn't a getBuildingsEnabled
did anyone knows how to fix this annoying problem? I don't want kotlin to hide methods that may be useful to me, thanks.
Methods that follow the Java conventions for getters and setters (no-argument methods with names starting with ‘get’ and single-argument methods with names starting with ‘set’) are represented as properties in Kotlin.
In other words if you had a Java method setTrafficEnabled(true) Kotlin will provide you a property access syntax isTrafficEnabled = true. This is one of Kotlin advantages.
If you ignore Kotlin property access syntax and use getters and setters, it will work all the same.

Is there better way for handle kotlinx serialization?

I use kotlinx.serialization on Kotlin native project, I a defined Super class for my models and all of the models extends from it.
I defined a function to called toJSON() for serialize variables and fields inside model that all of class models have it.
#Serializable
open class Model {
fun toJSON(): String = JSON.stringify(this);
}
And I created a subclass
class Me : Model() {
var name:String = "Jack";
}
but when I invoke JSON.stringify(this), IDE get a Warning to me:
This declaration is experimental and its usage must be marked with '#kotlinx.serialization.ImplicitReflectionSerializer' or '#UseExperimental(kotlinx.serialization.ImplicitReflectionSerializer::class)'
I paid attention and I used #ImplicitReflectionSerializer annotation while not worked.
Where is my problem?
This is discussed here. It's the particular overload you're using which is still experimental. So your options are either to use the other overload (which takes in a serializer) or to use one of the annotations mentioned in the error message. If you look at the answer to the question I linked (and the comments following it), you'll see it talks about using #UseExperimental and where it should be used.

Android Studio (Kotlin) GsonBuilder.registerTypeAdapter() gives 2 errors

I am using the Kotlin plugin and trying to create a gson variable using GsonBuilder.
This used to work without problems in Java, but now in I get the two errors when trying to use registerTypeAdapter(), as shown below:
val gson = GsonBuilder().registerTypeAdapter(DateTime.class, DateTimeTypeConverter()).create()
For the first parameter (type), I get "name expected" error.
For the second parameter (typeAdapter), I get "expecting an expression" error
DateTime.class should be changed to Date::class.java
Maybe it will resolve your second issue as well, otherwise please post your DateTimeTypeConverter source code
Class References
The most basic reflection feature is getting the runtime reference to
a Kotlin class. To obtain the reference to a statically known Kotlin
class, you can use the class literal syntax:
val c = MyClass::class The reference is a value of type KClass.
Note that a Kotlin class reference is not the same as a Java class
reference. To obtain a Java class reference, use the .java property on
a KClass instance.
Reference: https://kotlinlang.org/docs/reference/reflection.html

Categories

Resources