I have a settings screen where I am setting some values. When I set those values it gets saved in shared preferences and these values are needed in my request to the network
Assuming your network request is already providing you a LiveData class. For example with Retrofit and a CallAdapter like LiveDataCallAdapter.
Once you have the last observed value by either:
OnSharedPreferenceChangeListener, as you already mentioned, to update a MutableLiveDataThen you can apply the previous LiveData to either:
This is the related example for the Transformations.switchMap in UserViewModel.kt:
private val _login = MutableLiveData()
val login: LiveData
get() = _login
val repositories: LiveData>> = Transformations
.switchMap(_login) { login ->
if (login == null) {
AbsentLiveData.create()
} else {
repoRepository.loadRepos(login)
}
}