Skip to content

Commit 1809475

Browse files
committed
Don't require Activity to be passed into UploadController.
1 parent 8255bac commit 1809475

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

app/src/main/java/fr/free/nrw/commons/upload/MultipleShareActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
203203
@Override
204204
protected void onCreate(Bundle savedInstanceState) {
205205
super.onCreate(savedInstanceState);
206-
uploadController = new UploadController(this);
206+
uploadController = new UploadController();
207207

208208
setContentView(R.layout.activity_multiple_uploads);
209209
app = CommonsApplication.getInstance();

app/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ protected void onAuthFailure() {
214214
@Override
215215
public void onCreate(Bundle savedInstanceState) {
216216
super.onCreate(savedInstanceState);
217-
uploadController = new UploadController(this);
217+
uploadController = new UploadController();
218218
setContentView(R.layout.activity_share);
219219
ButterKnife.bind(this);
220220
initBack();

app/src/main/java/fr/free/nrw/commons/upload/UploadController.java

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fr.free.nrw.commons.upload;
22

3-
import android.app.Activity;
43
import android.content.ComponentName;
54
import android.content.Context;
65
import android.content.Intent;
@@ -26,16 +25,13 @@
2625

2726
public class UploadController {
2827
private UploadService uploadService;
29-
30-
private final Activity activity;
31-
final CommonsApplication app;
28+
private final CommonsApplication app;
3229

3330
public interface ContributionUploadProgress {
3431
void onUploadStarted(Contribution contribution);
3532
}
3633

37-
public UploadController(Activity activity) {
38-
this.activity = activity;
34+
public UploadController() {
3935
app = CommonsApplication.getInstance();
4036
}
4137

@@ -55,15 +51,15 @@ public void onServiceDisconnected(ComponentName componentName) {
5551
};
5652

5753
public void prepareService() {
58-
Intent uploadServiceIntent = new Intent(activity, UploadService.class);
54+
Intent uploadServiceIntent = new Intent(app, UploadService.class);
5955
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
60-
activity.startService(uploadServiceIntent);
61-
activity.bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
56+
app.startService(uploadServiceIntent);
57+
app.bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
6258
}
6359

6460
public void cleanup() {
6561
if(isUploadServiceConnected) {
66-
activity.unbindService(uploadServiceConnection);
62+
app.unbindService(uploadServiceConnection);
6763
}
6864
}
6965

@@ -82,7 +78,7 @@ public void startUpload(String title, Uri mediaUri, String description, String m
8278

8379
public void startUpload(final Contribution contribution, final ContributionUploadProgress onComplete) {
8480

85-
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
81+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
8682

8783
//Set creator, desc, and license
8884
if(TextUtils.isEmpty(contribution.getCreator())) {
@@ -107,10 +103,10 @@ protected Contribution doInBackground(Void... voids /* stare into you */) {
107103
long length;
108104
try {
109105
if(contribution.getDataLength() <= 0) {
110-
length = activity.getContentResolver().openAssetFileDescriptor(contribution.getLocalUri(), "r").getLength();
106+
length = app.getContentResolver().openAssetFileDescriptor(contribution.getLocalUri(), "r").getLength();
111107
if(length == -1) {
112108
// Let us find out the long way!
113-
length = Utils.countBytes(activity.getContentResolver().openInputStream(contribution.getLocalUri()));
109+
length = Utils.countBytes(app.getContentResolver().openInputStream(contribution.getLocalUri()));
114110
}
115111
contribution.setDataLength(length);
116112
}
@@ -126,7 +122,7 @@ protected Contribution doInBackground(Void... voids /* stare into you */) {
126122
Boolean imagePrefix = false;
127123

128124
if(mimeType == null || TextUtils.isEmpty(mimeType) || mimeType.endsWith("*")) {
129-
mimeType = activity.getContentResolver().getType(contribution.getLocalUri());
125+
mimeType = app.getContentResolver().getType(contribution.getLocalUri());
130126
}
131127

132128
if(mimeType != null) {
@@ -136,7 +132,7 @@ protected Contribution doInBackground(Void... voids /* stare into you */) {
136132
}
137133

138134
if(imagePrefix && contribution.getDateCreated() == null) {
139-
Cursor cursor = activity.getContentResolver().query(contribution.getLocalUri(),
135+
Cursor cursor = app.getContentResolver().query(contribution.getLocalUri(),
140136
new String[]{MediaStore.Images.ImageColumns.DATE_TAKEN}, null, null, null);
141137
if(cursor != null && cursor.getCount() != 0) {
142138
cursor.moveToFirst();

0 commit comments

Comments
 (0)