package com.rthoni.camotion.ui.fragments;

import com.luticate.utils.business.LuPromise;
import com.luticate.utils.dbo.LuMultipleDbo;
import com.rthoni.camotion.business.CamerasBusiness;
import com.rthoni.camotion.dbo.CameraDbo;
import com.rthoni.camotion.ui.views.CameraView;

/**
 *
 * Created by robin on 11/29/15.
 */
public class CamerasFragment extends CamotionFragment<CameraDbo, CameraView> {

    public CamerasFragment() {
        super();
        _perPage = 6;
    }

    @Override
    protected LuPromise<LuMultipleDbo<CameraDbo>> getLoadPagePromise(int page, int perPage, String query) {
        return CamerasBusiness.getAll(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), page, perPage)
                .map(new LuPromise.LuConverter<CameraDbo.MultipleCameraDbo, LuMultipleDbo<CameraDbo>>() {
                    @Override
                    public LuMultipleDbo<CameraDbo> convert(CameraDbo.MultipleCameraDbo data) {
                        return data;
                    }
                });
    }

    @Override
    public void onPause() {
        super.onPause();
        for (CameraView view : _views)
        {
            view.pause();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        for (CameraView view : _views)
        {
            view.play();
        }
    }

    @Override
    protected CameraView getDboView(CameraDbo camera) {
        CameraView imageView = new CameraView(getActivity());
        imageView.setCamotionDbo(_fullLoginDbo, _currentLocation);
        imageView.setCamera(camera);
        imageView.play();
        return imageView;
    }
}
