<commit_before>/*
 * This program is part of the OpenLMIS logistics management information
 * system platform software.
 *
 * Copyright © 2015 ThoughtWorks, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version. This program is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details. You should
 * have received a copy of the GNU Affero General Public License along with
 * this program. If not, see http://www.gnu.org/licenses. For additional
 * information contact <EMAIL>
 */

package org.openlmis.core.view.holder;

import android.app.DatePickerDialog;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.InputFilter;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;

import org.apache.commons.lang3.StringUtils;
import org.openlmis.core.R;
import org.openlmis.core.manager.MovementReasonManager;
import org.openlmis.core.model.StockCard;
import org.openlmis.core.model.StockMovementItem;
import org.openlmis.core.utils.DateUtil;
import org.openlmis.core.utils.SingleTextWatcher;
import org.openlmis.core.utils.ToastUtil;
import org.openlmis.core.view.adapter.StockMovementAdapter;
import org.openlmis.core.view.viewmodel.StockMovementViewModel;
import org.openlmis.core.view.widget.InputFilterMinMax;
import org.openlmis.core.view.widget.MovementTypeDialog;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import roboguice.inject.InjectView;

public class StockMovementViewHolder extends BaseViewHolder {

    @InjectView(R.id.tx_date)TextView txMovementDate;
    @InjectView(R.id.tx_reason)TextView txReason;
    @InjectView(R.id.et_document_no)EditText etDocumentNo;
    @InjectView(R.id.et_received)EditText etReceived;
    @InjectView(R.id.et_negative_adjustment)EditText etNegativeAdjustment;
    @InjectView(R.id.et_positive_adjustment)EditText etPositiveAdjustment;
    @InjectView(R.id.et_issued)EditText etIssued;
    @InjectView(R.id.tx_stock_on_hand)TextView txStockExistence;
//    @InjectView(R.id.tx_signature)TextView txSignature;
    private final int blackColor;
    private final int redColor;
    private Drawable editTextBackground;

    private StockMovementAdapter.MovementChangedListener movementChangeListener;

    public StockMovementViewHolder(View itemView, StockMovementAdapter.MovementChangedListener movementChangeListener) {
        super(itemView);
        this.movementChangeListener = movementChangeListener;

        blackColor = context.getResources().getColor(R.color.black);
        redColor = context.getResources().getColor(R.color.red);

        InputFilter[] filters = new InputFilter[]{new InputFilterMinMax(Integer.MAX_VALUE)};
        etReceived.setFilters(filters);
        etNegativeAdjustment.setFilters(filters);
        etPositiveAdjustment.setFilters(filters);
        etIssued.setFilters(filters);

        editTextBackground = new EditText(context).getBackground();
    }

    public void populate(final StockMovementViewModel model, StockCard stockCard) {

        disableLine();
        hideUnderline();

        removeTextChangeListeners(model, stockCard.getStockOnHand());

        setRowFontColor(blackColor);

        txMovementDate.setText(model.getMovementDate());
        etDocumentNo.setText(model.getDocumentNo());
        etReceived.setText(model.getReceived());
        etNegativeAdjustment.setText(model.getNegativeAdjustment());
        etPositiveAdjustment.setText(model.getPositiveAdjustment());
        etIssued.setText(model.getIssued());
        txStockExistence.setText(model.getStockExistence());
//        txSignature.setText(model.getSignature());

        if (model.getReason() != null) {
            txReason.setText(model.getReason().getDescription());
        }

        setInventoryItemsFontColorToRed(model);

        if (model.isDraft()) {
            txMovementDate.setEnabled(true);
            txReason.setEnabled(true);
            setEditableQuantityField(model);
        } else {
            itemView.setBackgroundResource(R.color.white);
        }

        addClickListeners(model, getPreviousMovementDate(stockCard));

        addTextChangedListeners(model, stockCard.getStockOnHand());

    }

