From 3a3f6aa3479ab2b139828dcbd709a2738b6f1504 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 20 Nov 2022 09:45:05 +0100 Subject: [PATCH] Fix issue #493 - Crash when adding account to a list from profile --- .../java/app/fedilab/android/activities/ProfileActivity.java | 4 ++-- .../android/client/endpoints/MastodonTimelinesService.java | 2 +- .../app/fedilab/android/viewmodel/mastodon/TimelinesVM.java | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java index 0384c872..a307495c 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java @@ -875,7 +875,7 @@ public class ProfileActivity extends BaseActivity { updateAccount(); if (isChecked) { timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds).observe(ProfileActivity.this, success -> { - if (!success) { + if (success == null || !success) { Toasty.error(ProfileActivity.this, getString(R.string.toast_error_add_to_list), Toast.LENGTH_LONG).show(); } }); @@ -886,7 +886,7 @@ public class ProfileActivity extends BaseActivity { } else { if (isChecked) { timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds).observe(ProfileActivity.this, success -> { - if (!success) { + if (success == null || !success) { Toasty.error(ProfileActivity.this, getString(R.string.toast_error_add_to_list), Toast.LENGTH_LONG).show(); } }); diff --git a/app/src/main/java/app/fedilab/android/client/endpoints/MastodonTimelinesService.java b/app/src/main/java/app/fedilab/android/client/endpoints/MastodonTimelinesService.java index e09c70c6..7fdf0744 100644 --- a/app/src/main/java/app/fedilab/android/client/endpoints/MastodonTimelinesService.java +++ b/app/src/main/java/app/fedilab/android/client/endpoints/MastodonTimelinesService.java @@ -179,7 +179,7 @@ public interface MastodonTimelinesService { //Add account in a list @FormUrlEncoded @POST("lists/{id}/accounts") - Call addAccountsList( + Call addAccountsList( @Header("Authorization") String token, @Path("id") String id, @Field("account_ids[]") List account_ids diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java index 19e5b498..b3fff957 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java @@ -843,14 +843,15 @@ public class TimelinesVM extends AndroidViewModel { MastodonTimelinesService mastodonTimelinesService = init(instance); booleanMutableLiveData = new MutableLiveData<>(); new Thread(() -> { - Call addAccountsListCall = mastodonTimelinesService.addAccountsList(token, listId, accountIds); + Call addAccountsListCall = mastodonTimelinesService.addAccountsList(token, listId, accountIds); Boolean reply = null; if (addAccountsListCall != null) { try { - Response response = addAccountsListCall.execute(); + Response response = addAccountsListCall.execute(); reply = response.isSuccessful(); } catch (Exception e) { e.printStackTrace(); + reply = false; } } Handler mainHandler = new Handler(Looper.getMainLooper());