@Test public void sensorViewHolderBindsCorrectly() { final List<Sensor> sensors = Sensor.generateTestCaseList(); adapter.replaceAll(sensors); final FrameLayout fakeParent = new FrameLayout(getContext()); SensorResponseAdapter.SensorViewHolder viewHolder = RecyclerAdapterTesting.createAndBindView(adapter, fakeParent, 0); assertEquals("0°", viewHolder.value.getText().toString()); viewHolder = RecyclerAdapterTesting.createAndBindView(adapter, fakeParent, 1); assertEquals("1%", viewHolder.value.getText().toString()); viewHolder = RecyclerAdapterTesting.createAndBindView(adapter, fakeParent, 2); assertEquals("2.0", viewHolder.value.getText().toString()); assertEquals("lx", viewHolder.descriptor.getText().toString()); final SensorResponseAdapter.SensorGroupViewHolder groupViewHolder = RecyclerAdapterTesting.createAndBindView(adapter, fakeParent, 3); assertEquals("Air Quality", groupViewHolder.sensorGroupBinding.itemSensorGroupTitle.getText().toString()); assertEquals("message", groupViewHolder.sensorGroupBinding.itemSensorGroupBody.getText().toString()); assertThat(groupViewHolder.sensorGroupBinding.itemSensorGroupContent.getChildCount(), Matchers.greaterThan(2)); }
public void replaceAll(@NonNull final List<Sensor> sensors) { dismissMessage(); int firstAirQualitySensorPosition = RecyclerView.NO_POSITION; this.sensorGroupArray.clear(); final ArrayList<Sensor> normalSensors = new ArrayList<>(); for (final Sensor sensor : sensors) { switch (sensor.getType()) { case PARTICULATES: case CO2: case TVOC: if (firstAirQualitySensorPosition == RecyclerView.NO_POSITION) { firstAirQualitySensorPosition = normalSensors.size(); normalSensors.add(sensor); } addSensorToGroupAt(firstAirQualitySensorPosition, sensor); break; default: normalSensors.add(sensor); } } this.removeSingleSensorGroupsAt(firstAirQualitySensorPosition); super.replaceAll(normalSensors); }
SensorResponseAdapter extends ArrayRecyclerAdapter<Sensor, SensorResponseAdapter.BaseViewHolder> { public void replaceAll(@NonNull final List<Sensor> sensors) { dismissMessage(); int firstAirQualitySensorPosition = RecyclerView.NO_POSITION; this.sensorGroupArray.clear(); final ArrayList<Sensor> normalSensors = new ArrayList<>(); for (final Sensor sensor : sensors) { switch (sensor.getType()) { case PARTICULATES: case CO2: case TVOC: if (firstAirQualitySensorPosition == RecyclerView.NO_POSITION) { firstAirQualitySensorPosition = normalSensors.size(); normalSensors.add(sensor); } addSensorToGroupAt(firstAirQualitySensorPosition, sensor); break; default: normalSensors.add(sensor); } } this.removeSingleSensorGroupsAt(firstAirQualitySensorPosition); super.replaceAll(normalSensors); } }
SensorResponseAdapter extends ArrayRecyclerAdapter<Sensor, SensorResponseAdapter.BaseViewHolder> { public void replaceAll(@NonNull final List<Sensor> sensors) { dismissMessage(); int firstAirQualitySensorPosition = RecyclerView.NO_POSITION; this.sensorGroupArray.clear(); final ArrayList<Sensor> normalSensors = new ArrayList<>(); for (final Sensor sensor : sensors) { switch (sensor.getType()) { case PARTICULATES: case CO2: case TVOC: if (firstAirQualitySensorPosition == RecyclerView.NO_POSITION) { firstAirQualitySensorPosition = normalSensors.size(); normalSensors.add(sensor); } addSensorToGroupAt(firstAirQualitySensorPosition, sensor); break; default: normalSensors.add(sensor); } } this.removeSingleSensorGroupsAt(firstAirQualitySensorPosition); super.replaceAll(normalSensors); } SensorResponseAdapter(@NonNull final LayoutInflater inflater,
                                 @NonNull final UnitFormatter unitFormatter); }
