Skip to content

Commit

Permalink
add clear cache method
Browse files Browse the repository at this point in the history
  • Loading branch information
Gru110110110 committed Jun 25, 2017
1 parent 825c635 commit a27cade
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 14 additions & 3 deletions library/src/main/java/com/seek/biscuit/Biscuit.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public static Builder with(Context context) {
return new Builder(context);
}

//default
public static void clearCache(Context context) {
Utils.clearCache(context);
}

//if have been customize cache dir
public static void clearCache(String dir) {
Utils.clearCache(dir);
}

@IntDef({SAMPLE, SCALE})
@Retention(RetentionPolicy.SOURCE)
public @interface CompressType {
Expand Down Expand Up @@ -59,9 +69,9 @@ public Builder(Context context) {
}

public Builder targetDir(String targetDir) {
if (!TextUtils.isEmpty(targetDir)){
String last = targetDir.substring(targetDir.length()-1,targetDir.length());
if (!last.equals("/")){
if (!TextUtils.isEmpty(targetDir)) {
String last = targetDir.substring(targetDir.length() - 1, targetDir.length());
if (!last.equals("/")) {
throw new IllegalArgumentException("targetDir must be end with \"/\"");
}
}
Expand Down Expand Up @@ -127,4 +137,5 @@ public Biscuit build() {
return new Biscuit(mPaths, mTargetDir, mIgnoreAlpha, mQuality, mCompressType, mUseOriginalName, loggingEnabled, mCompressListener, mExecutor);
}
}

}
10 changes: 7 additions & 3 deletions library/src/main/java/com/seek/biscuit/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ public static String getCacheDir(Context context) {
}

// delete all cache image
public static void clearCacheImage(Context context) {
File file = new File(getCacheDir(context));
public static void clearCache(Context context) {
clearCache(getCacheDir(context));
}

public static void clearCache(String dir) {
File file = new File(dir);
File[] files = file.listFiles();
if (files.length > 0) {
for (File f : files) {
Expand Down Expand Up @@ -103,7 +107,7 @@ public static Bitmap rotateBitmap(Bitmap bitmap, int degree) {
return bitmap;
}

public static void log(String tag, String msg) {
static void log(String tag, String msg) {
if (loggingEnabled) {
Log.e(tag, msg);
}
Expand Down

0 comments on commit a27cade

Please sign in to comment.