    private void setEditableQuantityField(StockMovementViewModel model) {
        if (model.getReason() != null) {
            enableAndUnderlineEditText(etDocumentNo);
            switch (model.getReason().getMovementType()) {
                case ISSUE:
                    enableAndUnderlineEditText(etIssued);
                    break;
                case RECEIVE:
                    enableAndUnderlineEditText(etReceived);
                    break;
                case NEGATIVE_ADJUST:
                    enableAndUnderlineEditText(etNegativeAdjustment);<commit_msg>MG - #000 - Should show bottom btn when rotate screen<commit_after>/*
 * This program is part of the OpenLMIS logistics management information
 * system platform software.
 *
 * Copyright © 2015 ThoughtWorks, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version. This program is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details. You should
 * have received a copy of the GNU Affero General Public License along with
 * this program. If not, see http://www.gnu.org/licenses. For additional
 * information contact <EMAIL>
 */

package org.openlmis.core.view.holder;

import android.app.DatePickerDialog;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;

import org.apache.commons.lang3.StringUtils;
import org.openlmis.core.R;
import org.openlmis.core.manager.MovementReasonManager;
import org.openlmis.core.model.StockCard;
import org.openlmis.core.model.StockMovementItem;
import org.openlmis.core.utils.DateUtil;
import org.openlmis.core.utils.SingleTextWatcher;
import org.openlmis.core.utils.ToastUtil;
import org.openlmis.core.view.adapter.StockMovementAdapter;
import org.openlmis.core.view.viewmodel.StockMovementViewModel;
import org.openlmis.core.view.widget.InputFilterMinMax;
import org.openlmis.core.view.widget.MovementTypeDialog;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import roboguice.inject.InjectView;

public class StockMovementViewHolder extends BaseViewHolder {

    @InjectView(R.id.tx_date)TextView txMovementDate;
    @InjectView(R.id.tx_reason)TextView txReason;
    @InjectView(R.id.et_document_no)EditText etDocumentNo;
    @InjectView(R.id.et_received)EditText etReceived;
    @InjectView(R.id.et_negative_adjustment)EditText etNegativeAdjustment;
    @InjectView(R.id.et_positive_adjustment)EditText etPositiveAdjustment;
    @InjectView(R.id.et_issued)EditText etIssued;
    @InjectView(R.id.tx_stock_on_hand)TextView txStockExistence;
//    @InjectView(R.id.tx_signature)TextView txSignature;
    private final int blackColor;
    private final int redColor;
    private Drawable editTextBackground;

    private StockMovementAdapter.MovementChangedListener movementChangeListener;

    public StockMovementViewHolder(View itemView, StockMovementAdapter.MovementChangedListener movementChangeListener) {
        super(itemView);
        this.movementChangeListener = movementChangeListener;

        blackColor = context.getResources().getColor(R.color.black);
        redColor = context.getResources().getColor(R.color.red);

        InputFilter[] filters = new InputFilter[]{new InputFilterMinMax(Integer.MAX_VALUE)};
        etReceived.setFilters(filters);
        etNegativeAdjustment.setFilters(filters);
        etPositiveAdjustment.setFilters(filters);
        etIssued.setFilters(filters);

        editTextBackground = new EditText(context).getBackground();
    }

    public void populate(final StockMovementViewModel model, StockCard stockCard) {

        disableLine();
        hideUnderline();

        removeTextChangeListeners(model, stockCard.getStockOnHand());

        setRowFontColor(blackColor);

        txMovementDate.setText(model.getMovementDate());
        etDocumentNo.setText(model.getDocumentNo());
        etReceived.setText(model.getReceived());
        etNegativeAdjustment.setText(model.getNegativeAdjustment());
        etPositiveAdjustment.setText(model.getPositiveAdjustment());
        etIssued.setText(model.getIssued());
        txStockExistence.setText(model.getStockExistence());
//        txSignature.setText(model.getSignature());

        if (model.getReason() != null) {
            txReason.setText(model.getReason().getDescription());
        }

        setInventoryItemsFontColorToRed(model);

        if (model.isDraft()) {
            txMovementDate.setEnabled(true);
            txReason.setEnabled(true);
            setEditableQuantityField(model);
            if (!TextUtils.isEmpty(model.getMovementDate())) {
                highLightAndShowBottomBtn();
            }
        } else {
            itemView.setBackgroundResource(R.color.white);
        }

        addClickListeners(model, getPreviousMovementDate(stockCard));

        addTextChangedListeners(model, stockCard.getStockOnHand());

    }

    private void setEditableQuantityField(StockMovementViewModel model) {
        if (model.getReason() != null) {
            enableAndUnderlineEditText(etDocumentNo);
            switch (model.getReason().getMovementType()) {
                case ISSUE:
                    enableAndUnderlineEditText(etIssued);
                    break;
                case RECEIVE:
                    enableAndUnderlineEditText(etReceived);
                    break;
                case NEGATIVE_ADJUST:
                    enableAndUnderlineEditText(etNegativeAdjustment);
{'fraction_non_alphanumeric': 0.0883916083916084, 'fraction_numerical': 0.0013986013986013986, 'mean_word_length': 3.758651286601597, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '141925', 'n_tokens_mistral': 3012, 'n_tokens_neox': 2909, 'n_words': 608}