Skip to content

Instantly share code, notes, and snippets.

@lawloretienne
Created July 21, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawloretienne/c358e0b9cdecb24f20cab831697054b5 to your computer and use it in GitHub Desktop.
Save lawloretienne/c358e0b9cdecb24f20cab831697054b5 to your computer and use it in GitHub Desktop.
@AndroidEntryPoint
class SettingsFragment : Fragment() {
private val settingsViewModel: SettingsViewModel by viewModels()
// ...
}
class SettingsViewModel @ViewModelInject constructor() : ViewModel() {
// ...
}
@HiltAndroidApp
class Application : MultiDexApplication() {
// ...
}
@Module
@InstallIn(ApplicationComponent::class)
class NetworkModule {
@Provides
fun provideCache(@ApplicationContext context: Context): Cache? {
val cacheSize = 10 * 1024 * 1024L // 10MB
var cache: Cache? = null
// Install an HTTP cache in the application cache directory.
try {
val cacheDir = File(context.cacheDir, "http")
cache = Cache(cacheDir, cacheSize)
} catch (e: Exception) {
Timber.e(e, "Unable to install disk cache.")
}
return cache
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment