refactor(cache): 泛名 Utils 重命名为 DiskCacheUtils
该类只服务磁盘缓存(版本号、缓存键哈希、Bitmap/Drawable 转换),原名 Utils 语义不清;仅 CacheHelper 使用,调用点同步更新。 验证::app:assembleOfficialZhanRuiRelease 编译通过。
This commit is contained in:
1 parent
363dc10e86
commit
c557706d23
2 files changed
+13
-10
No files matched your search
@@ -69,7 +69,7 @@ public class CacheHelper {
|
||||
dir + " is not a directory or does not exists. ");
|
||||
}
|
||||
|
||||
int appVersion = context == null ? DEFAULT_APP_VERSION : Utils.getAppVersion(context);
|
||||
int appVersion = context == null ? DEFAULT_APP_VERSION : DiskCacheUtils.getAppVersion(context);
|
||||
|
||||
try {
|
||||
return DiskLruCache.open(
|
||||
@@ -87,7 +87,7 @@ public class CacheHelper {
|
||||
try {
|
||||
return DiskLruCache.open(
|
||||
getDiskCacheDir(context, dirName),
|
||||
Utils.getAppVersion(context),
|
||||
DiskCacheUtils.getAppVersion(context),
|
||||
DEFAULT_APP_VERSION,
|
||||
maxCount);
|
||||
} catch (IOException e) {
|
||||
@@ -340,7 +340,7 @@ public class CacheHelper {
|
||||
// ============== bitmap 数据 读写 =============
|
||||
// =======================================
|
||||
public void put(String key, Bitmap bitmap) {
|
||||
put(key, Utils.bitmap2Bytes(bitmap));
|
||||
put(key, DiskCacheUtils.bitmap2Bytes(bitmap));
|
||||
}
|
||||
|
||||
public Bitmap getAsBitmap(String key) {
|
||||
@@ -348,14 +348,14 @@ public class CacheHelper {
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
return Utils.bytes2Bitmap(bytes);
|
||||
return DiskCacheUtils.bytes2Bitmap(bytes);
|
||||
}
|
||||
|
||||
// =======================================
|
||||
// ============= drawable 数据 读写 =============
|
||||
// =======================================
|
||||
public void put(String key, Drawable value) {
|
||||
put(key, Utils.drawable2Bitmap(value));
|
||||
put(key, DiskCacheUtils.drawable2Bitmap(value));
|
||||
}
|
||||
|
||||
public Drawable getAsDrawable(String key) {
|
||||
@@ -363,7 +363,7 @@ public class CacheHelper {
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
return Utils.bitmap2Drawable(Utils.bytes2Bitmap(bytes));
|
||||
return DiskCacheUtils.bitmap2Drawable(DiskCacheUtils.bytes2Bitmap(bytes));
|
||||
}
|
||||
|
||||
// =======================================
|
||||
@@ -371,7 +371,7 @@ public class CacheHelper {
|
||||
// =======================================
|
||||
public boolean remove(String key) {
|
||||
try {
|
||||
String hashKey = Utils.hashKeyForDisk(key);
|
||||
String hashKey = DiskCacheUtils.hashKeyForDisk(key);
|
||||
return mDiskLruCache.remove(hashKey);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -418,7 +418,7 @@ public class CacheHelper {
|
||||
//basic editor
|
||||
public DiskLruCache.Editor editor(String key) {
|
||||
try {
|
||||
String hashKey = Utils.hashKeyForDisk(key);
|
||||
String hashKey = DiskCacheUtils.hashKeyForDisk(key);
|
||||
//wirte DIRTY
|
||||
DiskLruCache.Editor edit = mDiskLruCache.edit(hashKey);
|
||||
//edit maybe null :the entry is editing
|
||||
@@ -438,7 +438,7 @@ public class CacheHelper {
|
||||
//basic get
|
||||
public InputStream get(String key) {
|
||||
try {
|
||||
DiskLruCache.Snapshot snapshot = mDiskLruCache.get(Utils.hashKeyForDisk(key));
|
||||
DiskLruCache.Snapshot snapshot = mDiskLruCache.get(DiskCacheUtils.hashKeyForDisk(key));
|
||||
if (snapshot == null) //not find entry , or entry.readable = false
|
||||
{
|
||||
Log.e(TAG, "not find entry , or entry.readable = false");
|
||||
|
||||
+4
-1
@@ -14,7 +14,10 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class Utils {
|
||||
/**
|
||||
* 磁盘缓存底层工具:版本号、缓存键哈希与 Bitmap/Drawable 互转。
|
||||
*/
|
||||
public class DiskCacheUtils {
|
||||
public static int getAppVersion(Context context) {
|
||||
try {
|
||||
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
||||
Reference in new issue
Block a user