forked from organicmaps/organicmaps
[android] Castomized dividers for bookmark lists.
This commit is contained in:
parent
7a82f0612e
commit
aca8c8c832
7 changed files with 90 additions and 3 deletions
5
android/res/drawable/divider_base.xml
Normal file
5
android/res/drawable/divider_base.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:drawable="@drawable/divider_shape" />
|
||||
</layer-list>
|
6
android/res/drawable/divider_shape.xml
Normal file
6
android/res/drawable/divider_shape.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="?android:textColorTertiary" />
|
||||
<size android:height="1dp" />
|
||||
</shape>
|
|
@ -20,6 +20,7 @@
|
|||
<dimen name="margin_double_and_half">40dp</dimen>
|
||||
<dimen name="margin_double_plus">48dp</dimen>
|
||||
<dimen name="margin_quadruple">64dp</dimen>
|
||||
<dimen name="margin_quadruple_plus_half">72dp</dimen>
|
||||
|
||||
<dimen name="neg_margin_eighth">-2dp</dimen>
|
||||
<dimen name="neg_margin_quarter">-4dp</dimen>
|
||||
|
|
|
@ -20,6 +20,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
|
@ -324,7 +325,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
private void configureRecyclerDividers(@NonNull RecyclerView recyclerView)
|
||||
{
|
||||
RecyclerView.ItemDecoration decorWithPadding = ItemDecoratorFactory
|
||||
.createVerticalDefaultDecorator(requireContext());
|
||||
.createDecoratorWithPadding(requireContext());
|
||||
recyclerView.addItemDecoration(decorWithPadding);
|
||||
recyclerView.addOnScrollListener(mRecyclerListener);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class Holders
|
|||
}
|
||||
}
|
||||
|
||||
static class HeaderViewHolder extends RecyclerView.ViewHolder
|
||||
public static class HeaderViewHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
@NonNull
|
||||
private TextView mButton;
|
||||
|
@ -385,7 +385,7 @@ public class Holders
|
|||
}
|
||||
}
|
||||
|
||||
static class SectionViewHolder extends BaseBookmarkHolder
|
||||
public static class SectionViewHolder extends BaseBookmarkHolder
|
||||
{
|
||||
@NonNull
|
||||
private final TextView mView;
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package com.mapswithme.maps.widget.recycler;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Dimension;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.mapswithme.maps.bookmarks.Holders;
|
||||
|
||||
public class DividerItemDecorationWithPadding extends RecyclerView.ItemDecoration
|
||||
{
|
||||
@Dimension
|
||||
private final int mStartMargin;
|
||||
@NonNull
|
||||
private final Drawable mDivider;
|
||||
|
||||
public DividerItemDecorationWithPadding(@NonNull Drawable divider, @Dimension int startMargin)
|
||||
{
|
||||
mDivider = divider;
|
||||
mStartMargin = startMargin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
|
||||
{
|
||||
if (state.isMeasuring())
|
||||
return;
|
||||
|
||||
int right = parent.getWidth();
|
||||
int dividerHeight = mDivider.getIntrinsicHeight();
|
||||
|
||||
int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount; i++)
|
||||
{
|
||||
View child = parent.getChildAt(i);
|
||||
View nextChild = parent.getChildAt(i + 1);
|
||||
RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);
|
||||
RecyclerView.ViewHolder viewHolderNext = null;
|
||||
if (nextChild != null)
|
||||
viewHolderNext = parent.getChildViewHolder(nextChild);
|
||||
|
||||
int top = child.getBottom();
|
||||
int bottom = top + dividerHeight;
|
||||
|
||||
if (viewHolder instanceof Holders.SectionViewHolder
|
||||
|| viewHolder instanceof Holders.HeaderViewHolder
|
||||
|| viewHolderNext instanceof Holders.SectionViewHolder
|
||||
|| viewHolderNext instanceof Holders.HeaderViewHolder)
|
||||
mDivider.setBounds(0, top, right, bottom);
|
||||
else if (i == childCount - 1)
|
||||
mDivider.setBounds(0, top - dividerHeight, right, bottom);
|
||||
else
|
||||
mDivider.setBounds(mStartMargin, top, right, bottom);
|
||||
|
||||
mDivider.draw(c);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package com.mapswithme.maps.widget.recycler;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.DimenRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
@ -68,6 +70,18 @@ public class ItemDecoratorFactory
|
|||
return new DividerItemDecoration(context, DividerItemDecoration.VERTICAL);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static RecyclerView.ItemDecoration createDecoratorWithPadding(@NonNull Context context)
|
||||
{
|
||||
@DrawableRes
|
||||
int dividerRes = R.drawable.divider_base;
|
||||
@DimenRes
|
||||
int marginDimen = R.dimen.margin_quadruple_plus_half;
|
||||
return new DividerItemDecorationWithPadding(
|
||||
Objects.requireNonNull(context.getDrawable(dividerRes)),
|
||||
context.getResources().getDimensionPixelSize(marginDimen));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static RecyclerView.ItemDecoration createRatingRecordDecorator(@NonNull Context context,
|
||||
int horizontal)
|
||||
|
|
Loading…
Add table
Reference in a new issue