@Override protected FilterResults performFiltering(CharSequence constraint) { String filterString = constraint.toString().toLowerCase(); FilterResults results = new FilterResults(); final ArrayList<TemperatureInfo> list = data; int count = list.size(); final ArrayList<TemperatureInfo> temperatureInfos = new ArrayList<>(count); TemperatureInfo filterableObject; for (int i = 0; i < count; i++) { filterableObject = list.get(i); if (filterableObject.getName().toLowerCase().contains(filterString)) { temperatureInfos.add(filterableObject); } } results.values = temperatureInfos; results.count = temperatureInfos.size(); return results; }
@Override public void onBindViewHolder(final DataObjectHolder holder, final int position) { if (filteredData != null && filteredData.size() > 0) { final TemperatureInfo mTemperatureInfo = filteredData.get(position); if (mSharedPrefs.darkThemeEnabled()) { holder.dayButton.setBackground( ContextCompat.getDrawable(context, R.drawable.button_dark_status)); holder.monthButton.setBackground( ContextCompat.getDrawable(context, R.drawable.button_dark_status)); holder.yearButton.setBackground( ContextCompat.getDrawable(context, R.drawable.button_dark_status)); holder.weekButton.setBackground( ContextCompat.getDrawable(context, R.drawable.button_dark_status)); if (holder.setButton != null) holder.setButton.setBackground( ContextCompat.getDrawable(context, R.drawable.button_status_dark)); } holder.isProtected = mTemperatureInfo.isProtected(); int modeIconRes = 0; boolean tooHot = false; if (mTemperatureInfo.getTemperature() > 30) tooHot = true; Picasso.with(context) .load( DomoticzIcons.getDrawableIcon( mTemperatureInfo.getTypeImg(), mTemperatureInfo.getType(), null, tooHot, false, null)) .into(holder.iconRow); if ("evohome".equals(mTemperatureInfo.getHardwareName())) { holder.setButton.setVisibility(View.VISIBLE); modeIconRes = getEvohomeStateIcon(mTemperatureInfo.getStatus()); } else { holder.setButton.setVisibility(View.GONE); } holder.setButton.setText(context.getString(R.string.set_temperature)); holder.setButton.setId(mTemperatureInfo.getIdx()); holder.setButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { for (TemperatureInfo t : filteredData) { if (t.getIdx() == v.getId()) listener.onSetClick(t); } } }); holder.dayButton.setId(mTemperatureInfo.getIdx()); holder.dayButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { for (TemperatureInfo t : filteredData) { if (t.getIdx() == v.getId()) listener.onLogClick(t, DomoticzValues.Graph.Range.DAY); } } }); holder.monthButton.setId(mTemperatureInfo.getIdx()); holder.monthButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { for (TemperatureInfo t : filteredData) { if (t.getIdx() == v.getId()) listener.onLogClick(t, DomoticzValues.Graph.Range.MONTH); } } }); holder.weekButton.setId(mTemperatureInfo.getIdx()); holder.weekButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { for (TemperatureInfo t : filteredData) { if (t.getIdx() == v.getId()) listener.onLogClick(t, DomoticzValues.Graph.Range.WEEK); } } }); holder.yearButton.setId(mTemperatureInfo.getIdx()); holder.yearButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { for (TemperatureInfo t : filteredData) { if (t.getIdx() == v.getId()) listener.onLogClick(t, DomoticzValues.Graph.Range.YEAR); } } }); if (holder.likeButton != null) { holder.likeButton.setId(mTemperatureInfo.getIdx()); holder.likeButton.setLiked(mTemperatureInfo.getFavoriteBoolean()); holder.likeButton.setOnLikeListener( new OnLikeListener() { @Override public void liked(LikeButton likeButton) { handleLikeButtonClick(likeButton.getId(), true); } @Override public void unLiked(LikeButton likeButton) { handleLikeButtonClick(likeButton.getId(), false); } }); } holder.name.setText(mTemperatureInfo.getName()); if (mTemperatureInfo.getType().equalsIgnoreCase(DomoticzValues.Device.Type.Name.WIND)) { holder.data.setText(R.string.wind); holder.data.append( ": " + mTemperatureInfo.getData() + " " + mTemperatureInfo.getDirection()); holder.data2.setVisibility(View.GONE); } else { double temperature = mTemperatureInfo.getTemperature(); double setPoint = mTemperatureInfo.getSetPoint(); if (temperature <= 0 || setPoint <= 0) { holder.data.setText( context.getString(R.string.temperature) + ": " + mTemperatureInfo.getData()); holder.data2.setVisibility(View.GONE); } else { holder.data.setText( context.getString(R.string.temperature) + ": " + mTemperatureInfo.getTemperature() + " C"); holder.data2.setText( context.getString(R.string.set_point) + ": " + mTemperatureInfo.getSetPoint() + " C"); holder.data2.setVisibility(View.VISIBLE); } } if (holder.iconMode != null) { if (modeIconRes == 0) { holder.iconMode.setVisibility(View.GONE); } else { holder.iconMode.setImageResource(modeIconRes); holder.iconMode.setVisibility(View.VISIBLE); } } holder.itemView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { listener.onItemLongClicked(position); return true; } }); holder.itemView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { listener.onItemClicked(v, position); } }); } }