kotlin

Split list when predicate is true

Deadly 提交于 2020-12-12 05:40:07
问题 Does Kotlin provide a mutation function to split a list when a specific predicate is true? In the following example the list should be split when the element is a . . The result should be of the type List<List<String>> . // input list val list = listOf( "This is", "the", "first sentence", ".", "And", "now there is", "a second", "one", ".", "Nice", "." ) // the following should be the result of the transformation listOf( listOf("This is", "the", "first sentence"), listOf("And", "now there is",

Firebase Auth - After updating the user's email, Firebase Auth logs out the user

谁说我不能喝 提交于 2020-12-12 04:57:46
问题 I am using Firebase Auth in my app. I update the email like follows: firebaseAuth.currentUser?.updateEmail(email) The email is updating 100% (I do a re-auth when necessary as well). My problem is after the e-mail has changed, the user is being logged out of his account and has to login again. When I call val user = firebaseAuth.currentUser after updating the email the user is null and my app wants you to login again with the new email address. Is this the correct behaviour? It makes for a

createFromAsset and fallbackToDestructiveMigration methods of Room library - no data exists

南楼画角 提交于 2020-12-11 09:01:55
问题 I have a .db file in assets folder. My RoomDatabase class is as the following. I install the app to my device. Then I changed version = 2 in the below class, and make my prepopulated database version 2. Then i renamed one of the columns in my table so that schema is changed. Then i installed the app again. And boom! Room gives me the following error : Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by

createFromAsset and fallbackToDestructiveMigration methods of Room library - no data exists

半城伤御伤魂 提交于 2020-12-11 08:56:55
问题 I have a .db file in assets folder. My RoomDatabase class is as the following. I install the app to my device. Then I changed version = 2 in the below class, and make my prepopulated database version 2. Then i renamed one of the columns in my table so that schema is changed. Then i installed the app again. And boom! Room gives me the following error : Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by

How to ignore fields when using @Parcelize annotation in Kotlin

懵懂的女人 提交于 2020-12-11 05:14:08
问题 I want to ignore a field when using the @Parcelize annotation in Kotlin so that the field is not parceled, since this field does not implement the Parcelable interface. Starting with this, we get an error because PagedList is not parcelable: @Parcelize data class LeaderboardState( val progressShown: Boolean = true, val pagedList: PagedList<QUser>? = null ) : Parcelable Gives: Type is not directly supported by 'Parcelize'. Annotate the parameter type with '@RawValue' if you want it to be

How to ignore fields when using @Parcelize annotation in Kotlin

ぐ巨炮叔叔 提交于 2020-12-11 05:06:31
问题 I want to ignore a field when using the @Parcelize annotation in Kotlin so that the field is not parceled, since this field does not implement the Parcelable interface. Starting with this, we get an error because PagedList is not parcelable: @Parcelize data class LeaderboardState( val progressShown: Boolean = true, val pagedList: PagedList<QUser>? = null ) : Parcelable Gives: Type is not directly supported by 'Parcelize'. Annotate the parameter type with '@RawValue' if you want it to be

Kotlin override fun with subtype

不羁岁月 提交于 2020-12-11 02:51:43
问题 Im having trouble inheriting an interface containing a method/fun of a base type, that i would like to override as a subtype in the class implementing it. So far i have the interface interface IModel { fun convert(dataModel: BaseDataModel) } And the class implementing it: class SettingsModel: IModel { override fun convert(dataModel: BaseDataModel) { // Conversion of models here } } And i also have the SettingsDataModel which is: class SettingsDataModel: BaseDataModel() { } What i'm trying to

Exclude a Kotlin data class property/field from serialization/deserialization using gson

拥有回忆 提交于 2020-12-10 02:37:20
问题 I am trying to exclude a Kotlin property from deserialization using gson. I have tried different methods from annotating the property with @Transient to creating a custom annotation strategy (specifying the strategy in the gson builder of course), but nothing seems to be working, as the property keeps getting null instead of the value I initialized the property with. I have not tried using the @Expose annotation, but I do not want to annotate other fields with @Expose Please, how can I

Exclude a Kotlin data class property/field from serialization/deserialization using gson

末鹿安然 提交于 2020-12-10 02:35:06
问题 I am trying to exclude a Kotlin property from deserialization using gson. I have tried different methods from annotating the property with @Transient to creating a custom annotation strategy (specifying the strategy in the gson builder of course), but nothing seems to be working, as the property keeps getting null instead of the value I initialized the property with. I have not tried using the @Expose annotation, but I do not want to annotate other fields with @Expose Please, how can I

How to combine two different length lists in kotlin?

社会主义新天地 提交于 2020-12-10 00:39:51
问题 I want to combine two different length lists. For example; val list1 = listOf(1,2,3,4,5) val list2 = listOf("a","b","c") I want to result like this (1,"a",2,"b",3,"c",4,5) Is there any suggestion? 回答1: You may use the .zip function for that list1.zip(list2){ a,b -> listOf(a,b)}.flatten() The only problem is that it will only process elements, with both sets, so if (like in the example) let's have different size - it will not work The alternative could be to add specific markers and filter