From 3229907fc67646845691822d530fc26ebc14a0d3 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Mon, 20 Mar 2017 22:53:46 -0400 Subject: [PATCH] Fixes a couple of crashes. 1.) When on the account page, if the request for user info beats the call that initialises the header image, it can touch a header image with illegal dimensions that get handed to Picasso and cause an exception. 2.) A crash due to a few retrofit responses not being handled properly. --- .../keylesspalace/tusky/AccountFragment.java | 17 +++++++++++++---- .../com/keylesspalace/tusky/MainActivity.java | 7 ++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java b/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java index 416c5211e..006721be0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java @@ -35,6 +35,7 @@ import java.util.List; import retrofit2.Call; import retrofit2.Callback; +import retrofit2.Response; public class AccountFragment extends BaseFragment implements AccountActionListener { private static final String TAG = "Account"; // logging tag @@ -160,8 +161,12 @@ public class AccountFragment extends BaseFragment implements AccountActionListen private void fetchAccounts(final String fromId, String uptoId) { Callback> cb = new Callback>() { @Override - public void onResponse(Call> call, retrofit2.Response> response) { - onFetchAccountsSuccess(response.body(), fromId); + public void onResponse(Call> call, Response> response) { + if (response.isSuccessful()) { + onFetchAccountsSuccess(response.body(), fromId); + } else { + onFetchAccountsFailure(new Exception(response.message())); + } } @Override @@ -229,8 +234,12 @@ public class AccountFragment extends BaseFragment implements AccountActionListen public void onBlock(final boolean block, final String id, final int position) { Callback cb = new Callback() { @Override - public void onResponse(Call call, retrofit2.Response response) { - onBlockSuccess(block, position); + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + onBlockSuccess(block, position); + } else { + onBlockFailure(block, id); + } } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index 04cf5d7fb..3bf969457 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -93,9 +93,6 @@ public class MainActivity extends BaseActivity { ButterKnife.bind(this); - // Fetch user info while we're doing other things. - fetchUserInfo(); - floatingBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -107,6 +104,10 @@ public class MainActivity extends BaseActivity { setupDrawer(); setupSearchView(); + /* Fetch user info while we're doing other things. This has to be after setting up the + * drawer, though, because its callback touches the header in the drawer. */ + fetchUserInfo(); + // Setup the tabs and timeline pager. TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager()); String[] pageTitles = {