package com.epson.memcardacc; import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import epson.common.ExternalFileUtils; import epson.common.ImageUtil; import epson.print.IprintApplication; import java.io.File; import java.util.ArrayList; import java.util.Iterator; class FileConvertTask extends AsyncTask> { private static final int FILE_SIZE_LIMIT = 10485760; private final ConvertEndListener mConvertEndListener; private ErrorType mErrorType = ErrorType.NO_ERROR; private final ArrayList mOrgFileList; interface ConvertEndListener { void onConvertEnd(@NonNull ErrorType errorType, @Nullable ArrayList arrayList); } enum ErrorType { NO_ERROR, FILE_SIZE_ERROR, CONVERT_ERROR } FileConvertTask(@NonNull ArrayList arrayList, @NonNull ConvertEndListener convertEndListener) { this.mOrgFileList = arrayList; this.mConvertEndListener = convertEndListener; } static boolean checkSize(ArrayList arrayList) { long j; try { j = MemcardUtil.getFileLength(arrayList.get(0)); } catch (Exception unused) { j = 0; } if (j > 10485760) { return false; } return true; } @NonNull static File initTempDirectory() { return ExternalFileUtils.getInstance(IprintApplication.getInstance()).initTempCacheDirectory(ExternalFileUtils.TempCacheDirectory.MEMORY_CARD_ACCESS); } protected void onPostExecute(ArrayList arrayList) { ConvertEndListener convertEndListener = this.mConvertEndListener; if (convertEndListener != null) { convertEndListener.onConvertEnd(this.mErrorType, arrayList); } } protected ArrayList doInBackground(Void... voidArr) { ArrayList convertImageFile = convertImageFile(this.mOrgFileList); if (convertImageFile == null) { return null; } if (checkSize(convertImageFile)) { return convertImageFile; } this.mErrorType = ErrorType.FILE_SIZE_ERROR; return null; } @Nullable private ArrayList convertImageFile(@NonNull ArrayList arrayList) { ArrayList arrayList2 = new ArrayList<>(); File initTempDirectory = initTempDirectory(); Iterator it = arrayList.iterator(); while (it.hasNext()) { String next = it.next(); String notDuplicateFilename = ExternalFileUtils.getNotDuplicateFilename(next, initTempDirectory.getPath(), 1); if (notDuplicateFilename == null) { this.mErrorType = ErrorType.CONVERT_ERROR; return null; } else if (!ImageUtil.convertHEIFtoJPEG(next, notDuplicateFilename)) { this.mErrorType = ErrorType.CONVERT_ERROR; return null; } else { arrayList2.add(notDuplicateFilename); } } return arrayList2; } }