package com.rthoni.camotion.ui.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.luticate.auth.dbo.LuFullLoginDbo;
import com.luticate.utils.business.LuPromise;
import com.rthoni.camotion.R;
import com.rthoni.camotion.dbo.CommandDbo;
import com.rthoni.camotion.dbo.LocationDbo;

/**
 * Created by robin on 12/10/15.
 */
public class CommandView extends RelativeLayout {
    private LuFullLoginDbo _fullLoginDbo = null;
    private LocationDbo _currentLocation = null;

    private CommandDbo _command;

    private LuPromise.LuConsumer<CommandDbo> _onClicked = null;

    public CommandView(Context context) {
        super(context);
        init();
    }

    public CommandView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CommandView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init()
    {
        inflate(getContext(), R.layout.command_view, this);
        findViewById(R.id.textViewName).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (_onClicked != null) {
                    _onClicked.execute(_command);
                }
            }
        });
    }

    public void setCamotionDbo(LuFullLoginDbo fullLoginDbo, LocationDbo currentLocation)
    {
        _fullLoginDbo = fullLoginDbo;
        _currentLocation = currentLocation;
    }

    public CommandDbo getCommand() {
        return _command;
    }

    public void setCommand(CommandDbo command) {
        _command = command;
        ((TextView)findViewById(R.id.textViewName)).setText(command.getName());
    }

    public void setOnClickedListener(LuPromise.LuConsumer<CommandDbo> onClicked)
    {
        _onClicked = onClicked;
    }
}
