Skip to content

Commit 41c5ce4

Browse files
author
crypticminds
committed
[Persisting images into disk] : Added logic to enable perisiting downloaded images to disk
1 parent 8b1e132 commit 41c5ce4

File tree

12 files changed

+413
-111
lines changed

12 files changed

+413
-111
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ You can annotate any ImageView present in an Activity , fragement or another vie
7575
@LoadImage(
7676
R.id.image_1,
7777
"https://images.unsplash.com/photo-1549740425-5e9ed4d8cd34?ixlib=rb-1.2.1&w=1000&q=80",
78-
placeHolder = R.drawable.loading, enableLoadingAnimation = true
78+
placeHolder = R.drawable.loading, enableLoadingAnimation = true, persistImageToDisk = true
7979
)
8080
lateinit var imageWithAnimation: ImageView
8181
```
8282

83+
Images can be persisted into the internal storage using the "persistImageToDisk" parameter. By default images are not persisted.
84+
You can specify how long images should be persisted in the disk by passing "timeToLiveForDiskStorage" to the Cache.initialize method.
85+
By default all data is kept in the disk for upto 2 days.
86+
8387
### Parameters
8488

8589
* imageViewResourceId : The resource id of the image view (Eg R.id.imageView1)

app/src/main/java/com/arcane/coldstorage/MainActivity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import com.arcane.coldstoragecache.callback.OnValueFetchedCallback
1515
import com.squareup.picasso.Picasso
1616

1717
/**
18-
* The mainactivity for the example app.
18+
* The main activity for the example app.
1919
* This shows the example of @LoadImage annotation.
2020
*
2121
* @author Anurag
@@ -39,9 +39,10 @@ class MainActivity : AppCompatActivity(), OnValueFetchedCallback<Bitmap?> {
3939

4040
@LoadImage(
4141
R.id.image_view_2,
42-
"https://www.ddfl.org/wp-content/uploads/2018/03/bunnies-easter.png",
42+
"https://images.unsplash.com/photo-1485550409059-9afb054cada4?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80",
4343
R.drawable.test_load,
44-
enableLoadingAnimation = true
44+
enableLoadingAnimation = true,
45+
persistImageToDisk = true
4546
)
4647
lateinit var imageView2: ImageView
4748

coldstorageannotation/src/main/java/com/arcane/coldstorageannotation/LoadImage.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ package com.arcane.coldstorageannotation
1717
* background and enabling the animation will rotate the image which will give the impression
1818
* of a circular progress bar.
1919
*
20+
* @param persistImageToDisk Boolean representing whether the images will be persisted in the disk
21+
* or not.
22+
*
2023
* TODO : Change height , width of the image
2124
*
2225
* TODO : Accept custom animation classes.
2326
*
24-
* TODO : Accept boolean to decide whether to store the image to disk for future use.
2527
*
2628
* @author Anurag
2729
*/
@@ -35,7 +37,9 @@ annotation class LoadImage(
3537

3638
val placeHolder: Int = -1,
3739

38-
val enableLoadingAnimation: Boolean = false
40+
val enableLoadingAnimation: Boolean = false,
41+
42+
val persistImageToDisk: Boolean = false
3943

4044
)
4145

0 commit comments

Comments
 (0)