Skip to content

Commit

Permalink
Remove unused DiskCache context argument. (#1099)
Browse files Browse the repository at this point in the history
* Remove unused DiskCache context argument.

* Fix tests.

* Fix API.
  • Loading branch information
colinrtwhite authored Jan 21, 2022
1 parent 4c422f8 commit 7c8cbfb
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion coil-base/api/coil-base.api
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public abstract interface class coil/disk/DiskCache {
}

public final class coil/disk/DiskCache$Builder {
public fun <init> (Landroid/content/Context;)V
public fun <init> ()V
public final fun build ()Lcoil/disk/DiskCache;
public final fun cleanupDispatcher (Lkotlinx/coroutines/CoroutineDispatcher;)Lcoil/disk/DiskCache$Builder;
public final fun directory (Ljava/io/File;)Lcoil/disk/DiskCache$Builder;
Expand Down
3 changes: 1 addition & 2 deletions coil-base/src/main/java/coil/disk/DiskCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package coil.disk

import android.content.Context
import android.os.StatFs
import androidx.annotation.FloatRange
import coil.annotation.ExperimentalCoilApi
Expand Down Expand Up @@ -101,7 +100,7 @@ interface DiskCache {
fun abort()
}

class Builder(private val context: Context) {
class Builder {

private var directory: File? = null
private var maxSizePercent = 0.02 // 2%
Expand Down
2 changes: 1 addition & 1 deletion coil-base/src/main/java/coil/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ internal object SingletonDiskCache {
fun get(context: Context): DiskCache {
return instance ?: run {
// Create the singleton disk cache instance.
DiskCache.Builder(context)
DiskCache.Builder()
.directory(context.safeCacheDir.resolve(FOLDER_NAME))
.build()
.also { instance = it }
Expand Down
6 changes: 1 addition & 5 deletions coil-base/src/test/java/coil/disk/DiskCacheTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package coil.disk

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import okio.buffer
import okio.sink
import okio.source
Expand All @@ -19,13 +17,11 @@ import kotlin.test.assertTrue
@RunWith(RobolectricTestRunner::class)
class DiskCacheTest {

private lateinit var context: Context
private lateinit var diskCache: DiskCache

@Before
fun before() {
context = ApplicationProvider.getApplicationContext()
diskCache = DiskCache.Builder(context).directory(File("build/cache")).build()
diskCache = DiskCache.Builder().directory(File("build/cache")).build()
}

@After
Expand Down
2 changes: 1 addition & 1 deletion coil-base/src/test/java/coil/fetch/HttpUriFetcherTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class HttpUriFetcherTest {
fun before() {
context = ApplicationProvider.getApplicationContext()
server = createMockWebServer()
diskCache = DiskCache.Builder(context)
diskCache = DiskCache.Builder()
.directory(File("build/cache"))
.maxSizeBytes(10L * 1024 * 1024) // 10MB
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Application : Application(), ImageLoaderFactory {
.build()
}
.diskCache {
DiskCache.Builder(this)
DiskCache.Builder()
.directory(filesDir.resolve("image_cache"))
.maxSizeBytes(512L * 1024 * 1024) // 512MB
.build()
Expand Down

0 comments on commit 7c8cbfb

Please sign in to comment.