Commit fed17b05 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Unity][Android] Hide secondary TextView if full name is not available

This CL dynamically hides and displays TextView in
AccountPickerDialogFragment depending on whether the full name is
available for an account. It also changes the layout structure to make
sure that all elements are properly positioned when full name is not
available and the secondary TextView is hidden.

Bug: 814728
Change-Id: I7fffec089a7ee3f72d31a89211ebaefc46d192a7
Reviewed-on: https://chromium-review.googlesource.com/1010484Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550540}
parent 443f4880
...@@ -2,50 +2,48 @@ ...@@ -2,50 +2,48 @@
<!-- Copyright 2018 The Chromium Authors. All rights reserved. <!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. --> found in the LICENSE file. -->
<RelativeLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="8dp"> android:padding="8dp">
<ImageView <ImageView
android:id="@+id/account_image" android:id="@+id/account_image"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:contentDescription="@null"/> android:contentDescription="@null"
<TextView tools:src="@drawable/logo_avatar_anonymous"/>
android:id="@+id/account_name" <LinearLayout
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toStartOf="@+id/account_selection_mark"
android:layout_toEndOf="@id/account_image"
android:gravity="center_vertical"
android:minHeight="20dp"
android:textAppearance="@style/BlackBodyDefault"
tools:text="John Doe"/>
<TextView
android:id="@+id/account_email"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/account_name" android:layout_weight="1"
android:layout_toStartOf="@+id/account_selection_mark" android:orientation="vertical">
android:layout_toEndOf="@id/account_image" <TextView
android:gravity="center_vertical" android:id="@+id/account_text_primary"
android:minHeight="20dp" android:layout_width="match_parent"
android:textAppearance="@style/BlackCaption" android:layout_height="wrap_content"
tools:text="john.doe@example.com"/> android:gravity="center_vertical"
<!-- TODO(https://crbug.com/828841): Use animated drawable for checkmark. --> android:minHeight="20dp"
android:textAppearance="@style/BlackBodyDefault"
tools:text="John Doe"/>
<TextView
android:id="@+id/account_text_secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="20dp"
android:textAppearance="@style/BlackCaption"
tools:text="john.doe@example.com"/>
</LinearLayout>
<ImageView <ImageView
android:id="@+id/account_selection_mark" android:id="@+id/account_selection_mark"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:contentDescription="@null" android:contentDescription="@null"
android:src="@drawable/ic_check_googblue_24dp"/> android:src="@drawable/ic_check_googblue_24dp"/>
</RelativeLayout> </LinearLayout>
...@@ -14,6 +14,7 @@ import android.support.v4.util.ObjectsCompat; ...@@ -14,6 +14,7 @@ import android.support.v4.util.ObjectsCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -58,17 +59,18 @@ public class AccountPickerDialogFragment extends DialogFragment { ...@@ -58,17 +59,18 @@ public class AccountPickerDialogFragment extends DialogFragment {
private class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> { private class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
class ViewHolder extends RecyclerView.ViewHolder { class ViewHolder extends RecyclerView.ViewHolder {
private final @Nullable ImageView mAccountImage; private final @Nullable ImageView mAccountImage;
private final @Nullable TextView mAccountName; private final @Nullable TextView mAccountTextPrimary;
private final @Nullable TextView mAccountEmail; private final @Nullable TextView mAccountTextSecondary;
private final @Nullable ImageView mSelectionMark; private final @Nullable ImageView mSelectionMark;
/** Used for displaying profile data for existing account. */ /** Used for displaying profile data for existing account. */
ViewHolder(View view, @Nullable ImageView accountImage, @Nullable TextView accountName, ViewHolder(View view, @Nullable ImageView accountImage,
@Nullable TextView accountEmail, @Nullable ImageView selectionMark) { @Nullable TextView accountTextPrimary, @Nullable TextView accountTextSecondary,
@Nullable ImageView selectionMark) {
super(view); super(view);
mAccountImage = accountImage; mAccountImage = accountImage;
mAccountName = accountName; mAccountTextPrimary = accountTextPrimary;
mAccountEmail = accountEmail; mAccountTextSecondary = accountTextSecondary;
mSelectionMark = selectionMark; mSelectionMark = selectionMark;
} }
...@@ -79,8 +81,18 @@ public class AccountPickerDialogFragment extends DialogFragment { ...@@ -79,8 +81,18 @@ public class AccountPickerDialogFragment extends DialogFragment {
void onBind(DisplayableProfileData profileData, boolean isSelected) { void onBind(DisplayableProfileData profileData, boolean isSelected) {
mAccountImage.setImageDrawable(profileData.getImage()); mAccountImage.setImageDrawable(profileData.getImage());
mAccountName.setText(profileData.getFullNameOrEmail());
mAccountEmail.setText(profileData.getAccountName()); String fullName = profileData.getFullName();
if (!TextUtils.isEmpty(fullName)) {
mAccountTextPrimary.setText(fullName);
mAccountTextSecondary.setText(profileData.getAccountName());
mAccountTextSecondary.setVisibility(View.VISIBLE);
} else {
// Full name is not available, show the email in the primary TextView.
mAccountTextPrimary.setText(profileData.getAccountName());
mAccountTextSecondary.setVisibility(View.GONE);
}
mSelectionMark.setVisibility(isSelected ? View.VISIBLE : View.GONE); mSelectionMark.setVisibility(isSelected ? View.VISIBLE : View.GONE);
} }
} }
...@@ -103,10 +115,12 @@ public class AccountPickerDialogFragment extends DialogFragment { ...@@ -103,10 +115,12 @@ public class AccountPickerDialogFragment extends DialogFragment {
} }
View view = inflater.inflate(R.layout.account_picker_row, viewGroup, false); View view = inflater.inflate(R.layout.account_picker_row, viewGroup, false);
ImageView accountImage = (ImageView) view.findViewById(R.id.account_image); ImageView accountImage = (ImageView) view.findViewById(R.id.account_image);
TextView accountName = (TextView) view.findViewById(R.id.account_name); TextView accountTextPrimary = (TextView) view.findViewById(R.id.account_text_primary);
TextView accountEmail = (TextView) view.findViewById(R.id.account_email); TextView accountTextSecondary =
(TextView) view.findViewById(R.id.account_text_secondary);
ImageView selectionMark = (ImageView) view.findViewById(R.id.account_selection_mark); ImageView selectionMark = (ImageView) view.findViewById(R.id.account_selection_mark);
return new ViewHolder(view, accountImage, accountName, accountEmail, selectionMark); return new ViewHolder(
view, accountImage, accountTextPrimary, accountTextSecondary, selectionMark);
} }
@Override @Override
......
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