package com.rthoni.camotion.ui.fragments;

import com.luticate.utils.business.LuPromise;
import com.luticate.utils.dbo.LuMultipleDbo;
import com.rthoni.camotion.business.SensorsBusiness;
import com.rthoni.camotion.dbo.SensorDbo;
import com.rthoni.camotion.ui.views.SensorView;

/**
 *
 * Created by robin on 11/29/15.
 */
public class SensorsFragment extends CamotionFragment<SensorDbo, SensorView> {

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

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

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

    @Override
    protected SensorView getDboView(SensorDbo sensor) {
        SensorView imageView = new SensorView(getActivity());
        imageView.setCamotionDbo(_fullLoginDbo, _currentLocation);
        imageView.setSensor(sensor);
        imageView.play();
        return imageView;
    }
}
