package kz.arta.synergy.workflow.mobile.android.forms.general.components.link;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import kz.arta.synergy.workflow.mobile.android.R;
import kz.arta.synergy.workflow.mobile.android.common.components.ACheckBox;

/**
 * Created by neox on 03.05.16.
 * Ссылка
 */
public class LinkActivity extends Activity {

    /**
     * Заголовок
     */
    public static final String TITLE = "TITLE";

    /**
     * Ссылка
     */
    public static final String URL = "URL";

    /**
     * Открывать ли в новом окне или нет
     */
    public static final String NEW = "NEW";

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.link_activity);

        android.app.ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }

        final TextView titleEditText = (TextView) findViewById(R.id.link_activity_name);
        final TextView urlEditText = (TextView) findViewById(R.id.link_activity_url);
        final ACheckBox checkBox = (ACheckBox) findViewById(R.id.link_activity_check_box);
        checkBox.setEnabled(true);
        checkBox.setText(getString(R.string.open_new_window));

        Intent intent = getIntent();
        final String title = intent.getStringExtra(TITLE);
        final String url = intent.getStringExtra(URL);
        final boolean newWindow = intent.getBooleanExtra(NEW, false);

        titleEditText.setText(title);
        urlEditText.setText(url);
        checkBox.setValue(newWindow);

        Button save = (Button) findViewById(R.id.link_activity_finish_button);
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra(TITLE, titleEditText.getText().toString());
                intent.putExtra(URL, urlEditText.getText().toString());
                intent.putExtra(NEW, checkBox.getValue());
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}
