mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
With more unit test cases (#3269)
This commit is contained in:
parent
d2fb3b36e7
commit
f27749fa51
7 changed files with 139 additions and 30 deletions
|
|
@ -47,12 +47,4 @@ public class PageEditClient {
|
|||
}
|
||||
}
|
||||
|
||||
public Observable<Integer> addEditTag(long revisionId, String tagName, String reason) {
|
||||
try {
|
||||
return service.addEditTag(String.valueOf(revisionId), tagName, reason, csrfTokenClient.getTokenBlocking())
|
||||
.map(mwPostResponse -> mwPostResponse.getSuccessVal());
|
||||
} catch (Throwable throwable) {
|
||||
return Observable.just(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package fr.free.nrw.commons.auth;
|
||||
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import org.wikipedia.dataclient.Service;
|
||||
import org.wikipedia.dataclient.mwapi.MwPostResponse;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import org.wikipedia.dataclient.Service;
|
||||
import org.wikipedia.dataclient.ServiceFactory;
|
||||
import org.wikipedia.dataclient.WikiSite;
|
||||
import org.wikipedia.dataclient.mwapi.MwPostResponse;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Handler for logout
|
||||
|
|
@ -20,9 +21,8 @@ public class LogoutClient {
|
|||
private final Service service;
|
||||
|
||||
@Inject
|
||||
public LogoutClient(@Named("commons-wikisite")
|
||||
WikiSite commonsWikiSite) {
|
||||
service = ServiceFactory.get(commonsWikiSite);
|
||||
public LogoutClient(@Named("commons-service") Service service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ import android.text.TextUtils;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.imagepipeline.core.ImagePipeline;
|
||||
import org.wikipedia.login.LoginResult;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -91,6 +89,10 @@ public class SessionManager {
|
|||
return currentAccount;
|
||||
}
|
||||
|
||||
public boolean doesAccountExist() {
|
||||
return getCurrentAccount() != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getUserName() {
|
||||
Account account = getCurrentAccount();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package fr.free.nrw.commons.delete;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
|
||||
import org.wikipedia.util.DateUtil;
|
||||
|
|
@ -16,7 +15,7 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.achievements.FeedbackResponse;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import fr.free.nrw.commons.utils.ViewUtilWrapper;
|
||||
import io.reactivex.Single;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -26,14 +25,21 @@ public class ReasonBuilder {
|
|||
private SessionManager sessionManager;
|
||||
private OkHttpJsonApiClient okHttpJsonApiClient;
|
||||
private Context context;
|
||||
private ViewUtilWrapper viewUtilWrapper;
|
||||
|
||||
@Inject
|
||||
public ReasonBuilder(Context context,
|
||||
SessionManager sessionManager,
|
||||
OkHttpJsonApiClient okHttpJsonApiClient) {
|
||||
OkHttpJsonApiClient okHttpJsonApiClient,
|
||||
ViewUtilWrapper viewUtilWrapper) {
|
||||
this.context = context;
|
||||
this.sessionManager = sessionManager;
|
||||
this.okHttpJsonApiClient = okHttpJsonApiClient;
|
||||
this.viewUtilWrapper = viewUtilWrapper;
|
||||
}
|
||||
|
||||
public Single<String> getReason(Media media, String reason) {
|
||||
return fetchArticleNumber(media, reason);
|
||||
}
|
||||
|
||||
private String prettyUploadedDate(Media media) {
|
||||
|
|
@ -47,7 +53,7 @@ public class ReasonBuilder {
|
|||
private Single<String> fetchArticleNumber(Media media, String reason) {
|
||||
if (checkAccount()) {
|
||||
return okHttpJsonApiClient
|
||||
.getAchievements(sessionManager.getCurrentAccount().name)
|
||||
.getAchievements(sessionManager.getUserName())
|
||||
.map(feedbackResponse -> appendArticlesUsed(feedbackResponse, media, reason));
|
||||
}
|
||||
return Single.just("");
|
||||
|
|
@ -60,20 +66,14 @@ public class ReasonBuilder {
|
|||
return reason;
|
||||
}
|
||||
|
||||
|
||||
public Single<String> getReason(Media media, String reason) {
|
||||
return fetchArticleNumber(media, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* check to ensure that user is logged in
|
||||
* @return
|
||||
*/
|
||||
private boolean checkAccount(){
|
||||
Account currentAccount = sessionManager.getCurrentAccount();
|
||||
if(currentAccount == null) {
|
||||
if (!sessionManager.doesAccountExist()) {
|
||||
Timber.d("Current account is null");
|
||||
ViewUtil.showLongToast(context, context.getResources().getString(R.string.user_not_logged_in));
|
||||
viewUtilWrapper.showLongToast(context, context.getResources().getString(R.string.user_not_logged_in));
|
||||
sessionManager.forceLogin(context);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,8 @@ public class ViewUtilWrapper {
|
|||
public void showShortToast(Context context, String text) {
|
||||
ViewUtil.showShortToast(context, text);
|
||||
}
|
||||
|
||||
public void showLongToast(Context context, String text) {
|
||||
ViewUtil.showLongToast(context, text);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue