forked from organicmaps/organicmaps
[android] Return old description block in users bookmarks.
This commit is contained in:
parent
24c81b4a38
commit
faa6a1131b
4 changed files with 177 additions and 8 deletions
android
res/layout
src/com/mapswithme/maps/bookmarks
42
android/res/layout/item_category_description.xml
Normal file
42
android/res/layout/item_category_description.xml
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?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,6 +28,7 @@ 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;
|
||||
|
@ -59,6 +60,13 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
|
||||
public BookmarkCategory getCategory() { return mDataSource.getData(); }
|
||||
|
||||
boolean hasDescription()
|
||||
{
|
||||
return mDataSource.getData().isMyCategory() &&
|
||||
(!mDataSource.getData().getAnnotation().isEmpty() ||
|
||||
!mDataSource.getData().getDescription().isEmpty());
|
||||
}
|
||||
|
||||
public abstract int getSectionsCount();
|
||||
public abstract boolean isEditable(int sectionIndex);
|
||||
public abstract boolean hasTitle(int sectionIndex);
|
||||
|
@ -76,6 +84,7 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
private int mSectionsCount;
|
||||
private int mBookmarksSectionIndex;
|
||||
private int mTracksSectionIndex;
|
||||
private int mDescriptionSectionIndex;
|
||||
|
||||
CategorySectionsDataSource(@NonNull DataSource<BookmarkCategory> dataSource)
|
||||
{
|
||||
|
@ -87,8 +96,11 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
{
|
||||
mBookmarksSectionIndex = SectionPosition.INVALID_POSITION;
|
||||
mTracksSectionIndex = SectionPosition.INVALID_POSITION;
|
||||
mDescriptionSectionIndex = SectionPosition.INVALID_POSITION;
|
||||
|
||||
mSectionsCount = 0;
|
||||
if (hasDescription())
|
||||
mDescriptionSectionIndex = mSectionsCount++;
|
||||
if (getCategory().getTracksCount() > 0)
|
||||
mTracksSectionIndex = mSectionsCount++;
|
||||
if (getCategory().getBookmarksCount() > 0)
|
||||
|
@ -101,7 +113,7 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Override
|
||||
public boolean isEditable(int sectionIndex)
|
||||
{
|
||||
return !getCategory().isFromCatalog();
|
||||
return sectionIndex != mDescriptionSectionIndex && !getCategory().isFromCatalog();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,6 +122,8 @@ 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);
|
||||
|
@ -118,6 +132,8 @@ 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)
|
||||
|
@ -128,6 +144,8 @@ 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)
|
||||
|
@ -217,23 +235,30 @@ 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)
|
||||
{
|
||||
return mSortedBlocks.get(sectionIndex);
|
||||
if (isDescriptionSection(sectionIndex))
|
||||
throw new IllegalArgumentException("Invalid section index for sorted block.");
|
||||
int blockIndex = sectionIndex - (hasDescription() ? 1 : 0);
|
||||
return mSortedBlocks.get(blockIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSectionsCount()
|
||||
{
|
||||
return mSortedBlocks.size();
|
||||
return mSortedBlocks.size() + (hasDescription() ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(int sectionIndex)
|
||||
{
|
||||
return true;
|
||||
return !isDescriptionSection(sectionIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -242,12 +267,16 @@ 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();
|
||||
|
@ -257,6 +286,8 @@ 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;
|
||||
|
@ -265,7 +296,10 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
@Override
|
||||
public void onDelete(@NonNull SectionPosition pos)
|
||||
{
|
||||
int blockIndex = pos.getSectionIndex();
|
||||
if (isDescriptionSection(pos.getSectionIndex()))
|
||||
throw new IllegalArgumentException("Delete failed. Invalid section index.");
|
||||
|
||||
int blockIndex = pos.getSectionIndex() - (hasDescription() ? 1 : 0);
|
||||
SortedBlock block = mSortedBlocks.get(blockIndex);
|
||||
if (block.isBookmarksBlock())
|
||||
{
|
||||
|
@ -392,6 +426,10 @@ 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)
|
||||
|
@ -457,6 +495,9 @@ 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)
|
||||
{
|
||||
|
|
|
@ -349,13 +349,11 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
boolean isEmptyRecycler = isEmpty() || isEmptySearchResults();
|
||||
|
||||
showPlaceholder(isEmptyRecycler);
|
||||
UiUtils.showIf(!isEmptyRecycler, getRecyclerView(), mFabViewOnMap, mDescriptionView);
|
||||
UiUtils.hideIf(getAdapter().isSearchResults(), mCollectionRecyclerView, mDescriptionView);
|
||||
UiUtils.showIf(!isEmptyRecycler, getRecyclerView(), mFabViewOnMap, mDescriptionView);
|
||||
|
||||
if (getCategoryOrThrow().isMyCategory())
|
||||
{
|
||||
UiUtils.hide(mDescriptionView);
|
||||
}
|
||||
|
||||
requireActivity().invalidateOptionsMenu();
|
||||
}
|
||||
|
@ -623,6 +621,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
switch (adapter.getItemViewType(position))
|
||||
{
|
||||
case BookmarkListAdapter.TYPE_SECTION:
|
||||
case BookmarkListAdapter.TYPE_DESC:
|
||||
return;
|
||||
|
||||
case BookmarkListAdapter.TYPE_BOOKMARK:
|
||||
|
@ -677,6 +676,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
switch (type)
|
||||
{
|
||||
case BookmarkListAdapter.TYPE_SECTION:
|
||||
case BookmarkListAdapter.TYPE_DESC:
|
||||
// Do nothing here?
|
||||
break;
|
||||
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
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;
|
||||
|
@ -468,4 +474,84 @@ public class Holders
|
|||
mView.setText(sectionsDataSource.getTitle(position.getSectionIndex(), mView.getResources()));
|
||||
}
|
||||
}
|
||||
|
||||
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 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