title: Change retrofit okhttp client at runtime
body: <pre><code>fun getClient(token: String, userId: Long, language: String = "en", maxTry: Int = 2): Retrofit {
          val okHttpClient = OkHttpClient.Builder()
          okHttpClient.readTimeout(30, TimeUnit.SECONDS)
          okHttpClient.connectTimeout(30, TimeUnit.SECONDS)
          okHttpClient.writeTimeout(90, TimeUnit.SECONDS)
          var tryCount = 0
          okHttpClient.addInterceptor { chain -&gt;
              val original = chain.request()
              val request = original.newBuilder()
                      .addHeader("Content-Type", "application/json")
                      .addHeader("secToken", token)
                      .addHeader("userId", userId.toString()).build()
              var response = chain.proceed(request)
              while (!response.isSuccessful &amp;&amp; tryCount &lt; maxTry) {
                  Log.d("intercept", "Request is not successful - $tryCount")
                  tryCount++
                  response = chain.proceed(request)
              }
              response
          }
  
          val builder = GsonBuilder()
          builder.registerTypeAdapter(TransModel::class.java, NotificationTypeAdapter(language))
          val gson = builder.create()
  
          if (retrofit == null) {
              retrofit = Retrofit.Builder()
                      .baseUrl(BASE_URL)
                      .addConverterFactory(GsonConverterFactory.create(gson))
                      .client(okHttpClient.build())
                      .build()
          } else {
  
          }
  
          //            .client(getHttpClientForFile())
          return retrofit!!
      }
  </code></pre>
  
  <p>Above code is to get singleton retrofit client for every request in App.</p>
  
  <p>What I need to do is what to do in else part of retrofit == null.</p>
  
  <p>Here language is initialized only once. while initializing retrofit, but for second request I don't have idea to change language and maxTry count for request.</p>
  
  <p><strong>I want to change language, and maxTry at runTime. For every request there must different maxTry count and may language also.</strong></p>
  
  <p><strong>Edit:</strong> 
  As per suggestion of <strong>@EarlOfEgo</strong> my else part is </p>
  
  <pre><code> retrofit!!.newBuilder().baseUrl(BASE_URL)
                      .addConverterFactory(GsonConverterFactory.create(gson))
                      .client(okHttpClient.build())
                      .build()
  </code></pre>
  
  <p>but It is not changing language.</p>
  
  <p><strong>Edit 2</strong>: 
  <em>TransModel</em></p>
  
  <pre><code>class TransModel {
  
      var en: String = ""
      var gu: String = ""
      var hi: String = ""
  
      constructor()
  
      fun get(language: String): String? {
          return when (language) {
              LanguageUtil.languageEn -&gt; {
                  en
              }
  
              LanguageUtil.languageGu -&gt; {
                  gu
              }
  
              LanguageUtil.languageHi -&gt; {
                  hi
              }
  
              else -&gt; {
                  null
              }
          }
      }
  
      constructor(language: String, value: String) {
          when (language) {
              LanguageUtil.languageEn -&gt; {
                  en = value
              }
  
              LanguageUtil.languageGu -&gt; {
                  gu = value
              }
  
              LanguageUtil.languageHi -&gt; {
                  hi = value
              }
          }
      }
  
      fun getValueByLanguage(language: String): String? {
          return when (language) {
              LanguageUtil.languageEn -&gt; {
                  en
              }
  
              LanguageUtil.languageGu -&gt; {
                  gu
              }
  
              LanguageUtil.languageHi -&gt; {
                  hi
              }
  
              else -&gt; {
                  null
              }
          }
      }
  
      fun updateIt(title: TransModel, currentLanguage: String) {
          when (currentLanguage) {
              LanguageUtil.languageEn -&gt; {
                  gu = title.gu
                  hi = title.hi
              }
  
              LanguageUtil.languageGu -&gt; {
                  en = title.en
                  hi = title.hi
              }
  
              LanguageUtil.languageHi -&gt; {
                  gu = title.gu
                  en = title.en
              }
  
          }
      }
  }
  </code></pre>
  
  <p>and my <em>NotificationTypeAdapter</em></p>
  
  <pre><code>class NotificationTypeAdapter(val language: String) : TypeAdapter&lt;TransModel&gt;() {
      override fun write(out: JsonWriter?, value: TransModel?) {
          if (out == null || value == null) return
          out.beginObject()
          out.name("title")
          out.value(value.getValueByLanguage(language))
          out.endObject()
      }
  
      override fun read(reader: JsonReader?): TransModel? {
          if (reader == null) return null
          val jsonParser = JsonParser()
          val je = jsonParser.parse(reader)
          val trans = TransModel(language, (je.asString))
          return trans
      }
  }
  </code></pre>