After deleting the last track in a category, the category itself is now deleted

The issue was caused by calling RecyclerView.AdapterDataObserver.onChanged() at an unexpected time.

I decided not to modify the onChanged() method because it works with a cached version of the native object. To prevent the developer from having to think about when to invalidate the DataSource, I integrated it into the already existing onDelete.

This PR is an alternative to: https://github.com/organicmaps/organicmaps/pull/9189.

Signed-off-by: Mikhail Mitrofanov <mk.mitrofanov@outlook.com>
This commit is contained in:
Mikhail Mitrofanov 2024-09-09 16:32:26 +02:00 committed by Viktor Havaka
parent 165b81e263
commit 384807e776
3 changed files with 16 additions and 0 deletions

View file

@ -69,6 +69,11 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
!mDataSource.getData().getDescription().isEmpty());
}
void invalidate()
{
mDataSource.invalidate();
}
public abstract int getSectionsCount();
public abstract boolean isEditable(int sectionIndex);
public abstract boolean hasTitle(int sectionIndex);
@ -157,6 +162,9 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
@Override
public void onDelete(@NonNull SectionPosition pos)
{
// we must invalidate datasource before calculate sections
invalidate();
calculateSections();
}

View file

@ -34,4 +34,10 @@ public class CategoryDataSource extends RecyclerView.AdapterDataObserver impleme
if (index >= 0)
mCategory = categories.get(index);
}
@Override
public void invalidate()
{
onChanged();
}
}

View file

@ -6,4 +6,6 @@ public interface DataSource<D>
{
@NonNull
D getData();
void invalidate();
}