diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/room/face/DynamicFaceModel.java b/core/src/main/java/com/yizhuan/xchat_android_core/room/face/DynamicFaceModel.java index cb756e079..eb54b57ce 100644 --- a/core/src/main/java/com/yizhuan/xchat_android_core/room/face/DynamicFaceModel.java +++ b/core/src/main/java/com/yizhuan/xchat_android_core/room/face/DynamicFaceModel.java @@ -713,12 +713,12 @@ public class DynamicFaceModel extends BaseModel implements IDynamicFaceModel { @Override public void onNext(ProgressInfo progressInfo) { - Logger.d("zip " + progressInfo.getProgress() + ""); + //Logger.d("zip " + progressInfo.getProgress() + ""); } @Override public void onError(Throwable e) { - Logger.d("zip " + "error"); + //Logger.d("zip " + "error"); isRequestingZip = false; } @@ -739,60 +739,63 @@ public class DynamicFaceModel extends BaseModel implements IDynamicFaceModel { * @param faceListInfo-- */ private void unzipFaceZipFile(FaceListInfo faceListInfo) { - try { - // 如果zip包不存在,或者说zip包的md5值不一样则返回 - if (!facesZipPath.exists() || faceListInfo == null || - !faceListInfo.getZipMd5().equalsIgnoreCase(MD5Utils.getFileMD5String(facesZipPath))) { - return; + new Thread(() -> { + try { + // 如果zip包不存在,或者说zip包的md5值不一样则返回 + if (!facesZipPath.exists() || faceListInfo == null || + !faceListInfo.getZipMd5().equalsIgnoreCase(MD5Utils.getFileMD5String(facesZipPath))) { + return; + } + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); - } - long startTime = System.currentTimeMillis(); - try { - ZipInputStream zis = new ZipInputStream(new FileInputStream(facesZipPath)); - BufferedInputStream bis = new BufferedInputStream(zis); - //输出路径(文件夹目录) - String parent = facesRootDir.getAbsolutePath() + "/" + faceListInfo.getVersion(); - File file; - ZipEntry entry; - while ((entry = zis.getNextEntry()) != null) { - if (entry.isDirectory()) { - // 如果有对应的路径名字的文件,则删除,重建一个目录 - file = new File(parent, entry.getName()); - if (file.exists() && file.isFile()) { - boolean b = file.delete(); - if (b) { - file.mkdirs(); + long startTime = System.currentTimeMillis(); + try { + ZipInputStream zis = new ZipInputStream(new FileInputStream(facesZipPath)); + BufferedInputStream bis = new BufferedInputStream(zis); + //输出路径(文件夹目录) + String parent = facesRootDir.getAbsolutePath() + "/" + faceListInfo.getVersion(); + File file; + ZipEntry entry; + while ((entry = zis.getNextEntry()) != null) { + if (entry.isDirectory()) { + // 如果有对应的路径名字的文件,则删除,重建一个目录 + file = new File(parent, entry.getName()); + if (file.exists() && file.isFile()) { + boolean b = file.delete(); + if (b) { + file.mkdirs(); + } } + continue; } - continue; + file = new File(parent, entry.getName()); + if (!file.exists()) { + (new File(file.getParent())).mkdirs(); + } else if (file.exists() && file.isFile() && file.length() > 0) { + continue; + } + FileOutputStream out = new FileOutputStream(file); + BufferedOutputStream bos = new BufferedOutputStream(out); + int b; + while ((b = bis.read()) != -1) { + bos.write(b); + } + bos.close(); + out.close(); } - file = new File(parent, entry.getName()); - if (!file.exists()) { - (new File(file.getParent())).mkdirs(); - } else if (file.exists() && file.isFile() && file.length() > 0) { - continue; - } - FileOutputStream out = new FileOutputStream(file); - BufferedOutputStream bos = new BufferedOutputStream(out); - int b; - while ((b = bis.read()) != -1) { - bos.write(b); - } - bos.close(); - out.close(); + bis.close(); + zis.close(); + } catch (Exception e) { + e.printStackTrace(); } - bis.close(); - zis.close(); - } catch (Exception e) { - e.printStackTrace(); - } - long endTime = System.currentTimeMillis(); - // 更新对应的faceInfoList中的图片根目录 - setPicRootDirectoryIntoFaceInfo(faceListInfo); - // 如果有dialog.可以显示出对应的数据 - EventBus.getDefault().post(new FaceIsReadyEvent()); + long endTime = System.currentTimeMillis(); + LogUtils.d("unzipFaceZipFileTime="+(endTime-startTime)); + // 更新对应的faceInfoList中的图片根目录 + setPicRootDirectoryIntoFaceInfo(faceListInfo); + // 如果有dialog.可以显示出对应的数据 + EventBus.getDefault().post(new FaceIsReadyEvent()); + }).start(); } private interface Api {