From 3c655a25dc7744499d5ee1c081a5305f3c057dfe Mon Sep 17 00:00:00 2001 From: Vavassor Date: Tue, 4 Apr 2017 17:32:34 -0400 Subject: [PATCH] Fixes a crash that can occur when the drawer on the main page is being initialized while it is in a closed state. --- app/build.gradle | 3 --- .../com/keylesspalace/tusky/MainActivity.java | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 083d523c..b05e8867 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,9 +18,6 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - lintOptions { - disable 'MissingTranslation' - } } dependencies { diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index f694afb4..dd651af5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -30,6 +30,7 @@ import android.support.v4.view.ViewPager; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; +import android.text.style.StyleSpan; import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -346,7 +347,7 @@ public class MainActivity extends BaseActivity { String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username; 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.setMaxLines(1); textView.setEllipsize(TextUtils.TruncateAt.END); @@ -368,7 +369,7 @@ public class MainActivity extends BaseActivity { mastodonAPI.accountVerifyCredentials().enqueue(new Callback() { @Override - public void onResponse(Call call, retrofit2.Response response) { + public void onResponse(Call call, Response response) { if (!response.isSuccessful()) { onFetchUserInfoFailure(new Exception(response.message())); return; @@ -376,11 +377,20 @@ public class MainActivity extends BaseActivity { Account me = response.body(); 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) .load(me.header) .placeholder(R.drawable.account_header_missing) - .resize(background.getWidth(), background.getHeight()) + .resize(backgroundWidth, backgroundHeight) .centerCrop() .into(background);