Fix issue #482 - Warn when the app fails to add account into a list
This commit is contained in:
parent
26bc658bee
commit
9298f22b5d
|
@ -857,14 +857,22 @@ public class ProfileActivity extends BaseActivity {
|
||||||
relationship = newRelationShip;
|
relationship = newRelationShip;
|
||||||
updateAccount();
|
updateAccount();
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds);
|
timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds).observe(ProfileActivity.this, success -> {
|
||||||
|
if (!success) {
|
||||||
|
Toasty.error(ProfileActivity.this, getString(R.string.toast_error_add_to_list), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
timelinesVM.deleteAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds);
|
timelinesVM.deleteAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds);
|
timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds).observe(ProfileActivity.this, success -> {
|
||||||
|
if (!success) {
|
||||||
|
Toasty.error(ProfileActivity.this, getString(R.string.toast_error_add_to_list), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
timelinesVM.deleteAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds);
|
timelinesVM.deleteAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Void> addAccountsList(
|
Call<Boolean> 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
|
||||||
|
|
|
@ -74,6 +74,7 @@ public class TimelinesVM extends AndroidViewModel {
|
||||||
|
|
||||||
|
|
||||||
private MutableLiveData<List<Account>> accountListMutableLiveData;
|
private MutableLiveData<List<Account>> accountListMutableLiveData;
|
||||||
|
private MutableLiveData<Boolean> booleanMutableLiveData;
|
||||||
private MutableLiveData<List<StatusDraft>> statusDraftListMutableLiveData;
|
private MutableLiveData<List<StatusDraft>> statusDraftListMutableLiveData;
|
||||||
private MutableLiveData<Status> statusMutableLiveData;
|
private MutableLiveData<Status> statusMutableLiveData;
|
||||||
private MutableLiveData<Statuses> statusesMutableLiveData;
|
private MutableLiveData<Statuses> statusesMutableLiveData;
|
||||||
|
@ -838,18 +839,26 @@ public class TimelinesVM extends AndroidViewModel {
|
||||||
* @param listId ID of the list
|
* @param listId ID of the list
|
||||||
* @param accountIds Array of account IDs to add to the list.
|
* @param accountIds Array of account IDs to add to the list.
|
||||||
*/
|
*/
|
||||||
public void addAccountsList(@NonNull String instance, String token, @NonNull String listId, @NonNull List<String> accountIds) {
|
public LiveData<Boolean> addAccountsList(@NonNull String instance, String token, @NonNull String listId, @NonNull List<String> accountIds) {
|
||||||
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
||||||
|
booleanMutableLiveData = new MutableLiveData<>();
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
Call<Void> addAccountsListCall = mastodonTimelinesService.addAccountsList(token, listId, accountIds);
|
Call<Boolean> addAccountsListCall = mastodonTimelinesService.addAccountsList(token, listId, accountIds);
|
||||||
|
Boolean reply = null;
|
||||||
if (addAccountsListCall != null) {
|
if (addAccountsListCall != null) {
|
||||||
try {
|
try {
|
||||||
addAccountsListCall.execute();
|
Response<Boolean> response = addAccountsListCall.execute();
|
||||||
|
reply = response.isSuccessful();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
Boolean finalReply = reply;
|
||||||
|
Runnable myRunnable = () -> booleanMutableLiveData.setValue(finalReply);
|
||||||
|
mainHandler.post(myRunnable);
|
||||||
}).start();
|
}).start();
|
||||||
|
return booleanMutableLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1898,4 +1898,5 @@
|
||||||
<string name="add_keyword">Add keyword</string>
|
<string name="add_keyword">Add keyword</string>
|
||||||
<string name="show_anyway">Show anyway</string>
|
<string name="show_anyway">Show anyway</string>
|
||||||
<string name="filtered_by">Filtered: %1$s</string>
|
<string name="filtered_by">Filtered: %1$s</string>
|
||||||
|
<string name="toast_error_add_to_list">The app failed to add the account into the list!</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue