From 38ffd5f5f786d0cf38668e441f21ae1b110701d8 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Sat, 24 Sep 2022 16:07:05 -0700 Subject: [PATCH] download progress --- .../java/asgardius/page/s3manager/Downloader.java | 13 ++++++------- app/src/main/res/layout/activity_downloader.xml | 5 +++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/Downloader.java b/app/src/main/java/asgardius/page/s3manager/Downloader.java index cccb165..2a46594 100644 --- a/app/src/main/java/asgardius/page/s3manager/Downloader.java +++ b/app/src/main/java/asgardius/page/s3manager/Downloader.java @@ -46,7 +46,7 @@ public class Downloader extends AppCompatActivity { boolean started = false; boolean cancel = false; long filesize = 0; - long transfered; + long transfered = 0; private WifiManager.WifiLock mWifiLock; private PowerManager.WakeLock mWakeLock; private PowerManager powerManager; @@ -110,7 +110,7 @@ public class Downloader extends AppCompatActivity { //s3client.createBucket(bucket, location); //System.out.println(fkey); object = s3client.getObject(bucket, prefix+filename); - filesize = object.getObjectMetadata().getContentLength(); + filesize = (object.getObjectMetadata().getContentLength())/1024; writeContentToFile(fileuri); runOnUiThread(new Runnable() { @Override @@ -125,7 +125,7 @@ public class Downloader extends AppCompatActivity { mWakeLock.release(); //System.out.println("WakeLock released"); } - simpleProgressBar.setVisibility(View.INVISIBLE); + simpleProgressBar.setProgress(100); fileDownload.setText(getResources().getString(R.string.download_success)); fileDownload.setEnabled(false); //simpleProgressBar.setVisibility(View.INVISIBLE); @@ -149,7 +149,6 @@ public class Downloader extends AppCompatActivity { mWakeLock.release(); //System.out.println("WakeLock released"); } - simpleProgressBar.setVisibility(View.INVISIBLE); if (cancel) { fileDownload.setText(getResources().getString(R.string.download_canceled)); } else { @@ -167,13 +166,12 @@ public class Downloader extends AppCompatActivity { @Override public void run() { - simpleProgressBar.setVisibility(View.VISIBLE); try { //Your code goes here - while (!cancel && fileDownload.isEnabled()) { + while (fileDownload.isEnabled()) { try { if (filesize != 0) { - System.out.println("file size: "+Long.toString(filesize)); + simpleProgressBar.setProgress((int)((transfered*100)/filesize)); } Thread.sleep(500); } catch (Exception e) { @@ -252,6 +250,7 @@ public class Downloader extends AppCompatActivity { byte[] buffer = new byte[1024]; for (int len; (len = in.read(buffer)) != -1; ) { out.write(buffer, 0, len); + transfered ++; } } } diff --git a/app/src/main/res/layout/activity_downloader.xml b/app/src/main/res/layout/activity_downloader.xml index 71525ad..000f473 100644 --- a/app/src/main/res/layout/activity_downloader.xml +++ b/app/src/main/res/layout/activity_downloader.xml @@ -28,12 +28,13 @@