Folder navigation (#2)
This commit is contained in:
commit
feec49a755
4 changed files with 112 additions and 16 deletions
|
@ -28,7 +28,8 @@ public class BucketSelect extends AppCompatActivity {
|
|||
ArrayList Name;
|
||||
ArrayList Img;
|
||||
RecyclerView recyclerView;
|
||||
String username, password, endpoint;
|
||||
String username, password, endpoint, prefix;
|
||||
int treelevel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -36,6 +37,7 @@ public class BucketSelect extends AppCompatActivity {
|
|||
endpoint = getIntent().getStringExtra("endpoint");
|
||||
username = getIntent().getStringExtra("username");
|
||||
password = getIntent().getStringExtra("password");
|
||||
prefix = "";
|
||||
setContentView(R.layout.activity_bucket_select);
|
||||
Region region = Region.getRegion(US_EAST_1);
|
||||
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
|
||||
|
@ -118,10 +120,13 @@ public class BucketSelect extends AppCompatActivity {
|
|||
private void explorer(String bucket) {
|
||||
|
||||
Intent intent = new Intent(this, ObjectSelect.class);
|
||||
treelevel = 0;
|
||||
intent.putExtra("endpoint", endpoint);
|
||||
intent.putExtra("username", username);
|
||||
intent.putExtra("password", password);
|
||||
intent.putExtra("bucket", bucket);
|
||||
intent.putExtra("prefix", prefix);
|
||||
intent.putExtra("treelevel", treelevel);
|
||||
startActivity(intent);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ import com.amazonaws.services.s3.AmazonS3Client;
|
|||
import com.amazonaws.services.s3.S3ClientOptions;
|
||||
import com.amazonaws.services.s3.model.Bucket;
|
||||
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
|
||||
import com.amazonaws.services.s3.model.ListObjectsRequest;
|
||||
import com.amazonaws.services.s3.model.ListObjectsV2Request;
|
||||
import com.amazonaws.services.s3.model.ListObjectsV2Result;
|
||||
import com.amazonaws.services.s3.model.ObjectListing;
|
||||
import com.amazonaws.services.s3.model.S3Object;
|
||||
|
@ -26,14 +28,18 @@ import com.amazonaws.services.s3.model.S3ObjectSummary;
|
|||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ObjectSelect extends AppCompatActivity {
|
||||
|
||||
ArrayList Name;
|
||||
ArrayList Img;
|
||||
//ArrayList object;
|
||||
RecyclerView recyclerView;
|
||||
String username, password, endpoint, bucket;
|
||||
String username, password, endpoint, bucket, prefix;
|
||||
int treelevel;
|
||||
String[] filename, path;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -42,6 +48,8 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
username = getIntent().getStringExtra("username");
|
||||
password = getIntent().getStringExtra("password");
|
||||
bucket = getIntent().getStringExtra("bucket");
|
||||
prefix = getIntent().getStringExtra("prefix");
|
||||
treelevel = getIntent().getIntExtra("treelevel", 0);
|
||||
setContentView(R.layout.activity_object_select);
|
||||
Region region = Region.getRegion(US_EAST_1);
|
||||
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
|
||||
|
@ -62,29 +70,67 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
public void run() {
|
||||
try {
|
||||
//Your code goes here
|
||||
List<Bucket> buckets = s3client.listBuckets();
|
||||
//List<Bucket> buckets = s3client.listBuckets();
|
||||
ListObjectsRequest orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(prefix).withMaxKeys(2000);
|
||||
//List<S3Object> objects = (List<S3Object>) s3client.listObjects(bucket, "/");
|
||||
ListObjectsV2Result result = s3client.listObjectsV2(bucket, "/");
|
||||
ObjectListing result = s3client.listObjects(orequest);
|
||||
//System.out.println(objects);
|
||||
//This convert bucket list to an array list
|
||||
Name = new ArrayList<String>();
|
||||
Img = new ArrayList<String>();
|
||||
LinkedHashSet<String> object = new LinkedHashSet<String>();
|
||||
// Print bucket names
|
||||
//System.out.println("Buckets:");
|
||||
int i=0;
|
||||
//int i=0;
|
||||
List<S3ObjectSummary> objects = result.getObjectSummaries();
|
||||
for (S3ObjectSummary os : objects) {
|
||||
Name.add(os.getKey());
|
||||
if (os.getKey().endsWith(".opus") || os.getKey().endsWith(".ogg")
|
||||
|| os.getKey().endsWith(".oga") || os.getKey().endsWith(".mp3")
|
||||
|| os.getKey().endsWith(".m4a")) {
|
||||
boolean nextbatch = false;
|
||||
while (result.isTruncated() || !nextbatch) {
|
||||
if (nextbatch) {
|
||||
result = s3client.listNextBatchOfObjects (result);
|
||||
objects = result.getObjectSummaries();
|
||||
} else {
|
||||
nextbatch = true;
|
||||
}
|
||||
for (S3ObjectSummary os : objects) {
|
||||
filename = os.getKey().split("/");
|
||||
if (filename.length == treelevel+1) {
|
||||
object.add(filename[treelevel]);
|
||||
}
|
||||
else {
|
||||
object.add(filename[treelevel]+"/");
|
||||
}
|
||||
|
||||
//i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Name = new ArrayList<String>(object);
|
||||
object.clear();
|
||||
//Img.add(R.drawable.unknownfile);
|
||||
int i = 0;
|
||||
while(i<Name.size()) {
|
||||
//Img.add(R.drawable.unknownfile);
|
||||
if (Name.get(i).toString().endsWith("/")) {
|
||||
Img.add(R.drawable.folder);
|
||||
}
|
||||
else if (Name.get(i).toString().endsWith(".opus") || Name.get(i).toString().endsWith(".ogg")
|
||||
|| Name.get(i).toString().endsWith(".oga") || Name.get(i).toString().endsWith(".mp3")
|
||||
|| Name.get(i).toString().endsWith(".m4a") || Name.get(i).toString().endsWith(".flac")
|
||||
|| Name.get(i).toString().endsWith(".mka")) {
|
||||
Img.add(R.drawable.audiofile);
|
||||
}
|
||||
else {
|
||||
else if(Name.get(i).toString().endsWith(".mp4") || Name.get(i).toString().endsWith(".mkv")
|
||||
|| Name.get(i).toString().endsWith(".webm") || Name.get(i).toString().endsWith(".m4v")) {
|
||||
Img.add(R.drawable.videofile);
|
||||
}
|
||||
else {
|
||||
Img.add(R.drawable.unknownfile);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*for (Bucket bucket : buckets) {
|
||||
//i++;
|
||||
//System.out.println(bucket.getName());
|
||||
|
@ -105,6 +151,8 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
//System.out.println("tree "+treelevel);
|
||||
//System.out.println("prefix "+prefix);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -124,11 +172,18 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), recyclerView, new RecyclerTouchListener.ClickListener() {
|
||||
@Override
|
||||
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());
|
||||
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, Name.get(position).toString());
|
||||
URL objectURL = s3client.generatePresignedUrl(request);
|
||||
videoplayer(objectURL.toString());
|
||||
if (Img.get(position).equals(R.drawable.folder)) {
|
||||
//go to subfolder
|
||||
explorer(Name.get(position).toString());
|
||||
}
|
||||
else {
|
||||
//load media file
|
||||
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString());
|
||||
URL objectURL = s3client.generatePresignedUrl(request);
|
||||
videoplayer(objectURL.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,4 +200,40 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
private void explorer(String object) {
|
||||
|
||||
Intent intent = new Intent(this, ObjectSelect.class);
|
||||
//treelevel ++;
|
||||
intent.putExtra("endpoint", endpoint);
|
||||
intent.putExtra("username", username);
|
||||
intent.putExtra("password", password);
|
||||
intent.putExtra("bucket", bucket);
|
||||
intent.putExtra("prefix", prefix + object);
|
||||
intent.putExtra("treelevel", treelevel+1);
|
||||
startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
public void onBackPressed() {
|
||||
if (treelevel >= 2) {
|
||||
path = prefix.split("/");
|
||||
prefix = "";
|
||||
int i = 0;
|
||||
//System.out.println("path "+i);
|
||||
while(i <= path.length-2) {
|
||||
prefix = prefix.concat(path[i]);
|
||||
prefix = prefix.concat("/");
|
||||
//System.out.println("position "+i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else if (treelevel == 1) {
|
||||
prefix = "";
|
||||
}
|
||||
treelevel --;
|
||||
//System.out.println("tree "+treelevel);
|
||||
//System.out.println("prefix "+prefix);
|
||||
finish();
|
||||
}
|
||||
}
|
BIN
app/src/main/res/drawable/folder.png
Normal file
BIN
app/src/main/res/drawable/folder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
BIN
app/src/main/res/drawable/unknownfile.png
Normal file
BIN
app/src/main/res/drawable/unknownfile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
Loading…
Reference in a new issue