bucketlist function

This commit is contained in:
Page Asgardius 2022-09-01 11:14:30 -07:00
parent f9a38c607d
commit 47509ffdf8
2 changed files with 51 additions and 27 deletions

View file

@ -33,7 +33,7 @@ public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder>{
public void onBindViewHolder(@NonNull Adapter.ViewHolder holder, int position) { public void onBindViewHolder(@NonNull Adapter.ViewHolder holder, int position) {
int res = (int) Img.get(position); int res = (int) Img.get(position);
holder.images.setImageResource(res); holder.images.setImageResource(res);
holder.text.setText((Integer) Name.get(position)); holder.text.setText((CharSequence) Name.get(position));
} }
@Override @Override
public int getItemCount() { public int getItemCount() {

View file

@ -3,6 +3,8 @@ package asgardius.page.s3manager;
import static com.amazonaws.regions.Regions.US_EAST_1; import static com.amazonaws.regions.Regions.US_EAST_1;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -21,6 +23,9 @@ import java.util.List;
public class BucketSelect extends AppCompatActivity { public class BucketSelect extends AppCompatActivity {
AmazonS3 s3client; AmazonS3 s3client;
ArrayList Name;
ArrayList Img;
RecyclerView recyclerView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -33,35 +38,54 @@ public class BucketSelect extends AppCompatActivity {
s3client = new AmazonS3Client(myCredentials, region); s3client = new AmazonS3Client(myCredentials, region);
s3client.setEndpoint(getResources().getString(R.string.endpoint_url)); s3client.setEndpoint(getResources().getString(R.string.endpoint_url));
s3client.setS3ClientOptions(s3ClientOptions); s3client.setS3ClientOptions(s3ClientOptions);
listbucket list = new listbucket();
list.execute("test");
}
private class listbucket extends AsyncTask<String, Void, String> { recyclerView = findViewById(R.id.recyclerview);
// layout for vertical orientation
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(linearLayoutManager);
Thread listbucket = new Thread(new Runnable() {
@Override @Override
protected String doInBackground(String[] params) { public void run() {
// do above Server call here try {
//This get bucket list //Your code goes here
List<Bucket> buckets = s3client.listBuckets(); List<Bucket> buckets = s3client.listBuckets();
//This convert bucket list to an array list //This convert bucket list to an array list
List<String> bucketList = new ArrayList<String>(); Name = new ArrayList<String>();
Img = new ArrayList<String>();
// Print bucket names // Print bucket names
//System.out.println("Buckets:"); //System.out.println("Buckets:");
int i=0; int i=0;
for (Bucket bucket : buckets) { for (Bucket bucket : buckets) {
//i++; //i++;
//System.out.println(bucket.getName()); //System.out.println(bucket.getName());
bucketList.add(bucket.getName()); Name.add(bucket.getName());
} //Img.add(R.drawable.ic_launcher_foreground);
System.out.println(bucketList); Img.add(R.drawable.ic_launcher_foreground);
//System.out.println(s3client.listBuckets().toArray());
return "some message";
} }
System.out.println(Name);
runOnUiThread(new Runnable() {
@Override @Override
protected void onPostExecute(String message) { public void run() {
//process message // Sending reference and data to Adapter
Adapter adapter = new Adapter(BucketSelect.this, Img, Name);
// Setting Adapter to RecyclerView
recyclerView.setAdapter(adapter);
} }
});
} catch (Exception e) {
e.printStackTrace();
}
}
});
listbucket.start();
//listbucket list = new listbucket();
//list.execute("test");
} }
} }