From 0c736c170ff9787364275ed4e4ea9d0c86b82e14 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Sun, 11 Sep 2022 12:12:48 -0700 Subject: [PATCH] hide missing feature --- .../page/s3manager/BucketSelect.java | 11 +- .../page/s3manager/CreateBucket.java | 2 +- .../page/s3manager/ObjectSelect.java | 13 +- .../asgardius/page/s3manager/Uploader.java | 141 +++++++++++++++++- .../res/layout/activity_create_bucket.xml | 2 +- app/src/main/res/layout/activity_uploader.xml | 55 ++++++- app/src/main/res/menu/bucket_menu.xml | 4 +- app/src/main/res/menu/folder_menu.xml | 4 +- app/src/main/res/menu/object_menu.xml | 4 +- app/src/main/res/values/strings.xml | 10 +- 10 files changed, 214 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/BucketSelect.java b/app/src/main/java/asgardius/page/s3manager/BucketSelect.java index dd860f2..9e7237d 100644 --- a/app/src/main/java/asgardius/page/s3manager/BucketSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/BucketSelect.java @@ -155,11 +155,9 @@ public class BucketSelect extends AppCompatActivity { public boolean onMenuItemClick(MenuItem menuItem) { // Toast message on menu item clicked //Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); - if (menuItem.getTitle() == getResources().getString(R.string.upload_tobucket)) { - //upload(); - upload(Name.get(position).toString()); - //System.out.println(file); - //Toast.makeText(BucketSelect.this, intent.getData().toString(), Toast.LENGTH_SHORT).show(); + if (menuItem.getTitle() == getResources().getString(R.string.upload_file_tobucket)) { + Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show(); + //upload(Name.get(position).toString(), false); } else if (menuItem.getTitle() == getResources().getString(R.string.create_bucket)) { //upload(); @@ -276,7 +274,7 @@ public class BucketSelect extends AppCompatActivity { dialog.show(); } - private void upload(String bucket) { + private void upload(String bucket, boolean isfolder) { Intent intent = new Intent(this, Uploader.class); intent.putExtra("endpoint", endpoint); intent.putExtra("username", username); @@ -284,6 +282,7 @@ public class BucketSelect extends AppCompatActivity { intent.putExtra("bucket", bucket); intent.putExtra("prefix", prefix); intent.putExtra("region", location); + intent.putExtra("isfolder", isfolder); startActivity(intent); } diff --git a/app/src/main/java/asgardius/page/s3manager/CreateBucket.java b/app/src/main/java/asgardius/page/s3manager/CreateBucket.java index 20aabc1..5a41e9d 100644 --- a/app/src/main/java/asgardius/page/s3manager/CreateBucket.java +++ b/app/src/main/java/asgardius/page/s3manager/CreateBucket.java @@ -51,7 +51,7 @@ public class CreateBucket extends AppCompatActivity { s3client = new AmazonS3Client(myCredentials, region); s3client.setEndpoint(endpoint); s3client.setS3ClientOptions(s3ClientOptions); - bname = (EditText)findViewById(R.id.bname); + bname = (EditText)findViewById(R.id.bname); Button cbucket = (Button)findViewById(R.id.cbucket); simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar); cbucket.setOnClickListener(new View.OnClickListener(){ diff --git a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java index 61eb60b..1d51e42 100644 --- a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java @@ -248,8 +248,9 @@ public class ObjectSelect extends AppCompatActivity { public boolean onMenuItemClick(MenuItem menuItem) { // Toast message on menu item clicked //Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); - if (menuItem.getTitle() == getResources().getString(R.string.upload_here)) { - upload(Name.get(position).toString()); + 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(Name.get(position).toString(), false); } else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) { if (Name.size() == 1 && treelevel >= 1) { Toast.makeText(ObjectSelect.this, getResources().getString(R.string.only_item_onlist), Toast.LENGTH_SHORT).show(); @@ -273,8 +274,9 @@ public class ObjectSelect extends AppCompatActivity { public boolean onMenuItemClick(MenuItem menuItem) { // Toast message on menu item clicked //Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); - if (menuItem.getTitle() == getResources().getString(R.string.upload_here)) { - upload(Name.get(position).toString()); + 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(Name.get(position).toString(), false); } else if (menuItem.getTitle() == getResources().getString(R.string.file_external)) { GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()); URL objectURL = s3client.generatePresignedUrl(request); @@ -454,7 +456,7 @@ public class ObjectSelect extends AppCompatActivity { dialog.show(); } - private void upload(String object) { + private void upload(String object, boolean isfolder) { Intent intent = new Intent(this, Uploader.class); intent.putExtra("endpoint", endpoint); intent.putExtra("username", username); @@ -462,6 +464,7 @@ public class ObjectSelect extends AppCompatActivity { intent.putExtra("bucket", bucket); intent.putExtra("prefix", prefix + object); intent.putExtra("region", location); + intent.putExtra("isfolder", isfolder); startActivity(intent); } } \ No newline at end of file diff --git a/app/src/main/java/asgardius/page/s3manager/Uploader.java b/app/src/main/java/asgardius/page/s3manager/Uploader.java index 31b2f76..9f7300f 100644 --- a/app/src/main/java/asgardius/page/s3manager/Uploader.java +++ b/app/src/main/java/asgardius/page/s3manager/Uploader.java @@ -2,12 +2,37 @@ package asgardius.page.s3manager; import androidx.appcompat.app.AppCompatActivity; +import android.app.Activity; +import android.content.Context; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; +import android.os.storage.StorageManager; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ProgressBar; import android.widget.Toast; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.regions.Region; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.S3ClientOptions; + +import java.net.URL; + public class Uploader extends AppCompatActivity { - String file, username, password, endpoint, bucket, prefix, location; + String username, password, endpoint, bucket, prefix, location; + boolean isfolder; + Uri file, folder; + EditText fprefix; + Region region; + S3ClientOptions s3ClientOptions; + AWSCredentials myCredentials; + AmazonS3 s3client; + ProgressBar simpleProgressBar; @Override protected void onCreate(Bundle savedInstanceState) { @@ -19,14 +44,114 @@ public class Uploader extends AppCompatActivity { bucket = getIntent().getStringExtra("bucket"); location = getIntent().getStringExtra("region"); prefix = getIntent().getStringExtra("prefix"); + isfolder = getIntent().getBooleanExtra("isfolder", false); + region = Region.getRegion(location); + s3ClientOptions = S3ClientOptions.builder().build(); + if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) { + s3ClientOptions.setPathStyleAccess(true); + } + myCredentials = new BasicAWSCredentials(username, password); + s3client = new AmazonS3Client(myCredentials, region); + s3client.setEndpoint(endpoint); + s3client.setS3ClientOptions(s3ClientOptions); + fprefix = (EditText)findViewById(R.id.fprefix); + Button fileUpload = (Button)findViewById(R.id.fileupload); + simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar); Toast.makeText(Uploader.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show(); - file = upload().getData() != null ? upload().getData().toString() : null; + /*if (isfolder) { + folder = uploadFolder(); + } else { + file = uploadFile(); + }*/ + fileUpload.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View view) { + //buttonaction + if (file == null && folder == null) { + Toast.makeText(Uploader.this, getResources().getString(R.string.no_file_selected), Toast.LENGTH_SHORT).show(); + } else { + //Toast.makeText(CreateBucket.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show(); + System.out.println(file.getPath()); + Thread uploadFile = new Thread(new Runnable() { + + @Override + public void run() { + try { + //Your code goes here + //s3client.createBucket(bucket, location); + runOnUiThread(new Runnable() { + + @Override + public void run() { + // Sending reference and data to Adapter + Toast.makeText(getApplicationContext(),getResources().getString(R.string.upload_success), Toast.LENGTH_SHORT).show(); + simpleProgressBar.setVisibility(View.INVISIBLE); + } + }); + //System.out.println("tree "+treelevel); + //System.out.println("prefix "+prefix); + + } catch (Exception e) { + e.printStackTrace(); + runOnUiThread(new Runnable() { + + @Override + public void run() { + 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(); + finish(); + } + } + }); + //simpleProgressBar.setVisibility(View.VISIBLE); + //uploadFile.start(); + } + } + + }); + } +/* + private Uri uploadFolder() { + StorageManager sm = (StorageManager) this.getSystemService(Context.STORAGE_SERVICE); + + Intent intent = sm.getPrimaryStorageVolume().createOpenDocumentTreeIntent(); + String startDir = "Documents"; + + Uri uri = intent.getParcelableExtra("android.provider.extra.INITIAL_URI"); + + String scheme = uri.toString(); + + scheme = scheme.replace("/root/", "/document/"); + + scheme += "%3A" + startDir; + + uri = Uri.parse(scheme); + + intent.putExtra("android.provider.extra.INITIAL_URI", uri); + ((Activity) this).startActivityForResult(intent,100); + return uri; } - private Intent upload() { - Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); - intent.setType("*/*"); - startActivityForResult(intent, 100); - return intent; - } + private Uri uploadFile() { + StorageManager sm = (StorageManager) this.getSystemService(Context.STORAGE_SERVICE); + + Intent intent = sm.getPrimaryStorageVolume().createOpenDocumentTreeIntent(); + String startDir = "Documents"; + + Uri uri = intent.getParcelableExtra("android.provider.extra.INITIAL_URI"); + + String scheme = uri.toString(); + + scheme = scheme.replace("/root/", "/document/"); + + scheme += "%3A" + startDir; + + uri = Uri.parse(scheme); + + intent.putExtra("android.provider.extra.INITIAL_URI", uri); + ((Activity) this).startActivityForResult(intent,100); + return uri; + }*/ } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_create_bucket.xml b/app/src/main/res/layout/activity_create_bucket.xml index 6152397..1bd9e66 100644 --- a/app/src/main/res/layout/activity_create_bucket.xml +++ b/app/src/main/res/layout/activity_create_bucket.xml @@ -15,7 +15,7 @@ android:textSize="30sp" /> - - \ No newline at end of file + + + + + + +