Fixes a crash that can occur when the drawer on the main page is being initialized while it is in a closed state.

main
Vavassor 8 years ago
parent 5fd9b6732d
commit 3c655a25dc
  1. 3
      app/build.gradle
  2. 16
      app/src/main/java/com/keylesspalace/tusky/MainActivity.java

@ -18,9 +18,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
lintOptions {
disable 'MissingTranslation'
}
} }
dependencies { dependencies {

@ -30,6 +30,7 @@ import android.support.v4.view.ViewPager;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -346,7 +347,7 @@ public class MainActivity extends BaseActivity {
String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username; String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username;
final SpannableStringBuilder str = new SpannableStringBuilder(searchStr); final SpannableStringBuilder str = new SpannableStringBuilder(searchStr);
str.setSpan(new android.text.style.StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(str); textView.setText(str);
textView.setMaxLines(1); textView.setMaxLines(1);
textView.setEllipsize(TextUtils.TruncateAt.END); textView.setEllipsize(TextUtils.TruncateAt.END);
@ -368,7 +369,7 @@ 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, retrofit2.Response<Account> response) { public void onResponse(Call<Account> call, Response<Account> response) {
if (!response.isSuccessful()) { if (!response.isSuccessful()) {
onFetchUserInfoFailure(new Exception(response.message())); onFetchUserInfoFailure(new Exception(response.message()));
return; return;
@ -376,11 +377,20 @@ public class MainActivity extends BaseActivity {
Account me = response.body(); Account me = response.body();
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();
}
Picasso.with(MainActivity.this) Picasso.with(MainActivity.this)
.load(me.header) .load(me.header)
.placeholder(R.drawable.account_header_missing) .placeholder(R.drawable.account_header_missing)
.resize(background.getWidth(), background.getHeight()) .resize(backgroundWidth, backgroundHeight)
.centerCrop() .centerCrop()
.into(background); .into(background);

Loading…
Cancel
Save