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

[Android] Add configurable image size support to ProfileDataCache

This CL replaces hard-coded image size in ProfileDataCache with a constructor
parameter and fixes its usages.

Bug: 746519
Change-Id: I1a663d4f9a1d9e6a57a73a3db12701c75ef09219
Reviewed-on: https://chromium-review.googlesource.com/591649Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490733}
parent 7679db6e
...@@ -41,8 +41,9 @@ public class AccountFirstRunFragment extends FirstRunPage implements AccountSign ...@@ -41,8 +41,9 @@ public class AccountFirstRunFragment extends FirstRunPage implements AccountSign
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
int imageSize = getResources().getDimensionPixelSize(R.dimen.signin_account_image_size);
ProfileDataCache profileDataCache = ProfileDataCache profileDataCache =
new ProfileDataCache(getActivity(), Profile.getLastUsedProfile()); new ProfileDataCache(getActivity(), Profile.getLastUsedProfile(), imageSize);
boolean isChildAccount = getProperties().getBoolean(IS_CHILD_ACCOUNT); boolean isChildAccount = getProperties().getBoolean(IS_CHILD_ACCOUNT);
String forceAccountTo = getProperties().getString(FORCE_SIGNIN_ACCOUNT_TO); String forceAccountTo = getProperties().getString(FORCE_SIGNIN_ACCOUNT_TO);
AccountSigninView.Listener listener = new AccountSigninView.Listener() { AccountSigninView.Listener listener = new AccountSigninView.Listener() {
......
...@@ -53,7 +53,9 @@ public class SignInPreference ...@@ -53,7 +53,9 @@ public class SignInPreference
*/ */
public SignInPreference(Context context, AttributeSet attrs) { public SignInPreference(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mProfileDataCache = new ProfileDataCache(context, Profile.getLastUsedProfile());
int imageSize = context.getResources().getDimensionPixelSize(R.dimen.user_picture_size);
mProfileDataCache = new ProfileDataCache(context, Profile.getLastUsedProfile(), imageSize);
} }
@Override @Override
......
...@@ -122,8 +122,9 @@ public class AccountSigninActivity extends AppCompatActivity ...@@ -122,8 +122,9 @@ public class AccountSigninActivity extends AppCompatActivity
mView = (AccountSigninView) LayoutInflater.from(this).inflate( mView = (AccountSigninView) LayoutInflater.from(this).inflate(
R.layout.account_signin_view, null); R.layout.account_signin_view, null);
int imageSize = getResources().getDimensionPixelSize(R.dimen.signin_account_image_size);
ProfileDataCache profileDataCache = ProfileDataCache profileDataCache =
new ProfileDataCache(this, Profile.getLastUsedProfile()); new ProfileDataCache(this, Profile.getLastUsedProfile(), imageSize);
String selectAccount = getIntent().getStringExtra(INTENT_SELECT_ACCOUNT); String selectAccount = getIntent().getStringExtra(INTENT_SELECT_ACCOUNT);
if (selectAccount == null) { if (selectAccount == null) {
mView.initFromSelectionPage(profileDataCache, false, this, this); mView.initFromSelectionPage(profileDataCache, false, this, this);
......
...@@ -57,17 +57,17 @@ public class ProfileDataCache implements ProfileDownloader.Observer { ...@@ -57,17 +57,17 @@ public class ProfileDataCache implements ProfileDownloader.Observer {
public String givenName; public String givenName;
} }
private final HashMap<String, CacheEntry> mCacheEntries = new HashMap<>(); private final Context mContext;
private final Profile mProfile;
private final int mImageSize;
private final Drawable mPlaceholderImage; private final Drawable mPlaceholderImage;
private final ObserverList<Observer> mObservers = new ObserverList<>(); private final ObserverList<Observer> mObservers = new ObserverList<>();
private final HashMap<String, CacheEntry> mCacheEntries = new HashMap<>();
private final Context mContext; public ProfileDataCache(Context context, Profile profile, int imageSize) {
private Profile mProfile;
public ProfileDataCache(Context context, Profile profile) {
mContext = context; mContext = context;
mProfile = profile; mProfile = profile;
mImageSize = imageSize;
mPlaceholderImage = mPlaceholderImage =
AppCompatResources.getDrawable(context, R.drawable.logo_avatar_anonymous); AppCompatResources.getDrawable(context, R.drawable.logo_avatar_anonymous);
...@@ -82,12 +82,10 @@ public class ProfileDataCache implements ProfileDownloader.Observer { ...@@ -82,12 +82,10 @@ public class ProfileDataCache implements ProfileDownloader.Observer {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
assert !mObservers.isEmpty(); assert !mObservers.isEmpty();
int imageSizePx =
mContext.getResources().getDimensionPixelSize(R.dimen.signin_account_image_size);
for (int i = 0; i < accounts.size(); i++) { for (int i = 0; i < accounts.size(); i++) {
if (mCacheEntries.get(accounts.get(i)) == null) { if (mCacheEntries.get(accounts.get(i)) == null) {
ProfileDownloader.startFetchingAccountInfoFor( ProfileDownloader.startFetchingAccountInfoFor(
mContext, mProfile, accounts.get(i), imageSizePx, true); mContext, mProfile, accounts.get(i), mImageSize, true);
} }
} }
} }
......
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