mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Refactor a little bit to avoid too much Intent passing around
This commit is contained in:
parent
9ea843b8a9
commit
91aa440eac
1 changed files with 15 additions and 13 deletions
|
|
@ -31,6 +31,8 @@ public class UploadService extends Service {
|
||||||
public static final String EXTRA_EDIT_SUMMARY = EXTRA_PREFIX + ".summary";
|
public static final String EXTRA_EDIT_SUMMARY = EXTRA_PREFIX + ".summary";
|
||||||
public static final String EXTRA_MIMETYPE = EXTRA_PREFIX + ".mimetype";
|
public static final String EXTRA_MIMETYPE = EXTRA_PREFIX + ".mimetype";
|
||||||
|
|
||||||
|
private static final int ACTION_UPLOAD_FILE = 1;
|
||||||
|
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
private ContentProviderClient contributionsProviderClient;
|
private ContentProviderClient contributionsProviderClient;
|
||||||
private CommonsApplication app;
|
private CommonsApplication app;
|
||||||
|
|
@ -51,7 +53,13 @@ public class UploadService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
onHandleIntent((Intent)msg.obj);
|
switch(msg.what) {
|
||||||
|
case ACTION_UPLOAD_FILE:
|
||||||
|
Contribution contrib = (Contribution)msg.obj;
|
||||||
|
uploadContribution(contrib);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
stopSelf(msg.arg1);
|
stopSelf(msg.arg1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,12 +177,10 @@ public class UploadService extends Service {
|
||||||
Contribution contribution = new Contribution(mediaUri, null, filename, description, length, dateCreated, null, app.getCurrentAccount().name, editSummary);
|
Contribution contribution = new Contribution(mediaUri, null, filename, description, length, dateCreated, null, app.getCurrentAccount().name, editSummary);
|
||||||
return contribution;
|
return contribution;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void postMessage(int type, Object obj) {
|
||||||
public void onStart(Intent intent, int startId) {
|
Message msg = mServiceHandler.obtainMessage(type);
|
||||||
Message msg = mServiceHandler.obtainMessage();
|
msg.obj = obj;
|
||||||
msg.arg1 = startId;
|
|
||||||
msg.obj = intent;
|
|
||||||
mServiceHandler.sendMessage(msg);
|
mServiceHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,20 +199,16 @@ public class UploadService extends Service {
|
||||||
|
|
||||||
contribution.save();
|
contribution.save();
|
||||||
|
|
||||||
Intent mediaUploadQueuedIntent = new Intent();
|
postMessage(ACTION_UPLOAD_FILE, contribution);
|
||||||
mediaUploadQueuedIntent.putExtra("dummy-data", contribution); // FIXME: Move to separate handler, do not inherit from IntentService
|
|
||||||
onStart(mediaUploadQueuedIntent, startId);
|
|
||||||
return START_REDELIVER_INTENT;
|
return START_REDELIVER_INTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onHandleIntent(Intent intent) {
|
void uploadContribution(Contribution contribution) {
|
||||||
MWApi api = app.getApi();
|
MWApi api = app.getApi();
|
||||||
|
|
||||||
ApiResult result;
|
ApiResult result;
|
||||||
RemoteViews notificationView;
|
RemoteViews notificationView;
|
||||||
Contribution contribution;
|
|
||||||
InputStream file = null;
|
InputStream file = null;
|
||||||
contribution = (Contribution) intent.getSerializableExtra("dummy-data");
|
|
||||||
|
|
||||||
String notificationTag = contribution.getLocalUri().toString();
|
String notificationTag = contribution.getLocalUri().toString();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue