Send: added progress bar

pull/209/head
M66B 2 years ago
parent 660cea96e2
commit ab3683d442

@ -9,7 +9,11 @@ public class Send {
static final int DEFAULT_TLIMIT = 0;
static final String DEFAULT_SERVER = "";
public static String upload(InputStream is, DocumentFile dfile, int dLimit, int timeLimit, String host) {
public static String upload(InputStream is, DocumentFile dfile, int dLimit, int timeLimit, String host, IProgress intf) {
return null;
}
public interface IProgress {
void onProgress(int percentage);
}
}

@ -57,7 +57,7 @@ public class Send {
private static final int TIMEOUT = 20 * 1000; // milliseconds
public static String upload(InputStream is, DocumentFile dfile, int dLimit, int timeLimit, String host) throws Throwable {
public static String upload(InputStream is, DocumentFile dfile, int dLimit, int timeLimit, String host, IProgress intf) throws Throwable {
String result;
SecureRandom rnd = new SecureRandom();
@ -153,11 +153,13 @@ public class Send {
while ((len = is.read(buffer, 0, buffer.length - 17)) > 0) {
Log.i("Send read=" + len);
size += len;
intf.onProgress((int) (100 * size / fileSize));
// add a delimiter octet (0x01 or 0x02)
// then 0x00-valued octets to rs-16 (or less on the last record)
// The last record uses a padding delimiter octet set to the value 2,
// all other records have a padding delimiter octet value of 1.
size += len;
if (size == fileSize)
buffer[len++] = 0x02;
else {
@ -255,4 +257,8 @@ public class Send {
return jupload;
}
public interface IProgress {
void onProgress(int percentage);
}
}

@ -376,6 +376,7 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
btnUpload.setEnabled(false);
sbDLimit.setEnabled(false);
sbTLimit.setEnabled(false);
pbUpload.setProgress(0);
pbUpload.setVisibility(View.VISIBLE);
}
@ -417,10 +418,24 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
ContentResolver resolver = context.getContentResolver();
try (InputStream is = resolver.openInputStream(uri)) {
return Send.upload(is, dfile, dlimit, tlimit * 60 * 60, send_host);
return Send.upload(is, dfile, dlimit, tlimit * 60 * 60, send_host, new Send.IProgress() {
@Override
public void onProgress(int percentage) {
Bundle args = new Bundle();
args.putInt("progress", percentage);
postProgress(null, args);
}
});
}
}
@Override
protected void onProgress(CharSequence status, Bundle data) {
int progress = data.getInt("progress");
Log.i("Send progress=" + progress);
pbUpload.setProgress(progress);
}
@Override
protected void onExecuted(Bundle args, String link) {
etLink.setText(link);

@ -124,27 +124,27 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMetadataRemark" />
<eu.faircode.email.ContentLoadingProgressBar
<ProgressBar
android:id="@+id/pbUpload"
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="@id/btnUpload"
app:layout_constraintStart_toEndOf="@id/btnUpload"
app:layout_constraintTop_toTopOf="@id/btnUpload" />
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:progress="25"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnUpload" />
<TextView
android:id="@+id/tvDLimit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginTop="12dp"
android:labelFor="@+id/sbDLimit"
android:text="@string/title_style_link_send_dlimit"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnUpload" />
app:layout_constraintTop_toBottomOf="@id/pbUpload" />
<SeekBar
android:id="@+id/sbDLimit"
@ -160,7 +160,7 @@
android:id="@+id/tvTLimit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginTop="12dp"
android:labelFor="@+id/sbTLimit"
android:text="@string/title_style_link_send_tlimit"
android:textAppearance="@style/TextAppearance.AppCompat.Small"

Loading…
Cancel
Save