package com.test.basd.smartjunkcleaner.activity.photocompress.photo;

import java.util.ArrayList;
import java.util.List;

public class PhotoCache {
    private static PhotoCache sInstance;
    private List<PhotoBean> mPhotoList;

    private PhotoCache() {
        mPhotoList = new ArrayList<>();
    }

    public static synchronized PhotoCache getInstance() {
        if (sInstance == null) {
            sInstance = new PhotoCache();
        }
        return sInstance;
    }

    public void addPhoto(PhotoBean photo) {
        if (!mPhotoList.contains(photo)) {
            boolean mBoolean = mPhotoList.add(photo);
        }
    }

    public void removePhoto(PhotoBean photo) {
        if (mPhotoList.contains(photo)) {
            boolean mBoolean = mPhotoList.remove(photo);
        }
    }

    public void clearCache() {
        if(!mPhotoList.isEmpty()){
            mPhotoList.clear();
        }

    }

    public List<PhotoBean> getPhotoList() {
        return mPhotoList;
    }

    public PhotoBean getPositionData(int position) {
        if (position >= 0 && position < mPhotoList.size()) {
            return mPhotoList.get(position);
        } else {
            return null;
        }
    }

    public int getCount() {

        return mPhotoList.size();
    }
}
