예제 #1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    ArticleDTO articleDTO = this.filtered.get(position);

    if (convertView == null) {
      convertView = View.inflate(this.getContext(), R.layout.lyt_stock_item, null);
      holder = new ViewHolder();
      holder.lblStockItemCodArticle =
          (TextView) convertView.findViewById(R.id.lblStockItemCodArticle);
      holder.lblStockItemDescription =
          (TextView) convertView.findViewById(R.id.lblStockItemDescription);
      holder.lblStockItemCodArtivleProvider =
          (TextView) convertView.findViewById(R.id.lblStockItemCodArticleProvider);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    if (articleDTO != null) {
      holder.lblStockItemCodArticle.setText(articleDTO.getCod_article());
      holder.lblStockItemDescription.setText(articleDTO.getDescription());
      holder.lblStockItemCodArtivleProvider.setText(articleDTO.getCod_article_provider());
    }

    return convertView;
  }
예제 #2
0
    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    protected FilterResults performFiltering(CharSequence constraint) {
      // NOTE: this function is *always* called from a background thread, and
      // not the UI thread.
      constraint = constraint.toString().toUpperCase();
      PreferenceStock preferenceStock = new PreferenceStock();
      preferenceStock.loadPreference(context);
      FilterResults result = new FilterResults();
      if (constraint != null && constraint.toString().length() > 0) {
        ArrayList<ArticleDTO> filt = new ArrayList<ArticleDTO>();
        int size = listArticle.size();
        ArticleDTO articleDTO = null;
        for (int i = 0; i < size; i++) {
          switch (preferenceStock.getCustomFilter()) {
            case PreferenceStock.VALUE_FILTER_CATEGORY:
              {
                articleDTO = listArticle.get(i);
                if (articleDTO.getCategoryName().contains(constraint)) {
                  filt.add(articleDTO);
                }
              }
              break;
            case PreferenceStock.VALUE_FILTER_COD_ARTICLE:
              {
                articleDTO = listArticle.get(i);
                if (articleDTO.getCod_article().contains(constraint)) {
                  filt.add(articleDTO);
                }
              }
              break;
            case PreferenceStock.VALUE_FILTER_COD_ARTICLE_PROVIDER:
              {
                articleDTO = listArticle.get(i);
                if (articleDTO.getCod_article_provider().contains(constraint)) {
                  filt.add(articleDTO);
                }
              }
            case PreferenceStock.VALUE_FILTER_PROVIDER:
              {
                articleDTO = listArticle.get(i);
                if (articleDTO.getProviderName().contains(constraint)) {
                  filt.add(articleDTO);
                }
              }
              break;

            case PreferenceStock.VALUE_FILTER_DESCRIPTION:
              {
                articleDTO = listArticle.get(i);
                if (articleDTO.getDescription().contains(constraint)) {
                  filt.add(articleDTO);
                }
              }
              break;
          }
        }

        switch (preferenceStock.getCustomOrder()) {
          case PreferenceStock.VALUE_ORDER_CATEGORY:
            {
              Collections.sort(
                  filt,
                  new Comparator() {
                    public int compare(Object o1, Object o2) {
                      ArticleDTO bl1 = (ArticleDTO) o1;
                      ArticleDTO bl2 = (ArticleDTO) o2;
                      return bl1.getCategoryName().compareToIgnoreCase(bl2.getCategoryName());
                    }
                  });
            }
            break;

          case PreferenceStock.VALUE_ORDER_COD_ARTICLE:
            {
              Collections.sort(
                  filt,
                  new Comparator() {
                    public int compare(Object o1, Object o2) {
                      ArticleDTO bl1 = (ArticleDTO) o1;
                      ArticleDTO bl2 = (ArticleDTO) o2;
                      return bl1.getCod_article().compareToIgnoreCase(bl2.getCod_article());
                    }
                  });
            }
            break;

          case PreferenceStock.VALUE_ORDER_COD_ARTICLE_PROVIDER:
            {
              Collections.sort(
                  filt,
                  new Comparator() {
                    public int compare(Object o1, Object o2) {
                      ArticleDTO bl1 = (ArticleDTO) o1;
                      ArticleDTO bl2 = (ArticleDTO) o2;
                      return bl1.getCod_article_provider()
                          .compareToIgnoreCase(bl2.getCod_article_provider());
                    }
                  });
            }
            break;

          case PreferenceStock.VALUE_ORDER_PROVIDER:
            {
              Collections.sort(
                  filt,
                  new Comparator() {
                    public int compare(Object o1, Object o2) {
                      ArticleDTO bl1 = (ArticleDTO) o1;
                      ArticleDTO bl2 = (ArticleDTO) o2;
                      return bl1.getProviderName().compareToIgnoreCase(bl2.getProviderName());
                    }
                  });
            }
            break;
        }

        result.count = filt.size();
        result.values = filt;
      } else {
        synchronized (listArticle) {
          result.values = listArticle;
          result.count = listArticle.size();
        }
      }
      return result;
    }