package com.epson.cameracopy.ui;

import android.content.Context;

import com.epson.cameracopy.alt.FileUtils;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;

import epson.common.ImageUtil;
import epson.print.IprintApplication;

/* renamed from: com.epson.cameracopy.ui.ImageFolderFile */
class ImageFolderFile implements ImagePreviewFile, Serializable {
    private static final long serialVersionUID = 1;
    private String mConvertFilename;
    private String mImageFolderFileName;
    private String mTemporaryFileName;

    public boolean doSave(String str) {
        return false;
    }

    public boolean needSaveButton() {
        return false;
    }

    public ImageFolderFile(String str) {
        mImageFolderFileName = str;
    }

    public String getImageProcFileName(Context context) {
        File newTemporaryJpegFile = FileUtils.getNewTemporaryJpegFile(context);
        if (!newTemporaryJpegFile.exists()) {
            try {
                FileUtils.copy(new File(getPrintFileName()), newTemporaryJpegFile);
            } catch (IOException unused) {
                return null;
            }
        }
        mTemporaryFileName = newTemporaryJpegFile.toString();
        return mTemporaryFileName;
    }

    public String getPrintFileName() {
        String str = mConvertFilename;
        return str != null ? str : mImageFolderFileName;
    }

    public void deleteTemporaryFile() {
        localDeleteFile(mTemporaryFileName);
        mTemporaryFileName = null;
        localDeleteFile(getHeifToJpegFile(IprintApplication.getInstance()).getPath());
        mConvertFilename = null;
    }

    private void localDeleteFile(@Nullable String str) {
        if (str != null) {
            File file = new File(str);
            if (file.exists()) {
                file.delete();
            }
        }
    }

    private boolean prepareImage(@NonNull Context context) {
        mConvertFilename = null;
        deleteTemporaryFile();
        if (!ImageUtil.isHEIFFormat(mImageFolderFileName)) {
            return true;
        }
        String path = getHeifToJpegFile(context).getPath();
        if (!ImageUtil.convertHEIFtoJPEG(mImageFolderFileName, path)) {
            return false;
        }
        mConvertFilename = path;
        return true;
    }

    public boolean needsConvert(@NonNull Context context) {
        return ImageUtil.isHEIFFormat(mImageFolderFileName);
    }

    @NonNull
    private File getHeifToJpegFile(@NonNull Context context) {
        return new File(FileUtils.getCameracopyTempDir(context), "heif_to_jpeg.jpg");
    }
}
