forked from organicmaps/organicmaps
[android] Removed description section from BookmarkListAdapter in Guides page..
Removed description section from BookmarkListAdapter.
This commit is contained in:
parent
23ed2f6a18
commit
705874d1d1
4 changed files with 85 additions and 167 deletions
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:padding="@dimen/margin_base"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body2.Primary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/author"
|
||||
app:layout_constraintTop_toBottomOf="@id/title"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toBottomOf="@id/author"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/more_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start|bottom"
|
||||
android:gravity="start|top"
|
||||
android:textColor="?attr/colorAccent"
|
||||
android:text="@string/category_desc_more"
|
||||
android:background="@android:color/transparent"/>
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -28,7 +28,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
static final int TYPE_TRACK = 0;
|
||||
static final int TYPE_BOOKMARK = 1;
|
||||
static final int TYPE_SECTION = 2;
|
||||
static final int TYPE_DESC = 3;
|
||||
|
||||
@NonNull
|
||||
private final DataSource<BookmarkCategory> mDataSource;
|
||||
|
@ -94,12 +93,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
|
||||
public BookmarkCategory getCategory() { return mDataSource.getData(); }
|
||||
|
||||
boolean hasDescription()
|
||||
{
|
||||
return !mDataSource.getData().getAnnotation().isEmpty() ||
|
||||
!mDataSource.getData().getDescription().isEmpty();
|
||||
}
|
||||
|
||||
public abstract int getSectionsCount();
|
||||
public abstract boolean isEditable(int sectionIndex);
|
||||
public abstract boolean hasTitle(int sectionIndex);
|
||||
|
@ -115,7 +108,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
private static class CategorySectionsDataSource extends SectionsDataSource
|
||||
{
|
||||
private int mSectionsCount;
|
||||
private int mDescriptionSectionIndex;
|
||||
private int mBookmarksSectionIndex;
|
||||
private int mTracksSectionIndex;
|
||||
|
||||
|
@ -127,13 +119,10 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
|
||||
private void calculateSections()
|
||||
{
|
||||
mDescriptionSectionIndex = SectionPosition.INVALID_POSITION;
|
||||
mBookmarksSectionIndex = SectionPosition.INVALID_POSITION;
|
||||
mTracksSectionIndex = SectionPosition.INVALID_POSITION;
|
||||
|
||||
mSectionsCount = 0;
|
||||
if (hasDescription())
|
||||
mDescriptionSectionIndex = mSectionsCount++;
|
||||
if (getCategory().getTracksCount() > 0)
|
||||
mTracksSectionIndex = mSectionsCount++;
|
||||
if (getCategory().getBookmarksCount() > 0)
|
||||
|
@ -146,7 +135,7 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Override
|
||||
public boolean isEditable(int sectionIndex)
|
||||
{
|
||||
return sectionIndex != mDescriptionSectionIndex && !getCategory().isFromCatalog();
|
||||
return !getCategory().isFromCatalog();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,8 +144,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Nullable
|
||||
public String getTitle(int sectionIndex, @NonNull Resources rs)
|
||||
{
|
||||
if (sectionIndex == mDescriptionSectionIndex)
|
||||
return rs.getString(R.string.description);
|
||||
if (sectionIndex == mTracksSectionIndex)
|
||||
return rs.getString(R.string.tracks_title);
|
||||
return rs.getString(R.string.bookmarks);
|
||||
|
@ -165,8 +152,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Override
|
||||
public int getItemsCount(int sectionIndex)
|
||||
{
|
||||
if (sectionIndex == mDescriptionSectionIndex)
|
||||
return 1;
|
||||
if (sectionIndex == mTracksSectionIndex)
|
||||
return getCategory().getTracksCount();
|
||||
if (sectionIndex == mBookmarksSectionIndex)
|
||||
|
@ -177,8 +162,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Override
|
||||
public int getItemsType(int sectionIndex)
|
||||
{
|
||||
if (sectionIndex == mDescriptionSectionIndex)
|
||||
return TYPE_DESC;
|
||||
if (sectionIndex == mTracksSectionIndex)
|
||||
return TYPE_TRACK;
|
||||
if (sectionIndex == mBookmarksSectionIndex)
|
||||
|
@ -268,30 +251,23 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
mSortedBlocks = sortedBlocks;
|
||||
}
|
||||
|
||||
private boolean isDescriptionSection(int sectionIndex)
|
||||
{
|
||||
return hasDescription() && sectionIndex == 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private SortedBlock getSortedBlock(int sectionIndex)
|
||||
{
|
||||
if (isDescriptionSection(sectionIndex))
|
||||
throw new IllegalArgumentException("Invalid section index for sorted block.");
|
||||
int blockIndex = sectionIndex - (hasDescription() ? 1 : 0);
|
||||
return mSortedBlocks.get(blockIndex);
|
||||
return mSortedBlocks.get(sectionIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSectionsCount()
|
||||
{
|
||||
return mSortedBlocks.size() + (hasDescription() ? 1 : 0);
|
||||
return mSortedBlocks.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(int sectionIndex)
|
||||
{
|
||||
return !isDescriptionSection(sectionIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -300,16 +276,12 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Nullable
|
||||
public String getTitle(int sectionIndex, @NonNull Resources rs)
|
||||
{
|
||||
if (isDescriptionSection(sectionIndex))
|
||||
return rs.getString(R.string.description);
|
||||
return getSortedBlock(sectionIndex).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemsCount(int sectionIndex)
|
||||
{
|
||||
if (isDescriptionSection(sectionIndex))
|
||||
return 1;
|
||||
SortedBlock block = getSortedBlock(sectionIndex);
|
||||
if (block.isBookmarksBlock())
|
||||
return block.getBookmarkIds().size();
|
||||
|
@ -319,8 +291,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Override
|
||||
public int getItemsType(int sectionIndex)
|
||||
{
|
||||
if (isDescriptionSection(sectionIndex))
|
||||
return TYPE_DESC;
|
||||
if (getSortedBlock(sectionIndex).isBookmarksBlock())
|
||||
return TYPE_BOOKMARK;
|
||||
return TYPE_TRACK;
|
||||
|
@ -329,10 +299,7 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Override
|
||||
public void onDelete(@NonNull SectionPosition pos)
|
||||
{
|
||||
if (isDescriptionSection(pos.getSectionIndex()))
|
||||
throw new IllegalArgumentException("Delete failed. Invalid section index.");
|
||||
|
||||
int blockIndex = pos.getSectionIndex() - (hasDescription() ? 1 : 0);
|
||||
int blockIndex = pos.getSectionIndex();
|
||||
SortedBlock block = mSortedBlocks.get(blockIndex);
|
||||
if (block.isBookmarksBlock())
|
||||
{
|
||||
|
@ -459,10 +426,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
TextView tv = (TextView) inflater.inflate(R.layout.item_category_title, parent, false);
|
||||
holder = new Holders.SectionViewHolder(tv);
|
||||
break;
|
||||
case TYPE_DESC:
|
||||
View desc = inflater.inflate(R.layout.item_category_description, parent, false);
|
||||
holder = new Holders.DescriptionViewHolder(desc, mSectionsDataSource.getCategory());
|
||||
break;
|
||||
}
|
||||
|
||||
if (holder == null)
|
||||
|
@ -528,9 +491,6 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
|
||||
public Object getItem(int position)
|
||||
{
|
||||
if (getItemViewType(position) == TYPE_DESC)
|
||||
throw new UnsupportedOperationException("Not supported here! Position = " + position);
|
||||
|
||||
SectionPosition pos = getSectionPosition(position);
|
||||
if (getItemViewType(position) == TYPE_TRACK)
|
||||
{
|
||||
|
|
|
@ -542,7 +542,6 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
switch (adapter.getItemViewType(position))
|
||||
{
|
||||
case BookmarkListAdapter.TYPE_SECTION:
|
||||
case BookmarkListAdapter.TYPE_DESC:
|
||||
return;
|
||||
|
||||
case BookmarkListAdapter.TYPE_BOOKMARK:
|
||||
|
@ -597,7 +596,6 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
switch (type)
|
||||
{
|
||||
case BookmarkListAdapter.TYPE_SECTION:
|
||||
case BookmarkListAdapter.TYPE_DESC:
|
||||
// Do nothing here?
|
||||
break;
|
||||
|
||||
|
|
|
@ -398,83 +398,85 @@ public class Holders
|
|||
}
|
||||
}
|
||||
|
||||
static class DescriptionViewHolder extends BaseBookmarkHolder
|
||||
{
|
||||
static final float SPACING_MULTIPLE = 1.0f;
|
||||
static final float SPACING_ADD = 0.0f;
|
||||
@NonNull
|
||||
private final TextView mTitle;
|
||||
@NonNull
|
||||
private final TextView mAuthor;
|
||||
@NonNull
|
||||
private final TextView mDescText;
|
||||
@NonNull
|
||||
private final View mMoreBtn;
|
||||
// TODO (@velichkomarija): Reuse this code.
|
||||
|
||||
DescriptionViewHolder(@NonNull View itemView, @NonNull BookmarkCategory category)
|
||||
{
|
||||
super(itemView);
|
||||
mDescText = itemView.findViewById(R.id.text);
|
||||
mTitle = itemView.findViewById(R.id.title);
|
||||
mAuthor = itemView.findViewById(R.id.author);
|
||||
|
||||
mMoreBtn = itemView.findViewById(R.id.more_btn);
|
||||
boolean isEmptyDesc = TextUtils.isEmpty(category.getDescription());
|
||||
UiUtils.hideIf(isEmptyDesc, mMoreBtn);
|
||||
mMoreBtn.setOnClickListener(v -> onMoreBtnClicked(v, category));
|
||||
}
|
||||
|
||||
private void onMoreBtnClicked(@NonNull View v, @NonNull BookmarkCategory category)
|
||||
{
|
||||
int lineCount = calcLineCount(mDescText, category.getDescription());
|
||||
mDescText.setMaxLines(lineCount);
|
||||
mDescText.setText(Html.fromHtml(category.getDescription()));
|
||||
v.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
void bind(@NonNull BookmarkListAdapter.SectionPosition position,
|
||||
@NonNull BookmarkListAdapter.SectionsDataSource sectionsDataSource)
|
||||
{
|
||||
mTitle.setText(sectionsDataSource.getCategory().getName());
|
||||
bindAuthor(sectionsDataSource.getCategory());
|
||||
bindDescriptionIfEmpty(sectionsDataSource.getCategory());
|
||||
}
|
||||
|
||||
private void bindDescriptionIfEmpty(@NonNull BookmarkCategory category)
|
||||
{
|
||||
if (TextUtils.isEmpty(mDescText.getText()))
|
||||
{
|
||||
String desc = TextUtils.isEmpty(category.getAnnotation())
|
||||
? category.getDescription()
|
||||
: category.getAnnotation();
|
||||
|
||||
Spanned spannedDesc = Html.fromHtml(desc);
|
||||
mDescText.setText(spannedDesc);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindAuthor(@NonNull BookmarkCategory category)
|
||||
{
|
||||
BookmarkCategory.Author author = category.getAuthor();
|
||||
Context c = itemView.getContext();
|
||||
CharSequence authorName = author == null
|
||||
? null
|
||||
: BookmarkCategory.Author.getRepresentation(c, author);
|
||||
mAuthor.setText(authorName);
|
||||
}
|
||||
|
||||
private static int calcLineCount(@NonNull TextView textView, @NonNull String src)
|
||||
{
|
||||
StaticLayout staticLayout = new StaticLayout(src,
|
||||
textView.getPaint(),
|
||||
textView.getWidth(),
|
||||
Layout.Alignment.ALIGN_NORMAL,
|
||||
SPACING_MULTIPLE,
|
||||
SPACING_ADD,
|
||||
true);
|
||||
|
||||
return staticLayout.getLineCount();
|
||||
}
|
||||
}
|
||||
// static class DescriptionViewHolder extends BaseBookmarkHolder
|
||||
// {
|
||||
// static final float SPACING_MULTIPLE = 1.0f;
|
||||
// static final float SPACING_ADD = 0.0f;
|
||||
// @NonNull
|
||||
// private final TextView mTitle;
|
||||
// @NonNull
|
||||
// private final TextView mAuthor;
|
||||
// @NonNull
|
||||
// private final TextView mDescText;
|
||||
// @NonNull
|
||||
// private final View mMoreBtn;
|
||||
//
|
||||
// DescriptionViewHolder(@NonNull View itemView, @NonNull BookmarkCategory category)
|
||||
// {
|
||||
// super(itemView);
|
||||
// mDescText = itemView.findViewById(R.id.text);
|
||||
// mTitle = itemView.findViewById(R.id.title);
|
||||
// mAuthor = itemView.findViewById(R.id.author);
|
||||
//
|
||||
// mMoreBtn = itemView.findViewById(R.id.more_btn);
|
||||
// boolean isEmptyDesc = TextUtils.isEmpty(category.getDescription());
|
||||
// UiUtils.hideIf(isEmptyDesc, mMoreBtn);
|
||||
// mMoreBtn.setOnClickListener(v -> onMoreBtnClicked(v, category));
|
||||
// }
|
||||
//
|
||||
// private void onMoreBtnClicked(@NonNull View v, @NonNull BookmarkCategory category)
|
||||
// {
|
||||
// int lineCount = calcLineCount(mDescText, category.getDescription());
|
||||
// mDescText.setMaxLines(lineCount);
|
||||
// mDescText.setText(Html.fromHtml(category.getDescription()));
|
||||
// v.setVisibility(View.GONE);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// void bind(@NonNull BookmarkListAdapter.SectionPosition position,
|
||||
// @NonNull BookmarkListAdapter.SectionsDataSource sectionsDataSource)
|
||||
// {
|
||||
// mTitle.setText(sectionsDataSource.getCategory().getName());
|
||||
// bindAuthor(sectionsDataSource.getCategory());
|
||||
// bindDescriptionIfEmpty(sectionsDataSource.getCategory());
|
||||
// }
|
||||
//
|
||||
// private void bindDescriptionIfEmpty(@NonNull BookmarkCategory category)
|
||||
// {
|
||||
// if (TextUtils.isEmpty(mDescText.getText()))
|
||||
// {
|
||||
// String desc = TextUtils.isEmpty(category.getAnnotation())
|
||||
// ? category.getDescription()
|
||||
// : category.getAnnotation();
|
||||
//
|
||||
// Spanned spannedDesc = Html.fromHtml(desc);
|
||||
// mDescText.setText(spannedDesc);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void bindAuthor(@NonNull BookmarkCategory category)
|
||||
// {
|
||||
// BookmarkCategory.Author author = category.getAuthor();
|
||||
// Context c = itemView.getContext();
|
||||
// CharSequence authorName = author == null
|
||||
// ? null
|
||||
// : BookmarkCategory.Author.getRepresentation(c, author);
|
||||
// mAuthor.setText(authorName);
|
||||
// }
|
||||
//
|
||||
// private static int calcLineCount(@NonNull TextView textView, @NonNull String src)
|
||||
// {
|
||||
// StaticLayout staticLayout = new StaticLayout(src,
|
||||
// textView.getPaint(),
|
||||
// textView.getWidth(),
|
||||
// Layout.Alignment.ALIGN_NORMAL,
|
||||
// SPACING_MULTIPLE,
|
||||
// SPACING_ADD,
|
||||
// true);
|
||||
//
|
||||
// return staticLayout.getLineCount();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue