summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/adapter/FeatureSectionAdapter.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/adapter/FeatureSectionAdapter.java')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/adapter/FeatureSectionAdapter.java265
1 files changed, 133 insertions, 132 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/adapter/FeatureSectionAdapter.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/adapter/FeatureSectionAdapter.java
index d86e06ea6d..012bbed4ca 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/adapter/FeatureSectionAdapter.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/adapter/FeatureSectionAdapter.java
@@ -18,161 +18,162 @@ import java.util.Comparator;
public class FeatureSectionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
- private static final int SECTION_TYPE = 0;
-
- private final Context context;
- private final SparseArray<Section> sections;
- private final RecyclerView.Adapter adapter;
-
- @LayoutRes
- private final int sectionRes;
-
- @IdRes
- private final int textRes;
-
- private boolean valid = true;
-
- public FeatureSectionAdapter(Context ctx, int sectionResourceId, int textResourceId, RecyclerView.Adapter baseAdapter) {
- context = ctx;
- sectionRes = sectionResourceId;
- textRes = textResourceId;
- adapter = baseAdapter;
- sections = new SparseArray<>();
- adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
- @Override
- public void onChanged() {
- valid = adapter.getItemCount() > 0;
- notifyDataSetChanged();
- }
-
- @Override
- public void onItemRangeChanged(int positionStart, int itemCount) {
- valid = adapter.getItemCount() > 0;
- notifyItemRangeChanged(positionStart, itemCount);
- }
-
- @Override
- public void onItemRangeInserted(int positionStart, int itemCount) {
- valid = adapter.getItemCount() > 0;
- notifyItemRangeInserted(positionStart, itemCount);
- }
-
- @Override
- public void onItemRangeRemoved(int positionStart, int itemCount) {
- valid = adapter.getItemCount() > 0;
- notifyItemRangeRemoved(positionStart, itemCount);
- }
- });
- }
+ private static final int SECTION_TYPE = 0;
+
+ private final Context context;
+ private final SparseArray<Section> sections;
+ private final RecyclerView.Adapter adapter;
+
+ @LayoutRes
+ private final int sectionRes;
+
+ @IdRes
+ private final int textRes;
+
+ private boolean valid = true;
+
+ public FeatureSectionAdapter(Context ctx, int sectionResourceId, int textResourceId,
+ RecyclerView.Adapter baseAdapter) {
+ context = ctx;
+ sectionRes = sectionResourceId;
+ textRes = textResourceId;
+ adapter = baseAdapter;
+ sections = new SparseArray<>();
+ adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
+ @Override
+ public void onChanged() {
+ valid = adapter.getItemCount() > 0;
+ notifyDataSetChanged();
+ }
+ @Override
+ public void onItemRangeChanged(int positionStart, int itemCount) {
+ valid = adapter.getItemCount() > 0;
+ notifyItemRangeChanged(positionStart, itemCount);
+ }
- public static class SectionViewHolder extends RecyclerView.ViewHolder {
+ @Override
+ public void onItemRangeInserted(int positionStart, int itemCount) {
+ valid = adapter.getItemCount() > 0;
+ notifyItemRangeInserted(positionStart, itemCount);
+ }
- public TextView title;
+ @Override
+ public void onItemRangeRemoved(int positionStart, int itemCount) {
+ valid = adapter.getItemCount() > 0;
+ notifyItemRangeRemoved(positionStart, itemCount);
+ }
+ });
+ }
- public SectionViewHolder(@NonNull View view, @IdRes int textRes) {
- super(view);
- title = (TextView) view.findViewById(textRes);
- title.setTypeface(FontCache.get("Roboto-Medium.ttf", view.getContext()));
- }
- }
- @Override
- public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int typeView) {
- if (typeView == SECTION_TYPE) {
- final View view = LayoutInflater.from(context).inflate(sectionRes, parent, false);
- return new SectionViewHolder(view, textRes);
- } else {
- return adapter.onCreateViewHolder(parent, typeView - 1);
- }
- }
+ public static class SectionViewHolder extends RecyclerView.ViewHolder {
- @Override
- public void onBindViewHolder(RecyclerView.ViewHolder sectionViewHolder, int position) {
- if (isSectionHeaderPosition(position)) {
- ((SectionViewHolder) sectionViewHolder).title.setText(sections.get(position).title);
- } else {
- adapter.onBindViewHolder(sectionViewHolder, getConvertedPosition(position));
- }
+ public TextView title;
+ public SectionViewHolder(@NonNull View view, @IdRes int textRes) {
+ super(view);
+ title = (TextView) view.findViewById(textRes);
+ title.setTypeface(FontCache.get("Roboto-Medium.ttf", view.getContext()));
}
-
- @Override
- public int getItemViewType(int position) {
- return isSectionHeaderPosition(position)
- ? SECTION_TYPE
- : adapter.getItemViewType(getConvertedPosition(position)) + 1;
+ }
+
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int typeView) {
+ if (typeView == SECTION_TYPE) {
+ final View view = LayoutInflater.from(context).inflate(sectionRes, parent, false);
+ return new SectionViewHolder(view, textRes);
+ } else {
+ return adapter.onCreateViewHolder(parent, typeView - 1);
}
-
-
- public static class Section {
- int firstPosition;
- int sectionedPosition;
- CharSequence title;
-
- public Section(int firstPosition, CharSequence title) {
- this.firstPosition = firstPosition;
- this.title = title;
- }
-
- public CharSequence getTitle() {
- return title;
- }
+ }
+
+ @Override
+ public void onBindViewHolder(RecyclerView.ViewHolder sectionViewHolder, int position) {
+ if (isSectionHeaderPosition(position)) {
+ ((SectionViewHolder) sectionViewHolder).title.setText(sections.get(position).title);
+ } else {
+ adapter.onBindViewHolder(sectionViewHolder, getConvertedPosition(position));
}
+ }
- public void setSections(Section[] sections) {
- this.sections.clear();
+ @Override
+ public int getItemViewType(int position) {
+ return isSectionHeaderPosition(position)
+ ? SECTION_TYPE
+ : adapter.getItemViewType(getConvertedPosition(position)) + 1;
+ }
- Arrays.sort(sections, new Comparator<Section>() {
- @Override
- public int compare(Section o, Section o1) {
- return (o.firstPosition == o1.firstPosition)
- ? 0
- : ((o.firstPosition < o1.firstPosition) ? -1 : 1);
- }
- });
- int offset = 0;
- for (Section section : sections) {
- section.sectionedPosition = section.firstPosition + offset;
- this.sections.append(section.sectionedPosition, section);
- ++offset;
- }
+ public static class Section {
+ int firstPosition;
+ int sectionedPosition;
+ CharSequence title;
- notifyDataSetChanged();
+ public Section(int firstPosition, CharSequence title) {
+ this.firstPosition = firstPosition;
+ this.title = title;
}
- public int getConvertedPosition(int sectionedPosition) {
- if (isSectionHeaderPosition(sectionedPosition)) {
- return RecyclerView.NO_POSITION;
- }
-
- int offset = 0;
- for (int i = 0; i < sections.size(); i++) {
- if (sections.valueAt(i).sectionedPosition > sectionedPosition) {
- break;
- }
- --offset;
- }
- return sectionedPosition + offset;
+ public CharSequence getTitle() {
+ return title;
}
-
- public boolean isSectionHeaderPosition(int position) {
- return sections.get(position) != null;
+ }
+
+
+ public void setSections(Section[] sections) {
+ this.sections.clear();
+
+ Arrays.sort(sections, new Comparator<Section>() {
+ @Override
+ public int compare(Section section, Section section1) {
+ return (section.firstPosition == section1.firstPosition)
+ ? 0
+ : ((section.firstPosition < section1.firstPosition) ? -1 : 1);
+ }
+ });
+
+ int offset = 0;
+ for (Section section : sections) {
+ section.sectionedPosition = section.firstPosition + offset;
+ this.sections.append(section.sectionedPosition, section);
+ ++offset;
}
+ notifyDataSetChanged();
+ }
- @Override
- public long getItemId(int position) {
- return isSectionHeaderPosition(position)
- ? Integer.MAX_VALUE - sections.indexOfKey(position)
- : adapter.getItemId(getConvertedPosition(position));
+ public int getConvertedPosition(int sectionedPosition) {
+ if (isSectionHeaderPosition(sectionedPosition)) {
+ return RecyclerView.NO_POSITION;
}
- @Override
- public int getItemCount() {
- return (valid ? adapter.getItemCount() + sections.size() : 0);
+ int offset = 0;
+ for (int i = 0; i < sections.size(); i++) {
+ if (sections.valueAt(i).sectionedPosition > sectionedPosition) {
+ break;
+ }
+ --offset;
}
+ return sectionedPosition + offset;
+ }
+
+ public boolean isSectionHeaderPosition(int position) {
+ return sections.get(position) != null;
+ }
+
+
+ @Override
+ public long getItemId(int position) {
+ return isSectionHeaderPosition(position)
+ ? Integer.MAX_VALUE - sections.indexOfKey(position)
+ : adapter.getItemId(getConvertedPosition(position));
+ }
+
+ @Override
+ public int getItemCount() {
+ return (valid ? adapter.getItemCount() + sections.size() : 0);
+ }
} \ No newline at end of file