Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private static final class ProcessorCallback implements ProgressCallback {

ProcessorCallback(long totalBytes, long offset, CallbackDispatcher dispatcher, final String requestId) {
// calculate step size for progress - prevent flooding the user with callbacks.
this.notifyThrottlingStepSize = totalBytes > 0 ? totalBytes / 100 : 500 * 1024 * 1024;
this.notifyThrottlingStepSize = totalBytes > 0 ? totalBytes / 100 : 500 * 1024;
this.totalBytes = totalBytes;
this.bytesNotified = offset;
this.bytesUploaded = offset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,10 @@ private void bindRegularView(final ResourceViewHolder holder, int position) {
break;
case UPLOADING:
holder.cancelRequest.setVisibility(View.VISIBLE);
double progressFraction = (double) resourceWithMeta.bytes / resourceWithMeta.totalBytes;
int progress = (int) Math.round(progressFraction * 1000);
holder.progressBar.setVisibility(View.VISIBLE);
holder.progressBar.setMax(1000);
holder.progressBar.setProgress(progress);
if (holder.blackOverlay.getVisibility() != View.VISIBLE) {
holder.blackOverlay.setAlpha(0);
holder.blackOverlay.setVisibility(View.VISIBLE);
holder.blackOverlay.animate().alpha(1f);
}
setProgress(holder, resourceWithMeta);
if (isVideo) {
holder.name.setText(resource.getName());
}
setProgressText(progressFraction, holder.statusText);
break;
case UPLOADED:
holder.blackOverlay.animate().cancel();
Expand Down Expand Up @@ -245,25 +235,36 @@ public void onUrlReady(Url url) {
}
});
}
}

private void setProgress(ResourceViewHolder holder, ResourceWithMeta resourceWithMeta) {
holder.progressBar.setVisibility(View.VISIBLE);
((ViewGroup)holder.progressBar.getParent()).findViewById(R.id.progressContainer).setVisibility(View.VISIBLE);

if (holder.blackOverlay.getVisibility() != View.VISIBLE) {
holder.blackOverlay.setAlpha(0);
holder.blackOverlay.setVisibility(View.VISIBLE);
holder.blackOverlay.animate().alpha(1f);
}

final String progressStr;
double bytesAsDouble = resourceWithMeta.bytes;
if (resourceWithMeta.totalBytes > 0) {
double progressFraction = (double) resourceWithMeta.bytes / resourceWithMeta.totalBytes;
double progressFraction = bytesAsDouble / resourceWithMeta.totalBytes;
int progress = (int) Math.round(progressFraction * 1000);
holder.progressBar.setVisibility(View.VISIBLE);
holder.progressBar.setIndeterminate(false);
holder.progressBar.setMax(1000);
holder.progressBar.setProgress(progress);
progressStr = String.valueOf(Math.round(progressFraction * 100)) + "%";
} else {
holder.progressBar.setProgress(0);
holder.progressBar.setVisibility(View.INVISIBLE);
holder.progressBar.setIndeterminate(true);
progressStr = String.format("%.2f[MB]", bytesAsDouble/ 1000000);
}
}

private void setProgressText(double progressFraction, TextView statusText) {
String progressStr = String.valueOf(Math.round(progressFraction * 100));
String text = statusText.getContext().getString(R.string.uploading, progressStr);
String text = holder.statusText.getContext().getString(R.string.uploading, progressStr);
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(new ForegroundColorSpan(statusText.getContext().getResources().getColor(R.color.buttonColor)), text.indexOf(progressStr), text.length(), 0);
statusText.setText(spannableString);
spannableString.setSpan(new ForegroundColorSpan(holder.statusText.getContext().getResources().getColor(R.color.buttonColor)), text.indexOf(progressStr), text.length(), 0);
holder.statusText.setText(spannableString);
}

private void addResource(Resource resource) {
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<string name="unknown_error">Unknown error.</string>
<string name="effect_video_rotate">\u25CF Rotate the video by 20 degrees (automatically adds a bounding box)</string>
<string name="effect_desc_video_round_corners">\u25CF Add rounded corners</string>
<string name="uploading">Uploading %s%%</string>
<string name="uploading">Uploading %s</string>
<string name="rescheduled">Rescheduled</string>
<string name="queued">Queued</string>
<string name="failed">Failed</string>
Expand Down