Android Open Source - BehatReporter Steps And Outline Examples Adapter






From Project

Back to project page BehatReporter.

License

The source code is released under:

Copyright (C) 2013 Fabian Kiss <headrevision@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software...

If you think the Android project BehatReporter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package headrevision.BehatReporter.report;
/*from  w ww.  jav  a 2  s.  co  m*/
import headrevision.BehatReporter.R;
import headrevision.BehatReporter.json.ParserException;
import headrevision.BehatReporter.ui.Message;
import headrevision.BehatReporter.ui.ResultColor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.fasterxml.jackson.databind.JsonNode;

public class StepsAndOutlineExamplesAdapter extends StepsAdapter {

  public StepsAndOutlineExamplesAdapter(Activity activity, int itemViewId, List<JsonNode> items) {
    super(activity, itemViewId, items);
  }

  @Override
  public ItemParserFactory getItemParserFactory() {
    return new StepOrOutlineExampleParserFactory();
  }

  @Override
  public ItemsAdapterFactory getSubItemsAdapterFactory(JsonNode item) {
    throw new UnsupportedOperationException();
  }

  @Override
  protected List<List<JsonNode>> getGroupedItems(List<JsonNode> items) {
    List<List<JsonNode>> groupedItems = new ArrayList<List<JsonNode>>();
    List<JsonNode> outlineSteps = new ArrayList<JsonNode>();
    List<JsonNode> outlineExamples = new ArrayList<JsonNode>();
    groupedItems.add(outlineSteps);
    groupedItems.add(outlineExamples);
    groupItems(items, outlineSteps, outlineExamples);
    return groupedItems;
  }

  @Override
  protected List<String> getGroupNames(List<List<JsonNode>> groupedItems) {
    List<String> groupNames = new ArrayList<String>();
    groupNames.add(getGroupHeading(new StepsAdapterFactory()));
    groupNames.add(getGroupHeading(new StepsAndOutlineExamplesAdapterFactory()));
    return groupNames;
  }

  @Override
  protected void setItemViewContent(View itemView, int groupPosition, int childPosition) {
    JsonNode item = getChild(groupPosition, childPosition);
    ItemParser itemParser = getItemParserFactory().getItemParser(item);
    if (itemParser instanceof StepParser) {
      itemView = itemView.findViewById(R.id.stepListItem);
      super.setItemViewContent(itemView, groupPosition, childPosition);
    } else if (itemParser instanceof OutlineExampleParser) {
      itemView = itemView.findViewById(R.id.outlineExampleListItem);
      try {
        String values = ((OutlineExampleParser) itemParser).parseValues();
        Result result = itemParser.parseResult();
        setValues(values, result, itemView);
      } catch (ParserException e) {
        Message.getInstance(activity).showError(e);
      }
    }
    itemView.setVisibility(View.VISIBLE);
  }

  @Override
  protected void setResultColor(Result result, View itemView, TextView textView) {
  }

  private void setValues(String values, Result result, View itemView) {
    TextView textView = (TextView) itemView.findViewById(R.id.outlineExampleValues);
    textView.setText(values);
    ResultColor.getInstance(activity).set(result, itemView, textView, false);
  }

  private void groupItems(List<JsonNode> items, List<JsonNode> outlineSteps, List<JsonNode> outlineExamples) {
    Iterator<JsonNode> iterator = items.iterator();
    while (iterator.hasNext()) {
      JsonNode item = iterator.next();
      StepParser stepParser = new StepParser(item);
      OutlineExampleParser outlineExampleParser = new OutlineExampleParser(item);
      try {
        if (stepParser.isStep()) {
          outlineSteps.add(item);
        } else if (outlineExampleParser.isOutlineExample()) {
          outlineExamples.add(item);
        }
      } catch (ParserException e) {
      }
    }
  }

}




Java Source Code List

headrevision.BehatReporter.ItemHandler.java
headrevision.BehatReporter.ListHandler.java
headrevision.BehatReporter.MainActivity.java
headrevision.BehatReporter.ReportHandler.java
headrevision.BehatReporter.json.ParserException.java
headrevision.BehatReporter.json.Parser.java
headrevision.BehatReporter.json.ReaderException.java
headrevision.BehatReporter.json.Reader.java
headrevision.BehatReporter.report.FeatureParserFactory.java
headrevision.BehatReporter.report.FeatureParser.java
headrevision.BehatReporter.report.FeaturesAdapterFactory.java
headrevision.BehatReporter.report.FeaturesAdapter.java
headrevision.BehatReporter.report.ItemParserFactory.java
headrevision.BehatReporter.report.ItemParser.java
headrevision.BehatReporter.report.ItemsAdapterFactory.java
headrevision.BehatReporter.report.ItemsAdapter.java
headrevision.BehatReporter.report.LoaderException.java
headrevision.BehatReporter.report.LoaderTaskListener.java
headrevision.BehatReporter.report.LoaderTask.java
headrevision.BehatReporter.report.Loader.java
headrevision.BehatReporter.report.OutlineExampleParser.java
headrevision.BehatReporter.report.OutlineParser.java
headrevision.BehatReporter.report.ReportParser.java
headrevision.BehatReporter.report.Result.java
headrevision.BehatReporter.report.ScenarioOrOutlineParserFactory.java
headrevision.BehatReporter.report.ScenarioParser.java
headrevision.BehatReporter.report.ScenariosAndOutlinesAdapterFactory.java
headrevision.BehatReporter.report.ScenariosAndOutlinesAdapter.java
headrevision.BehatReporter.report.StepOrOutlineExampleParserFactory.java
headrevision.BehatReporter.report.StepParserFactory.java
headrevision.BehatReporter.report.StepParser.java
headrevision.BehatReporter.report.StepsAdapterFactory.java
headrevision.BehatReporter.report.StepsAdapter.java
headrevision.BehatReporter.report.StepsAndOutlineExamplesAdapterFactory.java
headrevision.BehatReporter.report.StepsAndOutlineExamplesAdapter.java
headrevision.BehatReporter.store.ItemTitles.java
headrevision.BehatReporter.store.ReportJson.java
headrevision.BehatReporter.store.ReportUrl.java
headrevision.BehatReporter.ui.ItemDepth.java
headrevision.BehatReporter.ui.Message.java
headrevision.BehatReporter.ui.OptionsMenu.java
headrevision.BehatReporter.ui.ResultColor.java
headrevision.BehatReporter.ui.SetReportDialogListener.java
headrevision.BehatReporter.ui.SetReportDialog.java