Ejemplo n.º 1
0
  private void initFilters() {
    mFilterHolder = (ViewGroup) getRootView().findViewById(R.id.shop_filters);
    mChildrenFilterHolder = (ViewGroup) getRootView().findViewById(R.id.shop_child_filters);
    // determine the set of the articles' icons
    List<Integer> riddleIconIds = new ArrayList<>();
    List<Integer> otherIconIds = new ArrayList<>();
    for (ShopArticle article : mArticleHolder.getAllArticles()) {
      int id = article.getIconResId();
      boolean isRiddleIcon = false;
      for (PracticalRiddleType type : PracticalRiddleType.ALL_PLAYABLE_TYPES) {
        if (type.getIconResId() == id) {
          isRiddleIcon = true;
          break;
        }
      }
      if (isRiddleIcon) {
        if (!riddleIconIds.contains(id)) {
          riddleIconIds.add(id);
        }
      } else {
        if (!otherIconIds.contains(id)) {
          otherIconIds.add(id);
        }
      }
    }

    List<ShopArticleFilter> riddleFilters = new ArrayList<>();
    for (Integer iconId : riddleIconIds) {
      PracticalRiddleType lastVisibleType = Riddle.getLastVisibleRiddleType(getContext());
      riddleFilters.add(
          new ShopArticleFilterIcon(
              iconId, iconId, lastVisibleType != null && lastVisibleType.getIconResId() == iconId));
    }
    ShopArticleGroupFilter riddleGroupFilter =
        new ShopArticleGroupFilter(
            mChildrenFilterHolder, R.drawable.icon_laboratory, riddleFilters, false, this);

    List<ShopArticleFilter> rootFilters = new ArrayList<>();
    rootFilters.add(new ShopArticleFilterImportant(R.drawable.icon_important));
    rootFilters.add(riddleGroupFilter);
    for (Integer iconId : otherIconIds) {
      rootFilters.add(new ShopArticleFilterIcon(iconId, iconId, false));
    }
    rootFilters.add(
        new ShopArticleFilterPurchased(R.drawable.icon_filter_progress_complete, true, false));
    rootFilters.add(new ShopArticleFilterPurchased(R.drawable.icon_filter_progress, false, false));
    ShopArticleGroupFilter rootFilter =
        new ShopArticleGroupFilter(mFilterHolder, 0, rootFilters, true, this);

    // init filters and filter views and listeners
    mArticleHolder.setFilter(rootFilter);
  }
Ejemplo n.º 2
0
 @Override
 public View getChildView(
     int groupPosition,
     int childPosition,
     boolean isLastChild,
     View convertView,
     ViewGroup parent) {
   ShopArticle article = mArticleHolder.getArticle(groupPosition);
   SubProduct product = article.getSubProduct(mInflater, childPosition);
   if (product != null) {
     convertView = product.getView();
   }
   return convertView;
 }
Ejemplo n.º 3
0
    @Override
    public View getGroupView(
        int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
      View name = convertView == null ? null : convertView.findViewById(R.id.shop_article_name);
      if (name == null) {
        convertView = mInflater.inflate(R.layout.shop_article, null);
        name = convertView.findViewById(R.id.shop_article_name);
      }
      if (mExpandedGroup == -1 || isExpanded) {
        convertView.setAlpha(1.f);
      } else {
        convertView.setAlpha(0.25f);
      }
      ShopArticle article = mArticleHolder.getArticle(groupPosition);
      ((TextView) name).setText(article.getName(getResources()));
      int imageResId = article.getIconResId();
      if (imageResId != 0) {
        ((ImageView) convertView.findViewById(R.id.shop_article_image))
            .setImageResource(imageResId);
      }
      ((TextView) convertView.findViewById(R.id.shop_article_descr))
          .setText(article.getDescription(getResources()));
      ImageViewWithText costView =
          ((ImageViewWithText) convertView.findViewById(R.id.shop_article_cost));
      costView.setText(article.getSpentScore(getResources()).toString());
      costView.setVisibility(costView.getText().length() > 0 ? View.VISIBLE : View.GONE);

      LinearLayoutProgressBar progressListener =
          ((LinearLayoutProgressBar) convertView.findViewById(R.id.progress_bar));
      int progressPercent = article.getPurchaseProgressPercent();
      if (progressPercent >= PercentProgressListener.PROGRESS_COMPLETE) {
        progressListener.onProgressUpdate(0);
        convertView.setBackgroundColor(progressListener.getStartColor());
      } else {
        convertView.setBackgroundColor(progressListener.getEndColor());
        progressListener.onProgressUpdate(progressPercent);
      }
      return convertView;
    }
Ejemplo n.º 4
0
 @Override
 public boolean isChildSelectable(int i, int childPosition) {
   ShopArticle article = mArticleHolder.getArticle(i);
   return article != null && article.isClickable(childPosition);
 }