upload progress

This commit is contained in:
Page Asgardius 2022-09-24 17:36:31 -07:00
parent 38ffd5f5f7
commit 493c17643e
3 changed files with 48 additions and 15 deletions

View file

@ -179,15 +179,6 @@ public class Downloader extends AppCompatActivity {
} }
} }
runOnUiThread(new Runnable() {
@Override
public void run() {
//simpleProgressBar.setProgress(100);
}
});
//System.out.println("tree "+treelevel);
//System.out.println("prefix "+prefix);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();

View file

@ -57,8 +57,9 @@ public class Uploader extends AppCompatActivity {
File ufile; File ufile;
Intent intent; Intent intent;
Button fileUpload; Button fileUpload;
Thread uploadFile; Thread uploadFile, uploadProgress;
boolean started = false; boolean started = false;
long transfered = 0;
private static final long MAX_SINGLE_PART_UPLOAD_BYTES = 5 * 1024 * 1024; private static final long MAX_SINGLE_PART_UPLOAD_BYTES = 5 * 1024 * 1024;
private WifiManager.WifiLock mWifiLock; private WifiManager.WifiLock mWifiLock;
private PowerManager.WakeLock mWakeLock; private PowerManager.WakeLock mWakeLock;
@ -103,6 +104,8 @@ public class Uploader extends AppCompatActivity {
//simpleProgressBar.setVisibility(View.INVISIBLE); //simpleProgressBar.setVisibility(View.INVISIBLE);
} else { } else {
started = true; started = true;
transfered = 0;
//simpleProgressBar.setProgress(0);
simpleProgressBar.setVisibility(View.VISIBLE); simpleProgressBar.setVisibility(View.VISIBLE);
if (fileuri == null && folder == null) { if (fileuri == null && folder == null) {
Toast.makeText(Uploader.this, getResources().getString(R.string.no_file_selected), Toast.LENGTH_SHORT).show(); Toast.makeText(Uploader.this, getResources().getString(R.string.no_file_selected), Toast.LENGTH_SHORT).show();
@ -152,9 +155,10 @@ public class Uploader extends AppCompatActivity {
mWakeLock.release(); mWakeLock.release();
//System.out.println("WakeLock released"); //System.out.println("WakeLock released");
} }
//simpleProgressBar.setProgress(100); simpleProgressBar.setProgress(100);
simpleProgressBar.setVisibility(View.INVISIBLE); //simpleProgressBar.setVisibility(View.INVISIBLE);
fileUpload.setText(getResources().getString(R.string.upload_success)); fileUpload.setText(getResources().getString(R.string.upload_success));
started = false;
fileUpload.setEnabled(false); fileUpload.setEnabled(false);
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.upload_success), Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.upload_success), Toast.LENGTH_SHORT).show();
//simpleProgressBar.setVisibility(View.INVISIBLE); //simpleProgressBar.setVisibility(View.INVISIBLE);
@ -178,7 +182,8 @@ public class Uploader extends AppCompatActivity {
mWakeLock.release(); mWakeLock.release();
//System.out.println("WakeLock released"); //System.out.println("WakeLock released");
} }
simpleProgressBar.setVisibility(View.INVISIBLE); started = false;
//simpleProgressBar.setVisibility(View.INVISIBLE);
//fileUpload.setEnabled(true); //fileUpload.setEnabled(true);
fileUpload.setText(getResources().getString(R.string.retry)); fileUpload.setText(getResources().getString(R.string.retry));
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
@ -189,8 +194,43 @@ public class Uploader extends AppCompatActivity {
} }
} }
}); });
uploadProgress = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
while (started) {
try {
if (filesize != 0) {
//simpleProgressBar.setProgress((int)((transfered*100)/filesize));
simpleProgressBar.setProgress((int)((transfered*100)/filesize));
}
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
//simpleProgressBar.setProgress(100);
}
});
//System.out.println("tree "+treelevel);
//System.out.println("prefix "+prefix);
} catch (Exception e) {
e.printStackTrace();
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
//finish();
}
}
});
//simpleProgressBar.setVisibility(View.VISIBLE); //simpleProgressBar.setVisibility(View.VISIBLE);
uploadFile.start(); uploadFile.start();
uploadProgress.start();
/*while (progress <= 99) { /*while (progress <= 99) {
System.out.println("Upload in progress"); System.out.println("Upload in progress");
if (upload != null) { if (upload != null) {
@ -327,6 +367,7 @@ public class Uploader extends AppCompatActivity {
partETags.add(uploadResult.getPartETag()); partETags.add(uploadResult.getPartETag());
fileOffset += partSize; fileOffset += partSize;
transfered = fileOffset;
} }
// Complete the multipart upload. // Complete the multipart upload.

View file

@ -46,12 +46,13 @@
<ProgressBar <ProgressBar
android:id="@+id/simpleProgressBar" android:id="@+id/simpleProgressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:indeterminate="true" android:indeterminate="false"
android:max="100" android:max="100"
android:padding="20dp" android:padding="20dp"
android:progress="50" android:progress="0"
android:visibility="invisible" android:visibility="invisible"
tools:ignore="MissingConstraints" /> tools:ignore="MissingConstraints" />