The unloaded drawer header was sometimes returning zero dimensions and crashing. It's just easier to let it handle resizing and cropping.
This commit is contained in:
parent
30d7f269de
commit
1d10a7f6e8
|
@ -292,6 +292,7 @@ public class MainActivity extends BaseActivity {
|
||||||
.withActivity(this)
|
.withActivity(this)
|
||||||
.withSelectionListEnabledForSingleProfile(false)
|
.withSelectionListEnabledForSingleProfile(false)
|
||||||
.withDividerBelowHeader(false)
|
.withDividerBelowHeader(false)
|
||||||
|
.withHeaderBackgroundScaleType(ImageView.ScaleType.CENTER_CROP)
|
||||||
.withOnAccountHeaderProfileImageListener(new AccountHeader.OnAccountHeaderProfileImageListener() {
|
.withOnAccountHeaderProfileImageListener(new AccountHeader.OnAccountHeaderProfileImageListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onProfileImageClick(View view, IProfile profile, boolean current) {
|
public boolean onProfileImageClick(View view, IProfile profile, boolean current) {
|
||||||
|
@ -438,11 +439,11 @@ public class MainActivity extends BaseActivity {
|
||||||
mastodonApi.accountVerifyCredentials().enqueue(new Callback<Account>() {
|
mastodonApi.accountVerifyCredentials().enqueue(new Callback<Account>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<Account> call, Response<Account> response) {
|
public void onResponse(Call<Account> call, Response<Account> response) {
|
||||||
if (!response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
|
onFetchUserInfoSuccess(response.body(), domain);
|
||||||
|
} else {
|
||||||
onFetchUserInfoFailure(new Exception(response.message()));
|
onFetchUserInfoFailure(new Exception(response.message()));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
onFetchUserInfoSuccess(response.body(), domain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -454,28 +455,14 @@ public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
private void onFetchUserInfoSuccess(Account me, String domain) {
|
private void onFetchUserInfoSuccess(Account me, String domain) {
|
||||||
// Add the header image and avatar from the account, into the navigation drawer header.
|
// Add the header image and avatar from the account, into the navigation drawer header.
|
||||||
headerResult.clear();
|
|
||||||
|
|
||||||
ImageView background = headerResult.getHeaderBackgroundView();
|
ImageView background = headerResult.getHeaderBackgroundView();
|
||||||
int backgroundWidth = background.getWidth();
|
|
||||||
int backgroundHeight = background.getHeight();
|
|
||||||
if (backgroundWidth == 0 || backgroundHeight == 0) {
|
|
||||||
/* The header ImageView may not be layed out when the verify credentials call returns so
|
|
||||||
* measure the dimensions and use those. */
|
|
||||||
background.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
|
|
||||||
backgroundWidth = background.getMeasuredWidth();
|
|
||||||
backgroundHeight = background.getMeasuredHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));
|
background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));
|
||||||
|
|
||||||
Picasso.with(MainActivity.this)
|
Picasso.with(MainActivity.this)
|
||||||
.load(me.header)
|
.load(me.header)
|
||||||
.placeholder(R.drawable.account_header_default)
|
.placeholder(R.drawable.account_header_default)
|
||||||
.resize(backgroundWidth, backgroundHeight)
|
|
||||||
.centerCrop()
|
|
||||||
.into(background);
|
.into(background);
|
||||||
|
|
||||||
|
headerResult.clear();
|
||||||
headerResult.addProfiles(
|
headerResult.addProfiles(
|
||||||
new ProfileDrawerItem()
|
new ProfileDrawerItem()
|
||||||
.withName(me.getDisplayName())
|
.withName(me.getDisplayName())
|
||||||
|
|
Loading…
Reference in New Issue