Search in sources :

Example 1 with CategoryImageListItem

use of com.faltenreich.diaguard.feature.timeline.table.CategoryImageListItem in project Diaguard by Faltenreich.

the class TimelineDayFragment method invalidateList.

public void invalidateList() {
    if (isAdded() && !data.needsListData()) {
        Log.d(TAG, "Invalidating view for list on " + data.getDay().toString());
        List<CategoryValueListItem> valueListItems = data.getListData();
        if (valueAdapter.getItemCount() > 0) {
            for (int index = 0; index < valueListItems.size(); index++) {
                CategoryValueListItem listItem = valueListItems.get(index);
                RecyclerView.ViewHolder viewHolder = valueListView.findViewHolderForAdapterPosition(index);
                if (viewHolder instanceof CategoryValueViewHolder) {
                    valueAdapter.setItem(listItem, index);
                    // We access the ViewHolder directly for better performance compared to notifyItem(Range)Changed
                    CategoryValueViewHolder categoryValueViewHolder = (CategoryValueViewHolder) viewHolder;
                    categoryValueViewHolder.bind(listItem);
                }
            }
        } else {
            for (Category category : categories) {
                imageAdapter.addItem(new CategoryImageListItem(category));
            }
            imageAdapter.notifyDataSetChanged();
            // Other notify methods lead to rendering issues on view paging
            valueAdapter.addItems(valueListItems);
            valueAdapter.notifyDataSetChanged();
        }
    }
}
Also used : CategoryImageListItem(com.faltenreich.diaguard.feature.timeline.table.CategoryImageListItem) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) RecyclerView(androidx.recyclerview.widget.RecyclerView) CategoryValueListItem(com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem) CategoryValueViewHolder(com.faltenreich.diaguard.feature.timeline.table.CategoryValueViewHolder)

Aggregations

RecyclerView (androidx.recyclerview.widget.RecyclerView)1 CategoryImageListItem (com.faltenreich.diaguard.feature.timeline.table.CategoryImageListItem)1 CategoryValueListItem (com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem)1 CategoryValueViewHolder (com.faltenreich.diaguard.feature.timeline.table.CategoryValueViewHolder)1 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)1