How to use Jackson JsonSubTypes annotation in Kotlin

I believe this has been resolved and nowadays you can write it like this: import com.fasterxml.jackson.annotation.JsonSubTypes import com.fasterxml.jackson.annotation.JsonTypeInfo @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = “type”) @JsonSubTypes( JsonSubTypes.Type(value = Comment::class, name = “CommentNote”), JsonSubTypes.Type(value = Photo::class, name = “PhotoNote”), JsonSubTypes.Type(value = Document::class, name = “DocumentNote”)) interface Note Note the missing @ and class …

Read more

How to setOnEditorActionListener with Kotlin

The onEditorAction returns a Boolean while your Kotlin lambda returns Unit. Change it to i.e: editText.setOnEditorActionListener { v, actionId, event -> if(actionId == EditorInfo.IME_ACTION_DONE){ doSomething() true } else { false } } The documentation on lambda expressions and anonymous functions is a good read.

repeat string n times in Kotlin

The built in CharSequence.repeat extension does this in an efficient way, see the source here. val str: String = “*”.repeat(100) Of course, this will still require O(n) steps to create the string. However, using this built-in stdlib function has its advantages: it’s cross-platform, easy to read, and can be improved in performance over time, if …

Read more

Converting a byte array into a hex string

As I am on Kotlin 1.3 you may also be interested in the UByte soon (note that it’s an experimental feature. See also Kotlin 1.3M1 and 1.3M2 announcement) E.g.: @ExperimentalUnsignedTypes // just to make it clear that the experimental unsigned types are used fun ByteArray.toHexString() = asUByteArray().joinToString(“”) { it.toString(16).padStart(2, ‘0’) } The formatting option is …

Read more

Broadcast Receiver in kotlin

you can do it in the following way Create a broadcast receiver object in your activity class val broadCastReceiver = object : BroadcastReceiver() { override fun onReceive(contxt: Context?, intent: Intent?) { when (intent?.action) { BROADCAST_DEFAULT_ALBUM_CHANGED -> handleAlbumChanged() BROADCAST_CHANGE_TYPE_CHANGED -> handleChangeTypeChanged() } } } Register broadcast receiver in onCreate() function of your activity LocalBroadcastManager.getInstance(this) .registerReceiver(broadCastReceiver, IntentFilter(BROADCAST_DEFAULT_ALBUM_CHANGED)) …

Read more

Keyboard hides BottomSheetDialogFragment

I found the solution for 27 api. So the reason why keyboard hides view even with SOFT_INPUT_ADJUST_RESIZE is that the windowIsFloating is set for Dialogs. The most convenient way that I found to change this is by creating style: <style name=”DialogStyle” parent=”Theme.Design.Light.BottomSheetDialog”> <item name=”android:windowIsFloating”>false</item> <item name=”android:statusBarColor”>@android:color/transparent</item> <item name=”android:windowSoftInputMode”>adjustResize</item> </style> And set this in onCreate method …

Read more