package com.navinfo.outdoor.util;

import android.content.Context;

import com.navinfo.outdoor.bean.Info;
import com.navinfo.outdoor.room.PoiDao;
import com.navinfo.outdoor.room.PoiDatabase;
import com.navinfo.outdoor.room.PoiEntity;

import java.io.File;
import java.util.List;

/**
 * 删除数据库 已提交的数据，和本地的图片
 */
public class DataDeleteUtil {
    public void initData(Context context, List<PoiEntity> poiEntities) {
        PoiDatabase poiDatabase = PoiDatabase.getInstance(context);
        PoiDao poiDao = poiDatabase.getPoiDao();
        for (int i = 0; i < poiEntities.size(); i++) {
            int taskStatus = poiEntities.get(i).getTaskStatus();
            if (taskStatus==1){
                poiDao.deleteFormName(taskStatus);
                List<Info> photoInfo = poiEntities.get(i).getPhotoInfo();
                for (int i1 = 0; i1 < photoInfo.size(); i1++) {
                    File deleteImage = new File(photoInfo.get(i1).getPhoto());
                    deleteImage.delete();
                }
            }
        }
    }
}