Commit 1827194d authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Mfill Android] Fix spacing between footer commands and user infos

This CL adds a space below the last UserInfo element and the first
non-UserInfo element.
Effectively, this means the FooterCommands have the same padding to the
UserInfo as UserInfo elements have to each other.

Screenshot before:
https://photos.app.goo.gl/h3By5RN2zUiDGVLw8
Screenshot after:
https://photos.app.goo.gl/MVzu6uirjkkVhnBF9

Alternatives considered:
1. A static top margin for a footer command would not work here since
footer commands are not supposed to have paddings between each other.
2. Adding the space relative to the first Footer Command adds a padding
between the "No saved passwords" text and the footer commands if no
UserInfo is available. Such padding isn't supposed to exist either.
3. Wrapping FooterCommands or UserInfos into a Layout and add the
margin to the layout would work but degrades the effectiveness of the
RecyclerView which wants to reuse containers.

Change-Id: I63e08ab42215f81befb05bd5a26b96d27dc4b908
Reviewed-on: https://chromium-review.googlesource.com/c/1481295Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634617}
parent 818ed23c
......@@ -6,11 +6,14 @@ package org.chromium.chrome.browser.autofill.keyboard_accessory;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
......@@ -25,6 +28,26 @@ class PasswordAccessoryInfoView extends LinearLayout {
private ChipView mUsername;
private ChipView mPassword;
/**
* This decoration adds a space between the last PasswordAccessoryInfoView and the first
* non-PasswordAccessoryInfoView. This allows to define a margin below the whole list of
* PasswordAccessoryInfoViews without having to wrap them in a new layout. This would reduce
* the reusability of single info containers in a RecyclerView.
*/
public static class DynamicBottomSpacer extends RecyclerView.ItemDecoration {
@Override
public void getItemOffsets(
Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
if (view instanceof PasswordAccessoryInfoView) return;
int previous = parent.indexOfChild(view) - 1;
if (previous < 0) return;
if (!(parent.getChildAt(previous) instanceof PasswordAccessoryInfoView)) return;
outRect.top = view.getContext().getResources().getDimensionPixelSize(
R.dimen.keyboard_accessory_suggestion_padding);
}
}
/**
* Constructor for inflating from XML.
*/
......
......@@ -69,5 +69,6 @@ class PasswordAccessorySheetModernViewBinder {
static void initializeView(RecyclerView view, AccessorySheetTabModel model) {
view.setAdapter(PasswordAccessorySheetCoordinator.createModernAdapter(model));
view.addItemDecoration(new PasswordAccessoryInfoView.DynamicBottomSpacer());
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment