https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
stackoverflow
  • u

    user

    06/21/2022, 11:31 AM
    Serialising to Enum in Kotlin? I am writing an android app as an ios developer, and struggling to get my Enum values to encode with kotlin. I currently have data class Context( val context_type: ContextType ) enum class ContextType { WALKING, STATIONARY } the Json looks like this "context": [{ "context_type": "walking" }] However it doesnt seem to serialise the values to an enum and is just null. It crashes on attempt to access with: java.lang.NullPointerException: Attempt to invoke virtual method...
  • u

    user

    06/21/2022, 11:31 AM
    Parse json response without key - Android How to parse this type of JSON response { "translationsLatestUpdate": "2022/05/30 06:07:05", "translations": { "S40_BottomNavigationShoppingListTitle": { "en": "Home", "da": "Indkøbsliste", "de": "Einkaufsliste", "pl": "Lista Zakupów", "zu": "S40_BottomNavigationShoppingListTitle" }, "S40_BottomNavigationScanTitle": { "en": "Check the price", "da": "Scan", "de": "Preis Scanner", "pl": "Sprawdź Cenę", "zu": "S40_BottomNavigationScanTitle" }, ... } } There is no key defined. as the values for...
  • u

    user

    06/21/2022, 11:51 AM
    I'm using CallBackFlow to return result whenever it is available but it shows error Android Kotlin I'm trying to return result from function using CallBackFlow but getting error, private fun callSocket( eventEmmit: String, eventOn: String, request: JSONObject ) = callbackFlow { try { if (socket.connected()) { var response: JSONObject Log.e("EMIT $eventEmmit", JSONObject(Gson().toJson(request)).toString()) socket.on( eventOn ) {...
  • u

    user

    06/21/2022, 11:51 AM
    Live Date vs State Flow:observing vs collecting let's assume we have two Activities(A and B), when navigate from A(that has live data or flow) -> B then navigate back from B -> A. if we observe using live data : live data will not observe the data again. if we use collecting flow using repeatOnLifeCycle Api or(flowWithLifecycle) : to achieve Live data scenario we use Lifecycle.State.STARTED, but that will be different from live data when we navigate from A -> B then navigate back from B -> A , the flow is re-collecting . if some one...
  • u

    user

    06/21/2022, 12:11 PM
    Heterogeneous Views with unknow EditText number I'm working on a dynamicViews (not sure if that's the right word for creating a view from a json file). I'm getting the schema from a JSON file, I've stepped up the recycleView and its adapter, so far so good, each Recycleview item (must or not) contain a number of EditText whose number is unknown in advance, so based on the Json file, I have to inflate inside. I searched a lot but the similar solution I found for Heterogene Recycleview: the idea was to use separate layout and inflate each of...
  • u

    user

    06/21/2022, 12:11 PM
    Spring boot serialize kotlin enum by custom property I have an Enum and I would like to serialize it using custom property. It works in my tests but not when I make request. Enum should be mapped using JsonValue enum class PlantProtectionSortColumn( @get:JsonValue val propertyName: String, ) { NAME("name"), REGISTRATION_NUMBER("registrationNumber"); } In test the lowercase case works as expected. class PlantProtectionSortColumnTest : ServiceSpec() { @Autowired lateinit var mapper: ObjectMapper data class...
  • u

    user

    06/21/2022, 12:11 PM
    Room "Not sure how to convert a Cursor to this method's return type" I'm new to android development and I'm working on a project called " water drink reminder " . this is my Dao and database codes. i'm getting "Room "Not sure how to convert a Cursor to this method's return type" error every time I run the app. so I searched about this and what I gained was " don't use LiveData with suspend keyword". I didn't use these two together but I still get this error. anyone can help? @Dao interface Dao { @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun...
  • u

    user

    06/21/2022, 12:11 PM
    How to loop through Seal Class object without Reflection? I try to loop through my seal class of sealed class NavigationItem(val route: String, val icon: Int, val title: String, val color: String) { object Home : NavigationItem("home", R.drawable.ic_home, "Home", "#FFFF00") object Music : NavigationItem("music", R.drawable.ic_music, "Music", "#FF00FF") object Movies : NavigationItem("movies", R.drawable.ic_movie, "Movies", "#00FFFF") object Books : NavigationItem("books", R.drawable.ic_book, "Books", "#FFAAAA") object Profile :...
  • u

    user

    06/21/2022, 12:31 PM
    Align a composable view to right side inside a Row Composable like alignParentRight I'm building a custom composable function view inside which I used Row composable, however I want to align the right icon to right end of the Row(align to the end of the parent) below is my code: Row(modifier = Modifier .fillMaxWidth() .wrapContentHeight() .padding(vertical = Spacing30), verticalAlignment = Alignment.CenterVertically) { Icon(modifier = Modifier.padding(vertical = 14.dp), painter = painterResource(id = R.drawable.ic_wallet),...
  • u

    user

    06/21/2022, 12:51 PM
    XML Data binding, how to get callback parameter This is the callback that I used: var onSelectionChanged: (Boolean) -> Unit = {} My databinding XML syntax is wrong, and unfortunately it doesn't compiled, How to get the Boolean invocation result of the callback
  • u

    user

    06/21/2022, 12:51 PM
    Localazy: Localazy Gradle plugin requires Android Gradle plugin 3.5.0 and newer I am trying to use https://localazy.com/p/locakalazy/integration/android for android language localization. But while adding this in app module -> apply plugin: 'com.localazy.gradle' localazy { readKey "########" writeKey "########" } I am getting this error -> Build file 'C:\Users\91863\AndroidStudioProjects\android-localization\app\build.gradle' line: 4 An exception occurred applying...
  • u

    user

    06/21/2022, 1:11 PM
    Why Spring kills file's encoding during downloading? I have the following code: @Throws(IOException::class) private fun convertInputStreamToString(`is`: InputStream): String? { val result = ByteArrayOutputStream() val buffer = ByteArray(DEFAULT_BUFFER_SIZE) var length: Int while (
    is
    .read(buffer).also { length = it } != -1) { result.write(buffer, 0, length) } return result.toString("windows-1251") } @RequestMapping(path = ["/download/{id}"], method =...
  • u

    user

    06/21/2022, 1:11 PM
    How to display a certain view from layout in Picture in Picture mod in android? I am trying to implement pip mode in android. There is a LiveStreamActivity which contains these elements: Header layout, VideoStream layout and custom popup that I show programatically. Their contexts are the same: LiveStreamActivity. When I enter pip mode LiveStreamActivity's root layout shrinks and fits in small pip screen. But I only want to show VideoStream layout. I tried setSourceRectHint to achieve this but it does not work. Summary : How to show desired view (or views) in pip mode?...
  • u

    user

    06/21/2022, 1:31 PM
    Show different views in recyclerview adapter on the comparison of two lists I am having a scenario in which I want to show two different items in one adapter. Here is a scenario, I have two lists on which I want to make a comparison, one list which is coming back end and one is coming from my local room database. Basically, I need to list the items coming from back-end, in these items which exist in my database will have different view in adapter and and if the item coming from backend does not exist in my database will have different views. If I'll make comparison...
  • u

    user

    06/21/2022, 2:11 PM
    Why it says " List contains no element matching the predicate." for android jetpack compose? I have Onboarding Screens for my project, and it work correctly, but I want to show users it just once, and I was using shared preferences for it, and when debug the project it is throw an error like that in logcat, List contains no element matching the predicate. , and in android emulator I can see main screen, but app crash quickly, when I open app again on simulator, onboarding screen shows just 1 second and open main screen, than app crash, I do not know why? I guess problem is because...
  • u

    user

    06/21/2022, 2:31 PM
    TelephonyManager.UssdResponseCallback sometimes use to dial the code successfully but still go to the onReceiveUssdResponseFailed callback Am working on an app to dial ussd code in background but am having a critical issue concerning the ussd callback, sometimes the code will successfully dialed but still the onReceiveUssdResponseFailed is still called public void dialUssdToGetPhoneNumber(String ussdCode, int sim) { if (ussdCode.equalsIgnoreCase("")) return; if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new...
  • u

    user

    06/21/2022, 2:51 PM
    Multiple MIME types pdf and image From file manager I want to allow choose only pdf and images, is it possible to do in Android? I tried do same things from another answer, but I don't know why, file manager allow choose any file. override fun createIntent(context: Context, input: Array?): Intent { val mimeTypes = arrayListOf("image/*", "application/pdf") return Intent().apply { type = "*/*" action...
  • u

    user

    06/21/2022, 2:51 PM
    Read Gradle module metadata to select an artifact with maven Maven doesn't read Gradle module metadata to select an artifact. With Kotlin MultiPlatform, for instance okio publishes a bunch of artifacts like okio-jvm/ okio-linuxx64/ okio-macosarm64/ okio-macosx64/ okio-metadata/ okio-mingwx64/ When depending on it with Gradle, one can declare a dependency on com.squareup.okio:okio and Gradle will select the corresponding artifact. If the dependency is defined in Maven, the...
  • u

    user

    06/21/2022, 2:51 PM
    nested list filtering without changing object type in kotlin I want to filter nested lists with kotlin without changing the object type.

    https://i.stack.imgur.com/dSYjq.png▾

    https://i.stack.imgur.com/D5OYC.png▾

    https://i.stack.imgur.com/TPtEP.png▾

    For example, I want to get the list 'ExamObj' with age value 27 for the above model. The method to return the list is as follows. fun progress(respList: List): List{} this method takes a list...
  • u

    user

    06/21/2022, 3:11 PM
    How to get collection values in Kotlin lambda I have two collections: A and B. Both of them consist of equal amount of chars. I zip them. Then I need to count pairs of the same elements, like 'A' and 'A'. I need to write a predicate, but I can't find the way to get both elements from a zipped collection. I've tried something like this: val num = A.zip(B).count { it.i: Int, it.j:Int -> it.i == it.j} and this: val num = A.zip(guess).count { it[0] == it[2] } But it doesn't work. How can I reach both elements from these sub lists...
  • u

    user

    06/21/2022, 3:31 PM
    Proper usage of com.fasterxml.jackson.module.kotlin.UIntDeserializer I would like to make use of extra deserializers defined for Kotlin-specific data types: UInt, ULong and UShort. The following code does work as expected: val actual: UInt = objectMapper.readValue("4294967295") val expected: UInt = 4294967295u assertThat(actual).isEqualTo(expected) However I can't make it work for a data class like this: data class U( @JsonProperty("x") @JsonDeserialize(using = UIntDeserializer::class) val x: UInt ) val actual: U =...
  • u

    user

    06/21/2022, 3:31 PM
    Android add toolbar to fullScreen SDK On my job, I have a task to implement new SDK in the app. Everything works fine, but I have one situation. I start SDK like this in my fragment: IdenttWebViewSdk.start( activity = requireActivity(), sessionId = documentUploadResponse.sessionId, /* SESSION ID */ documentId = documentUploadResponse.reference, /* DOCUMENT ID */ frontendVerificationUrl = configurationRepository.getIdenttVerificationUrl(), requestCode = 100 ) The...
  • u

    user

    06/21/2022, 3:51 PM
    MVVM - What is the best layer for this logic? I am fetching images by using retrofit with MVVM Architecture. Now I want to add some features like image editing or compression and uploading. My question is . For MVVM architecture, is the business logic for these features a use case? domain usecase ImageCompressionUseCase.kt UploadImageUseCase.kt ui ImageCompressionViewModel.kt ImageCompressionFragment.kt UploadImageViewModel.kt UploadImageFragment.kt My brain says it's use cases but I'm a bit hesitant :) ImageCompressionUseCase.kt...
  • u

    user

    06/21/2022, 4:11 PM
    How to add title, image and description for a deep link in our app? I know this can be achieved using Firebase Deep Linking, but I find it a bit too complicated with a custom domain, so I go with the regular one. But, I could not find how do I add an image, title and subtitle for it? Also, the URL will be dynamic like this: forms.mysitename.in/solve/randomFormId
  • u

    user

    06/21/2022, 4:31 PM
    App crashes and gives this error java.lang.NullPointerException: null cannot be cast to non-null type android.content.Context i am new to android development,any help will be really appreciated, here is the code class Dashboard : Fragment() { lateinit var recycle:RecyclerView lateinit var reLayout:RecyclerView.LayoutManager lateinit var RecObj: AdapterData var bookInfoList = arrayListOf() override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.fragment_dashboard, container, false) recycle =...
  • u

    user

    06/21/2022, 4:51 PM
    Serialization omitting nulls I have a class like this: @Serializable data class MyClass( val prop1: Int, val prop2: Int? ) When prop2 is null, I want to serialize this class without including the prop2 property. I can do this like this: val json = Json { explicitNulls = false } json.encodeToString(MyClass(42, null)) // gives {"prop1": 42} Unfortunately, there are many places in a large project that serialize this class, and currently they just use Json.encodeToString which includes the nulls explicitly. How...
  • u

    user

    06/21/2022, 5:11 PM
    Sending a notification if a document is added on a collection (firestore) Is there a way to get a notification everytime a document is added on a collection viewable in a recyclerview? This is what i have tried so far. It works if something is added, but a notification is sent again if i open the activity containing the recyclerview. I only wanted the notification to appear if outside the app or on another part of the app. private val CHANNEL_ID = "channel_id_example_01" private val notificationId = 101...
  • u

    user

    06/21/2022, 5:11 PM
    How to perform action in fragments by clicking action bar icon in activity Hello I have two icons in action bar update and edit when I click on edit icon my edit text becomes editable and I can edit data their. By clicking on update button my these editable edit texts data updated in firebase. I am doing this work in activity right now but I want fragment when I click on action bar icon in activity it perform update or edit functionality in fragment. Please guide me how to do this???
  • u

    user

    06/21/2022, 5:31 PM
    Android kotlin calling same api with different date params and inserting to room all together I have an api to return data based on from and to date params. The api is limited to return only 1 day data at a time. I need to fetch data for 7 days and insert it to room db. Fetching day by day and inserting to db is time consuming and hence causing bad user experience. How can I make 7 parallel calls to same api with different date params? After making all 7 parallel api calls, how can I combine the responses and bulk insert to room db Is there any other better way to fetch the entire...
  • u

    user

    06/21/2022, 5:51 PM
    Switch control in function not working after being hoisted After hoisting my isChecked variable, it seems that the Switch is not working whenever I click on it. @Composable fun PreferencesScreen(navController: NavController) { var isChecked by rememberSaveable { mutableStateOf(false) } Scaffold( topBar = {...}, content = { LazyColumn(modifier = Modifier.padding(it).fillMaxSize()) { item { MyPreference(isChecked, "Test preference") } } },...
Powered by Linen
Title
u

user

06/21/2022, 5:51 PM
Switch control in function not working after being hoisted After hoisting my isChecked variable, it seems that the Switch is not working whenever I click on it. @Composable fun PreferencesScreen(navController: NavController) { var isChecked by rememberSaveable { mutableStateOf(false) } Scaffold( topBar = {...}, content = { LazyColumn(modifier = Modifier.padding(it).fillMaxSize()) { item { MyPreference(isChecked, "Test preference") } } },...
View count: 8