mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
@Inject the MediaWikiApi where needed to reduce coupling between classes.
This commit is contained in:
parent
ed1ae98d8e
commit
647cc166ef
16 changed files with 85 additions and 82 deletions
|
|
@ -4,9 +4,6 @@ import android.accounts.Account;
|
|||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.ContentProvider;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
|
|
@ -29,9 +26,6 @@ import javax.inject.Inject;
|
|||
|
||||
import dagger.android.AndroidInjector;
|
||||
import dagger.android.DaggerApplication;
|
||||
import dagger.android.DispatchingAndroidInjector;
|
||||
import dagger.android.HasActivityInjector;
|
||||
import dagger.android.HasContentProviderInjector;
|
||||
import fr.free.nrw.commons.auth.AccountUtil;
|
||||
import fr.free.nrw.commons.caching.CacheController;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
|
|
@ -79,20 +73,12 @@ public class CommonsApplication extends DaggerApplication {
|
|||
public static final String FEEDBACK_EMAIL = "commons-app-android@googlegroups.com";
|
||||
public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App (%s) Feedback";
|
||||
|
||||
private MediaWikiApi api = null;
|
||||
private LruCache<String, String> thumbnailUrlCache = new LruCache<>(1024);
|
||||
private CacheController cacheData = null;
|
||||
private DBOpenHelper dbOpenHelper = null;
|
||||
private NearbyPlaces nearbyPlaces = null;
|
||||
private CommonsApplicationComponent component;
|
||||
|
||||
public MediaWikiApi getMWApi() {
|
||||
if (api == null) {
|
||||
api = new ApacheHttpClientMediaWikiApi(API_URL);
|
||||
}
|
||||
return api;
|
||||
}
|
||||
|
||||
public CacheController getCacheData() {
|
||||
if (cacheData == null) {
|
||||
cacheData = new CacheController();
|
||||
|
|
|
|||
|
|
@ -11,10 +11,14 @@ import android.widget.Toast;
|
|||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class MediaWikiImageView extends SimpleDraweeView {
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
private ThumbnailFetchTask currentThumbnailTask;
|
||||
|
||||
public MediaWikiImageView(Context context) {
|
||||
|
|
@ -40,13 +44,11 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
return;
|
||||
}
|
||||
|
||||
CommonsApplication app = (CommonsApplication) getContext().getApplicationContext();
|
||||
if (app.getThumbnailUrlCache().get(media.getFilename()) != null) {
|
||||
setImageUrl(app.getThumbnailUrlCache().get(media.getFilename()));
|
||||
if (application.getThumbnailUrlCache().get(media.getFilename()) != null) {
|
||||
setImageUrl(application.getThumbnailUrlCache().get(media.getFilename()));
|
||||
} else {
|
||||
setImageUrl(null);
|
||||
MediaWikiApi mediaWikiApi = app.getMWApi();
|
||||
currentThumbnailTask = new ThumbnailFetchTask(media, mediaWikiApi);
|
||||
currentThumbnailTask = new ThumbnailFetchTask(media, mwApi);
|
||||
currentThumbnailTask.execute(media.getFilename());
|
||||
}
|
||||
}
|
||||
|
|
@ -60,6 +62,7 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
}
|
||||
|
||||
private void init() {
|
||||
((CommonsApplication) getContext().getApplicationContext()).injector().inject(this);
|
||||
setHierarchy(GenericDraweeHierarchyBuilder
|
||||
.newInstance(getResources())
|
||||
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import fr.free.nrw.commons.WelcomeActivity;
|
|||
|
||||
import fr.free.nrw.commons.PageTitle;
|
||||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.view.KeyEvent.KEYCODE_ENTER;
|
||||
|
|
@ -36,6 +37,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
public static final String PARAM_USERNAME = "fr.free.nrw.commons.login.username";
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject AccountUtil accountUtil;
|
||||
|
||||
private SharedPreferences prefs = null;
|
||||
|
|
@ -145,7 +147,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
canonicializeUsername(usernameEdit.getText().toString()),
|
||||
passwordEdit.getText().toString(),
|
||||
twoFactorEdit.getText().toString(),
|
||||
accountUtil, application
|
||||
accountUtil, application, mwApi
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.io.IOException;
|
|||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.mwapi.EventLog;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
class LoginTask extends AsyncTask<String, String, String> {
|
||||
|
|
@ -21,14 +22,16 @@ class LoginTask extends AsyncTask<String, String, String> {
|
|||
private String twoFactorCode = "";
|
||||
private AccountUtil accountUtil;
|
||||
private CommonsApplication app;
|
||||
private MediaWikiApi mwApi;
|
||||
|
||||
public LoginTask(LoginActivity loginActivity, String username, String password, String twoFactorCode, AccountUtil accountUtil, CommonsApplication application) {
|
||||
public LoginTask(LoginActivity loginActivity, String username, String password, String twoFactorCode, AccountUtil accountUtil, CommonsApplication application, MediaWikiApi mwApi) {
|
||||
this.loginActivity = loginActivity;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.twoFactorCode = twoFactorCode;
|
||||
this.accountUtil = accountUtil;
|
||||
this.app = application;
|
||||
this.mwApi = mwApi;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -46,9 +49,9 @@ class LoginTask extends AsyncTask<String, String, String> {
|
|||
protected String doInBackground(String... params) {
|
||||
try {
|
||||
if (twoFactorCode.isEmpty()) {
|
||||
return app.getMWApi().login(username, password);
|
||||
return mwApi.login(username, password);
|
||||
} else {
|
||||
return app.getMWApi().login(username, password, twoFactorCode);
|
||||
return mwApi.login(username, password, twoFactorCode);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Do something better!
|
||||
|
|
@ -61,7 +64,7 @@ class LoginTask extends AsyncTask<String, String, String> {
|
|||
super.onPostExecute(result);
|
||||
Timber.d("Login done!");
|
||||
|
||||
EventLog.schema(CommonsApplication.EVENT_LOGIN_ATTEMPT, app)
|
||||
EventLog.schema(CommonsApplication.EVENT_LOGIN_ATTEMPT, app, mwApi)
|
||||
.param("username", username)
|
||||
.param("result", result)
|
||||
.log();
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ import android.os.IBinder;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
|
||||
public class WikiAccountAuthenticatorService extends Service {
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject AccountUtil accountUtil;
|
||||
private WikiAccountAuthenticator wikiAccountAuthenticator = null;
|
||||
|
||||
|
|
@ -23,7 +24,7 @@ public class WikiAccountAuthenticatorService extends Service {
|
|||
|
||||
((CommonsApplication)getApplication()).injector().inject(this);
|
||||
if (wikiAccountAuthenticator == null) {
|
||||
wikiAccountAuthenticator = new WikiAccountAuthenticator(this, accountUtil, application.getMWApi());
|
||||
wikiAccountAuthenticator = new WikiAccountAuthenticator(this, accountUtil, mwApi);
|
||||
}
|
||||
return wikiAccountAuthenticator.getIBinder();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import dagger.android.support.DaggerFragment;
|
|||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.data.Category;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.upload.MwVolleyApi;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
|
|
@ -66,7 +67,7 @@ public class CategorizationFragment extends DaggerFragment {
|
|||
@BindView(R.id.categoriesExplanation)
|
||||
TextView categoriesSkip;
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
|
||||
private RVRendererAdapter<CategoryItem> categoriesAdapter;
|
||||
private OnCategoriesSaveHandler onCategoriesSaveHandler;
|
||||
|
|
@ -253,7 +254,7 @@ public class CategorizationFragment extends DaggerFragment {
|
|||
SharedPreferences titleDesc = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
String title = titleDesc.getString("Title", "");
|
||||
|
||||
return application.getMWApi()
|
||||
return mwApi
|
||||
.searchTitles(title, SEARCH_CATS_LIMIT)
|
||||
.map(name -> new CategoryItem(name, false));
|
||||
}
|
||||
|
|
@ -276,7 +277,7 @@ public class CategorizationFragment extends DaggerFragment {
|
|||
}
|
||||
|
||||
//otherwise, search API for matching categories
|
||||
return application.getMWApi()
|
||||
return mwApi
|
||||
.allCategories(term, SEARCH_CATS_LIMIT)
|
||||
.map(name -> new CategoryItem(name, false));
|
||||
}
|
||||
|
|
@ -287,7 +288,7 @@ public class CategorizationFragment extends DaggerFragment {
|
|||
return Observable.empty();
|
||||
}
|
||||
|
||||
return application.getMWApi()
|
||||
return mwApi
|
||||
.searchCategories(term, SEARCH_CATS_LIMIT)
|
||||
.map(s -> new CategoryItem(s, false));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import timber.log.Timber;
|
|||
public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
private static int COMMIT_THRESHOLD = 10;
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
|
||||
public ContributionsSyncAdapter(Context context, boolean autoInitialize) {
|
||||
super(context, autoInitialize);
|
||||
|
|
@ -41,22 +41,23 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
return limit; // FIXME: Parameterize!
|
||||
}
|
||||
|
||||
private static final String[] existsQuery = { Contribution.Table.COLUMN_FILENAME };
|
||||
private static final String[] existsQuery = {Contribution.Table.COLUMN_FILENAME};
|
||||
private static final String existsSelection = Contribution.Table.COLUMN_FILENAME + " = ?";
|
||||
|
||||
private boolean fileExists(ContentProviderClient client, String filename) {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = client.query(ContributionsContentProvider.BASE_URI,
|
||||
existsQuery,
|
||||
existsSelection,
|
||||
new String[] { filename },
|
||||
new String[]{filename},
|
||||
""
|
||||
);
|
||||
return cursor.getCount() != 0;
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if ( cursor != null ) {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -64,21 +65,20 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
|
||||
@Override
|
||||
public void onPerformSync(Account account, Bundle bundle, String s, ContentProviderClient contentProviderClient, SyncResult syncResult) {
|
||||
((CommonsApplication)getContext().getApplicationContext()).injector().inject(this);
|
||||
((CommonsApplication) getContext().getApplicationContext()).injector().inject(this);
|
||||
|
||||
// This code is fraught with possibilities of race conditions, but lalalalala I can't hear you!
|
||||
String user = account.name;
|
||||
MediaWikiApi api = application.getMWApi();
|
||||
SharedPreferences prefs = getContext().getSharedPreferences("prefs", Context.MODE_PRIVATE);
|
||||
String lastModified = prefs.getString("lastSyncTimestamp", "");
|
||||
Date curTime = new Date();
|
||||
LogEventResult result;
|
||||
Boolean done = false;
|
||||
String queryContinue = null;
|
||||
while(!done) {
|
||||
while (!done) {
|
||||
|
||||
try {
|
||||
result = api.logEvents(user, lastModified, queryContinue, getLimit());
|
||||
result = mwApi.logEvents(user, lastModified, queryContinue, getLimit());
|
||||
} catch (IOException e) {
|
||||
// There isn't really much we can do, eh?
|
||||
// FIXME: Perhaps add EventLogging?
|
||||
|
|
@ -97,7 +97,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
continue;
|
||||
}
|
||||
String filename = image.getFilename();
|
||||
if(fileExists(contentProviderClient, filename)) {
|
||||
if (fileExists(contentProviderClient, filename)) {
|
||||
Timber.d("Skipping %s", filename);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
contrib.setState(Contribution.STATE_COMPLETED);
|
||||
imageValues.add(contrib.toContentValues());
|
||||
|
||||
if(imageValues.size() % COMMIT_THRESHOLD == 0) {
|
||||
if (imageValues.size() % COMMIT_THRESHOLD == 0) {
|
||||
try {
|
||||
contentProviderClient.bulkInsert(ContributionsContentProvider.BASE_URI, imageValues.toArray(new ContentValues[]{}));
|
||||
} catch (RemoteException e) {
|
||||
|
|
@ -117,7 +117,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
if(imageValues.size() != 0) {
|
||||
if (imageValues.size() != 0) {
|
||||
try {
|
||||
contentProviderClient.bulkInsert(ContributionsContentProvider.BASE_URI, imageValues.toArray(new ContentValues[]{}));
|
||||
} catch (RemoteException e) {
|
||||
|
|
@ -126,7 +126,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
}
|
||||
|
||||
queryContinue = result.getQueryContinue();
|
||||
if(TextUtils.isEmpty(queryContinue)) {
|
||||
if (TextUtils.isEmpty(queryContinue)) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import dagger.android.AndroidInjectionModule;
|
|||
import dagger.android.AndroidInjector;
|
||||
import dagger.android.support.AndroidSupportInjectionModule;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.MediaWikiImageView;
|
||||
import fr.free.nrw.commons.auth.WikiAccountAuthenticatorService;
|
||||
import fr.free.nrw.commons.contributions.ContributionsSyncAdapter;
|
||||
import fr.free.nrw.commons.modifications.ModificationsSyncAdapter;
|
||||
|
|
@ -31,6 +32,8 @@ public interface CommonsApplicationComponent extends AndroidInjector<CommonsAppl
|
|||
|
||||
void inject(ModificationsSyncAdapter syncAdapter);
|
||||
|
||||
void inject(MediaWikiImageView mediaWikiImageView);
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
Builder appModule(CommonsApplicationModule applicationModule);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import fr.free.nrw.commons.MediaWikiImageView;
|
|||
import fr.free.nrw.commons.PageTitle;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.ui.widget.CompatTextView;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -57,8 +58,7 @@ public class MediaDetailFragment extends DaggerFragment {
|
|||
return mf;
|
||||
}
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
|
||||
@Inject MediaWikiApi mwApi;
|
||||
private MediaWikiImageView image;
|
||||
private MediaDetailSpacer spacer;
|
||||
private int initialListTop = 0;
|
||||
|
|
@ -194,7 +194,7 @@ public class MediaDetailFragment extends DaggerFragment {
|
|||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
extractor = new MediaDataExtractor(media.getFilename(), licenseList, application.getMWApi());
|
||||
extractor = new MediaDataExtractor(media.getFilename(), licenseList, mwApi);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||
import fr.free.nrw.commons.mwapi.EventLog;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
|
||||
public class MediaDetailPagerFragment extends DaggerFragment implements ViewPager.OnPageChangeListener {
|
||||
|
||||
|
|
@ -52,6 +53,7 @@ public class MediaDetailPagerFragment extends DaggerFragment implements ViewPage
|
|||
}
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
|
||||
private ViewPager pager;
|
||||
private Boolean editable;
|
||||
|
|
@ -134,7 +136,7 @@ public class MediaDetailPagerFragment extends DaggerFragment implements ViewPage
|
|||
switch(item.getItemId()) {
|
||||
case R.id.menu_share_current_image:
|
||||
// Share - this is just logs it, intent set in onCreateOptionsMenu, around line 252
|
||||
EventLog.schema(CommonsApplication.EVENT_SHARE_ATTEMPT, application)
|
||||
EventLog.schema(CommonsApplication.EVENT_SHARE_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
.param("filename", m.getFilename())
|
||||
.log();
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import timber.log.Timber;
|
|||
|
||||
public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
|
||||
public ModificationsSyncAdapter(Context context, boolean autoInitialize) {
|
||||
super(context, autoInitialize);
|
||||
|
|
@ -64,12 +64,11 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
return;
|
||||
}
|
||||
|
||||
MediaWikiApi api = application.getMWApi();
|
||||
api.setAuthCookie(authCookie);
|
||||
mwApi.setAuthCookie(authCookie);
|
||||
String editToken;
|
||||
|
||||
try {
|
||||
editToken = api.getEditToken();
|
||||
editToken = mwApi.getEditToken();
|
||||
} catch (IOException e) {
|
||||
Timber.d("Can not retreive edit token!");
|
||||
return;
|
||||
|
|
@ -100,7 +99,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
if (contrib.getState() == Contribution.STATE_COMPLETED) {
|
||||
String pageContent;
|
||||
try {
|
||||
pageContent = api.revisionsByFilename(contrib.getFilename());
|
||||
pageContent = mwApi.revisionsByFilename(contrib.getFilename());
|
||||
} catch (IOException e) {
|
||||
Timber.d("Network fuckup on modifications sync!");
|
||||
continue;
|
||||
|
|
@ -111,7 +110,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
|
||||
String editResult;
|
||||
try {
|
||||
editResult = api.edit(editToken, processedPageContent, contrib.getFilename(), sequence.getEditSummary());
|
||||
editResult = mwApi.edit(editToken, processedPageContent, contrib.getFilename(), sequence.getEditSummary());
|
||||
} catch (IOException e) {
|
||||
Timber.d("Network fuckup on modifications sync!");
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ public class EventLog {
|
|||
}
|
||||
}
|
||||
|
||||
private static LogBuilder schema(String schema, long revision, CommonsApplication application) {
|
||||
return new LogBuilder(schema, revision, application);
|
||||
private static LogBuilder schema(String schema, long revision, CommonsApplication application, MediaWikiApi mwApi) {
|
||||
return new LogBuilder(schema, revision, application, mwApi);
|
||||
}
|
||||
|
||||
public static LogBuilder schema(Object[] scid, CommonsApplication application) {
|
||||
public static LogBuilder schema(Object[] scid, CommonsApplication application, MediaWikiApi mwApi) {
|
||||
if (scid.length != 2) {
|
||||
throw new IllegalArgumentException("Needs an object array with schema as first param and revision as second");
|
||||
}
|
||||
return schema((String) scid[0], (Long) scid[1], application);
|
||||
return schema((String) scid[0], (Long) scid[1], application, mwApi);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,17 +16,20 @@ import fr.free.nrw.commons.CommonsApplication;
|
|||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class LogBuilder {
|
||||
private final CommonsApplication application;
|
||||
private JSONObject data;
|
||||
private long rev;
|
||||
private String schema;
|
||||
private final MediaWikiApi mwApi;
|
||||
private final JSONObject data;
|
||||
private final long rev;
|
||||
private final String schema;
|
||||
|
||||
LogBuilder(String schema, long revision, CommonsApplication application) {
|
||||
data = new JSONObject();
|
||||
LogBuilder(String schema, long revision, CommonsApplication application, MediaWikiApi mwApi) {
|
||||
this.data = new JSONObject();
|
||||
this.schema = schema;
|
||||
this.rev = revision;
|
||||
this.application = application;
|
||||
this.mwApi = mwApi;
|
||||
}
|
||||
|
||||
public LogBuilder param(String key, Object value) {
|
||||
|
|
@ -62,7 +65,7 @@ public class LogBuilder {
|
|||
if (!settings.getBoolean(Prefs.TRACKING_ENABLED, true) && !force) {
|
||||
return; // User has disabled tracking
|
||||
}
|
||||
LogTask logTask = new LogTask(application.getMWApi());
|
||||
LogTask logTask = new LogTask(mwApi);
|
||||
logTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import fr.free.nrw.commons.modifications.ModificationsContentProvider;
|
|||
import fr.free.nrw.commons.modifications.ModifierSequence;
|
||||
import fr.free.nrw.commons.modifications.TemplateRemoveModifier;
|
||||
import fr.free.nrw.commons.mwapi.EventLog;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class MultipleShareActivity
|
||||
|
|
@ -49,8 +50,8 @@ public class MultipleShareActivity
|
|||
FragmentManager.OnBackStackChangedListener,
|
||||
MultipleUploadListFragment.OnMultipleUploadInitiatedHandler,
|
||||
OnCategoriesSaveHandler {
|
||||
@Inject
|
||||
CommonsApplication application;
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
|
||||
private ArrayList<Contribution> photosList = null;
|
||||
|
||||
|
|
@ -181,7 +182,7 @@ public class MultipleShareActivity
|
|||
// FIXME: Make sure that the content provider is up
|
||||
// This is the wrong place for it, but bleh - better than not having it turned on by default for people who don't go throughl ogin
|
||||
ContentResolver.setSyncAutomatically(application.getCurrentAccount(), ModificationsContentProvider.AUTHORITY, true); // Enable sync by default!
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application)
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
.param("categories-count", categories.size())
|
||||
.param("files-count", photosList.size())
|
||||
|
|
@ -248,7 +249,7 @@ public class MultipleShareActivity
|
|||
|
||||
@Override
|
||||
protected void onAuthCookieAcquired(String authCookie) {
|
||||
application.getMWApi().setAuthCookie(authCookie);
|
||||
mwApi.setAuthCookie(authCookie);
|
||||
Intent intent = getIntent();
|
||||
|
||||
if(intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
|
||||
|
|
@ -291,7 +292,7 @@ public class MultipleShareActivity
|
|||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
if(categorizationFragment != null && categorizationFragment.isVisible()) {
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application)
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
.param("categories-count", categorizationFragment.getCurrentSelectedCount())
|
||||
.param("files-count", photosList.size())
|
||||
|
|
@ -299,7 +300,7 @@ public class MultipleShareActivity
|
|||
.param("result", "cancelled")
|
||||
.log();
|
||||
} else {
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application)
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
.param("source", getIntent().getStringExtra(UploadService.EXTRA_SOURCE))
|
||||
.param("multiple", true)
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import fr.free.nrw.commons.modifications.ModificationsContentProvider;
|
|||
import fr.free.nrw.commons.modifications.ModifierSequence;
|
||||
import fr.free.nrw.commons.modifications.TemplateRemoveModifier;
|
||||
import fr.free.nrw.commons.mwapi.EventLog;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.DUPLICATE_PROCEED;
|
||||
|
|
@ -66,6 +67,7 @@ public class ShareActivity
|
|||
private CategorizationFragment categorizationFragment;
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
|
||||
private String source;
|
||||
private String mimeType;
|
||||
|
|
@ -169,7 +171,7 @@ public class ShareActivity
|
|||
// This is the wrong place for it, but bleh - better than not having it turned on by default for people who don't go throughl ogin
|
||||
ContentResolver.setSyncAutomatically(application.getCurrentAccount(), ModificationsContentProvider.AUTHORITY, true); // Enable sync by default!
|
||||
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application)
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
.param("categories-count", categories.size())
|
||||
.param("files-count", 1)
|
||||
|
|
@ -191,7 +193,7 @@ public class ShareActivity
|
|||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
if(categorizationFragment != null && categorizationFragment.isVisible()) {
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application)
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
.param("categories-count", categorizationFragment.getCurrentSelectedCount())
|
||||
.param("files-count", 1)
|
||||
|
|
@ -199,7 +201,7 @@ public class ShareActivity
|
|||
.param("result", "cancelled")
|
||||
.log();
|
||||
} else {
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application)
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
.param("source", getIntent().getStringExtra(UploadService.EXTRA_SOURCE))
|
||||
.param("multiple", true)
|
||||
|
|
@ -210,8 +212,7 @@ public class ShareActivity
|
|||
|
||||
@Override
|
||||
protected void onAuthCookieAcquired(String authCookie) {
|
||||
application.getMWApi().setAuthCookie(authCookie);
|
||||
|
||||
mwApi.setAuthCookie(authCookie);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -385,7 +386,7 @@ public class ShareActivity
|
|||
Timber.d("%s duplicate check: %s", mediaUri.toString(), result);
|
||||
duplicateCheckPassed = (result == DUPLICATE_PROCEED
|
||||
|| result == NO_DUPLICATE);
|
||||
}, application.getMWApi());
|
||||
}, mwApi);
|
||||
fileAsyncTask.execute();
|
||||
} catch (IOException e) {
|
||||
Timber.d(e, "IO Exception: ");
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
public static final String EXTRA_CAMPAIGN = EXTRA_PREFIX + ".campaign";
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private ContentProviderClient contributionsProviderClient;
|
||||
|
|
@ -182,8 +183,6 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
private void uploadContribution(Contribution contribution) {
|
||||
MediaWikiApi api = application.getMWApi();
|
||||
|
||||
InputStream file = null;
|
||||
|
||||
String notificationTag = contribution.getLocalUri().toString();
|
||||
|
|
@ -222,7 +221,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
filename = findUniqueFilename(filename);
|
||||
unfinishedUploads.add(filename);
|
||||
}
|
||||
if (!api.validateLogin()) {
|
||||
if (!mwApi.validateLogin()) {
|
||||
// Need to revalidate!
|
||||
if (application.revalidateAuthToken()) {
|
||||
Timber.d("Successfully revalidated token!");
|
||||
|
|
@ -240,7 +239,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
getString(R.string.upload_progress_notification_title_finishing, contribution.getDisplayTitle()),
|
||||
contribution
|
||||
);
|
||||
UploadResult uploadResult = api.uploadFile(filename, file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
|
||||
UploadResult uploadResult = mwApi.uploadFile(filename, file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
|
||||
|
||||
Timber.d("Response is %s", uploadResult.toString());
|
||||
|
||||
|
|
@ -249,7 +248,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
String resultStatus = uploadResult.getResultStatus();
|
||||
if (!resultStatus.equals("Success")) {
|
||||
showFailedNotification(contribution);
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application)
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
.param("source", contribution.getSource())
|
||||
.param("multiple", contribution.getMultiple())
|
||||
|
|
@ -263,7 +262,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
contribution.setDateUploaded(uploadResult.getDateUploaded());
|
||||
contribution.save();
|
||||
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application)
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
.param("source", contribution.getSource()) //FIXME
|
||||
.param("filename", contribution.getFilename())
|
||||
|
|
@ -304,7 +303,6 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
}
|
||||
|
||||
private String findUniqueFilename(String fileName) throws IOException {
|
||||
MediaWikiApi api = application.getMWApi();
|
||||
String sequenceFileName;
|
||||
for (int sequenceNumber = 1; true; sequenceNumber++) {
|
||||
if (sequenceNumber == 1) {
|
||||
|
|
@ -320,7 +318,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
sequenceFileName = regexMatcher.replaceAll("$1 " + sequenceNumber + "$2");
|
||||
}
|
||||
}
|
||||
if (!api.fileExistsWithName(sequenceFileName)
|
||||
if (!mwApi.fileExistsWithName(sequenceFileName)
|
||||
&& !unfinishedUploads.contains(sequenceFileName)) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue