package com.epson.cameracopy.p006ui;

import android.content.Context;

import android.support.annotation.Nullable;
import com.epson.cameracopy.alt.FileUtils;
import epson.common.ImageUtil;
import epson.print.IprintApplication;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;

/* 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) {
        this.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;
            }
        }
        this.mTemporaryFileName = newTemporaryJpegFile.toString();
        return this.mTemporaryFileName;
    }

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

    public void deleteTemporaryFile() {
        localDeleteFile(this.mTemporaryFileName);
        this.mTemporaryFileName = null;
        localDeleteFile(getHeifToJpegFile(IprintApplication.getInstance()).getPath());
        this.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) {
        this.mConvertFilename = null;
        deleteTemporaryFile();
        if (!ImageUtil.isHEIFFormat(this.mImageFolderFileName)) {
            return true;
        }
        String path = getHeifToJpegFile(context).getPath();
        if (!ImageUtil.convertHEIFtoJPEG(this.mImageFolderFileName, path)) {
            return false;
        }
        this.mConvertFilename = path;
        return true;
    }

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

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