forked from organicmaps/organicmaps
[android] Moved SectionPosition to a separate class.
This commit is contained in:
parent
c60c06d9bd
commit
67086d606c
4 changed files with 44 additions and 80 deletions
|
@ -38,44 +38,12 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
@Nullable
|
||||
private OnItemClickListener<BookmarkCategory> mClickListener;
|
||||
|
||||
static class SectionPosition
|
||||
{
|
||||
static final int INVALID_POSITION = -1;
|
||||
|
||||
private final int mSectionIndex;
|
||||
private final int mItemIndex;
|
||||
|
||||
SectionPosition(int sectionInd, int itemInd)
|
||||
{
|
||||
mSectionIndex = sectionInd;
|
||||
mItemIndex = itemInd;
|
||||
}
|
||||
|
||||
int getSectionIndex()
|
||||
{
|
||||
return mSectionIndex;
|
||||
}
|
||||
|
||||
int getItemIndex()
|
||||
{
|
||||
return mItemIndex;
|
||||
}
|
||||
|
||||
boolean isTitlePosition()
|
||||
{
|
||||
return mSectionIndex != INVALID_POSITION && mItemIndex == INVALID_POSITION;
|
||||
}
|
||||
|
||||
boolean isItemPosition()
|
||||
{
|
||||
return mSectionIndex != INVALID_POSITION && mItemIndex != INVALID_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
BookmarkCollectionAdapter(@NonNull List<BookmarkCategory> itemsCategories,
|
||||
@NonNull List<BookmarkCategory> itemsCollection)
|
||||
{
|
||||
//noinspection AssignmentOrReturnOfFieldWithMutableType
|
||||
mItemsCategory = itemsCategories;
|
||||
//noinspection AssignmentOrReturnOfFieldWithMutableType
|
||||
mItemsCollection = itemsCollection;
|
||||
|
||||
mSectionCount = 0;
|
||||
|
@ -126,8 +94,8 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
{
|
||||
List<BookmarkCategory> categories = getItemsListByType(type);
|
||||
|
||||
int itemIndex = sp.mItemIndex;
|
||||
if (sp.mItemIndex > categories.size() - 1)
|
||||
int itemIndex = sp.getItemIndex();
|
||||
if (sp.getItemIndex() > categories.size() - 1)
|
||||
throw new ArrayIndexOutOfBoundsException(itemIndex);
|
||||
return categories.get(itemIndex);
|
||||
}
|
||||
|
@ -185,7 +153,7 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
if (sectionPosition.isTitlePosition())
|
||||
bindHeaderHolder(holder, sectionPosition.getSectionIndex() + 1);
|
||||
else
|
||||
bindCollectionHolder(holder, sectionPosition, getItemsType(sectionPosition.mSectionIndex));
|
||||
bindCollectionHolder(holder, sectionPosition, getItemsType(sectionPosition.getSectionIndex()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -47,40 +47,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Nullable
|
||||
private RecyclerLongClickListener mLongClickListener;
|
||||
|
||||
static class SectionPosition
|
||||
{
|
||||
static final int INVALID_POSITION = -1;
|
||||
|
||||
private final int mSectionIndex;
|
||||
private final int mItemIndex;
|
||||
|
||||
SectionPosition(int sectionInd, int itemInd)
|
||||
{
|
||||
mSectionIndex = sectionInd;
|
||||
mItemIndex = itemInd;
|
||||
}
|
||||
|
||||
int getSectionIndex()
|
||||
{
|
||||
return mSectionIndex;
|
||||
}
|
||||
|
||||
int getItemIndex()
|
||||
{
|
||||
return mItemIndex;
|
||||
}
|
||||
|
||||
boolean isTitlePosition()
|
||||
{
|
||||
return mSectionIndex != INVALID_POSITION && mItemIndex == INVALID_POSITION;
|
||||
}
|
||||
|
||||
boolean isItemPosition()
|
||||
{
|
||||
return mSectionIndex != INVALID_POSITION && mItemIndex != INVALID_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class SectionsDataSource
|
||||
{
|
||||
@NonNull
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.location.Location;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.text.Layout;
|
||||
import android.text.Spanned;
|
||||
import android.text.StaticLayout;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
|
@ -266,7 +261,7 @@ public class Holders
|
|||
mView = itemView;
|
||||
}
|
||||
|
||||
abstract void bind(@NonNull BookmarkListAdapter.SectionPosition position,
|
||||
abstract void bind(@NonNull SectionPosition position,
|
||||
@NonNull BookmarkListAdapter.SectionsDataSource sectionsDataSource);
|
||||
|
||||
void setOnClickListener(@Nullable RecyclerClickListener listener)
|
||||
|
@ -308,7 +303,7 @@ public class Holders
|
|||
}
|
||||
|
||||
@Override
|
||||
void bind(@NonNull BookmarkListAdapter.SectionPosition position,
|
||||
void bind(@NonNull SectionPosition position,
|
||||
@NonNull BookmarkListAdapter.SectionsDataSource sectionsDataSource)
|
||||
{
|
||||
final long bookmarkId = sectionsDataSource.getBookmarkId(position);
|
||||
|
@ -362,7 +357,7 @@ public class Holders
|
|||
}
|
||||
|
||||
@Override
|
||||
void bind(@NonNull BookmarkListAdapter.SectionPosition position,
|
||||
void bind(@NonNull SectionPosition position,
|
||||
@NonNull BookmarkListAdapter.SectionsDataSource sectionsDataSource)
|
||||
{
|
||||
final long trackId = sectionsDataSource.getTrackId(position);
|
||||
|
@ -391,7 +386,7 @@ public class Holders
|
|||
}
|
||||
|
||||
@Override
|
||||
void bind(@NonNull BookmarkListAdapter.SectionPosition position,
|
||||
void bind(@NonNull SectionPosition position,
|
||||
@NonNull BookmarkListAdapter.SectionsDataSource sectionsDataSource)
|
||||
{
|
||||
mView.setText(sectionsDataSource.getTitle(position.getSectionIndex(), mView.getResources()));
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
public class SectionPosition
|
||||
{
|
||||
static final int INVALID_POSITION = -1;
|
||||
|
||||
private final int mSectionIndex;
|
||||
private final int mItemIndex;
|
||||
|
||||
SectionPosition(int sectionInd, int itemInd)
|
||||
{
|
||||
mSectionIndex = sectionInd;
|
||||
mItemIndex = itemInd;
|
||||
}
|
||||
|
||||
int getSectionIndex()
|
||||
{
|
||||
return mSectionIndex;
|
||||
}
|
||||
|
||||
int getItemIndex()
|
||||
{
|
||||
return mItemIndex;
|
||||
}
|
||||
|
||||
boolean isTitlePosition()
|
||||
{
|
||||
return mSectionIndex != INVALID_POSITION && mItemIndex == INVALID_POSITION;
|
||||
}
|
||||
|
||||
boolean isItemPosition()
|
||||
{
|
||||
return mSectionIndex != INVALID_POSITION && mItemIndex != INVALID_POSITION;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue