package com.epson.memcardacc;

import android.content.Context;
import android.view.Window;

import epson.common.MimeType;
import epson.common.Utils;
import epson.print.CommonDefine;
import epson.print.MyPrinter;

import java.io.File;

public class MemcardUtil {
    public static boolean isJpegFile(String str) {
        String extention;
        String extType;
        if (str == null || (extention = Utils.getExtention(str)) == null || (extType = Utils.getExtType(extention)) == null || MimeType.toMimeType(extType) != MimeType.IMAGE_TYPE) {
            return false;
        }
        return true;
    }

    public static boolean isJpegOrHeif(String str) {
        String extention;
        String extType;
        if (str == null || (extention = Utils.getExtention(str)) == null || (extType = Utils.getExtType(extention)) == null) {
            return false;
        }
        if (MimeType.toMimeType(extType) == MimeType.IMAGE_TYPE || MimeType.toMimeType(extType) == MimeType.IMAGE_TYPE_HEIF) {
            return true;
        }
        return false;
    }

    public static String getPrinterIpAddress(Context context) {
        String ip = MyPrinter.getCurPrinter(context).getIp();
        return ip == null ? "" : ip;
    }

    public static boolean checkFileName(String str) {
        if (CommonDefine.DOT.equals(str) || "..".equals(str) || "".equals(str) || str.startsWith(CommonDefine.SLASH) || str.endsWith(CommonDefine.SLASH) || str.endsWith("/..") || str.lastIndexOf("/../") >= 0) {
            return false;
        }
        return true;
    }

    public static void keepScreenOn(Window window) {
        window.addFlags(128);
    }

    public static void clearKeepScreenOn(Window window) {
        window.clearFlags(128);
    }

    public static long getFileLength(String str) {
        return new File(str).length();
    }
}
