diff --git a/.idea/misc.xml b/.idea/misc.xml index c42851f..df97170 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -6,6 +6,7 @@ + diff --git a/app/src/main/java/asgardius/page/s3manager/BucketSelect.java b/app/src/main/java/asgardius/page/s3manager/BucketSelect.java index 47c903a..4d50590 100644 --- a/app/src/main/java/asgardius/page/s3manager/BucketSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/BucketSelect.java @@ -25,7 +25,6 @@ import java.util.List; public class BucketSelect extends AppCompatActivity { - AmazonS3 s3client; ArrayList Name; ArrayList Img; RecyclerView recyclerView; @@ -46,7 +45,7 @@ public class BucketSelect extends AppCompatActivity { s3client.setEndpoint(endpoint); s3client.setS3ClientOptions(s3ClientOptions); - recyclerView = findViewById(R.id.recyclerview); + recyclerView = findViewById(R.id.blist); // layout for vertical orientation LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext()); @@ -106,22 +105,24 @@ public class BucketSelect extends AppCompatActivity { recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), recyclerView, new RecyclerTouchListener.ClickListener() { @Override public void onClick(View view, int position) { - System.out.println("Click on "+Integer.toString(position)); + System.out.println("Click on "+Name.get(position).toString()); + explorer(Name.get(position).toString()); } @Override public void onLongClick(View view, int position) { - System.out.println("Long click on "+Integer.toString(position)); + System.out.println("Long click on "+Name.get(position).toString()); } })); } - private void explorer() { + private void explorer(String bucket) { - Intent intent = new Intent(this, BucketSelect.class); + Intent intent = new Intent(this, ObjectSelect.class); intent.putExtra("endpoint", endpoint); intent.putExtra("username", username); intent.putExtra("password", password); + intent.putExtra("bucket", bucket); startActivity(intent); } diff --git a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java index 9a7c451..73669f3 100644 --- a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java @@ -1,14 +1,114 @@ package asgardius.page.s3manager; +import static com.amazonaws.regions.Regions.US_EAST_1; + import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.os.Bundle; +import android.view.View; +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 com.amazonaws.services.s3.model.Bucket; + +import java.util.ArrayList; +import java.util.List; public class ObjectSelect extends AppCompatActivity { + ArrayList Name; + ArrayList Img; + RecyclerView recyclerView; + String username, password, endpoint, bucket; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + endpoint = getIntent().getStringExtra("endpoint"); + username = getIntent().getStringExtra("username"); + password = getIntent().getStringExtra("password"); + bucket = getIntent().getStringExtra("bucket"); setContentView(R.layout.activity_object_select); + Region region = Region.getRegion(US_EAST_1); + S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build(); + s3ClientOptions.setPathStyleAccess(true); + AWSCredentials myCredentials = new BasicAWSCredentials(username, password); + AmazonS3 s3client = new AmazonS3Client(myCredentials, region); + s3client.setEndpoint(endpoint); + s3client.setS3ClientOptions(s3ClientOptions); + + recyclerView = findViewById(R.id.olist); + + // layout for vertical orientation + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext()); + recyclerView.setLayoutManager(linearLayoutManager); + Thread listobject = new Thread(new Runnable() { + + @Override + public void run() { + try { + //Your code goes here + List buckets = s3client.listBuckets(); + //This convert bucket list to an array list + Name = new ArrayList(); + Img = new ArrayList(); + // Print bucket names + //System.out.println("Buckets:"); + int i=0; + for (Bucket bucket : buckets) { + //i++; + //System.out.println(bucket.getName()); + Name.add(bucket.getName()); + //Img.add(R.drawable.ic_launcher_foreground); + Img.add(R.drawable.bucket); + } + System.out.println(Name); + + runOnUiThread(new Runnable() { + + @Override + public void run() { + // Sending reference and data to Adapter + Adapter adapter = new Adapter(ObjectSelect.this, Img, Name); + + // Setting Adapter to RecyclerView + recyclerView.setAdapter(adapter); + } + }); + + } 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(); + } + } + }); + listobject.start(); + 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()); + //explorer(Name.get(position).toString()); + } + + @Override + public void onLongClick(View view, int position) { + System.out.println("Long click on "+Name.get(position).toString()); + } + })); } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_bucket_select.xml b/app/src/main/res/layout/activity_bucket_select.xml index 09b7ddd..b4d2780 100644 --- a/app/src/main/res/layout/activity_bucket_select.xml +++ b/app/src/main/res/layout/activity_bucket_select.xml @@ -7,7 +7,7 @@ tools:context=".BucketSelect"> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c116b3..e73d315 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,11 +2,11 @@ Asgardius S3 Manager VideoPlayer - s3server - username - password - bucket - object + https://object.asgardius.company + asgardius + DTMp5kftamr49Ke7 + asgardiustest + peces felices.mp4 File Explorer Test Video Test Cannot load media file