From 5fd9b6732d8cceee91a2acff0c022466ebac520b Mon Sep 17 00:00:00 2001 From: Vavassor Date: Tue, 4 Apr 2017 16:36:42 -0400 Subject: [PATCH] Fixes a crash that can occur when entering or rotating within the profile page. Closes #43 --- .../keylesspalace/tusky/AccountActivity.java | 17 ++++++++++++++--- .../com/keylesspalace/tusky/MainActivity.java | 8 +++++--- .../tusky/NotificationsAdapter.java | 3 ++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java index e6b65764d..a86df1c26 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java @@ -44,6 +44,7 @@ import com.keylesspalace.tusky.entity.Relationship; import com.pkmmte.view.CircularImageView; import com.squareup.picasso.Picasso; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; @@ -72,8 +73,12 @@ public class AccountActivity extends BaseActivity { setContentView(R.layout.activity_account); ButterKnife.bind(this); - Intent intent = getIntent(); - accountId = intent.getStringExtra("id"); + if (savedInstanceState != null) { + accountId = savedInstanceState.getString("accountId"); + } else { + Intent intent = getIntent(); + accountId = intent.getStringExtra("id"); + } SharedPreferences preferences = getSharedPreferences( getString(R.string.preferences_file_key), Context.MODE_PRIVATE); @@ -178,6 +183,12 @@ public class AccountActivity extends BaseActivity { }); } + @Override + protected void onSaveInstanceState(Bundle outState) { + outState.putString("accountId", accountId); + super.onSaveInstanceState(outState); + } + private void onObtainAccountSuccess(Account account) { loadedAccount = account; @@ -213,7 +224,7 @@ public class AccountActivity extends BaseActivity { .placeholder(R.drawable.account_header_missing) .into(header); - java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); + NumberFormat nf = NumberFormat.getInstance(); // Add counts to the tabs in the TabLayout. String[] counts = { diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index f602c2f0d..f694afb47 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -243,9 +243,11 @@ public class MainActivity extends BaseActivity { long drawerItemIdentifier = drawerItem.getIdentifier(); if (drawerItemIdentifier == 0) { - Intent intent = new Intent(MainActivity.this, AccountActivity.class); - intent.putExtra("id", loggedInAccountId); - startActivity(intent); + if (loggedInAccountId != null) { + Intent intent = new Intent(MainActivity.this, AccountActivity.class); + intent.putExtra("id", loggedInAccountId); + startActivity(intent); + } } else if (drawerItemIdentifier == 1) { Intent intent = new Intent(MainActivity.this, FavouritesActivity.class); startActivity(intent); diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java index 21d6e0046..c3cbee060 100644 --- a/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java @@ -22,6 +22,7 @@ import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.text.SpannableStringBuilder; import android.text.Spanned; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -261,7 +262,7 @@ class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRe } String wholeMessage = String.format(format, displayName); final SpannableStringBuilder str = new SpannableStringBuilder(wholeMessage); - str.setSpan(new android.text.style.StyleSpan(Typeface.BOLD), 0, displayName.length(), + str.setSpan(new StyleSpan(Typeface.BOLD), 0, displayName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); message.setText(str); statusContent.setText(status.content);