Skip to content

Commit

Permalink
[17415] Add config to pass custom base url when initializing TripKit …
Browse files Browse the repository at this point in the history
…to be used on api calls instead of tripgo/region base url

[17415] Add config to pass custom headers when initializing TripKit
- Fix TripKitSample
  • Loading branch information
MichaelReyes committed Sep 23, 2022
1 parent cd44a6f commit b4f476d
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.skedgo.tripkit.data

import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import com.google.gson.Gson

@SuppressLint("StaticFieldLeak")
object HttpClientCustomDataStore {

private val gson = Gson()
private var context: Context? = null
private var sharedPreferences: SharedPreferences? = null
private const val KEY_CUSTOM_HEADERS = "_custom_headers"
private const val KEY_CUSTOM_BASE_URL = "_custom_base_url"

fun init(context: Context) {
this.context = context
sharedPreferences = context.getSharedPreferences("HttpClientSharedPref", 0)
}

fun setCustomHeaders(headers: Map<String, String>) {
sharedPreferences?.apply {
edit().putString(KEY_CUSTOM_HEADERS, gson.toJson(headers)).apply()
}
}

fun getCustomHeadersString(): String? = sharedPreferences?.getString(KEY_CUSTOM_HEADERS, null)

fun setCustomBaseUrl(url: String) {
sharedPreferences?.apply {
edit().putString(KEY_CUSTOM_BASE_URL, url).apply()
}
}

fun getCustomBaseUrl(): String? = sharedPreferences?.getString(KEY_CUSTOM_BASE_URL, null)
}

0 comments on commit b4f476d

Please sign in to comment.