https://kotlinlang.org
Join Slack
how can I use kotlin-reflect to get all subclasses of an abstract base class? the base class is NOT ...
p

Peter Ertl

over 4 years ago
how can I use kotlin-reflect to get all subclasses of an abstract base class? the base class is NOT sealed
p
m
t
  • 3
  • 34
  • 1094
Is there a way to prevent Focus on a TextField? `Modifier.focusable(false)` isn't doing what I expec...
c

Chris Johnson

over 2 years ago
Is there a way to prevent Focus on a TextField?
Modifier.focusable(false)
isn't doing what I expect it to do. My use case is I want to have a TextField that looks editable, but when clicked on is not focused and instead goes to a different screen. Ideally I'd like to use
enabled = false
but that changes the colors in an undesirable way. Currently, it still focuses the text in the TextField before navigating away
c
k
+3
  • 5
  • 11
  • 1089
Hello, I get this error. What is the reason? " error: @Binds methods' parameter type must be assign...
h

Hovhannes

over 3 years ago
Hello, I get this error. What is the reason? " error: @Binds methods' parameter type must be assignable to the return type public abstract com.example.data.network.AuthApi " in AppModule
@Module
@InstallIn(SingletonComponent::class)
abstract class AppModule {


    companion object {
        @Singleton
        @Provides
        fun provideRemoteDataSource(): RemoteDataSource {
            return RemoteDataSource()
        }



        @Singleton
        @Provides
        fun provideUserApi(
            remoteDataSource: RemoteDataSource,
      
        ): UserApi {
            return remoteDataSource.buildTokenApi()
        }

        @Provides
        fun provideAuthRepository(authApi: AuthApi): AuthRepository {
            return AuthRepository(authApi)
        }


        @Provides
        fun provideUserRepository(userApi: UserApi): UserRepository {
            return UserRepository(userApi)
        }
    }



        @Binds
        @Singleton
        abstract fun bindsRemoteDataSource(authRepository: AuthRepository): AuthApi
}
class AuthRepository @Inject constructor(private val api: AuthApi) : BaseRepository(api) {....}
h
a
  • 2
  • 8
  • 1089
```Experimental context receivers are deprecated and will be superseded by context parameters. Pleas...
p

phldavies

10 months ago
>
Experimental context receivers are deprecated and will be superseded by context parameters. Please don't use context receivers. You can either pass parameters explicitly or use members with extensions.  
> 
> See new context parameters proposal: <https://github.com/Kotlin/KEEP/blob/context-parameters/proposals/context-parameters.md>. During the transition period, neither context receivers nor context parameters will be supported. This warning will become an error in future releases.
As a quick straw poll, how are most of us
context-receivers
lovers expecting to handle the migration? 1️⃣ go full ostrich, ignore it, stick to the last kotlin version that supports
context-receivers
and hope we can wait out the kotlin release that enables
context-parameters
2️⃣ stop using
context-receivers
for the time being, revert to
.bind()
et al, or where possible use
Raise<E>
as an extension receiver 😭 find a corner and cry until it all blows over
1️⃣ 5
😭 15
p
k
+3
  • 5
  • 5
  • 1085
Hey there! Is there any way to get the file name in a Kotlin file? This functionality could be helpf...
m

Marc Reichelt

about 3 years ago
Hey there! Is there any way to get the file name in a Kotlin file? This functionality could be helpful with e.g. logging, where the other approaches have drawbacks: • need to manually define tag (manual, can be messed up when filename changes) • or: throw a full
Throwable()
, to only get the file / class name (performance issues) • or: using
reified
to get the class name (will print weird log tags when scope changes (e.g. it will print
CoroutineScope
in some instances))
m
e
+5
  • 7
  • 18
  • 1084
Is there a notion of priority with coroutines? I'd like to do some job in background but I'd like it...
d

dekans

about 7 years ago
Is there a notion of priority with coroutines? I'd like to do some job in background but I'd like it to be executed ASAP, before other queued & less important jobs
d
p
+3
  • 5
  • 31
  • 1082
I'm trying to use kapt in my project and it is working well when I compile manually using maven. How...
d

David Kubecka

over 2 years ago
I'm trying to use kapt in my project and it is working well when I compile manually using maven. However, the Intellij IDEA integrated builder has trouble when compiling the generated sources. I've filed a bug to IDEA directly as I think the issue might be there (there's a simple reproducer project if anyone would be glad to look at it). To understand the issue more, I would like to know the reasoning behind and perhaps more details of this Maven/Kotlin guide that I followed. I noticed that when I don't "disable" the
maven-compiler-plugin
I get the same error during manual maven compilation ("package does not exist") as I get in IDEA when the pom is set up correctly. Can anyone shed more light into this issue?
d
a
  • 2
  • 17
  • 1076
Hello, I am discovering the new `plugins` declaration. Applying below in the root Gradle file ```pl...
n

nuhkoca

almost 3 years ago
Hello, I am discovering the new
plugins
declaration. Applying below in the root Gradle file
plugins {
    id("com.android.application") version "7.2" apply false
    id("com.android.library") version "7.2" apply false
}
But I also need to apply
Gradle
plugin in
buildSrc
so I have this in there
implementation("com.android.tools.build:gradle:7.2.0")
but then IDE throws an exception
Error resolving plugin [id: ‘com.android.application’, version: ‘7.2.0’, apply: false]
> The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.
How do I have the same plugin works for the both places?
n
v
a
  • 3
  • 8
  • 1076
Just curious, in compose-desktop do we have a local database like `room` ? I think other desktop app...
v

Vivek Sharma

over 3 years ago
Just curious, in compose-desktop do we have a local database like
room
? I think other desktop app uses remote db for their apps, no?
v
a
+7
  • 9
  • 32
  • 1075
What is the best practice to refresh OAuth access tokens using a refresh token in OkHttp? I have the...
l

Lukasz Kalnik

over 2 years ago
What is the best practice to refresh OAuth access tokens using a refresh token in OkHttp? I have the following setup, but it's failing in case of parallel calls. The
synchronized(lock)
doesn't seem to prevent the second call to try to refresh the token as well.
val okHttpClient = OkHttpClient.Builder()
    .addInterceptor(AccessTokenInterceptor(oAuthRepository))
    .authenticator(RefreshTokenAuthenticator(oAuthRepository))
    .build()

val lock = Any()

private class AccessTokenInterceptor(
    private val oAuthRepository: OAuthRepository
) : Interceptor {

    override fun intercept(chain: Chain): Response {
        synchronized(lock) {
            val token = oAuthRepository.accessToken

            val request = chain.request().newBuilder().apply {
                if (token != null) header("Authorization", "Bearer $token")
            }.build()
            return chain.proceed(request)
        }
    }
}

private class RefreshTokenAuthenticator(
    private val oAuthRepository: OAuthRepository
) : Authenticator {

    override fun authenticate(route: Route?, response: Response): Request? {
        if (response.responseCount >= 2) return null

        synchronized(lock) {
            return runBlocking {
                oAuthRepository.refreshTokens().map {
                    oAuthRepository.accessToken
                }
            }.fold(
                ifLeft = { null },
                ifRight = {
                    it?.let { token ->
                        response.request.newBuilder()
                            .header("Authorization", "Bearer $token")
                            .build()
                    }
                }
            )
        }
    }
}
l
y
+2
  • 4
  • 8
  • 1069
Previous293031Next

kotlinlang

A modern programming language that makes developers happier.

Powered by