package com.datarecovery.master.data.repositories;


import com.atmob.common.logging.AtmobLog;
import com.atmob.common.runtime.ContextUtil;
import com.datarecovery.master.utils.SystemUtil;
import com.datarecovery.master.utils.filedetect.DetectFile;
import com.datarecovery.master.utils.filedetect.FileScanHelper;
import com.datarecovery.master.utils.xfile.XFile;
import com.datarecovery.master.utils.xfile.XSAFFile;

import org.reactivestreams.Subscription;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

import atmob.reactivex.rxjava3.annotations.NonNull;
import atmob.reactivex.rxjava3.core.FlowableSubscriber;

@Singleton
public class FileScanRepository {

    private static final String TAG = "FileScanRepository";
    long l;
    int size = 0;
    @Inject
    public FileScanRepository() {

    }

    public void refreshImageDetect(@FileScanHelper.RefreshScanType int type) {
        FileScanHelper.refreshImageDetect(ContextUtil.getContext(), type)
                .subscribe(new FlowableSubscriber<List<DetectFile>>() {
                    @Override
                    public void onSubscribe(@NonNull Subscription s) {
                        l = System.currentTimeMillis();
                        size = 0;
                    }

                    @Override
                    public void onNext(List<DetectFile> fileList) {
                        size += fileList.size();
                        for (DetectFile file : fileList) {
                            AtmobLog.d(TAG, file.getPath());
                        }
                    }

                    @Override
                    public void onError(Throwable t) {

                    }

                    @Override
                    public void onComplete() {
                        AtmobLog.d(TAG, "refreshImageDetect time: " + (System.currentTimeMillis() - l) + "---数量：" + size);
                    }
                });
    }
}
