Merge branch 'improve_download_progress'

This commit is contained in:
cketti 2018-05-07 18:09:44 +02:00
commit 2a7dbb19ee
2 changed files with 41 additions and 6 deletions

View file

@ -23,11 +23,11 @@ public class AttachmentDownloadDialogFragment extends DialogFragment {
private MessagingController messagingController;
public static AttachmentDownloadDialogFragment newInstance(int size, String message) {
public static AttachmentDownloadDialogFragment newInstance(long size, String message) {
AttachmentDownloadDialogFragment fragment = new AttachmentDownloadDialogFragment();
Bundle args = new Bundle();
args.putInt(ARG_SIZE, size);
args.putLong(ARG_SIZE, size);
args.putString(ARG_MESSAGE, message);
fragment.setArguments(args);
@ -37,13 +37,15 @@ public class AttachmentDownloadDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle args = getArguments();
int size = args.getInt(ARG_SIZE);
long size = args.getLong(ARG_SIZE);
String message = args.getString(ARG_MESSAGE);
final SizeUnit sizeUnit = SizeUnit.getAppropriateFor(size);
messagingListener = new SimpleMessagingListener() {
@Override
public void updateProgress(int progress) {
dialog.setProgress(progress);
dialog.setProgress(sizeUnit.valueInSizeUnit(progress));
}
};
@ -52,9 +54,10 @@ public class AttachmentDownloadDialogFragment extends DialogFragment {
dialog = new ProgressDialog(getActivity());
dialog.setMessage(message);
dialog.setMax(size);
dialog.setMax(sizeUnit.valueInSizeUnit(size));
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(0);
dialog.setProgressNumberFormat("%1d/%2d " + sizeUnit.shortName);
dialog.show();
return dialog;
@ -78,6 +81,38 @@ public class AttachmentDownloadDialogFragment extends DialogFragment {
}
private enum SizeUnit {
BYTE("B", 1L),
KIBIBYTE("KiB", 1024L),
MEBIBYTE("MiB", 1024L * 1024L),
GIBIBYTE("GiB", 1024L * 1024L * 1024L),
TEBIBYTE("TiB", 1024L * 1024L * 1024L * 1024L),
PEBIBYTE("PiB", 1024L * 1024L * 1024L * 1024L * 1024L);
public final String shortName;
public final long size;
static SizeUnit getAppropriateFor(long value) {
for (SizeUnit sizeUnit : values()) {
if (value < 1024L * 10L * sizeUnit.size) {
return sizeUnit;
}
}
return SizeUnit.BYTE;
}
SizeUnit(String shortName, long size) {
this.shortName = shortName;
this.size = size;
}
int valueInSizeUnit(long value) {
return (int) (value / size);
}
}
public interface AttachmentDownloadCancelListener {
void onProgressCancel(AttachmentDownloadDialogFragment fragment);
}

View file

@ -534,7 +534,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
}
case R.id.dialog_attachment_progress: {
String message = getString(R.string.dialog_attachment_progress_title);
int size = (int) currentAttachmentViewInfo.size;
long size = currentAttachmentViewInfo.size;
fragment = AttachmentDownloadDialogFragment.newInstance(size, message);
break;
}