Hello, I've a question. encrypted's value doesn't ...
# android
h
Hello, I've a question. encrypted's value doesn't pass to Data. In Logcat I get null then I get the value.  What mistakes did I make? Thanks in advance. In RemoteDataSource
Copy code
fun buildTokenApi(): UserApi {
        return Retrofit.Builder()
            .baseUrl(BASE_URL)
            .client(getRetrofitClient<Any>())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
            .create(UserApi::class.java)
    }

fun buildApi(
    encr: String
): AuthApi {
    return Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(getRetrofitClient(encr))
        .addConverterFactory(GsonConverterFactory.create())
        .build()
        .create(AuthApi::class.java)
}

 fun  getRetrofitClient(
  
    encr: String?=null
): OkHttpClient {
    Log.d("getRetrofitClient()", "encr:\t $encr")
    val body = "{\r\n    \"Data\":\" $encr\"\r\n}"
        .toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
In VM
Copy code
fun getBuildApi(encr: String):AuthApi{
        return remoteDataSource.buildApi(encr)
    }
In Fragment
Copy code
val encrypted = encrypt(rootObject.toString(), publicKey)
Log.d("LogFrag", "encrypted:\t $encrypted")
viewModel.getBuildApi(encrypted)
In AppModule
Copy code
@Module
@InstallIn(SingletonComponent::class)
object AppModule {

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

    @Singleton
    @Provides
     fun provideAuthApi(
        remoteDataSource: RemoteDataSource,
        encryption: String
    ): AuthApi {
        return remoteDataSource.buildApi(encryption)
    }

    @Singleton
    @Provides
    fun provideString() = ""


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