<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.component.stocklist;

import android.app.Activity;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.google.inject.Inject;

import org.openlmis.core.R;
import org.openlmis.core.model.StockCard;
import org.openlmis.core.view.activity.StockMovementActivity;
import org.openlmis.core.component.Component;

import java.util.List;

import roboguice.inject.InjectView;

public class Fragment extends Component implements Presenter.StockCardListView, AdapterView.OnItemSelectedListener {

    public static final int REQUEST_CODE_CHANGE = 1;

    @InjectView(R.id.sort_spinner)
    Spinner sortSpinner;

    @InjectView(R.id.products_list)
    RecyclerView stockCardRecycleView;

    @Inject
    Presenter presenter;

    Adapter mAdapter;
    String className;

    View contentView;
    private List<StockCard> stockCards;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        setRetainInstance(true);
        contentView = inflater.inflate(R.layout.fragment_stockcard_list, container, false);
        presenter.attachView(this);
        initView();
        return contentView;
    }

    @Override
    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
        super.onInflate(activity, attrs, savedInstanceState);

        TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.ComponentAttr);
        try {
            className = a.getString(R.styleable.ComponentAttr_className);
        } catch (NullPointerException e) {
            e.printStackTrace();
        } finally {
            a.recycle();
        }
    }

    private void initView() {
        if (className == null) {
            className = StockMovementActivity.class.getName();
        }

        sortSpinner = (Spinner) contentView.findViewById(R.id.sort_spinner);
        stockCardRecycleView = (RecyclerView) contentView.findViewById(R.id.products_list);
        stockCards = presenter.getStockCards();
        mAdapter = new Adapter(this, presenter, stockCards, className);

        initProductList();
        initSortSpinner();
    }


    private void initProductList() {
        stockCardRecycleView.setHasFixedSize(true);
        LinearLayoutManager mLayoutManager = new LinearLayoutManager(contentView.getContext());
        stockCardRecycleView.setLayoutManager(mLayoutManager);
        stockCardRecycleView.setAdapter(mAdapter);

        presenter.loadStockCards();
    }

    private void initSortSpinner() {
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(contentView.getContext(),
                R.array.sort_items_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sortSpinner.setAdapter(adapter);
        sortSpinner.setOnItemSelectedListener(this);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case 0:
                mAdapter.sortByName(true);
                break;
            case 1:
                mAdapter.sortByName(false);
                break;
            case 2:
                mAdapter.sortBySOH(false);
                break;
            case 3:
                mAdapter.sortBySOH(true);
                break;
            default:
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

    @Override
    public void loading() {

    }

    @Override
    public void loaded() {

    }

    @Override
    public void refresh() {
        stockCards = presenter.getStockCards();
        mAdapter = new Adapter(this, presenter, stockCards, className);
        stockCardRecycleView.setAdapter(mAdapter);
    }
<commit_msg> HK/ZS -#000- fix the sort bug after change SOH<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.component.stocklist;

import android.app.Activity;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.google.inject.Inject;

import org.openlmis.core.R;
import org.openlmis.core.model.StockCard;
import org.openlmis.core.view.activity.StockMovementActivity;
import org.openlmis.core.component.Component;

import java.util.List;

import roboguice.inject.InjectView;

public class Fragment extends Component implements Presenter.StockCardListView, AdapterView.OnItemSelectedListener {

    public static final int REQUEST_CODE_CHANGE = 1;

    @InjectView(R.id.sort_spinner)
    Spinner sortSpinner;

    @InjectView(R.id.products_list)
    RecyclerView stockCardRecycleView;

    @Inject
    Presenter presenter;

    Adapter mAdapter;
    String className;

    View contentView;
    private List<StockCard> stockCards;
    int currentPostion;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        setRetainInstance(true);
        contentView = inflater.inflate(R.layout.fragment_stockcard_list, container, false);
        presenter.attachView(this);
        initView();
        return contentView;
    }

    @Override
    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
        super.onInflate(activity, attrs, savedInstanceState);

        TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.ComponentAttr);
        try {
            className = a.getString(R.styleable.ComponentAttr_className);
        } catch (NullPointerException e) {
            e.printStackTrace();
        } finally {
            a.recycle();
        }
    }

    private void initView() {
        if (className == null) {
            className = StockMovementActivity.class.getName();
        }

        sortSpinner = (Spinner) contentView.findViewById(R.id.sort_spinner);
        stockCardRecycleView = (RecyclerView) contentView.findViewById(R.id.products_list);
        stockCards = presenter.getStockCards();
        mAdapter = new Adapter(this, presenter, stockCards, className);

        initProductList();
        initSortSpinner();
    }


    private void initProductList() {
        stockCardRecycleView.setHasFixedSize(true);
        LinearLayoutManager mLayoutManager = new LinearLayoutManager(contentView.getContext());
        stockCardRecycleView.setLayoutManager(mLayoutManager);
        stockCardRecycleView.setAdapter(mAdapter);

        presenter.loadStockCards();
    }

    private void initSortSpinner() {
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(contentView.getContext(),
                R.array.sort_items_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sortSpinner.setAdapter(adapter);
        sortSpinner.setOnItemSelectedListener(this);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        currentPostion = position;
        switch (position) {
            case 0:
                mAdapter.sortByName(true);
                break;
            case 1:
                mAdapter.sortByName(false);
                break;
            case 2:
                mAdapter.sortBySOH(false);
                break;
            case 3:
                mAdapter.sortBySOH(true);
                break;
            default:
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

    @Override
    public void loading() {

    }

    @Override
    public void loaded() {

    }

    @Override
    public void refresh() {
        stockCards = presenter.getStockCards();
        mAdapter = new Adapter(this, presenter, stockCards, className);
        stockCardRecycleView.setAdapter(mAdapter);
        onItemSelected(sortSpinner, null, currentPostion, 0L);
    }

{'fraction_non_alphanumeric': 0.08218522770761577, 'fraction_numerical': 0.0026789131266743206, 'mean_word_length': 3.0927956147220046, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '376154', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2775, 'n_words': 713}