downloader working
This commit is contained in:
parent
17731813e3
commit
bd5d3fc741
7 changed files with 27 additions and 33 deletions
|
@ -20,6 +20,7 @@
|
|||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".Downloader"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|uiMode|keyboardHidden"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".CreateBucket"
|
||||
|
|
|
@ -156,7 +156,7 @@ public class BucketSelect extends AppCompatActivity {
|
|||
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), 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);
|
||||
upload(Name.get(position).toString());
|
||||
|
||||
} else if (menuItem.getTitle() == getResources().getString(R.string.create_bucket)) {
|
||||
//upload();
|
||||
|
@ -275,7 +275,7 @@ public class BucketSelect extends AppCompatActivity {
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
private void upload(String bucket, boolean isfolder) {
|
||||
private void upload(String bucket) {
|
||||
Intent intent = new Intent(this, Uploader.class);
|
||||
intent.putExtra("endpoint", endpoint);
|
||||
intent.putExtra("username", username);
|
||||
|
@ -283,7 +283,6 @@ public class BucketSelect extends AppCompatActivity {
|
|||
intent.putExtra("bucket", bucket);
|
||||
intent.putExtra("prefix", prefix);
|
||||
intent.putExtra("region", location);
|
||||
intent.putExtra("isfolder", isfolder);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ 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.S3Object;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -50,19 +51,21 @@ public class Downloader extends AppCompatActivity {
|
|||
Intent intent;
|
||||
Button fileDownload;
|
||||
Thread downloadFile;
|
||||
DownloadManager downloadManager;
|
||||
S3Object object;
|
||||
InputStream in;
|
||||
OutputStream out;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_downloader);
|
||||
filekey = getIntent().getStringExtra("file_url");
|
||||
filename = getIntent().getStringExtra("file_name");
|
||||
filename = getIntent().getStringExtra("filename");
|
||||
endpoint = getIntent().getStringExtra("endpoint");
|
||||
username = getIntent().getStringExtra("username");
|
||||
password = getIntent().getStringExtra("password");
|
||||
bucket = getIntent().getStringExtra("bucket");
|
||||
location = getIntent().getStringExtra("region");
|
||||
prefix = getIntent().getStringExtra("prefix");
|
||||
simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
|
||||
fileDownload = (Button)findViewById(R.id.filedownload);
|
||||
region = Region.getRegion(location);
|
||||
|
@ -80,6 +83,7 @@ public class Downloader extends AppCompatActivity {
|
|||
public void onClick(View view) {
|
||||
//buttonaction
|
||||
simpleProgressBar.setVisibility(View.VISIBLE);
|
||||
fileDownload.setEnabled(false);
|
||||
fileDownload.setText(getResources().getString(R.string.download_in_progress));
|
||||
downloadFile = new Thread(new Runnable() {
|
||||
|
||||
|
@ -90,13 +94,15 @@ public class Downloader extends AppCompatActivity {
|
|||
//Your code goes here
|
||||
//s3client.createBucket(bucket, location);
|
||||
//System.out.println(fkey);
|
||||
object = s3client.getObject(bucket, prefix+filename);
|
||||
writeContentToFile(fileuri);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//simpleProgressBar.setProgress(100);
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
fileDownload.setText(getResources().getString(R.string.download_success));
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.upload_success), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.download_success), Toast.LENGTH_SHORT).show();
|
||||
//simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
|
@ -110,7 +116,7 @@ public class Downloader extends AppCompatActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
fileDownload.setText(getResources().getString(R.string.retry));
|
||||
fileDownload.setText(getResources().getString(R.string.download_failed));
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
@ -164,17 +170,15 @@ public class Downloader extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private File writeContentToFile(Uri uri) throws IOException {
|
||||
final File file = new File(getCacheDir(), getDisplayName(uri));
|
||||
private void writeContentToFile(Uri uri) throws IOException {
|
||||
try (
|
||||
final InputStream in = new FileInputStream(file);
|
||||
final InputStream in = object.getObjectContent();
|
||||
final OutputStream out = getContentResolver().openOutputStream(uri);
|
||||
) {
|
||||
byte[] buffer = new byte[1024];
|
||||
for (int len; (len = in.read(buffer)) != -1; ) {
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
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(false);
|
||||
upload();
|
||||
} 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();
|
||||
|
@ -275,12 +275,10 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
if (menuItem.getTitle() == getResources().getString(R.string.download_file)) {
|
||||
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||
//GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString());
|
||||
//URL objectURL = s3client.generatePresignedUrl(request);
|
||||
//download(objectURL.toString(), Name.get(position).toString());
|
||||
download(Name.get(position).toString());
|
||||
} else 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(false);
|
||||
upload();
|
||||
} else if (menuItem.getTitle() == getResources().getString(R.string.file_external)) {
|
||||
try {
|
||||
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString());
|
||||
|
@ -464,7 +462,7 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
private void upload(boolean isfolder) {
|
||||
private void upload() {
|
||||
Intent intent = new Intent(this, Uploader.class);
|
||||
intent.putExtra("endpoint", endpoint);
|
||||
intent.putExtra("username", username);
|
||||
|
@ -472,18 +470,17 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
intent.putExtra("bucket", bucket);
|
||||
intent.putExtra("prefix", prefix);
|
||||
intent.putExtra("region", location);
|
||||
intent.putExtra("isfolder", isfolder);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void download(String url, String filename) {
|
||||
private void download(String filename) {
|
||||
|
||||
Intent intent = new Intent(this, Downloader.class);
|
||||
intent.putExtra("file_url", url);
|
||||
intent.putExtra("file_name", filename);
|
||||
intent.putExtra("filename", filename);
|
||||
intent.putExtra("endpoint", endpoint);
|
||||
intent.putExtra("username", username);
|
||||
intent.putExtra("password", password);
|
||||
intent.putExtra("prefix", prefix);
|
||||
intent.putExtra("region", location);
|
||||
intent.putExtra("bucket", bucket);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -43,9 +43,8 @@ import java.util.List;
|
|||
|
||||
public class Uploader extends AppCompatActivity {
|
||||
String username, password, endpoint, bucket, prefix, location, fkey;
|
||||
//boolean isfolder;
|
||||
int progress;
|
||||
Uri fileuri, folder, uri;
|
||||
Uri fileuri, folder;
|
||||
EditText fprefix;
|
||||
Region region;
|
||||
S3ClientOptions s3ClientOptions;
|
||||
|
@ -56,6 +55,7 @@ public class Uploader extends AppCompatActivity {
|
|||
File ufile;
|
||||
Intent intent;
|
||||
Button fileUpload;
|
||||
Thread uploadFile;
|
||||
private static final long MAX_SINGLE_PART_UPLOAD_BYTES = 5 * 1024 * 1024;
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +68,6 @@ public class Uploader extends AppCompatActivity {
|
|||
bucket = getIntent().getStringExtra("bucket");
|
||||
location = getIntent().getStringExtra("region");
|
||||
prefix = getIntent().getStringExtra("prefix");
|
||||
//isfolder = getIntent().getBooleanExtra("isfolder", false);
|
||||
fprefix = (EditText)findViewById(R.id.fprefix);
|
||||
region = Region.getRegion(location);
|
||||
s3ClientOptions = S3ClientOptions.builder().build();
|
||||
|
@ -101,7 +100,7 @@ public class Uploader extends AppCompatActivity {
|
|||
simpleProgressBar.setVisibility(View.VISIBLE);
|
||||
fileUpload.setEnabled(false);
|
||||
fileUpload.setText(getResources().getString(R.string.upload_in_progress));
|
||||
Thread uploadFile = new Thread(new Runnable() {
|
||||
uploadFile = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -7,13 +7,6 @@
|
|||
android:orientation="vertical"
|
||||
tools:context=".Downloader">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/download_indicator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:textSize="25sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
<string name="upload_success">File uploaded successfully</string>
|
||||
<string name="upload_in_progress">Upload in progress</string>
|
||||
<string name="retry">Retry</string>
|
||||
<string name="download_failed">Download failed</string>
|
||||
<string name="success">Success</string>
|
||||
<string name="create_bucket">Create new bucket</string>
|
||||
<string name="create_bucket_success">Bucket created successfully</string>
|
||||
|
|
Loading…
Reference in a new issue