From 4e8d1375a0ed6e0ad04776140d3a87ee69f27ce2 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Mon, 13 Mar 2017 00:11:16 -0400 Subject: [PATCH 1/5] Switched the push notification server. --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 65166c0e..574ac06a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -129,7 +129,7 @@ Search accounts… NSFW Mention - http://tusky.zeonfederated.com + http://tuskynotify.keylesspalace.com %s mentioned you From dd68e79a93180107b2c7ef5a765f917a4b7821a8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 13 Mar 2017 15:41:17 +0100 Subject: [PATCH 2/5] Removed google-services.json from repository --- app/.gitignore | 3 ++- .../keylesspalace/tusky/ConversationLineItemDecoration.java | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/.gitignore b/app/.gitignore index e493cfc4..7c176a4e 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,2 +1,3 @@ /build -app-release.apk \ No newline at end of file +app-release.apk +google-services.json diff --git a/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java b/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java index 9dbce756..6c156541 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java +++ b/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java @@ -21,8 +21,6 @@ class ConversationLineItemDecoration extends RecyclerView.ItemDecoration { @Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { - // Fun fact: this method draws in pixels, but all layouts are in DP, so I'm using the divider's - // own 2dp width to calculate what I want int dividerLeft = parent.getPaddingLeft() + mContext.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin); int dividerRight = dividerLeft + mDivider.getIntrinsicWidth(); From 9fdd14b722a62403e2e35dcd8e25feb84b95cd2a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 13 Mar 2017 16:19:34 +0100 Subject: [PATCH 3/5] Rounded corners on avatars in statuses --- .../tusky/MyFirebaseMessagingService.java | 1 + .../tusky/RoundedTransformation.java | 45 +++++++++++++++++++ .../keylesspalace/tusky/StatusViewHolder.java | 1 + app/src/main/res/layout/item_status.xml | 2 +- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/keylesspalace/tusky/RoundedTransformation.java diff --git a/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java b/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java index 31060869..785f02e0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java +++ b/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java @@ -160,6 +160,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { Picasso.with(this) .load(body.account.avatar) .placeholder(R.drawable.avatar_default) + .transform(new RoundedTransformation(7, 0)) .into(mTarget); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { diff --git a/app/src/main/java/com/keylesspalace/tusky/RoundedTransformation.java b/app/src/main/java/com/keylesspalace/tusky/RoundedTransformation.java new file mode 100644 index 00000000..0ac1a4ac --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/RoundedTransformation.java @@ -0,0 +1,45 @@ +package com.keylesspalace.tusky; + +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.RectF; +import android.graphics.Shader; + +import com.squareup.picasso.Transformation; + +public class RoundedTransformation implements Transformation { + + private final int radius; + private final int margin; + + public RoundedTransformation(final int radius, final int margin) { + this.radius = radius; + this.margin = margin; + } + + @Override + public Bitmap transform(Bitmap source) { + final Paint paint = new Paint(); + + paint.setAntiAlias(true); + paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); + + Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(output); + + canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint); + + if (source != output) { + source.recycle(); + } + + return output; + } + + @Override + public String key() { + return "rounded"; + } +} diff --git a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java index 35168d04..619b187c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java @@ -158,6 +158,7 @@ class StatusViewHolder extends RecyclerView.ViewHolder { .load(url) .placeholder(R.drawable.avatar_default) .error(R.drawable.avatar_error) + .transform(new RoundedTransformation(7, 0)) .into(avatar); } diff --git a/app/src/main/res/layout/item_status.xml b/app/src/main/res/layout/item_status.xml index b6bde113..5525477f 100644 --- a/app/src/main/res/layout/item_status.xml +++ b/app/src/main/res/layout/item_status.xml @@ -40,7 +40,7 @@ android:scaleType="fitCenter" android:id="@+id/status_avatar" android:layout_below="@+id/status_reblogged_bar" - android:layout_marginTop="10dp" + android:layout_marginTop="11dp" android:layout_marginRight="10dp" /> Date: Mon, 13 Mar 2017 19:13:49 +0100 Subject: [PATCH 4/5] Fix usage of Retrofit in LoginActivity - baseUrl wasn't being set correctly since BaseActivity relies on the already saved preference LoginActivity instantiated its own, trimmed down MastodonAPI instance --- .../com/keylesspalace/tusky/LoginActivity.java | 17 +++++++++++++---- .../com/keylesspalace/tusky/MastodonAPI.java | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java index 32b3374f..07758956 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java @@ -39,6 +39,8 @@ import java.util.Map; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; public class LoginActivity extends BaseActivity { private static String OAUTH_SCOPES = "read write follow"; @@ -94,6 +96,15 @@ public class LoginActivity extends BaseActivity { startActivity(viewIntent); } + private MastodonAPI getApiFor(String domain) { + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("https://" + domain) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + + return retrofit.create(MastodonAPI.class); + } + /** * Obtain the oauth client credentials for this app. This is only necessary the first time the * app is run on a given server instance. So, after the first authentication, they are @@ -134,9 +145,7 @@ public class LoginActivity extends BaseActivity { } }; - List redirectUris = new ArrayList<>(); - redirectUris.add(getOauthRedirectUri()); - mastodonAPI.authenticateApp(getString(R.string.app_name), redirectUris, OAUTH_SCOPES, + getApiFor(domain).authenticateApp(getString(R.string.app_name), getOauthRedirectUri(), OAUTH_SCOPES, getString(R.string.app_website)).enqueue(callback); } @@ -245,7 +254,7 @@ public class LoginActivity extends BaseActivity { editText.setError(t.getMessage()); } }; - mastodonAPI.fetchOAuthToken(clientId, clientSecret, redirectUri, code, + getApiFor(domain).fetchOAuthToken(clientId, clientSecret, redirectUri, code, "authorization_code").enqueue(callback); } else if (error != null) { /* Authorization failed. Put the error response where the user can read it and they diff --git a/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java b/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java index e881f996..da42829f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java +++ b/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java @@ -175,7 +175,7 @@ public interface MastodonAPI { @POST("api/v1/apps") Call authenticateApp( @Field("client_name") String clientName, - @Field("redirect_uris[]") List redirectUris, + @Field("redirect_uris") String redirectUris, @Field("scopes") String scopes, @Field("website") String website); From ed08f708edcb8edb0508ab2587f72c91baaca7cc Mon Sep 17 00:00:00 2001 From: Vavassor Date: Mon, 13 Mar 2017 20:49:12 -0400 Subject: [PATCH 5/5] Fixed intermittent null pointer exceptions and disabled the light theme temporarily. This closes #21, closes #22, and closes #17. --- .../keylesspalace/tusky/AccountActivity.java | 40 ++++++++++++++----- .../com/keylesspalace/tusky/BaseActivity.java | 3 ++ .../keylesspalace/tusky/ComposeActivity.java | 17 ++++++-- .../keylesspalace/tusky/LoginActivity.java | 16 ++++++-- .../com/keylesspalace/tusky/MainActivity.java | 22 +++++----- .../tusky/MyFirebaseMessagingService.java | 4 +- .../tusky/NotificationsFragment.java | 7 +++- .../keylesspalace/tusky/ReportActivity.java | 12 ++++-- .../com/keylesspalace/tusky/SFragment.java | 12 ++++-- .../keylesspalace/tusky/TimelineAdapter.java | 6 ++- .../keylesspalace/tusky/TimelineFragment.java | 6 ++- .../tusky/ViewThreadFragment.java | 20 +++++++--- app/src/main/res/xml/preferences.xml | 9 ----- 13 files changed, 119 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java index 0a217c9f..a5ce6ab4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java @@ -160,7 +160,11 @@ public class AccountActivity extends BaseActivity { mastodonAPI.account(accountId).enqueue(new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - onObtainAccountSuccess(response.body()); + if (response.isSuccessful()) { + onObtainAccountSuccess(response.body()); + } else { + onObtainAccountFailure(); + } } @Override @@ -238,8 +242,12 @@ public class AccountActivity extends BaseActivity { mastodonAPI.relationships(ids).enqueue(new Callback>() { @Override public void onResponse(Call> call, retrofit2.Response> response) { - Relationship relationship = response.body().get(0); - onObtainRelationshipsSuccess(relationship.following, relationship.blocking, relationship.muting); + if (response.isSuccessful()) { + Relationship relationship = response.body().get(0); + onObtainRelationshipsSuccess(relationship.following, relationship.blocking, relationship.muting); + } else { + onObtainRelationshipsFailure(new Exception(response.message())); + } } @Override @@ -326,9 +334,13 @@ public class AccountActivity extends BaseActivity { Callback cb = new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - following = response.body().following; - // TODO: display message/indicator when "requested" is true (i.e. when the follow is awaiting approval) - updateButtons(); + if (response.isSuccessful()) { + following = response.body().following; + // TODO: display message/indicator when "requested" is true (i.e. when the follow is awaiting approval) + updateButtons(); + } else { + onFollowFailure(id); + } } @Override @@ -366,8 +378,12 @@ public class AccountActivity extends BaseActivity { Callback cb = new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - blocking = response.body().blocking; - updateButtons(); + if (response.isSuccessful()) { + blocking = response.body().blocking; + updateButtons(); + } else { + onBlockFailure(id); + } } @Override @@ -405,8 +421,12 @@ public class AccountActivity extends BaseActivity { Callback cb = new Callback() { @Override public void onResponse(Call call, Response response) { - muting = response.body().muting; - updateButtons(); + if (response.isSuccessful()) { + muting = response.body().muting; + updateButtons(); + } else { + onMuteFailure(id); + } } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java index 689df0dc..d79421b5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java @@ -56,9 +56,12 @@ public class BaseActivity extends AppCompatActivity { createMastodonAPI(); createTuskyAPI(); + /* Note from Andrew March 13, 2017: Keep this and restore it when the light theme is no + longer bugged. if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false)) { setTheme(R.style.AppTheme_Light); } + */ } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 356c0cb0..3fd55a93 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -653,7 +653,7 @@ public class ComposeActivity extends BaseActivity { private void sendStatus(String content, String visibility, boolean sensitive, String spoilerText) { - ArrayList mediaIds = new ArrayList(); + ArrayList mediaIds = new ArrayList<>(); for (QueuedMedia item : mediaQueued) { mediaIds.add(item.id); @@ -662,7 +662,11 @@ public class ComposeActivity extends BaseActivity { mastodonAPI.createStatus(content, inReplyToId, spoilerText, visibility, sensitive, mediaIds).enqueue(new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - onSendSuccess(); + if (response.isSuccessful()) { + onSendSuccess(); + } else { + onSendFailure(); + } } @Override @@ -970,8 +974,13 @@ public class ComposeActivity extends BaseActivity { item.uploadRequest.enqueue(new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - item.id = response.body().id; - waitForMediaLatch.countDown(); + if (response.isSuccessful()) { + item.id = response.body().id; + waitForMediaLatch.countDown(); + } else { + Log.d(TAG, "Upload request failed. " + response.message()); + onUploadFailure(item); + } } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java index 07758956..2b473783 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java @@ -31,9 +31,7 @@ import android.widget.TextView; import com.keylesspalace.tusky.entity.AccessToken; import com.keylesspalace.tusky.entity.AppCredentials; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import retrofit2.Call; @@ -43,6 +41,7 @@ import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; public class LoginActivity extends BaseActivity { + private static final String TAG = "LoginActivity"; // logging tag private static String OAUTH_SCOPES = "read write follow"; private SharedPreferences preferences; @@ -126,6 +125,13 @@ public class LoginActivity extends BaseActivity { Callback callback = new Callback() { @Override public void onResponse(Call call, Response response) { + if (!response.isSuccessful()) { + editText.setError( + "This app could not obtain authentication from that server " + + "instance."); + Log.e(TAG, "App authentication failed. " + response.message()); + return; + } AppCredentials credentials = response.body(); clientId = credentials.clientId; clientSecret = credentials.clientSecret; @@ -246,7 +252,11 @@ public class LoginActivity extends BaseActivity { Callback callback = new Callback() { @Override public void onResponse(Call call, Response response) { - onLoginSuccess(response.body().accessToken); + if (response.isSuccessful()) { + onLoginSuccess(response.body().accessToken); + } else { + editText.setError(response.message()); + } } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index cb1504ef..fa72166a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -15,8 +15,6 @@ package com.keylesspalace.tusky; -import android.app.AlarmManager; -import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -24,15 +22,11 @@ import android.graphics.PorterDuff; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.net.Uri; -import android.os.SystemClock; -import android.preference.PreferenceManager; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.TabLayout; import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewPager; import android.os.Bundle; -import android.support.v7.widget.Toolbar; -import android.text.Html; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; @@ -55,7 +49,6 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.ProfileDrawerItem; import com.mikepenz.materialdrawer.model.SecondaryDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; -import com.mikepenz.materialdrawer.model.interfaces.IProfile; import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; import com.mikepenz.materialdrawer.util.DrawerImageLoader; import com.squareup.picasso.Picasso; @@ -75,7 +68,7 @@ public class MainActivity extends BaseActivity { private String loggedInAccountId; private String loggedInAccountUsername; - Stack pageHistory = new Stack(); + Stack pageHistory = new Stack<>(); private AccountHeader headerResult; private Drawer drawer; @@ -296,8 +289,12 @@ public class MainActivity extends BaseActivity { mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { - searchView.swapSuggestions(response.body()); - searchView.hideProgress(); + if (response.isSuccessful()) { + searchView.swapSuggestions(response.body()); + searchView.hideProgress(); + } else { + searchView.hideProgress(); + } } @Override @@ -359,6 +356,11 @@ public class MainActivity extends BaseActivity { mastodonAPI.accountVerifyCredentials().enqueue(new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { + if (!response.isSuccessful()) { + onFetchUserInfoFailure(new Exception(response.message())); + return; + } + Account me = response.body(); ImageView background = headerResult.getHeaderBackgroundView(); diff --git a/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java b/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java index 785f02e0..5d1f1e92 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java +++ b/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java @@ -56,7 +56,9 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { mastodonAPI.notification(notificationId).enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { - buildNotification(response.body()); + if (response.isSuccessful()) { + buildNotification(response.body()); + } } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java index 60798f95..dacebb1e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java @@ -15,7 +15,6 @@ package com.keylesspalace.tusky; -import android.app.NotificationManager; import android.content.Context; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; @@ -141,7 +140,11 @@ public class NotificationsFragment extends SFragment implements api.notifications(fromId, uptoId, null).enqueue(new Callback>() { @Override public void onResponse(Call> call, retrofit2.Response> response) { - onFetchNotificationsSuccess(response.body(), fromId); + if (response.isSuccessful()) { + onFetchNotificationsSuccess(response.body(), fromId); + } else { + onFetchNotificationsFailure(new Exception(response.message())); + } } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java b/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java index 3f4b5c0b..b17255d4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java @@ -17,7 +17,6 @@ package com.keylesspalace.tusky; import android.content.Intent; import android.graphics.drawable.Drawable; -import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.Snackbar; @@ -29,7 +28,6 @@ import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.Button; import android.widget.EditText; import com.keylesspalace.tusky.entity.Status; @@ -122,7 +120,11 @@ public class ReportActivity extends BaseActivity { mastodonAPI.report(accountId, Arrays.asList(statusIds), comment).enqueue(new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - onSendSuccess(); + if (response.isSuccessful()) { + onSendSuccess(); + } else { + onSendFailure(accountId, statusIds, comment); + } } @Override @@ -155,6 +157,10 @@ public class ReportActivity extends BaseActivity { mastodonAPI.accountStatuses(accountId, null, null, null).enqueue(new Callback>() { @Override public void onResponse(Call> call, retrofit2.Response> response) { + if (!response.isSuccessful()) { + onFetchStatusesFailure(new Exception(response.message())); + return; + } List statusList = response.body(); List itemList = new ArrayList<>(); for (Status status : statusList) { diff --git a/app/src/main/java/com/keylesspalace/tusky/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/SFragment.java index 862e598c..10e5864d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/SFragment.java @@ -83,8 +83,10 @@ public class SFragment extends Fragment { Callback cb = new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - status.reblogged = reblog; - adapter.notifyItemChanged(position); + if (response.isSuccessful()) { + status.reblogged = reblog; + adapter.notifyItemChanged(position); + } } @Override @@ -107,8 +109,10 @@ public class SFragment extends Fragment { Callback cb = new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - status.favourited = favourite; - adapter.notifyItemChanged(position); + if (response.isSuccessful()) { + status.favourited = favourite; + adapter.notifyItemChanged(position); + } } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java b/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java index 877c8545..41dfeab7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java @@ -86,8 +86,10 @@ class TimelineAdapter extends RecyclerView.Adapter implements AdapterItemRemover int update(List newStatuses) { int scrollToPosition; - if (statuses == null || statuses.isEmpty()) { - statuses = newStatuses; + if (statuses.isEmpty()) { + if (newStatuses != null) { + statuses = newStatuses; + } scrollToPosition = 0; } else { int index = newStatuses.indexOf(statuses.get(0)); diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java index 76579307..4037dbc4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java @@ -168,7 +168,11 @@ public class TimelineFragment extends SFragment implements Callback> cb = new Callback>() { @Override public void onResponse(Call> call, retrofit2.Response> response) { - onFetchTimelineSuccess(response.body(), fromId); + if (response.isSuccessful()) { + onFetchTimelineSuccess(response.body(), fromId); + } else { + onFetchTimelineFailure(new Exception(response.message())); + } } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java index de535035..1dfaad1d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java @@ -82,8 +82,12 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene api.status(id).enqueue(new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - int position = adapter.insertStatus(response.body()); - recyclerView.scrollToPosition(position); + if (response.isSuccessful()) { + int position = adapter.insertStatus(response.body()); + recyclerView.scrollToPosition(position); + } else { + onThreadRequestFailure(id); + } } @Override @@ -99,10 +103,14 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene api.statusContext(id).enqueue(new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) { - StatusContext context = response.body(); - - adapter.addAncestors(context.ancestors); - adapter.addDescendants(context.descendants); + if (response.isSuccessful()) { + StatusContext context = response.body(); + + adapter.addAncestors(context.ancestors); + adapter.addDescendants(context.descendants); + } else { + onThreadRequestFailure(id); + } } @Override diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 9ace1a1e..ecd57b22 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -20,13 +20,4 @@ - - - - - -