SensorResponseAdapter extends ArrayRecyclerAdapter<Sensor, SensorResponseAdapter.BaseViewHolder> { public void replaceAll(@NonNull final List<Sensor> sensors) { dismissMessage(); int firstAirQualitySensorPosition = RecyclerView.NO_POSITION; this.sensorGroupArray.clear(); final ArrayList<Sensor> normalSensors = new ArrayList<>(); for (final Sensor sensor : sensors) { switch (sensor.getType()) { case PARTICULATES: case CO2: case TVOC: if (firstAirQualitySensorPosition == RecyclerView.NO_POSITION) { firstAirQualitySensorPosition = normalSensors.size(); normalSensors.add(sensor); } addSensorToGroupAt(firstAirQualitySensorPosition, sensor); break; default: normalSensors.add(sensor); } } this.removeSingleSensorGroupsAt(firstAirQualitySensorPosition); super.replaceAll(normalSensors); } SensorResponseAdapter(@NonNull final LayoutInflater inflater,
                                 @NonNull final UnitFormatter unitFormatter); void setErrorItemClickListener(@Nullable final ErrorItemClickListener listener); @Override Sensor getItem(final int position); @Override int getItemViewType(final int position); @Override int getItemCount(); void replaceAll(@NonNull final List<Sensor> sensors); @Override BaseViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType); @Override void onBindViewHolder(final BaseViewHolder holder, final int position); void showSenseMissingCard(@NonNull final Context context); void displayMessage(final boolean messageWantsSenseIcon,
                               @StringRes final int title,
                               @NonNull final CharSequence message,
                               @StringRes final int actionTitle,
                               @NonNull final View.OnClickListener actionOnClick); void dismissMessage(); void showWelcomeCard(final boolean show); void release(); }
SensorResponseAdapter extends ArrayRecyclerAdapter<Sensor, SensorResponseAdapter.BaseViewHolder> { public void replaceAll(@NonNull final List<Sensor> sensors) { dismissMessage(); int firstAirQualitySensorPosition = RecyclerView.NO_POSITION; this.sensorGroupArray.clear(); final ArrayList<Sensor> normalSensors = new ArrayList<>(); for (final Sensor sensor : sensors) { switch (sensor.getType()) { case PARTICULATES: case CO2: case TVOC: if (firstAirQualitySensorPosition == RecyclerView.NO_POSITION) { firstAirQualitySensorPosition = normalSensors.size(); normalSensors.add(sensor); } addSensorToGroupAt(firstAirQualitySensorPosition, sensor); break; default: normalSensors.add(sensor); } } this.removeSingleSensorGroupsAt(firstAirQualitySensorPosition); super.replaceAll(normalSensors); } SensorResponseAdapter(@NonNull final LayoutInflater inflater,
                                 @NonNull final UnitFormatter unitFormatter); void setErrorItemClickListener(@Nullable final ErrorItemClickListener listener); @Override Sensor getItem(final int position); @Override int getItemViewType(final int position); @Override int getItemCount(); void replaceAll(@NonNull final List<Sensor> sensors); @Override BaseViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType); @Override void onBindViewHolder(final BaseViewHolder holder, final int position); void showSenseMissingCard(@NonNull final Context context); void displayMessage(final boolean messageWantsSenseIcon,
                               @StringRes final int title,
                               @NonNull final CharSequence message,
                               @StringRes final int actionTitle,
                               @NonNull final View.OnClickListener actionOnClick); void dismissMessage(); void showWelcomeCard(final boolean show); void release(); static final int VIEW_SENSOR; static final int VIEW_ID_MESSAGE; static final int VIEW_SENSOR_GROUP; static final int VIEW_WELCOME_CARD; }