mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Further reduce code calling back to the CommonsApplication by pulling out a SessionManager to manage our current account.
This commit is contained in:
parent
e7d0c647c2
commit
9c0cbe7ad5
25 changed files with 273 additions and 294 deletions
|
|
@ -16,7 +16,6 @@ import android.support.annotation.RequiresApi;
|
|||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
|
|
@ -26,7 +25,7 @@ import timber.log.Timber;
|
|||
*/
|
||||
public class GPSExtractor {
|
||||
|
||||
private final CommonsApplication application;
|
||||
private final Context context;
|
||||
private ExifInterface exif;
|
||||
private double decLatitude;
|
||||
private double decLongitude;
|
||||
|
|
@ -39,30 +38,30 @@ public class GPSExtractor {
|
|||
/**
|
||||
* Construct from the file descriptor of the image (only for API 24 or newer).
|
||||
* @param fileDescriptor the file descriptor of the image
|
||||
* @param application the application
|
||||
* @param context the context
|
||||
*/
|
||||
@RequiresApi(24)
|
||||
public GPSExtractor(@NonNull FileDescriptor fileDescriptor, CommonsApplication application) {
|
||||
public GPSExtractor(@NonNull FileDescriptor fileDescriptor, Context context) {
|
||||
this.context = context;
|
||||
try {
|
||||
exif = new ExifInterface(fileDescriptor);
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
Timber.w(e);
|
||||
}
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct from the file path of the image.
|
||||
* @param path file path of the image
|
||||
* @param application the application
|
||||
* @param context the context
|
||||
*/
|
||||
public GPSExtractor(@NonNull String path, CommonsApplication application) {
|
||||
public GPSExtractor(@NonNull String path, Context context) {
|
||||
try {
|
||||
exif = new ExifInterface(path);
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
Timber.w(e);
|
||||
}
|
||||
this.application = application;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -71,7 +70,7 @@ public class GPSExtractor {
|
|||
*/
|
||||
private boolean gpsPreferenceEnabled() {
|
||||
SharedPreferences sharedPref
|
||||
= PreferenceManager.getDefaultSharedPreferences(application);
|
||||
= PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean gpsPref = sharedPref.getBoolean("allowGps", false);
|
||||
Timber.d("Gps pref set to: %b", gpsPref);
|
||||
return gpsPref;
|
||||
|
|
@ -81,8 +80,7 @@ public class GPSExtractor {
|
|||
* Registers a LocationManager to listen for current location
|
||||
*/
|
||||
protected void registerLocationManager() {
|
||||
locationManager = (LocationManager) application
|
||||
.getSystemService(Context.LOCATION_SERVICE);
|
||||
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||
Criteria criteria = new Criteria();
|
||||
String provider = locationManager.getBestProvider(criteria, true);
|
||||
myLocationListener = new MyLocationListener();
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import fr.free.nrw.commons.CommonsApplication;
|
|||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.auth.AuthenticatedActivity;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.category.CategorizationFragment;
|
||||
import fr.free.nrw.commons.category.OnCategoriesSaveHandler;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
|
|
@ -43,15 +44,15 @@ import fr.free.nrw.commons.mwapi.EventLog;
|
|||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class MultipleShareActivity
|
||||
extends AuthenticatedActivity
|
||||
implements MediaDetailPagerFragment.MediaDetailProvider,
|
||||
AdapterView.OnItemClickListener,
|
||||
FragmentManager.OnBackStackChangedListener,
|
||||
MultipleUploadListFragment.OnMultipleUploadInitiatedHandler,
|
||||
public class MultipleShareActivity extends AuthenticatedActivity
|
||||
implements MediaDetailPagerFragment.MediaDetailProvider,
|
||||
AdapterView.OnItemClickListener,
|
||||
FragmentManager.OnBackStackChangedListener,
|
||||
MultipleUploadListFragment.OnMultipleUploadInitiatedHandler,
|
||||
OnCategoriesSaveHandler {
|
||||
@Inject CommonsApplication application;
|
||||
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject SessionManager sessionManager;
|
||||
|
||||
private ArrayList<Contribution> photosList = null;
|
||||
|
||||
|
|
@ -68,7 +69,7 @@ public class MultipleShareActivity
|
|||
|
||||
@Override
|
||||
public int getTotalMediaCount() {
|
||||
if(photosList == null) {
|
||||
if (photosList == null) {
|
||||
return 0;
|
||||
}
|
||||
return photosList.size();
|
||||
|
|
@ -76,7 +77,7 @@ public class MultipleShareActivity
|
|||
|
||||
@Override
|
||||
public void notifyDatasetChanged() {
|
||||
if(uploadsList != null) {
|
||||
if (uploadsList != null) {
|
||||
uploadsList.notifyDatasetChanged();
|
||||
}
|
||||
}
|
||||
|
|
@ -129,7 +130,7 @@ public class MultipleShareActivity
|
|||
dialog.setTitle(getResources().getQuantityString(R.plurals.starting_multiple_uploads, photosList.size(), photosList.size()));
|
||||
dialog.show();
|
||||
|
||||
for(int i = 0; i < photosList.size(); i++) {
|
||||
for (int i = 0; i < photosList.size(); i++) {
|
||||
Contribution up = photosList.get(i);
|
||||
final int uploadCount = i + 1; // Goddamn Java
|
||||
|
||||
|
|
@ -137,11 +138,7 @@ public class MultipleShareActivity
|
|||
dialog.setProgress(uploadCount);
|
||||
if (uploadCount == photosList.size()) {
|
||||
dialog.dismiss();
|
||||
Toast startingToast = Toast.makeText(
|
||||
application,
|
||||
R.string.uploading_started,
|
||||
Toast.LENGTH_LONG
|
||||
);
|
||||
Toast startingToast = Toast.makeText(this, R.string.uploading_started, Toast.LENGTH_LONG);
|
||||
startingToast.show();
|
||||
}
|
||||
});
|
||||
|
|
@ -150,7 +147,7 @@ public class MultipleShareActivity
|
|||
uploadsList.setImageOnlyMode(true);
|
||||
|
||||
categorizationFragment = (CategorizationFragment) getSupportFragmentManager().findFragmentByTag("categorization");
|
||||
if(categorizationFragment == null) {
|
||||
if (categorizationFragment == null) {
|
||||
categorizationFragment = new CategorizationFragment();
|
||||
}
|
||||
// FIXME: Stops the keyboard from being shown 'stale' while moving out of this fragment into the next
|
||||
|
|
@ -167,9 +164,9 @@ public class MultipleShareActivity
|
|||
|
||||
@Override
|
||||
public void onCategoriesSave(List<String> categories) {
|
||||
if(categories.size() > 0) {
|
||||
ContentProviderClient client = getContentResolver().acquireContentProviderClient(ModificationsContentProvider.AUTHORITY);
|
||||
for(Contribution contribution: photosList) {
|
||||
if (categories.size() > 0) {
|
||||
ContentProviderClient client = getContentResolver().acquireContentProviderClient(ModificationsContentProvider.AUTHORITY);
|
||||
for (Contribution contribution : photosList) {
|
||||
ModifierSequence categoriesSequence = new ModifierSequence(contribution.getContentUri());
|
||||
|
||||
categoriesSequence.queueModifier(new CategoryModifier(categories.toArray(new String[]{})));
|
||||
|
|
@ -181,9 +178,9 @@ 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, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
ContentResolver.setSyncAutomatically(sessionManager.getCurrentAccount(), ModificationsContentProvider.AUTHORITY, true); // Enable sync by default!
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, getApplicationContext(), mwApi)
|
||||
.param("username", sessionManager.getCurrentAccount().name)
|
||||
.param("categories-count", categories.size())
|
||||
.param("files-count", photosList.size())
|
||||
.param("source", Contribution.SOURCE_EXTERNAL)
|
||||
|
|
@ -194,9 +191,9 @@ public class MultipleShareActivity
|
|||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
if(mediaDetails.isVisible()) {
|
||||
if (mediaDetails.isVisible()) {
|
||||
getSupportFragmentManager().popBackStack();
|
||||
}
|
||||
return true;
|
||||
|
|
@ -207,13 +204,13 @@ public class MultipleShareActivity
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
uploadController = new UploadController(application);
|
||||
uploadController = new UploadController(sessionManager, this);
|
||||
|
||||
setContentView(R.layout.activity_multiple_uploads);
|
||||
ButterKnife.bind(this);
|
||||
initDrawer();
|
||||
|
||||
if(savedInstanceState != null) {
|
||||
if (savedInstanceState != null) {
|
||||
photosList = savedInstanceState.getParcelableArrayList("uploadsList");
|
||||
}
|
||||
|
||||
|
|
@ -229,7 +226,7 @@ public class MultipleShareActivity
|
|||
}
|
||||
|
||||
private void showDetail(int i) {
|
||||
if(mediaDetails == null ||!mediaDetails.isVisible()) {
|
||||
if (mediaDetails == null || !mediaDetails.isVisible()) {
|
||||
mediaDetails = new MediaDetailPagerFragment(true);
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
|
|
@ -252,11 +249,11 @@ public class MultipleShareActivity
|
|||
mwApi.setAuthCookie(authCookie);
|
||||
Intent intent = getIntent();
|
||||
|
||||
if(intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
|
||||
if(photosList == null) {
|
||||
if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
|
||||
if (photosList == null) {
|
||||
photosList = new ArrayList<>();
|
||||
ArrayList<Uri> urisList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
for(int i=0; i < urisList.size(); i++) {
|
||||
for (int i = 0; i < urisList.size(); i++) {
|
||||
Contribution up = new Contribution();
|
||||
Uri uri = urisList.get(i);
|
||||
up.setLocalUri(uri);
|
||||
|
|
@ -269,8 +266,8 @@ public class MultipleShareActivity
|
|||
}
|
||||
|
||||
uploadsList = (MultipleUploadListFragment) getSupportFragmentManager().findFragmentByTag("uploadsList");
|
||||
if(uploadsList == null) {
|
||||
uploadsList = new MultipleUploadListFragment();
|
||||
if (uploadsList == null) {
|
||||
uploadsList = new MultipleUploadListFragment();
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(R.id.uploadsFragmentContainer, uploadsList, "uploadsList")
|
||||
|
|
@ -291,17 +288,17 @@ public class MultipleShareActivity
|
|||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
if(categorizationFragment != null && categorizationFragment.isVisible()) {
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
if (categorizationFragment != null && categorizationFragment.isVisible()) {
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, getApplicationContext(), mwApi)
|
||||
.param("username", sessionManager.getCurrentAccount().name)
|
||||
.param("categories-count", categorizationFragment.getCurrentSelectedCount())
|
||||
.param("files-count", photosList.size())
|
||||
.param("source", Contribution.SOURCE_EXTERNAL)
|
||||
.param("result", "cancelled")
|
||||
.log();
|
||||
} else {
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, getApplicationContext(), mwApi)
|
||||
.param("username", sessionManager.getCurrentAccount().name)
|
||||
.param("source", getIntent().getStringExtra(UploadService.EXTRA_SOURCE))
|
||||
.param("multiple", true)
|
||||
.param("result", "cancelled")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.upload;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.android.volley.Cache;
|
||||
|
|
@ -20,7 +21,6 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
|
|
@ -37,11 +37,11 @@ public class MwVolleyApi {
|
|||
private static List<String> categoryList;
|
||||
|
||||
private static final String MWURL = "https://commons.wikimedia.org/";
|
||||
private final CommonsApplication application;
|
||||
private final Context context;
|
||||
|
||||
public MwVolleyApi(CommonsApplication application) {
|
||||
public MwVolleyApi(Context context) {
|
||||
this.context = context;
|
||||
categorySet = new HashSet<>();
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public static List<String> getGpsCat() {
|
||||
|
|
@ -95,7 +95,7 @@ public class MwVolleyApi {
|
|||
|
||||
private synchronized RequestQueue getQueue() {
|
||||
if (REQUEST_QUEUE == null) {
|
||||
REQUEST_QUEUE = Volley.newRequestQueue(application);
|
||||
REQUEST_QUEUE = Volley.newRequestQueue(context);
|
||||
}
|
||||
return REQUEST_QUEUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import butterknife.ButterKnife;
|
|||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.auth.AuthenticatedActivity;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.caching.CacheController;
|
||||
import fr.free.nrw.commons.category.CategorizationFragment;
|
||||
import fr.free.nrw.commons.category.OnCategoriesSaveHandler;
|
||||
|
|
@ -69,9 +70,9 @@ public class ShareActivity
|
|||
private static final int REQUEST_PERM_ON_SUBMIT_STORAGE = 4;
|
||||
private CategorizationFragment categorizationFragment;
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject CacheController cacheController;
|
||||
@Inject SessionManager sessionManager;
|
||||
|
||||
private String source;
|
||||
private String mimeType;
|
||||
|
|
@ -132,11 +133,7 @@ public class ShareActivity
|
|||
private void uploadBegins() {
|
||||
getFileMetadata(locationPermitted);
|
||||
|
||||
Toast startingToast = Toast.makeText(
|
||||
application,
|
||||
R.string.uploading_started,
|
||||
Toast.LENGTH_LONG
|
||||
);
|
||||
Toast startingToast = Toast.makeText(this, R.string.uploading_started, Toast.LENGTH_LONG);
|
||||
startingToast.show();
|
||||
|
||||
if (!cacheFound) {
|
||||
|
|
@ -173,10 +170,10 @@ public class ShareActivity
|
|||
|
||||
// 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!
|
||||
ContentResolver.setSyncAutomatically(sessionManager.getCurrentAccount(), ModificationsContentProvider.AUTHORITY, true); // Enable sync by default!
|
||||
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, getApplicationContext(), mwApi)
|
||||
.param("username", sessionManager.getCurrentAccount().name)
|
||||
.param("categories-count", categories.size())
|
||||
.param("files-count", 1)
|
||||
.param("source", contribution.getSource())
|
||||
|
|
@ -197,16 +194,16 @@ public class ShareActivity
|
|||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
if(categorizationFragment != null && categorizationFragment.isVisible()) {
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, getApplicationContext(), mwApi)
|
||||
.param("username", sessionManager.getCurrentAccount().name)
|
||||
.param("categories-count", categorizationFragment.getCurrentSelectedCount())
|
||||
.param("files-count", 1)
|
||||
.param("source", contribution.getSource())
|
||||
.param("result", "cancelled")
|
||||
.log();
|
||||
} else {
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, getApplicationContext(), mwApi)
|
||||
.param("username", sessionManager.getCurrentAccount().name)
|
||||
.param("source", getIntent().getStringExtra(UploadService.EXTRA_SOURCE))
|
||||
.param("multiple", true)
|
||||
.param("result", "cancelled")
|
||||
|
|
@ -229,7 +226,7 @@ public class ShareActivity
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
uploadController = new UploadController(application);
|
||||
uploadController = new UploadController(sessionManager, this);
|
||||
setContentView(R.layout.activity_share);
|
||||
ButterKnife.bind(this);
|
||||
initBack();
|
||||
|
|
@ -454,12 +451,12 @@ public class ShareActivity
|
|||
= getContentResolver().openFileDescriptor(mediaUri, "r");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
if (descriptor != null) {
|
||||
imageObj = new GPSExtractor(descriptor.getFileDescriptor(), application);
|
||||
imageObj = new GPSExtractor(descriptor.getFileDescriptor(), this);
|
||||
}
|
||||
} else {
|
||||
String filePath = getPathOfMediaOrCopy();
|
||||
if (filePath != null) {
|
||||
imageObj = new GPSExtractor(filePath, application);
|
||||
imageObj = new GPSExtractor(filePath, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -489,7 +486,7 @@ public class ShareActivity
|
|||
cacheController.setQtPoint(decLongitude, decLatitude);
|
||||
}
|
||||
|
||||
MwVolleyApi apiCall = new MwVolleyApi(application);
|
||||
MwVolleyApi apiCall = new MwVolleyApi(this);
|
||||
|
||||
List<String> displayCatList = cacheController.findCategory();
|
||||
boolean catListEmpty = displayCatList.isEmpty();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons.upload;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
|
|
@ -21,20 +22,23 @@ import java.util.concurrent.Executors;
|
|||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.HandlerService;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class UploadController {
|
||||
private UploadService uploadService;
|
||||
private final CommonsApplication application;
|
||||
private SessionManager sessionManager;
|
||||
private Context context;
|
||||
|
||||
public interface ContributionUploadProgress {
|
||||
void onUploadStarted(Contribution contribution);
|
||||
}
|
||||
|
||||
public UploadController(CommonsApplication application) {
|
||||
this.application = application;
|
||||
public UploadController(SessionManager sessionManager, Context context) {
|
||||
this.sessionManager = sessionManager;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private boolean isUploadServiceConnected;
|
||||
|
|
@ -53,15 +57,15 @@ public class UploadController {
|
|||
};
|
||||
|
||||
public void prepareService() {
|
||||
Intent uploadServiceIntent = new Intent(application, UploadService.class);
|
||||
Intent uploadServiceIntent = new Intent(context, UploadService.class);
|
||||
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
||||
application.startService(uploadServiceIntent);
|
||||
application.bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
context.startService(uploadServiceIntent);
|
||||
context.bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
if(isUploadServiceConnected) {
|
||||
application.unbindService(uploadServiceConnection);
|
||||
context.unbindService(uploadServiceConnection);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +73,9 @@ public class UploadController {
|
|||
Contribution contribution;
|
||||
|
||||
//TODO: Modify this to include coords
|
||||
contribution = new Contribution(mediaUri, null, title, description, -1, null, null, application.getCurrentAccount().name, CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);
|
||||
contribution = new Contribution(mediaUri, null, title, description, -1,
|
||||
null, null, sessionManager.getCurrentAccount().name,
|
||||
CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);
|
||||
|
||||
contribution.setTag("mimeType", mimeType);
|
||||
contribution.setSource(source);
|
||||
|
|
@ -79,12 +85,11 @@ public class UploadController {
|
|||
}
|
||||
|
||||
public void startUpload(final Contribution contribution, final ContributionUploadProgress onComplete) {
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(application);
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
|
||||
|
||||
//Set creator, desc, and license
|
||||
if(TextUtils.isEmpty(contribution.getCreator())) {
|
||||
contribution.setCreator(application.getCurrentAccount().name);
|
||||
contribution.setCreator(sessionManager.getCurrentAccount().name);
|
||||
}
|
||||
|
||||
if(contribution.getDescription() == null) {
|
||||
|
|
@ -103,14 +108,15 @@ public class UploadController {
|
|||
@Override
|
||||
protected Contribution doInBackground(Void... voids /* stare into you */) {
|
||||
long length;
|
||||
ContentResolver contentResolver = context.getContentResolver();
|
||||
try {
|
||||
if(contribution.getDataLength() <= 0) {
|
||||
length = application.getContentResolver()
|
||||
length = contentResolver
|
||||
.openAssetFileDescriptor(contribution.getLocalUri(), "r")
|
||||
.getLength();
|
||||
if(length == -1) {
|
||||
// Let us find out the long way!
|
||||
length = countBytes(application.getContentResolver()
|
||||
length = countBytes(contentResolver
|
||||
.openInputStream(contribution.getLocalUri()));
|
||||
}
|
||||
contribution.setDataLength(length);
|
||||
|
|
@ -127,7 +133,7 @@ public class UploadController {
|
|||
Boolean imagePrefix = false;
|
||||
|
||||
if (mimeType == null || TextUtils.isEmpty(mimeType) || mimeType.endsWith("*")) {
|
||||
mimeType = application.getContentResolver().getType(contribution.getLocalUri());
|
||||
mimeType = contentResolver.getType(contribution.getLocalUri());
|
||||
}
|
||||
|
||||
if (mimeType != null) {
|
||||
|
|
@ -138,7 +144,7 @@ public class UploadController {
|
|||
|
||||
if (imagePrefix && contribution.getDateCreated() == null) {
|
||||
Timber.d("local uri " + contribution.getLocalUri());
|
||||
Cursor cursor = application.getContentResolver().query(contribution.getLocalUri(),
|
||||
Cursor cursor = contentResolver.query(contribution.getLocalUri(),
|
||||
new String[]{MediaStore.Images.ImageColumns.DATE_TAKEN}, null, null, null);
|
||||
if (cursor != null && cursor.getCount() != 0 && cursor.getColumnCount() != 0) {
|
||||
cursor.moveToFirst();
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import fr.free.nrw.commons.CommonsApplication;
|
|||
import fr.free.nrw.commons.HandlerService;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||
import fr.free.nrw.commons.contributions.ContributionsContentProvider;
|
||||
|
|
@ -47,8 +48,8 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
public static final String EXTRA_SOURCE = EXTRA_PREFIX + ".source";
|
||||
public static final String EXTRA_CAMPAIGN = EXTRA_PREFIX + ".campaign";
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject SessionManager sessionManager;
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private ContentProviderClient contributionsProviderClient;
|
||||
|
|
@ -221,7 +222,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
}
|
||||
if (!mwApi.validateLogin()) {
|
||||
// Need to revalidate!
|
||||
if (application.revalidateAuthToken()) {
|
||||
if (sessionManager.revalidateAuthToken()) {
|
||||
Timber.d("Successfully revalidated token!");
|
||||
} else {
|
||||
Timber.d("Unable to revalidate :(");
|
||||
|
|
@ -246,8 +247,8 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
String resultStatus = uploadResult.getResultStatus();
|
||||
if (!resultStatus.equals("Success")) {
|
||||
showFailedNotification(contribution);
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, getApplicationContext(), mwApi)
|
||||
.param("username", sessionManager.getCurrentAccount().name)
|
||||
.param("source", contribution.getSource())
|
||||
.param("multiple", contribution.getMultiple())
|
||||
.param("result", uploadResult.getErrorCode())
|
||||
|
|
@ -260,8 +261,8 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
contribution.setDateUploaded(uploadResult.getDateUploaded());
|
||||
contribution.save();
|
||||
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, application, mwApi)
|
||||
.param("username", application.getCurrentAccount().name)
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT, getApplicationContext(), mwApi)
|
||||
.param("username", sessionManager.getCurrentAccount().name)
|
||||
.param("source", contribution.getSource()) //FIXME
|
||||
.param("filename", contribution.getFilename())
|
||||
.param("multiple", contribution.getMultiple())
|
||||
|
|
@ -278,7 +279,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
toUpload--;
|
||||
if (toUpload == 0) {
|
||||
// Sync modifications right after all uplaods are processed
|
||||
ContentResolver.requestSync(application.getCurrentAccount(), ModificationsContentProvider.AUTHORITY, new Bundle());
|
||||
ContentResolver.requestSync(sessionManager.getCurrentAccount(), ModificationsContentProvider.AUTHORITY, new Bundle());
|
||||
stopForeground(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue