Sergio C.
11/01/2022, 11:11 PM@Module
@InstallIn(SingletonComponent::class)
class ApiModule @Inject constructor(
localPrefs: SharedPreferences,
app: Application,
) {
init {
localPrefs.registerOnSharedPreferenceChangeListener { prefs: SharedPreferences?, key: String? ->
if (key == app.getString(R.string.pref_key_api_url)) {
val newApiUrl = prefs?.getString(key, defaultApiUrl) ?: defaultApiUrl
Logger.w("API URL CHANGED!!! $newApiUrl")
}
}
}
}streetsofboston
11/01/2022, 11:16 PMSergio C.
11/01/2022, 11:18 PMstreetsofboston
11/01/2022, 11:20 PMinit { .... }
is called; they'll be initialized a bit later.
You may need to create a (lazy) accessor or create a method you'd need to call explicitly to do what happens originally in your init
block...Sergio C.
11/01/2022, 11:23 PMSergio C.
11/01/2022, 11:24 PM