diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java index cb3749b019..e21ca59e52 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java @@ -12,6 +12,7 @@ import android.widget.TextView; import com.mapswithme.maps.R; import com.mapswithme.maps.bookmarks.data.BookmarkCategory; import com.mapswithme.maps.bookmarks.data.BookmarkManager; +import com.mapswithme.maps.content.DataSource; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.location.LocationListener; import com.mapswithme.maps.widget.recycler.RecyclerClickListener; @@ -31,7 +32,7 @@ import static com.mapswithme.maps.bookmarks.Holders.BaseBookmarkHolder.calculate public class BookmarkListAdapter extends RecyclerView.Adapter { @NonNull - private BookmarkCategory mCategory; + private final DataSource mDataSource; // view types static final int TYPE_TRACK = 0; @@ -53,9 +54,9 @@ public class BookmarkListAdapter extends RecyclerView.Adapter dataSource) { - mCategory = category; + mDataSource = dataSource; } public void setOnClickListener(@Nullable RecyclerClickListener listener) @@ -87,19 +88,19 @@ public class BookmarkListAdapter extends RecyclerView.Adapter bmkPos && !isSectionEmpty(mCategory, SECTION_BMKS)) + if (position > bmkPos && !isSectionEmpty(getCategory(), SECTION_BMKS)) return TYPE_BOOKMARK; - else if (position > trackPos && !isSectionEmpty(mCategory, SECTION_TRACKS)) + else if (position > trackPos && !isSectionEmpty(getCategory(), SECTION_TRACKS)) return TYPE_TRACK; - else if (position > descPos && !isSectionEmpty(mCategory, SECTION_DESC)) + else if (position > descPos && !isSectionEmpty(getCategory(), SECTION_DESC)) return TYPE_DESC; throw new IllegalArgumentException("Position not found: " + position); @@ -147,10 +147,10 @@ public class BookmarkListAdapter extends RecyclerView.Adapter onMoreBtnClicked(v, category)); } - private void onMoreBtnClicked(@NonNull View v) + private void onMoreBtnClicked(@NonNull View v, @NonNull BookmarkCategory category) { - int lineCount = calcLineCount(mDescText, mCategory.getDescription()); + int lineCount = calcLineCount(mDescText, category.getDescription()); mDescText.setMaxLines(lineCount); - mDescText.setText(mCategory.getDescription()); + mDescText.setText(category.getDescription()); v.setVisibility(View.GONE); } @Override - void bind(int position) + void bind(int position, @NonNull BookmarkCategory category) { - mTitle.setText(mCategory.getName()); - bindAuthor(); - bindDescriptionIfEmpty(); + mTitle.setText(category.getName()); + bindAuthor(category); + bindDescriptionIfEmpty(category); } - private void bindDescriptionIfEmpty() + private void bindDescriptionIfEmpty(@NonNull BookmarkCategory category) { if (TextUtils.isEmpty(mDescText.getText())) { - String desc = TextUtils.isEmpty(mCategory.getAnnotation()) - ? mCategory.getDescription() - : mCategory.getAnnotation(); + String desc = TextUtils.isEmpty(category.getAnnotation()) + ? category.getDescription() + : category.getAnnotation(); mDescText.setText(desc); } } - private void bindAuthor() + private void bindAuthor(@NonNull BookmarkCategory category) { - BookmarkCategory.Author author = mCategory.getAuthor(); + BookmarkCategory.Author author = category.getAuthor(); Context c = itemView.getContext(); CharSequence authorName = author == null ? null diff --git a/android/src/com/mapswithme/maps/bookmarks/data/CategoryDataSource.java b/android/src/com/mapswithme/maps/bookmarks/data/CategoryDataSource.java new file mode 100644 index 0000000000..a47c6401bd --- /dev/null +++ b/android/src/com/mapswithme/maps/bookmarks/data/CategoryDataSource.java @@ -0,0 +1,36 @@ +package com.mapswithme.maps.bookmarks.data; + +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; + +import com.mapswithme.maps.content.DataSource; + +public class CategoryDataSource extends RecyclerView.AdapterDataObserver implements + DataSource +{ + @NonNull + private BookmarkCategory mCategory; + + public CategoryDataSource(@NonNull BookmarkCategory category) + { + mCategory = category; + } + + @NonNull + @Override + public BookmarkCategory getData() + { + return mCategory; + } + + @Override + public void onChanged() + { + super.onChanged(); + AbstractCategoriesSnapshot.Default snapshot = + BookmarkManager.INSTANCE.getCategoriesSnapshot(mCategory.getType().getFilterStrategy()); + + int index = snapshot.indexOfOrThrow(mCategory); + mCategory = snapshot.getItems().get(index); + } +} diff --git a/android/src/com/mapswithme/maps/content/DataSource.java b/android/src/com/mapswithme/maps/content/DataSource.java new file mode 100644 index 0000000000..39bb883119 --- /dev/null +++ b/android/src/com/mapswithme/maps/content/DataSource.java @@ -0,0 +1,9 @@ +package com.mapswithme.maps.content; + +import android.support.annotation.NonNull; + +public interface DataSource +{ + @NonNull + D getData(); +}