https://kotlinlang.org
Join Slack
I want to scroll a `LazyRow` so that the element is centered. `LazyListState.animateScrollToItem()`...
s

Stefan Oltmann

about 4 years ago
I want to scroll a
LazyRow
so that the element is centered.
LazyListState.animateScrollToItem()
takes an
index
and a
scrollOffset
as arguments. Per default it scrolls the list so that the item is the first one. If a positive
scrollOffset
is given it scrolls further, making the item go off scren. So I tried to give a negative
scrollOffset
and calculate what I need so that the element is in center position. The problem is: Negative Offsets are not allowed. 😞 How can I scroll to an index that it's at the center of the list?
👀 3
s
j
  • 2
  • 5
  • 992
Is Gson available in KMM? if not what would be the alternative of Gson, I used `Kotlin Serialization...
s

Suresh Maidaragi

almost 2 years ago
Is Gson available in KMM? if not what would be the alternative of Gson, I used
Kotlin Serialization
but not giving alternative of
TypeToken
example use case is I wanted to convert below snippet completely into KMM specific by just using
kotlin.serialization
end up seeing
typeToken
not found
fun <T : Any> getTypeListv(typeArgument: KClass<T>): KType? {
    return TypeToken.getParameterized(List::class, typeArgument).type
}
s
j
m
  • 3
  • 6
  • 992
Hey guys, Is it possible to tell retrofit to ignore certain fields of an object when sending the obj...
o

Ofir Bar

almost 6 years ago
Hey guys, Is it possible to tell retrofit to ignore certain fields of an object when sending the object over the network? We have a request object
Profession
that we send to our backend using Retrofit.
data class Profession (
	@SerializedName("activeSince") var activeSince : Long?,
	@SerializedName("name") var businessName : String?,
	@SerializedName("description") var businessDescription : String?,
	@SerializedName("licenseImageUrl") var licenseImageUrl : String?
)
Sometimes we send the entire object, but other times, I prefer to only send specific fields (for example, only the
businessDescription
and
businessName
). Is it possible to tell retrofit to not include the other 2 fields in the network request? (
activeSince
and
licenseImageUrl
). Note: I can’t send
activeSince
and
licenseImageUrl
as null. Our backend will send me back errors if I attempt to do that (edited)
o
o
+4
  • 6
  • 10
  • 988
Are there official Proguard rules for Ktor?
l

Lukasz Kalnik

over 1 year ago
Are there official Proguard rules for Ktor?
l
a
  • 2
  • 8
  • 986
Hello good people. Is it possible to have 2 versions catalog ( or some trick to merge two of them )?...
d

Davide Giuseppe Farella

about 3 years ago
Hello good people. Is it possible to have 2 versions catalog ( or some trick to merge two of them )? The scenario is: We have the
main
project and a
sub
project as a submodule. Having different dependency versions caused some troubles, so we wanna align them.
sub
will have some dependencies in its toml file, but
main
would need some dependencies that are not available in
sub
d
j
v
  • 3
  • 17
  • 986
Hi, I’m getting this error: `Property delegate must have a 'getValue(Nothing?, KProperty&lt;*&gt;)' ...
p

Partho Paul

almost 3 years ago
Hi, I’m getting this error:
Property delegate must have a 'getValue(Nothing?, KProperty<*>)' method. None of the following functions is suitable: public inline operator fun <T> Lazy<???>.getValue(thisRef: Any?, property: KProperty<*>): ??? defined in kotlin
in this line:
val slackCommandListener by inject<SlackCommandListener>()
My listener is defined in koin as follows:
//in modules.kt
val listenerModule = module {
    factory { SlackCommandListener(get(), get()) }
}

//in koin.kt
install(Koin) {
        slf4jLogger(level = org.koin.core.logger.Level.ERROR)
        modules(serviceModule, controllerModule, listenerModule)
}
I’m getting this while starting my app via
./gradlew run
. IntelliJ is not showing any error. Can someone please help? T.I.A.
p
a
  • 2
  • 1
  • 985
I'm using Compose Coil for image loading in my project, I have a grid of images shown in my composab...
r

Roudy Korkis Kanaan

about 3 years ago
I'm using Compose Coil for image loading in my project, I have a grid of images shown in my composable and they're driven by a state that would update the grid to another set of images. I'm using Coil with this image loader
val imageLoader = remember {
    ImageLoader.Builder(context)
        .bitmapFactoryMaxParallelism(10)
        .respectCacheHeaders(false)
        .build()
}
(I was playing around the bitmap parallelism and cache headers, I also tried providing disk/cache policies and enabling them in the
ImageRequest
but it seems like Coil is quite slow to load the images after they are cached. I tried my same code but use picasso-compose and the images load instantly (After being cached) whereas using Coil there's a split second load, I added a debugger to Coil to make sure it's not loading the image again from the internet (and it's not) The above was on production build for both Coil and Picasso Has anyone experience some performance issues with Coil in Compose?
r
c
c
  • 3
  • 29
  • 982
I have a `LiveData` of type `MutableLiveData&lt;MutableList&lt;User&gt;&gt;`. I have an issue. If ...
n

nilTheDev

about 4 years ago
I have a
LiveData
of type
MutableLiveData<MutableList<User>>
. I have an issue. If I update the
value
by another
MutableList<User>
the changes are emitted to the observers. However, if I simply add other elements to the
MutableList<User>
, that is already initialised in the
LiveData
, the changes are not emitted. Here is what I am doing...
//other codes 
private val _users: MutableLiveData<MutableList<User>> = MutableLiveData<MutableList<User>>()

init {
    _users.value = mutableListOf<User>()
}

val uiScope = CoroutineScope(Dispatchers.Main + Job())

fun loadUsers(){
    uiScope.launch{
        // this works perfectly
        _users.value = fetchUsers() as MutableList<User>
        // this doesn't work... no idea why
        _users.value.addAll(fetchUsers())
    }
}

suspend fun fetchUsers(): List<User>{
    return withContext(<http://Dispatchers.IO|Dispatchers.IO>){
        //fetch users asynchronously
    }
}
This is just an emulation of the actual program. That actual code is not that trivial.
n
d
+2
  • 4
  • 8
  • 979
What is a good way to schedule a repeating task in a platform agnostic way? ```fun main() = runBlock...
e

Exerosis

over 3 years ago
What is a good way to schedule a repeating task in a platform agnostic way?
fun main() = runBlocking {
    val component = Component {
        var a = 0; var b = 0
        every(50.milliseconds) {
            if (it % 20 == 0) println("A: ${a++}")
        }
        every(1.seconds) {
            println("B: ${b++}")
        }
    }
    component.enable()
    delay(50.seconds)
    println("Done!")
}
context(Toggled) @Base
suspend fun every(period: Duration, block: suspend (Int) -> (Unit)) {
    simultaneously {
        var i = 0
        while (isActive) {
            block(i++)
            delay(period)
        }
    }
}
The problem with this is that over time the two tasks get way out of sync: A: 47 B: 49 After 50 seconds
e
f
+4
  • 6
  • 14
  • 978
what's the kotlin equivalent to ```buildConfigField("String", "API_KEY", API_KEY)``` and under where...
k

Kaj Koivunen

almost 3 years ago
what's the kotlin equivalent to
buildConfigField("String", "API_KEY", API_KEY)
and under where should it be placed in the default build script intellij IDEA gives you for a jvm console project? I tried just about anything and it just seems buildConfigField is not recognized on kotlin side of things
k
s
+5
  • 7
  • 23
  • 977
Previous474849Next

kotlinlang

A modern programming language that makes developers happier.

Powered by