Fixes #4278 "Media details categories editor: Category not actually added" (#4328)

* rectified category update

* changed class name, added javadoc

* javadoc
This commit is contained in:
Aditya-Srivastav 2021-04-06 19:26:34 +05:30 committed by GitHub
parent c12ecf881b
commit 049dd7c79a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import org.wikipedia.AppAdapter;
import org.wikipedia.dataclient.Service;
import org.wikipedia.dataclient.ServiceFactory;
@ -142,7 +144,9 @@ public class CsrfTokenClient {
AppAdapter.get().getPassword(), "");
}
Response<MwQueryResponse> response = service.getCsrfTokenCall().execute();
// Get CSRFToken response off the main thread.
Response<MwQueryResponse> response = Executors.newSingleThreadExecutor().submit(new CsrfTokenCallExecutor(service)).get();
if (response.body() == null || response.body().query() == null
|| TextUtils.isEmpty(response.body().query().csrfToken())) {
continue;
@ -210,4 +214,34 @@ public class CsrfTokenClient {
private interface RetryCallback {
void retry();
}
/**
* Class CsrfTokenCallExecutor which implement callable interface to get CsrfTokenCall.
*/
class CsrfTokenCallExecutor implements Callable<Response<MwQueryResponse>> {
/**
* Service for token call.
*/
private Service service;
/**
* Default Constructor.
* @param service
*/
public CsrfTokenCallExecutor(Service service){
this.service = service;
}
/**
* Computes a result, or throws an exception if unable to do so.
*
* @return computed result
* @throws Exception if unable to compute a result
*/
@Override
public Response<MwQueryResponse> call() throws Exception {
return service.getCsrfTokenCall().execute();
}
}
}