11package fr .free .nrw .commons .upload ;
22
3- import android .app .Activity ;
43import android .content .ComponentName ;
54import android .content .Context ;
65import android .content .Intent ;
2625
2726public 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