first step

This commit is contained in:
Page Asgardius 2022-12-30 10:24:42 -07:00
parent 881eadc957
commit 9c45c4aaf0
9 changed files with 72 additions and 18 deletions

View file

@ -164,7 +164,11 @@ 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());
upload(Name.get(position).toString(), false);
} else if (menuItem.getTitle() == getResources().getString(R.string.upload_folder_tobucket)) {
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
upload(Name.get(position).toString(), true);
} else if (menuItem.getTitle() == getResources().getString(R.string.download_bucket)) {
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
@ -298,7 +302,7 @@ public class BucketSelect extends AppCompatActivity {
dialog.show();
}
private void upload(String bucket) {
private void upload(String bucket, boolean isfolder) {
Intent intent = new Intent(this, Uploader.class);
intent.putExtra("endpoint", endpoint);
intent.putExtra("username", username);
@ -307,6 +311,7 @@ public class BucketSelect extends AppCompatActivity {
intent.putExtra("prefix", prefix);
intent.putExtra("region", location);
intent.putExtra("style", style);
intent.putExtra("isfolder", isfolder);
startActivity(intent);
}

View file

@ -395,7 +395,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.upload_file_here)) {
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
upload();
upload(false);
} else if (menuItem.getTitle() == getResources().getString(R.string.upload_folder_here)) {
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
upload(true);
} else if (menuItem.getTitle() == getResources().getString(R.string.download_folder)) {
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
download(Name.get(position).toString(), true);
@ -431,7 +434,10 @@ public class ObjectSelect extends AppCompatActivity {
download(Name.get(position).toString(), false);
} 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();
upload(false);
} else if (menuItem.getTitle() == getResources().getString(R.string.upload_folder_here)) {
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
upload(true);
} else if (menuItem.getTitle() == getResources().getString(R.string.create_link)) {
share(prefix + Name.get(position).toString(), Name.get(position).toString(), Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile));
} else if (menuItem.getTitle() == getResources().getString(R.string.object_info)) {
@ -645,7 +651,7 @@ public class ObjectSelect extends AppCompatActivity {
dialog.show();
}
private void upload() {
private void upload(boolean isfolder) {
Intent intent = new Intent(this, Uploader.class);
intent.putExtra("endpoint", endpoint);
intent.putExtra("username", username);
@ -654,6 +660,7 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("prefix", prefix);
intent.putExtra("region", location);
intent.putExtra("style", style);
intent.putExtra("isfolder", isfolder);
startActivity(intent);
}

View file

@ -19,6 +19,7 @@ import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.amazonaws.auth.AWSCredentials;
@ -49,6 +50,7 @@ public class Uploader extends AppCompatActivity {
int progress;
Uri fileuri, folder;
EditText fprefix;
TextView fprefixlabel;
Region region;
S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials;
@ -59,7 +61,7 @@ public class Uploader extends AppCompatActivity {
Intent intent;
Button fileUpload;
Thread uploadFile, uploadProgress;
boolean style;
boolean style, isfolder;
boolean started = false;
long transfered = 0;
private static final long MAX_SINGLE_PART_UPLOAD_BYTES = 5 * 1024 * 1024;
@ -81,8 +83,10 @@ public class Uploader extends AppCompatActivity {
bucket = getIntent().getStringExtra("bucket");
location = getIntent().getStringExtra("region");
style = getIntent().getBooleanExtra("style", false);
isfolder = getIntent().getBooleanExtra("isfolder", false);
prefix = getIntent().getStringExtra("prefix");
fprefix = (EditText)findViewById(R.id.fprefix);
fprefixlabel = (TextView) findViewById(R.id.fprefixlabel);
region = Region.getRegion(location);
s3ClientOptions = S3ClientOptions.builder().build();
s3ClientOptions.setPathStyleAccess(style);
@ -133,11 +137,15 @@ public class Uploader extends AppCompatActivity {
//Your code goes here
//s3client.createBucket(bucket, location);
//System.out.println(fkey);
if (isfolder) {
//Nothing for now
} else {
ufile = readContentToFile(fileuri);
filesize = ufile.length();
//PutObjectRequest request = new PutObjectRequest(bucket, fkey, ufile);
//upload = s3client.putObject(request);
putS3Object(bucket, fprefix.getText().toString(), ufile);
}
runOnUiThread(new Runnable() {
@Override
@ -153,7 +161,11 @@ public class Uploader extends AppCompatActivity {
}
simpleProgressBar.setProgress(100);
//simpleProgressBar.setVisibility(View.INVISIBLE);
if (isfolder) {
fileUpload.setText(getResources().getString(R.string.batch_upload_success));
} else {
fileUpload.setText(getResources().getString(R.string.upload_success));
}
started = false;
fileUpload.setEnabled(false);
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.upload_success), Toast.LENGTH_SHORT).show();
@ -253,11 +265,15 @@ public class Uploader extends AppCompatActivity {
private void performFileSearch(String messageTitle) {
//uri = Uri.parse("content://com.android.externalstorage.documents/document/home");
intent = new Intent();
if (isfolder) {
intent.setAction(Intent.ACTION_OPEN_DOCUMENT_TREE);
} else {
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
//intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
//intent.putExtra("android.provider.extra.INITIAL_URI", uri);
intent.setType("*/*");
}
((Activity) this).startActivityForResult(intent, 100);
}
@ -276,7 +292,14 @@ public class Uploader extends AppCompatActivity {
if (resultData != null && resultData.getData() != null) {
fileuri = resultData.getData();
System.out.println(fileuri.toString());
if (isfolder) {
fprefix.setText(prefix);
fprefix.setHint(getResources().getString(R.string.upload_prefix));
fprefixlabel.setText(getResources().getString(R.string.upload_prefix));
fileUpload.setText(getResources().getString(R.string.batch_upload_button));
} else {
fprefix.setText(prefix+getDisplayName(fileuri));
}
//System.out.println("File selected successfully");
//System.out.println("content://com.android.externalstorage.documents"+file.getPath());
} else {

View file

@ -17,6 +17,7 @@
android:orientation="vertical">
<TextView
android:id="@+id/fprefixlabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/upload_key"

View file

@ -5,6 +5,10 @@
android:id="@+id/upload_file"
android:title="@string/upload_file_tobucket" />
<item
android:id="@+id/upload_folder"
android:title="@string/upload_folder_tobucket" />
<item
android:id="@+id/download_bucket"
android:title="@string/download_bucket" />

View file

@ -5,6 +5,10 @@
android:id="@+id/upload_file"
android:title="@string/upload_file_here" />
<item
android:id="@+id/upload_folder"
android:title="@string/upload_folder_here" />
<item
android:id="@+id/download_folder"
android:title="@string/download_folder" />

View file

@ -5,6 +5,10 @@
android:id="@+id/upload_file"
android:title="@string/upload_file_here" />
<item
android:id="@+id/upload_folder"
android:title="@string/upload_folder_here" />
<item
android:id="@+id/download_file"
android:title="@string/download_file" />

View file

@ -18,9 +18,12 @@
<string name="feature_not_supported">Su dispositivo no es compatible con esta característica</string>
<string name="file_path_fail">No se encuentra el uri del archivo</string>
<string name="upload_button">Subir archivo</string>
<string name="batch_upload_button">Subir archivos</string>
<string name="upload_key">Nombre del objeto</string>
<string name="upload_prefix">Prefijo de los objetos</string>
<string name="no_file_selected">Favor de seleccionar un archivo</string>
<string name="upload_success">Archivo subido exitosamente</string>
<string name="batch_upload_success">Archivos subidos exitosamente</string>
<string name="cancel_upload">Cancelar subida</string>
<string name="retry">Reintentar</string>
<string name="download_failed">Descarga fallida</string>

View file

@ -34,9 +34,12 @@
<string name="feature_not_supported">Your device is not compatible with this feature</string>
<string name="file_path_fail">File uri not found</string>
<string name="upload_button">Upload file</string>
<string name="batch_upload_button">Upload files</string>
<string name="upload_key">Object name</string>
<string name="upload_prefix">Object prefix</string>
<string name="no_file_selected">Please select a file</string>
<string name="upload_success">File uploaded successfully</string>
<string name="batch_upload_success">Files uploaded successfully</string>
<string name="cancel_upload">Cancel Upload</string>
<string name="retry">Retry</string>
<string name="download_failed">Download failed</string>