[android] Changed and refactored recycler decorator, changed size between items and top item offset

This commit is contained in:
Dmitry Donskoy 2018-10-22 11:51:10 +03:00 committed by Aleksandr Zatsepin
parent 3876594c71
commit 7c15784689
6 changed files with 40 additions and 19 deletions

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="@dimen/margin_half_plus_eight"
android:height="@dimen/margin_half_plus_eight"/>
<solid android:color="@android:color/transparent"/>
</shape>

View file

@ -2,6 +2,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:paddingTop="@dimen/margin_base"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView

View file

@ -16,11 +16,12 @@ public class UgcRouteTagsActivity extends BaseToolbarActivity
protected void safeOnCreate(@Nullable Bundle savedInstanceState)
{
super.safeOnCreate(savedInstanceState);
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
if (fragment == null)
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, new UgcRoutesFragment(), FRAGMENT_TAG)
.commit();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, new UgcRoutesFragment(), FRAGMENT_TAG)
.commit();
}
@Override

View file

@ -88,7 +88,7 @@ public class UgcRoutesFragment extends BaseMwmFragment implements BookmarkManage
mRecycler.setItemAnimator(null);
RecyclerView.ItemDecoration decor = ItemDecoratorFactory.createRatingRecordDecorator(
getContext().getApplicationContext(),
DividerItemDecoration.VERTICAL);
DividerItemDecoration.VERTICAL, R.drawable.divider_transparent_half_plus_eight);
mRecycler.addItemDecoration(decor);
}

View file

@ -30,10 +30,11 @@ public class ItemDecoratorFactory
@NonNull
public static RecyclerView.ItemDecoration createRatingRecordDecorator(@NonNull Context context,
int orientation)
int orientation,
int dividerResId)
{
DividerItemDecoration decoration = new DividerItemDecoration(context, orientation);
decoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.divider_transparent_base));
decoration.setDrawable(ContextCompat.getDrawable(context, dividerResId));
return decoration;
}
@ -49,4 +50,11 @@ public class ItemDecoratorFactory
{
return new DividerItemDecoration(context, DividerItemDecoration.VERTICAL);
}
@NonNull
public static RecyclerView.ItemDecoration createRatingRecordDecorator(@NonNull Context context,
int horizontal)
{
return createRatingRecordDecorator(context, horizontal, R.drawable.divider_transparent_base);
}
}

View file

@ -32,21 +32,26 @@ public class UgcRouteTagItemDecorator extends TagItemDecoration
outRect.left = mCurrentOffset == 0 ? 0 : getDivider().getIntrinsicWidth() / 2;
outRect.right = getDivider().getIntrinsicWidth() / 2;
FlexboxLayoutManager flexboxLayoutManager = (FlexboxLayoutManager) parent.getLayoutManager();
List<FlexLine> flexLines = flexboxLayoutManager.getFlexLines();
if (flexLines == null || flexLines.isEmpty())
{
outRect.top = 0;
return;
}
FlexLine flexLine = flexLines.get(0);
int position = parent.getLayoutManager().getPosition(view);
int itemCount = flexLine.getItemCount();
if (position < itemCount)
boolean isFirstLine = isFirstLineItem(view, parent, flexboxLayoutManager);
if (isFirstLine)
outRect.top = 0;
}
private boolean hasSpaceFromRight(Rect outRect, View view, RecyclerView parent)
private static boolean isFirstLineItem(@NonNull View view, @NonNull RecyclerView parent,
@NonNull FlexboxLayoutManager layoutManager)
{
List<FlexLine> flexLines = layoutManager.getFlexLines();
if (flexLines == null || flexLines.isEmpty())
return true;
FlexLine flexLine = flexLines.iterator().next();
int position = parent.getLayoutManager().getPosition(view);
int itemCount = flexLine.getItemCount();
return position < itemCount;
}
private boolean hasSpaceFromRight(@NonNull Rect outRect, @NonNull View view,
@NonNull RecyclerView parent)
{
int padding = parent.getPaddingLeft() + parent.getRight();
return mCurrentOffset + view.getWidth() + outRect.left < parent.getWidth() - padding;