Fix issue #493 - Crash when adding account to a list from profile

This commit is contained in:
Thomas 2022-11-20 09:45:05 +01:00
parent 9d8c815a1a
commit 3a3f6aa347
3 changed files with 6 additions and 5 deletions

View file

@ -875,7 +875,7 @@ public class ProfileActivity extends BaseActivity {
updateAccount(); updateAccount();
if (isChecked) { if (isChecked) {
timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds).observe(ProfileActivity.this, success -> { 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(); 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 { } else {
if (isChecked) { if (isChecked) {
timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds).observe(ProfileActivity.this, success -> { 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(); Toasty.error(ProfileActivity.this, getString(R.string.toast_error_add_to_list), Toast.LENGTH_LONG).show();
} }
}); });

View file

@ -179,7 +179,7 @@ public interface MastodonTimelinesService {
//Add account in a list //Add account in a list
@FormUrlEncoded @FormUrlEncoded
@POST("lists/{id}/accounts") @POST("lists/{id}/accounts")
Call<Boolean> addAccountsList( Call<Void> addAccountsList(
@Header("Authorization") String token, @Header("Authorization") String token,
@Path("id") String id, @Path("id") String id,
@Field("account_ids[]") List<String> account_ids @Field("account_ids[]") List<String> account_ids

View file

@ -843,14 +843,15 @@ public class TimelinesVM extends AndroidViewModel {
MastodonTimelinesService mastodonTimelinesService = init(instance); MastodonTimelinesService mastodonTimelinesService = init(instance);
booleanMutableLiveData = new MutableLiveData<>(); booleanMutableLiveData = new MutableLiveData<>();
new Thread(() -> { new Thread(() -> {
Call<Boolean> addAccountsListCall = mastodonTimelinesService.addAccountsList(token, listId, accountIds); Call<Void> addAccountsListCall = mastodonTimelinesService.addAccountsList(token, listId, accountIds);
Boolean reply = null; Boolean reply = null;
if (addAccountsListCall != null) { if (addAccountsListCall != null) {
try { try {
Response<Boolean> response = addAccountsListCall.execute(); Response<Void> response = addAccountsListCall.execute();
reply = response.isSuccessful(); reply = response.isSuccessful();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
reply = false;
} }
} }
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());