package de.beyondsoft.ownchat.filepicker.utils;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import de.beyondsoft.ownchat.filepicker.FilePickerConst;
import de.beyondsoft.ownchat.filepicker.cursors.DocScannerTask;
import de.beyondsoft.ownchat.filepicker.cursors.loadercallbacks.FileResultCallback;
import de.beyondsoft.ownchat.filepicker.cursors.loadercallbacks.ImageDirLoaderCallback;
import de.beyondsoft.ownchat.filepicker.models.Document;
import de.beyondsoft.ownchat.filepicker.models.ImageDirectory;

public class MediaStoreHelper {
    public static void getPhotoDirs(FragmentActivity activity, Bundle args, FileResultCallback<ImageDirectory> resultCallback) {
        if(activity.getSupportLoaderManager().getLoader(FilePickerConst.MEDIA_TYPE_IMAGE) != null) {
            activity.getSupportLoaderManager().restartLoader(FilePickerConst.MEDIA_TYPE_IMAGE, args, new ImageDirLoaderCallback(activity, resultCallback));
        } else {
            activity.getSupportLoaderManager().initLoader(FilePickerConst.MEDIA_TYPE_IMAGE, args, new ImageDirLoaderCallback(activity, resultCallback));
        }
    }

    public static void getVideoDirs(FragmentActivity activity, Bundle args, FileResultCallback<ImageDirectory> resultCallback) {
        if(activity.getSupportLoaderManager().getLoader(FilePickerConst.MEDIA_TYPE_VIDEO) != null) {
            activity.getSupportLoaderManager().restartLoader(FilePickerConst.MEDIA_TYPE_VIDEO, args, new ImageDirLoaderCallback(activity, resultCallback));
        } else {
            activity.getSupportLoaderManager().initLoader(FilePickerConst.MEDIA_TYPE_VIDEO, args, new ImageDirLoaderCallback(activity, resultCallback));
        }
    }

    public static void getDocs(FragmentActivity activity, FileResultCallback<Document> fileResultCallback) {
        new DocScannerTask(activity,fileResultCallback).execute();
    }
}
