@OnTextChanged(R.id.new_story_comment)
 protected void commentTextChanged(CharSequence text) {
   final boolean emptyComment = TextUtils.isEmpty(text);
   url.setEnabled(emptyComment);
   urlLabel.setEnabled(emptyComment);
   url.setFocusableInTouchMode(emptyComment);
   setPostButtonState();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_engine);

    mActivity = this;

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    /*if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_material);
        upArrow.setColorFilter(ContextCompat.getColor(this, android.R.color.white), PorterDuff.Mode.SRC_ATOP);
        mToolbar.setNavigationIcon(upArrow);
    }*/

    mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);

    mEditTextName = (EditText) findViewById(R.id.edit_name);
    mEditTextUrl = (EditText) findViewById(R.id.edit_url);
    mEditTextFileKey = (EditText) findViewById(R.id.edit_file_key);

    mFormTitle = (TextView) findViewById(R.id.post_form_title);

    mTextInputName = (TextInputLayout) findViewById(R.id.textInupt_name);
    mTextInputUrl = (TextInputLayout) findViewById(R.id.textInput_url);

    mSpinner = (DropDown) findViewById(R.id.dropDown);
    mSpinner.setAdapter(
        ArrayAdapter.createFromResource(
            this, R.array.custom_open_with, android.R.layout.simple_spinner_dropdown_item));

    mDbHelper = DatabaseHelper.instance(this);
    mData = CustomEngine.getList(this);

    mFAB = (FloatingActionButton) findViewById(R.id.fab);
    mFAB.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (!mEnabled) {
              onBackPressed();
            }

            if (!check()) {
              Snackbar.make(mCoordinatorLayout, R.string.check_your_data, Snackbar.LENGTH_LONG)
                  .show();
              return;
            }

            if (mLocation == -1) {
              add();
            } else {
              modify();
            }

            onBackPressed();
          }
        });

    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    mLayoutManager = new MyLinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(EditSitesActivity.getAdapter(this));
    mRecyclerView.setNestedScrollingEnabled(false);
    mRecyclerView.setHasFixedSize(false);

    ItemTouchHelper.SimpleCallback simpleItemTouchCallback =
        new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
          @Override
          public boolean onMove(
              RecyclerView recyclerView,
              RecyclerView.ViewHolder viewHolder,
              RecyclerView.ViewHolder target) {
            return false;
          }

          @Override
          public int getMovementFlags(
              RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            if (viewHolder.getLayoutPosition() == mAdapter.getItemCount() - 1) {
              return 0;
            }
            return super.getMovementFlags(recyclerView, viewHolder);
          }

          @Override
          public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
            mAdapter.notifyItemRemoved(viewHolder.getLayoutPosition());
            mAdapter.setItemCount(mAdapter.getItemCount() - 1);
            mLayoutManager.setFakeItemCount(1);
            mCoordinatorLayout.postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    mLayoutManager.setFakeItemCount(0);
                    mRecyclerView.requestLayout();
                  }
                },
                500);
          }
        };

    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);

    itemTouchHelper.attachToRecyclerView(mRecyclerView);

    Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_EDIT_LOCATION)) {
      mLocation = intent.getIntExtra(EXTRA_EDIT_LOCATION, -1);
      mItem = mData.get(mLocation);
      if (mItem != null) {
        mEditTextUrl.setText(mItem.getUpload_url());
        mEditTextName.setText(mItem.getName());
        mEditTextFileKey.setText(mItem.getPost_file_key());
        if (mItem.getResult_open_action() <= CustomEngine.RESULT_OPEN_ACTION.OPEN_HTML_FILE) {
          mSpinner.setSelection(mItem.getResult_open_action());
        }

        mEnabled = (mItem.getId() > 5);
        mAdapter = new PostFormAdapter(mItem, mEnabled);
        mRecyclerView.setAdapter(mAdapter);

        if (!mEnabled) {
          mTextInputName.setEnabled(false);
          mTextInputUrl.setEnabled(false);
          mEditTextUrl.setEnabled(false);
          mEditTextName.setEnabled(false);
          mEditTextFileKey.setEnabled(false);
          mSpinner.setEnabled(false);
          mSpinner.setAdapter(
              ArrayAdapter.createFromResource(
                  this,
                  R.array.custom_open_with_in_app,
                  android.R.layout.simple_spinner_dropdown_item));
          mSpinner.setSelection(mItem.getResult_open_action());
        }

      } else {
        mLocation = -1;
      }
    } else {
      mAdapter = new PostFormAdapter();
      mRecyclerView.setAdapter(mAdapter);
    }

    mEditTextFileKey.setOnFocusChangeListener(
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            setFormTitleColor(hasFocus);
          }
        });

    mAdapter.setOnFocusChangeListener(
        new PostFormAdapter.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View view, boolean hasFocus) {
            setFormTitleColor(hasFocus);
          }
        });

    mEditTextName.addTextChangedListener(new TextChangeRemoveErrorTextWatcher(mTextInputName));
    mEditTextUrl.addTextChangedListener(new TextChangeRemoveErrorTextWatcher(mTextInputUrl));
  }