From bd5d3fc741b5f56d9334f695f39750f472eb5380 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Thu, 15 Sep 2022 12:42:20 -0700 Subject: [PATCH] downloader working --- app/src/main/AndroidManifest.xml | 1 + .../page/s3manager/BucketSelect.java | 5 ++--- .../asgardius/page/s3manager/Downloader.java | 22 +++++++++++-------- .../page/s3manager/ObjectSelect.java | 17 ++++++-------- .../asgardius/page/s3manager/Uploader.java | 7 +++--- .../main/res/layout/activity_downloader.xml | 7 ------ app/src/main/res/values/strings.xml | 1 + 7 files changed, 27 insertions(+), 33 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 38c5b4d..52954c7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,7 @@ tools:targetApi="31"> = 1) { Toast.makeText(ObjectSelect.this, getResources().getString(R.string.only_item_onlist), Toast.LENGTH_SHORT).show(); @@ -275,12 +275,10 @@ public class ObjectSelect extends AppCompatActivity { //Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); if (menuItem.getTitle() == getResources().getString(R.string.download_file)) { //Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show(); - //GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()); - //URL objectURL = s3client.generatePresignedUrl(request); - //download(objectURL.toString(), Name.get(position).toString()); + download(Name.get(position).toString()); } else if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) { //Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show(); - upload(false); + upload(); } else if (menuItem.getTitle() == getResources().getString(R.string.file_external)) { try { GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()); @@ -464,7 +462,7 @@ public class ObjectSelect extends AppCompatActivity { dialog.show(); } - private void upload(boolean isfolder) { + private void upload() { Intent intent = new Intent(this, Uploader.class); intent.putExtra("endpoint", endpoint); intent.putExtra("username", username); @@ -472,18 +470,17 @@ public class ObjectSelect extends AppCompatActivity { intent.putExtra("bucket", bucket); intent.putExtra("prefix", prefix); intent.putExtra("region", location); - intent.putExtra("isfolder", isfolder); startActivity(intent); } - private void download(String url, String filename) { + private void download(String filename) { Intent intent = new Intent(this, Downloader.class); - intent.putExtra("file_url", url); - intent.putExtra("file_name", filename); + intent.putExtra("filename", filename); intent.putExtra("endpoint", endpoint); intent.putExtra("username", username); intent.putExtra("password", password); + intent.putExtra("prefix", prefix); intent.putExtra("region", location); intent.putExtra("bucket", bucket); startActivity(intent); diff --git a/app/src/main/java/asgardius/page/s3manager/Uploader.java b/app/src/main/java/asgardius/page/s3manager/Uploader.java index 25e4cd0..2065c94 100644 --- a/app/src/main/java/asgardius/page/s3manager/Uploader.java +++ b/app/src/main/java/asgardius/page/s3manager/Uploader.java @@ -43,9 +43,8 @@ import java.util.List; public class Uploader extends AppCompatActivity { String username, password, endpoint, bucket, prefix, location, fkey; - //boolean isfolder; int progress; - Uri fileuri, folder, uri; + Uri fileuri, folder; EditText fprefix; Region region; S3ClientOptions s3ClientOptions; @@ -56,6 +55,7 @@ public class Uploader extends AppCompatActivity { File ufile; Intent intent; Button fileUpload; + Thread uploadFile; private static final long MAX_SINGLE_PART_UPLOAD_BYTES = 5 * 1024 * 1024; @Override @@ -68,7 +68,6 @@ public class Uploader extends AppCompatActivity { bucket = getIntent().getStringExtra("bucket"); location = getIntent().getStringExtra("region"); prefix = getIntent().getStringExtra("prefix"); - //isfolder = getIntent().getBooleanExtra("isfolder", false); fprefix = (EditText)findViewById(R.id.fprefix); region = Region.getRegion(location); s3ClientOptions = S3ClientOptions.builder().build(); @@ -101,7 +100,7 @@ public class Uploader extends AppCompatActivity { simpleProgressBar.setVisibility(View.VISIBLE); fileUpload.setEnabled(false); fileUpload.setText(getResources().getString(R.string.upload_in_progress)); - Thread uploadFile = new Thread(new Runnable() { + uploadFile = new Thread(new Runnable() { @Override public void run() { diff --git a/app/src/main/res/layout/activity_downloader.xml b/app/src/main/res/layout/activity_downloader.xml index dba4eb9..71525ad 100644 --- a/app/src/main/res/layout/activity_downloader.xml +++ b/app/src/main/res/layout/activity_downloader.xml @@ -7,13 +7,6 @@ android:orientation="vertical" tools:context=".Downloader"> - - File uploaded successfully Upload in progress Retry + Download failed Success Create new bucket Bucket created successfully