1
1
package fr .free .nrw .commons .upload ;
2
2
3
- import android .app .Activity ;
4
3
import android .content .ComponentName ;
5
4
import android .content .Context ;
6
5
import android .content .Intent ;
26
25
27
26
public class UploadController {
28
27
private UploadService uploadService ;
29
-
30
- private final Activity activity ;
31
- final CommonsApplication app ;
28
+ private final CommonsApplication app ;
32
29
33
30
public interface ContributionUploadProgress {
34
31
void onUploadStarted (Contribution contribution );
35
32
}
36
33
37
- public UploadController (Activity activity ) {
38
- this .activity = activity ;
34
+ public UploadController () {
39
35
app = CommonsApplication .getInstance ();
40
36
}
41
37
@@ -55,15 +51,15 @@ public void onServiceDisconnected(ComponentName componentName) {
55
51
};
56
52
57
53
public void prepareService () {
58
- Intent uploadServiceIntent = new Intent (activity , UploadService .class );
54
+ Intent uploadServiceIntent = new Intent (app , UploadService .class );
59
55
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 );
62
58
}
63
59
64
60
public void cleanup () {
65
61
if (isUploadServiceConnected ) {
66
- activity .unbindService (uploadServiceConnection );
62
+ app .unbindService (uploadServiceConnection );
67
63
}
68
64
}
69
65
@@ -82,7 +78,7 @@ public void startUpload(String title, Uri mediaUri, String description, String m
82
78
83
79
public void startUpload (final Contribution contribution , final ContributionUploadProgress onComplete ) {
84
80
85
- SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (activity );
81
+ SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (app );
86
82
87
83
//Set creator, desc, and license
88
84
if (TextUtils .isEmpty (contribution .getCreator ())) {
@@ -107,10 +103,10 @@ protected Contribution doInBackground(Void... voids /* stare into you */) {
107
103
long length ;
108
104
try {
109
105
if (contribution .getDataLength () <= 0 ) {
110
- length = activity .getContentResolver ().openAssetFileDescriptor (contribution .getLocalUri (), "r" ).getLength ();
106
+ length = app .getContentResolver ().openAssetFileDescriptor (contribution .getLocalUri (), "r" ).getLength ();
111
107
if (length == -1 ) {
112
108
// 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 ()));
114
110
}
115
111
contribution .setDataLength (length );
116
112
}
@@ -126,7 +122,7 @@ protected Contribution doInBackground(Void... voids /* stare into you */) {
126
122
Boolean imagePrefix = false ;
127
123
128
124
if (mimeType == null || TextUtils .isEmpty (mimeType ) || mimeType .endsWith ("*" )) {
129
- mimeType = activity .getContentResolver ().getType (contribution .getLocalUri ());
125
+ mimeType = app .getContentResolver ().getType (contribution .getLocalUri ());
130
126
}
131
127
132
128
if (mimeType != null ) {
@@ -136,7 +132,7 @@ protected Contribution doInBackground(Void... voids /* stare into you */) {
136
132
}
137
133
138
134
if (imagePrefix && contribution .getDateCreated () == null ) {
139
- Cursor cursor = activity .getContentResolver ().query (contribution .getLocalUri (),
135
+ Cursor cursor = app .getContentResolver ().query (contribution .getLocalUri (),
140
136
new String []{MediaStore .Images .ImageColumns .DATE_TAKEN }, null , null , null );
141
137
if (cursor != null && cursor .getCount () != 0 ) {
142
138
cursor .moveToFirst ();
0 commit comments