bucket delete
This commit is contained in:
parent
1da20db5d6
commit
91639641fa
4 changed files with 149 additions and 34 deletions
|
@ -3,10 +3,12 @@ package asgardius.page.s3manager;
|
||||||
import static android.media.MediaExtractor.MetricsConstants.MIME_TYPE;
|
import static android.media.MediaExtractor.MetricsConstants.MIME_TYPE;
|
||||||
import static com.amazonaws.regions.Regions.US_EAST_1;
|
import static com.amazonaws.regions.Regions.US_EAST_1;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
@ -24,6 +26,11 @@ import com.amazonaws.services.s3.AmazonS3;
|
||||||
import com.amazonaws.services.s3.AmazonS3Client;
|
import com.amazonaws.services.s3.AmazonS3Client;
|
||||||
import com.amazonaws.services.s3.S3ClientOptions;
|
import com.amazonaws.services.s3.S3ClientOptions;
|
||||||
import com.amazonaws.services.s3.model.Bucket;
|
import com.amazonaws.services.s3.model.Bucket;
|
||||||
|
import com.amazonaws.services.s3.model.DeleteObjectRequest;
|
||||||
|
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
|
||||||
|
import com.amazonaws.services.s3.model.ListObjectsRequest;
|
||||||
|
import com.amazonaws.services.s3.model.ObjectListing;
|
||||||
|
import com.amazonaws.services.s3.model.S3ObjectSummary;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -35,6 +42,11 @@ public class BucketSelect extends AppCompatActivity {
|
||||||
RecyclerView recyclerView;
|
RecyclerView recyclerView;
|
||||||
String username, password, endpoint, prefix, location, file;
|
String username, password, endpoint, prefix, location, file;
|
||||||
int treelevel;
|
int treelevel;
|
||||||
|
Region region;
|
||||||
|
S3ClientOptions s3ClientOptions;
|
||||||
|
AWSCredentials myCredentials;
|
||||||
|
AmazonS3 s3client;
|
||||||
|
ProgressBar simpleProgressBar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -45,18 +57,18 @@ public class BucketSelect extends AppCompatActivity {
|
||||||
location = getIntent().getStringExtra("region");
|
location = getIntent().getStringExtra("region");
|
||||||
prefix = "";
|
prefix = "";
|
||||||
setContentView(R.layout.activity_bucket_select);
|
setContentView(R.layout.activity_bucket_select);
|
||||||
Region region = Region.getRegion("us-east-1");
|
region = Region.getRegion("us-east-1");
|
||||||
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
|
s3ClientOptions = S3ClientOptions.builder().build();
|
||||||
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
|
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
|
||||||
s3ClientOptions.setPathStyleAccess(true);
|
s3ClientOptions.setPathStyleAccess(true);
|
||||||
}
|
}
|
||||||
AWSCredentials myCredentials = new BasicAWSCredentials(username, password);
|
myCredentials = new BasicAWSCredentials(username, password);
|
||||||
AmazonS3 s3client = new AmazonS3Client(myCredentials, region);
|
s3client = new AmazonS3Client(myCredentials, region);
|
||||||
s3client.setEndpoint(endpoint);
|
s3client.setEndpoint(endpoint);
|
||||||
s3client.setS3ClientOptions(s3ClientOptions);
|
s3client.setS3ClientOptions(s3ClientOptions);
|
||||||
|
|
||||||
recyclerView = findViewById(R.id.blist);
|
recyclerView = findViewById(R.id.blist);
|
||||||
final ProgressBar simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
|
simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
|
||||||
|
|
||||||
// layout for vertical orientation
|
// layout for vertical orientation
|
||||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
|
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
|
||||||
|
@ -80,6 +92,11 @@ public class BucketSelect extends AppCompatActivity {
|
||||||
//Img.add(R.drawable.ic_launcher_foreground);
|
//Img.add(R.drawable.ic_launcher_foreground);
|
||||||
Img.add(R.drawable.bucket);
|
Img.add(R.drawable.bucket);
|
||||||
}
|
}
|
||||||
|
if (Name.size() == 0) {
|
||||||
|
Name.add(getResources().getString(R.string.create_bucket));
|
||||||
|
//Img.add(R.drawable.ic_launcher_foreground);
|
||||||
|
Img.add(R.drawable.create_new);
|
||||||
|
}
|
||||||
//System.out.println(Name);
|
//System.out.println(Name);
|
||||||
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
|
@ -117,40 +134,43 @@ public class BucketSelect extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view, int position) {
|
public void onClick(View view, int position) {
|
||||||
//System.out.println("Click on "+Name.get(position).toString());
|
//System.out.println("Click on "+Name.get(position).toString());
|
||||||
explorer(Name.get(position).toString());
|
if (Img.get(position).equals(R.drawable.bucket)) {
|
||||||
|
//go to bucket content
|
||||||
|
explorer(Name.get(position).toString());
|
||||||
|
} else {
|
||||||
|
newBucket();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongClick(View view, int position) {
|
public void onLongClick(View view, int position) {
|
||||||
//System.out.println("Long click on "+Name.get(position).toString());
|
//System.out.println("Long click on "+Name.get(position).toString());
|
||||||
PopupMenu popupMenu = new PopupMenu(recyclerView.getContext(), view);
|
if (Img.get(position).equals(R.drawable.bucket)) {
|
||||||
|
PopupMenu popupMenu = new PopupMenu(recyclerView.getContext(), view);
|
||||||
|
|
||||||
// Inflating popup menu from popup_menu.xml file
|
// Inflating popup menu from popup_menu.xml file
|
||||||
popupMenu.getMenuInflater().inflate(R.menu.bucket_menu, popupMenu.getMenu());
|
popupMenu.getMenuInflater().inflate(R.menu.bucket_menu, popupMenu.getMenu());
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||||
// Toast message on menu item clicked
|
// Toast message on menu item clicked
|
||||||
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
||||||
if (menuItem.getTitle() == getResources().getString(R.string.upload_tobucket)) {
|
if (menuItem.getTitle() == getResources().getString(R.string.upload_tobucket)) {
|
||||||
//upload();
|
//upload();
|
||||||
upload(Name.get(position).toString());
|
upload(Name.get(position).toString());
|
||||||
//System.out.println(file);
|
//System.out.println(file);
|
||||||
//Toast.makeText(BucketSelect.this, intent.getData().toString(), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(BucketSelect.this, intent.getData().toString(), Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
|
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
|
||||||
Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
/*if (Name.size() == 1 && treelevel >= 1) {
|
delete(prefix + Name.get(position).toString());
|
||||||
Toast.makeText(BucketSelect.this, getResources().getString(R.string.only_item_onlist), Toast.LENGTH_SHORT).show();
|
}
|
||||||
} else {
|
return true;
|
||||||
delete(prefix + Name.get(position).toString(), true);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
return true;
|
});
|
||||||
}
|
// Showing the popup menu
|
||||||
});
|
popupMenu.show();
|
||||||
// Showing the popup menu
|
}
|
||||||
popupMenu.show();
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -170,6 +190,86 @@ public class BucketSelect extends AppCompatActivity {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void delete(String bucket) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(BucketSelect.this);
|
||||||
|
builder.setCancelable(true);
|
||||||
|
builder.setTitle(getResources().getString(R.string.file_del));
|
||||||
|
builder.setMessage(getResources().getString(R.string.bucket_del_confirm));
|
||||||
|
builder.setPositiveButton(android.R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
|
Thread deleteBucket = new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
//Your code goes here
|
||||||
|
ListObjectsRequest orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(8000);
|
||||||
|
//List<S3Object> objects = (List<S3Object>) s3client.listObjects(bucket, "/");
|
||||||
|
ObjectListing result = s3client.listObjects(orequest);
|
||||||
|
ArrayList<String> objectl = new ArrayList<String>();
|
||||||
|
List<S3ObjectSummary> objects = result.getObjectSummaries();
|
||||||
|
boolean nextbatch = false;
|
||||||
|
while (result.isTruncated() || !nextbatch) {
|
||||||
|
if (nextbatch) {
|
||||||
|
result = s3client.listNextBatchOfObjects (result);
|
||||||
|
objects = result.getObjectSummaries();
|
||||||
|
} else {
|
||||||
|
nextbatch = true;
|
||||||
|
}
|
||||||
|
for (S3ObjectSummary os : objects) {
|
||||||
|
objectl.add(os.getKey());
|
||||||
|
|
||||||
|
//i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//System.out.println(object);
|
||||||
|
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucket).withKeys(objectl.toArray(new String[0]));
|
||||||
|
s3client.deleteObjects(deleteObjectsRequest);
|
||||||
|
s3client.deleteBucket(bucket);
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Sending reference and data to Adapter
|
||||||
|
Toast.makeText(getApplicationContext(),getResources().getString(R.string.bucket_del_success), Toast.LENGTH_SHORT).show();
|
||||||
|
recreate();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//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);
|
||||||
|
deleteBucket.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog dialog = builder.create();
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void upload(String bucket) {
|
private void upload(String bucket) {
|
||||||
Intent intent = new Intent(this, Uploader.class);
|
Intent intent = new Intent(this, Uploader.class);
|
||||||
intent.putExtra("endpoint", endpoint);
|
intent.putExtra("endpoint", endpoint);
|
||||||
|
@ -181,4 +281,14 @@ public class BucketSelect extends AppCompatActivity {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void newBucket() {
|
||||||
|
Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
|
/*Intent intent = new Intent(this, Uploader.class);
|
||||||
|
intent.putExtra("endpoint", endpoint);
|
||||||
|
intent.putExtra("username", username);
|
||||||
|
intent.putExtra("password", password);
|
||||||
|
intent.putExtra("region", location);
|
||||||
|
startActivity(intent);*/
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -53,6 +53,7 @@ public class ObjectSelect extends AppCompatActivity {
|
||||||
S3ClientOptions s3ClientOptions;
|
S3ClientOptions s3ClientOptions;
|
||||||
AWSCredentials myCredentials;
|
AWSCredentials myCredentials;
|
||||||
AmazonS3 s3client;
|
AmazonS3 s3client;
|
||||||
|
ProgressBar simpleProgressBar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -78,7 +79,7 @@ public class ObjectSelect extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
recyclerView = findViewById(R.id.olist);
|
recyclerView = findViewById(R.id.olist);
|
||||||
final ProgressBar simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
|
simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
|
||||||
|
|
||||||
// layout for vertical orientation
|
// layout for vertical orientation
|
||||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
|
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
|
||||||
|
@ -370,7 +371,7 @@ public class ObjectSelect extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
Thread deleteobject = new Thread(new Runnable() {
|
Thread deleteObject = new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -440,7 +441,8 @@ public class ObjectSelect extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
deleteobject.start();
|
simpleProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
deleteObject.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
|
|
BIN
app/src/main/res/drawable/create_new.png
Normal file
BIN
app/src/main/res/drawable/create_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
|
@ -12,10 +12,13 @@
|
||||||
<string name="pending_feature">This feature is not implemented yet</string>
|
<string name="pending_feature">This feature is not implemented yet</string>
|
||||||
<string name="file_external">Open in</string>
|
<string name="file_external">Open in</string>
|
||||||
<string name="upload_tobucket">Upload to this bucket</string>
|
<string name="upload_tobucket">Upload to this bucket</string>
|
||||||
|
<string name="create_bucket">Create new bucket</string>
|
||||||
<string name="upload_here">Upload in current folder</string>
|
<string name="upload_here">Upload in current folder</string>
|
||||||
<string name="file_del">Delete</string>
|
<string name="file_del">Delete</string>
|
||||||
<string name="file_del_confirm">Do you want to delete this file?</string>
|
<string name="file_del_confirm">Do you want to delete this file?</string>
|
||||||
<string name="folder_del_confirm">Do you want to delete this folder?</string>
|
<string name="folder_del_confirm">Do you want to delete this folder?</string>
|
||||||
|
<string name="bucket_del_confirm">Do you want to delete this bucket?</string>
|
||||||
|
<string name="bucket_del_success">Bucket deleted successfully</string>
|
||||||
<string name="folder_del_success">Folder deleted successfully</string>
|
<string name="folder_del_success">Folder deleted successfully</string>
|
||||||
<string name="file_del_success">File deleted successfully</string>
|
<string name="file_del_success">File deleted successfully</string>
|
||||||
<string name="only_item_onlist">This is the only item on this folder, you should delete the parent folder instead</string>
|
<string name="only_item_onlist">This is the only item on this folder, you should delete the parent folder instead</string>
|
||||||
|
|
Loading…
Reference in a new issue