package com.eitchsyh.instrument.eitc_erm_dental_flutter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;

import androidx.annotation.NonNull;

import java.io.File;

public class Utils
{
    @NonNull
    public static File getPhotoTempDir(@NonNull Context context)
    {
        File root = context.getExternalCacheDir();
        File dir = new File(root, "tempPhoto");
        if (!dir.exists())
        {
            dir.mkdir();
        }
        return dir;
    }

    @NonNull
    public static File getPhotoDir(@NonNull Context context)
    {
        File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        //root=context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File dir = new File(root, "dental");
        if (!dir.exists())
        {
            dir.mkdir();
        }
        return dir;
    }

    @NonNull
    public static File getRecordTempDir(Context context)
    {
        File root = context.getExternalCacheDir();
        File dir = new File(root, "tempMovie");
        if (!dir.exists())
        {
            dir.mkdir();
        }
        return dir;
    }

    @NonNull
    public static File getRecordDir(Context context)
    {
        File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
        //root=context.getExternalFilesDir(Environment.DIRECTORY_MOVIES);
        File dir = new File(root, "dental");
        if (!dir.exists())
        {
            dir.mkdir();
        }
        return dir;
    }

    public static void notifyScanFile(Context context, File file)
    {
        if (context == null || file == null)
        {
            return;
        }
        Uri uri = Uri.fromFile(file);
        context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
    }

    /// 获取照片的MediaStore相对路径
    @NonNull
    public static String getPhotoMediaStoreRelativePath()
    {
        return Environment.DIRECTORY_PICTURES + File.separator + "dental" +
                File.separator;
    }

    /// 获取视频的MediaStore相对路径
    @NonNull
    public static String getVideoMediaStoreRelativePath()
    {
        return Environment.DIRECTORY_MOVIES + File.separator + "dental" +
                File.separator;
    }
}
