package com.github.openwebnet.view.device;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.CheckBox;
import android.widget.EditText;

import com.github.openwebnet.R;
import com.github.openwebnet.component.Injector;
import com.github.openwebnet.service.ScenarioService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ScenarioActivity extends AbstractDeviceActivity {

    private static final Logger log = LoggerFactory.getLogger(ScenarioActivity.class);

    @Inject
    ScenarioService scenarioService;

    @BindView(R.id.editTextScenarioName)
    EditText editTextScenarioName;

    @BindView(R.id.editTextScenarioWhere)
    EditText editTextScenarioWhere;

    private String ScenarioUuid;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scenario);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        Injector.getApplicationComponent().inject(this);
        ButterKnife.bind(this);

        initSpinnerEnvironment();
        initSpinnerGateway();
        //initEditScenario();
    }

    @Override
    protected void onMenuSave() {
        
    }
    
}

@@ -111,40 +111,8 @@
 le;%0A
-import android.widget.CheckBox;%0A
 impo
@@ -221,16 +221,113 @@
 jector;%0A
+import com.github.openwebnet.model.RealmModel;%0Aimport com.github.openwebnet.model.ScenarioModel;%0A
 import c
@@ -899,17 +899,17 @@
  String 
-S
+s
 cenarioU
@@ -1321,10 +1321,8 @@
     
-//
 init
@@ -1352,70 +1352,2066 @@
     
-@Override%0A    protected void onMenuSave() %7B%0A        %0A    %7D%0A    
+private void initEditScenario() %7B%0A        scenarioUuid = getIntent().getStringExtra(RealmModel.FIELD_UUID);%0A        log.debug(%22initEditScenario: %7B%7D%22, scenarioUuid);%0A        if (scenarioUuid != null) %7B%0A            scenarioService.findById(scenarioUuid).subscribe(automation -%3E %7B%0A                editTextScenarioName.setText(String.valueOf(automation.getName()));%0A                editTextScenarioWhere.setText(String.valueOf(automation.getWhere()));%0A%0A                selectEnvironment(automation.getEnvironmentId());%0A                selectGateway(automation.getGatewayUuid());%0A                setFavourite(automation.isFavourite());%0A            %7D);%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected void onMenuSave() %7B%0A        log.debug(%22name: %7B%7D%22, editTextScenarioName.getText());%0A        log.debug(%22where: %7B%7D%22, editTextScenarioWhere.getText());%0A        log.debug(%22environment: %7B%7D%22, getSelectedEnvironment());%0A        log.debug(%22gateway: %7B%7D%22, getSelectedGateway());%0A        log.debug(%22favourite: %7B%7D%22, isFavourite());%0A%0A        if (isValidScenario()) %7B%0A            if (scenarioUuid == null) %7B%0A                scenarioService.add(parseScenario()).subscribe(uuid -%3E finish());%0A            %7D else %7B%0A                scenarioService.update(parseScenario())%0A                    .doOnCompleted(this::finish)%0A                    .subscribe();%0A            %7D%0A        %7D%0A    %7D%0A%0A    private boolean isValidScenario() %7B%0A        return isValidRequired(editTextScenarioName) &&%0A            isValidRequired(editTextScenarioWhere) &&%0A            isValidDeviceEnvironment() &&%0A            isValidDeviceGateway();%0A    %7D%0A%0A    private ScenarioModel parseScenario() %7B%0A        return (scenarioUuid == null ? ScenarioModel.addBuilder() : ScenarioModel.updateBuilder(scenarioUuid))%0A            .name(utilityService.sanitizedText(editTextScenarioName))%0A            .where(editTextScenarioWhere.getText().toString())%0A            .environment(getSelectedEnvironment().getId())%0A            .gateway(getSelectedGateway().getUuid())%0A            .favourite(isFavourite())%0A            .build();%0A    %7D%0A
 %0A%7D%0A

add activity