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