-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch RepoDataFetcher backend to OkHttp
This change adds caching to both repository and app metadata, incidentally adding better offline support. Closes #8 Closes #159 Partially resolves #150 Partially resolves #322
- Loading branch information
1 parent
6ea937f
commit 8e71d76
Showing
3 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/app/accrescent/client/di/OkHttpModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package app.accrescent.client.di | ||
|
||
import android.content.Context | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import okhttp3.Cache | ||
import okhttp3.OkHttpClient | ||
import java.io.File | ||
import javax.inject.Singleton | ||
|
||
// The cache size in bytes | ||
private const val CACHE_SIZE: Long = 50 * 1024 * 1024 | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object OkHttpModule { | ||
@Provides | ||
@Singleton | ||
fun getOkHttpClient(@ApplicationContext context: Context) = OkHttpClient() | ||
.newBuilder() | ||
.cache( | ||
Cache( | ||
directory = File(context.cacheDir.toURI()), | ||
maxSize = CACHE_SIZE, | ||
) | ||
) | ||
.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters