mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Don't require Activity to be passed into UploadController.
This commit is contained in:
parent
8255bac32e
commit
1809475fea
3 changed files with 13 additions and 17 deletions
|
|
@ -203,7 +203,7 @@ public class MultipleShareActivity
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
uploadController = new UploadController(this);
|
uploadController = new UploadController();
|
||||||
|
|
||||||
setContentView(R.layout.activity_multiple_uploads);
|
setContentView(R.layout.activity_multiple_uploads);
|
||||||
app = CommonsApplication.getInstance();
|
app = CommonsApplication.getInstance();
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ public class ShareActivity
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
uploadController = new UploadController(this);
|
uploadController = new UploadController();
|
||||||
setContentView(R.layout.activity_share);
|
setContentView(R.layout.activity_share);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
initBack();
|
initBack();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package fr.free.nrw.commons.upload;
|
package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
@ -26,16 +25,13 @@ import timber.log.Timber;
|
||||||
|
|
||||||
public class UploadController {
|
public class UploadController {
|
||||||
private UploadService uploadService;
|
private UploadService uploadService;
|
||||||
|
private final CommonsApplication app;
|
||||||
private final Activity activity;
|
|
||||||
final CommonsApplication app;
|
|
||||||
|
|
||||||
public interface ContributionUploadProgress {
|
public interface ContributionUploadProgress {
|
||||||
void onUploadStarted(Contribution contribution);
|
void onUploadStarted(Contribution contribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UploadController(Activity activity) {
|
public UploadController() {
|
||||||
this.activity = activity;
|
|
||||||
app = CommonsApplication.getInstance();
|
app = CommonsApplication.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,15 +51,15 @@ public class UploadController {
|
||||||
};
|
};
|
||||||
|
|
||||||
public void prepareService() {
|
public void prepareService() {
|
||||||
Intent uploadServiceIntent = new Intent(activity, UploadService.class);
|
Intent uploadServiceIntent = new Intent(app, UploadService.class);
|
||||||
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
||||||
activity.startService(uploadServiceIntent);
|
app.startService(uploadServiceIntent);
|
||||||
activity.bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
app.bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
if(isUploadServiceConnected) {
|
if(isUploadServiceConnected) {
|
||||||
activity.unbindService(uploadServiceConnection);
|
app.unbindService(uploadServiceConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,7 +78,7 @@ public class UploadController {
|
||||||
|
|
||||||
public void startUpload(final Contribution contribution, final ContributionUploadProgress onComplete) {
|
public void startUpload(final Contribution contribution, final ContributionUploadProgress onComplete) {
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
|
||||||
|
|
||||||
//Set creator, desc, and license
|
//Set creator, desc, and license
|
||||||
if(TextUtils.isEmpty(contribution.getCreator())) {
|
if(TextUtils.isEmpty(contribution.getCreator())) {
|
||||||
|
|
@ -107,10 +103,10 @@ public class UploadController {
|
||||||
long length;
|
long length;
|
||||||
try {
|
try {
|
||||||
if(contribution.getDataLength() <= 0) {
|
if(contribution.getDataLength() <= 0) {
|
||||||
length = activity.getContentResolver().openAssetFileDescriptor(contribution.getLocalUri(), "r").getLength();
|
length = app.getContentResolver().openAssetFileDescriptor(contribution.getLocalUri(), "r").getLength();
|
||||||
if(length == -1) {
|
if(length == -1) {
|
||||||
// Let us find out the long way!
|
// Let us find out the long way!
|
||||||
length = Utils.countBytes(activity.getContentResolver().openInputStream(contribution.getLocalUri()));
|
length = Utils.countBytes(app.getContentResolver().openInputStream(contribution.getLocalUri()));
|
||||||
}
|
}
|
||||||
contribution.setDataLength(length);
|
contribution.setDataLength(length);
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +122,7 @@ public class UploadController {
|
||||||
Boolean imagePrefix = false;
|
Boolean imagePrefix = false;
|
||||||
|
|
||||||
if(mimeType == null || TextUtils.isEmpty(mimeType) || mimeType.endsWith("*")) {
|
if(mimeType == null || TextUtils.isEmpty(mimeType) || mimeType.endsWith("*")) {
|
||||||
mimeType = activity.getContentResolver().getType(contribution.getLocalUri());
|
mimeType = app.getContentResolver().getType(contribution.getLocalUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mimeType != null) {
|
if(mimeType != null) {
|
||||||
|
|
@ -136,7 +132,7 @@ public class UploadController {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(imagePrefix && contribution.getDateCreated() == null) {
|
if(imagePrefix && contribution.getDateCreated() == null) {
|
||||||
Cursor cursor = activity.getContentResolver().query(contribution.getLocalUri(),
|
Cursor cursor = app.getContentResolver().query(contribution.getLocalUri(),
|
||||||
new String[]{MediaStore.Images.ImageColumns.DATE_TAKEN}, null, null, null);
|
new String[]{MediaStore.Images.ImageColumns.DATE_TAKEN}, null, null, null);
|
||||||
if(cursor != null && cursor.getCount() != 0) {
|
if(cursor != null && cursor.getCount() != 0) {
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue