mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Progress reported a lot more granularly!
Updated version of java-mwapi used
This commit is contained in:
parent
9175eaed95
commit
c3aaeb0d59
2 changed files with 17 additions and 3 deletions
Binary file not shown.
|
|
@ -61,10 +61,19 @@ public class UploadService extends IntentService {
|
||||||
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long countBytes(InputStream source) throws IOException {
|
||||||
|
long length = 0;
|
||||||
|
while(source.read() != -1) {
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
MWApi api = ((CommonsApplication)this.getApplicationContext()).getApi();
|
MWApi api = ((CommonsApplication)this.getApplicationContext()).getApi();
|
||||||
InputStream file;
|
InputStream file;
|
||||||
|
long length;
|
||||||
ApiResult result;
|
ApiResult result;
|
||||||
RemoteViews notificationView;
|
RemoteViews notificationView;
|
||||||
|
|
||||||
|
|
@ -76,8 +85,15 @@ public class UploadService extends IntentService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
file = this.getContentResolver().openInputStream(mediaUri);
|
file = this.getContentResolver().openInputStream(mediaUri);
|
||||||
|
InputStream streamForCounting = this.getContentResolver().openInputStream(mediaUri);
|
||||||
|
length = countBytes(streamForCounting);
|
||||||
|
streamForCounting.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
//I'm hoping there are no streams that can be opened and read only once.
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationView = new RemoteViews(getPackageName(), R.layout.layout_upload_progress);
|
notificationView = new RemoteViews(getPackageName(), R.layout.layout_upload_progress);
|
||||||
|
|
@ -97,10 +113,8 @@ public class UploadService extends IntentService {
|
||||||
startingToast.show();
|
startingToast.show();
|
||||||
Log.d("Commons", "Just before");
|
Log.d("Commons", "Just before");
|
||||||
try {
|
try {
|
||||||
result = api.upload(filename, file, pageContents, editSummary, new NotificationUpdateProgressListener(curNotification));
|
result = api.upload(filename, file, length, pageContents, editSummary, new NotificationUpdateProgressListener(curNotification));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Do error handling!
|
|
||||||
Log.d("Commons", "Fuck");
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue