Remove the data-client app adapter implementation (#5499)

* logErrorsInsteadOfCrashing only ever returned false, so remove it and simplify logger

* Removed unused getMediaWikiBaseUrl()

* Removed getDesiredLeadImageDp() from commons app adapter, since it's unused

* Inlined the isLoggedIn() method of the app adapter

* Inline the app adapter username/password

* Removed the unused getRestbaseUriFormat() from the commons app adapter

* Remove references to the data-client SharedPreferenceCookieManager

* Manage our own OkHttpClient and remove the AppAdapter implementation
This commit is contained in:
Paul Hawke 2024-01-30 19:21:43 -06:00 committed by GitHub
parent ab9e57f5be
commit 8db0b54929
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
57 changed files with 422 additions and 518 deletions

View file

@ -257,8 +257,8 @@ public class CommonsApplicationModule {
@Named("username")
@Provides
public String provideLoggedInUsername() {
return Objects.toString(AppAdapter.get().getUserName(), "");
public String provideLoggedInUsername(SessionManager sessionManager) {
return Objects.toString(sessionManager.getUserName(), "");
}
@Provides

View file

@ -12,7 +12,10 @@ import fr.free.nrw.commons.actions.PageEditClient;
import fr.free.nrw.commons.actions.PageEditInterface;
import fr.free.nrw.commons.actions.ThanksInterface;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient;
import fr.free.nrw.commons.auth.csrf.CsrfTokenInterface;
import fr.free.nrw.commons.auth.csrf.LogoutClient;
import fr.free.nrw.commons.auth.login.LoginClient;
import fr.free.nrw.commons.auth.login.LoginInterface;
import fr.free.nrw.commons.category.CategoryInterface;
import fr.free.nrw.commons.explore.depictions.DepictsClient;
@ -30,6 +33,8 @@ import fr.free.nrw.commons.upload.WikiBaseInterface;
import fr.free.nrw.commons.upload.depicts.DepictsInterface;
import fr.free.nrw.commons.wikidata.CommonsServiceFactory;
import fr.free.nrw.commons.wikidata.WikidataInterface;
import fr.free.nrw.commons.wikidata.cookies.CommonsCookieJar;
import fr.free.nrw.commons.wikidata.cookies.CommonsCookieStorage;
import java.io.File;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
@ -40,11 +45,8 @@ import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient;
import org.wikipedia.AppAdapter;
import org.wikipedia.dataclient.WikiSite;
import org.wikipedia.json.GsonUtil;
import fr.free.nrw.commons.auth.login.LoginClient;
import timber.log.Timber;
@Module
@ -78,8 +80,8 @@ public class NetworkingModule {
@Provides
@Singleton
public CommonsServiceFactory serviceFactory() {
return new CommonsServiceFactory(AppAdapter.get().getOkHttpClient());
public CommonsServiceFactory serviceFactory(CommonsCookieJar cookieJar) {
return new CommonsServiceFactory(OkHttpConnectionFactory.getClient(cookieJar));
}
@Provides
@ -107,12 +109,27 @@ public class NetworkingModule {
gson);
}
@Provides
@Singleton
public CommonsCookieStorage provideCookieStorage(
@Named("default_preferences") JsonKvStore preferences) {
CommonsCookieStorage cookieStorage = new CommonsCookieStorage(preferences);
cookieStorage.load();
return cookieStorage;
}
@Provides
@Singleton
public CommonsCookieJar provideCookieJar(CommonsCookieStorage storage) {
return new CommonsCookieJar(storage);
}
@Named(NAMED_COMMONS_CSRF)
@Provides
@Singleton
public CsrfTokenClient provideCommonsCsrfTokenClient(SessionManager sessionManager,
CsrfTokenInterface tokenInterface, LoginClient loginClient) {
return new CsrfTokenClient(sessionManager, tokenInterface, loginClient);
CsrfTokenInterface tokenInterface, LoginClient loginClient, LogoutClient logoutClient) {
return new CsrfTokenClient(sessionManager, tokenInterface, loginClient, logoutClient);
}
@Provides