Merge pull request 'object info' (#6) from objectinfo into main

Reviewed-on: https://patrice.asgardius.company/gitea/asgardius/s3manager/pulls/6
This commit is contained in:
Page Asgardius 2022-09-22 09:57:05 -07:00
commit c83f48ec3e
15 changed files with 317 additions and 44 deletions

View file

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/4.7_WXGA_API_24.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-09-17T22:23:51.793318Z" />
</component>
</project>

View file

@ -19,10 +19,12 @@ Current feature list
* File upload
* File download
* pdf file reader using user provided pdf.js server
* file sharing links
* get object info
* get bucket info
Planned feature list
* file sharing links
* better interface for uploads and downloads
This app is a work in progress, so it have some bugs that need to be fixed

View file

@ -9,8 +9,8 @@ android {
applicationId "asgardius.page.s3manager"
minSdk 24
targetSdk 33
versionCode 14
versionName "0.1.12"
versionCode 15
versionName "0.1.13"
setProperty("archivesBaseName", "s3-manager-$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -19,6 +19,14 @@
android:supportsRtl="true"
android:theme="@style/Theme.AsgardiusS3Manager"
tools:targetApi="31">
<activity
android:name=".ObjectInfo"
android:configChanges="orientation|keyboardHidden|screenSize|uiMode|keyboardHidden"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".Share"
android:exported="false" />

View file

@ -165,6 +165,8 @@ public class BucketSelect extends AppCompatActivity {
//System.out.println(file);
//Toast.makeText(BucketSelect.this, intent.getData().toString(), Toast.LENGTH_SHORT).show();
} else if (menuItem.getTitle() == getResources().getString(R.string.object_info)) {
objectInfo(Name.get(position).toString());
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
delete(prefix + Name.get(position).toString());
@ -288,6 +290,19 @@ public class BucketSelect extends AppCompatActivity {
startActivity(intent);
}
private void objectInfo(String bucket) {
Intent intent = new Intent(this, ObjectInfo.class);
//treelevel ++;
intent.putExtra("endpoint", endpoint);
intent.putExtra("username", username);
intent.putExtra("password", password);
intent.putExtra("bucket", bucket);
intent.putExtra("region", location);
startActivity(intent);
}
private void newBucket() {
Intent intent = new Intent(this, CreateBucket.class);
intent.putExtra("endpoint", endpoint);

View file

@ -0,0 +1,147 @@
package asgardius.page.s3manager;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
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 com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import java.util.ArrayList;
import java.util.List;
public class ObjectInfo extends AppCompatActivity {
String username, password, endpoint, bucket, object, location;
Region region;
S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials;
AmazonS3 s3client;
ProgressBar simpleProgressBar;
TextView filesize, filesizeinfo, objectcount;
boolean isobject, isfolder;
long totalSize = 0;
int totalItems = 0;
ListObjectsRequest orequest;
long KiB, MiB, GiB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_object_info);
KiB = 1024;
MiB = 1024 * KiB;
GiB = 1024 * MiB;
simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
filesize = (TextView) findViewById(R.id.size);
filesizeinfo = (TextView) findViewById(R.id.size_info);
objectcount = (TextView) findViewById(R.id.object_count);
endpoint = getIntent().getStringExtra("endpoint");
username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password");
bucket = getIntent().getStringExtra("bucket");
location = getIntent().getStringExtra("region");
object = getIntent().getStringExtra("object");
if (object == null) {
getSupportActionBar().setTitle(bucket+"/");
} else {
getSupportActionBar().setTitle(bucket+"/"+object);
}
region = Region.getRegion(location);
s3ClientOptions = S3ClientOptions.builder().build();
myCredentials = new BasicAWSCredentials(username, password);
try {
s3client = new AmazonS3Client(myCredentials, region);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
}
s3client.setEndpoint(endpoint);
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
s3ClientOptions.setPathStyleAccess(true);
}
s3client.setS3ClientOptions(s3ClientOptions);
Thread getInfo = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
if (object == null) {
isobject = false;
orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(8000);
} else {
isobject = true;
if (object.endsWith("/")) {
isfolder = true;
} else {
isfolder = false;
}
orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(object).withMaxKeys(8000);
}
ObjectListing result = s3client.listObjects(orequest);
do {
for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
totalSize += objectSummary.getSize();
totalItems++;
}
result = s3client.listNextBatchOfObjects (result);
} while (result.isTruncated());
runOnUiThread(new Runnable() {
@Override
public void run() {
if (isobject) {
if (isfolder) {
filesizeinfo.setText(getResources().getString(R.string.folder_size));
objectcount.setText(totalItems+" "+getResources().getString(R.string.file_count));
} else {
filesizeinfo.setText(getResources().getString(R.string.file_size));
}
} else {
filesizeinfo.setText(getResources().getString(R.string.bucket_size));
objectcount.setText(totalItems+" "+getResources().getString(R.string.file_count));
}
if (totalSize >= GiB) {
filesize.setText(Long.toString(totalSize/GiB)+" GiB");
} else if (totalSize >= MiB) {
filesize.setText(Long.toString(totalSize/MiB)+" MiB");
} else if (totalSize >= KiB) {
filesize.setText(Long.toString(totalSize/KiB)+" KiB");
} else {
filesize.setText(Long.toString(totalSize)+" Bytes");
}
simpleProgressBar.setVisibility(View.INVISIBLE);
}
});
} 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();
}
}
});
getInfo.start();
}
}

View file

@ -306,6 +306,8 @@ public class ObjectSelect extends AppCompatActivity {
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();
} else if (menuItem.getTitle() == getResources().getString(R.string.object_info)) {
objectInfo(prefix + Name.get(position).toString());
} 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();
@ -335,8 +337,10 @@ public class ObjectSelect extends AppCompatActivity {
} 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();
} else if (menuItem.getTitle() == getResources().getString(R.string.file_share)) {
} else if (menuItem.getTitle() == getResources().getString(R.string.create_link)) {
share(prefix + Name.get(position).toString());
} else if (menuItem.getTitle() == getResources().getString(R.string.object_info)) {
objectInfo(prefix + Name.get(position).toString());
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
if (Name.size() == 1 && treelevel >= 1) {
@ -418,6 +422,20 @@ public class ObjectSelect extends AppCompatActivity {
}
private void objectInfo(String object) {
Intent intent = new Intent(this, ObjectInfo.class);
//treelevel ++;
intent.putExtra("endpoint", endpoint);
intent.putExtra("username", username);
intent.putExtra("password", password);
intent.putExtra("bucket", bucket);
intent.putExtra("object", object);
intent.putExtra("region", location);
startActivity(intent);
}
private void delete(String object, boolean folder) {
AlertDialog.Builder builder = new AlertDialog.Builder(ObjectSelect.this);
builder.setCancelable(true);

View file

@ -31,7 +31,7 @@ public class Share extends AppCompatActivity {
Calendar mycal;
EditText datepick, monthpick, yearpick, hourpick, minutepick;
int date, month, year, hour, minute;
Button share;
Button share, external;
public static String URLify(String str) {
str = str.trim();
@ -73,6 +73,7 @@ public class Share extends AppCompatActivity {
hourpick = (EditText)findViewById(R.id.Hour);
minutepick = (EditText)findViewById(R.id.Minute);
share = (Button)findViewById(R.id.share);
external = (Button)findViewById(R.id.open_in);
endpoint = getIntent().getStringExtra("endpoint");
username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password");
@ -97,6 +98,11 @@ public class Share extends AppCompatActivity {
public void onClick(View view) {
//buttonaction
try {
if (datepick.getText().toString().equals("") || monthpick.getText().toString().equals("") ||
yearpick.getText().toString().equals("") || hourpick.getText().toString().equals("") ||
minutepick.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.null_expiration_date), Toast.LENGTH_SHORT).show();
} else {
date = Integer.parseInt(datepick.getText().toString());
month = Integer.parseInt(monthpick.getText().toString());
year = Integer.parseInt(yearpick.getText().toString());
@ -117,6 +123,25 @@ public class Share extends AppCompatActivity {
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, URLify(objectURL.toString()));
startActivity(Intent.createChooser(shareIntent, "choose one"));
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.invalid_expiration_date), Toast.LENGTH_SHORT).show();
}
}
});
external.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
try {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, object);
URL objectURL = s3client.generatePresignedUrl(request);
//System.out.println(URLify(objectURL.toString()));
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, URLify(objectURL.toString()));
startActivity(Intent.createChooser(shareIntent, "choose one"));
} catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.invalid_expiration_date), Toast.LENGTH_SHORT).show();
}

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ObjectInfo">
<TextView
android:id="@+id/size_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="25sp" />
<TextView
android:id="@+id/size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="25sp" />
<TextView
android:id="@+id/object_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="25sp" />
<ProgressBar
android:id="@+id/simpleProgressBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:max="100"
android:progress="50"
android:padding="20dp"
tools:ignore="MissingConstraints"
android:indeterminate="true" />
</LinearLayout>

View file

@ -112,7 +112,15 @@
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/create_link"
android:text="@string/file_share"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/open_in"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/file_external"
tools:ignore="MissingConstraints" />
</LinearLayout>

View file

@ -9,6 +9,10 @@
android:id="@+id/newbucket"
android:title="@string/create_bucket" />
<item
android:id="@+id/info"
android:title="@string/object_info" />
<item
android:id="@+id/deletefolder"
android:title="@string/file_del" />

View file

@ -5,6 +5,10 @@
android:id="@+id/upload_file"
android:title="@string/upload_file_here" />
<item
android:id="@+id/info"
android:title="@string/object_info" />
<item
android:id="@+id/deletefolder"
android:title="@string/file_del" />

View file

@ -11,7 +11,11 @@
<item
android:id="@+id/sharefile"
android:title="@string/file_share" />
android:title="@string/create_link" />
<item
android:id="@+id/info"
android:title="@string/object_info" />
<item
android:id="@+id/deletefile"

View file

@ -77,4 +77,11 @@
<string name="expiration_time">Hora de expiración</string>
<string name="create_link">Crear enlace al archivo</string>
<string name="invalid_expiration_date">La fecha de caducidad debe ser inferior a 7 días</string>
<string name="file_size">Tamaño del archivo</string>
<string name="object_info">Propiedades</string>
<string name="file_external">Abir en</string>
<string name="folder_size">Tamaño de la carpeta</string>
<string name="bucket_size">Tamaño del bucket</string>
<string name="file_count">Archivos</string>
<string name="null_expiration_date">Debe establecer una fecha de expiración para compartir archivos</string>
</resources>

View file

@ -18,12 +18,14 @@
<string name="share_year">YYYY</string>
<string name="create_link">Create file link</string>
<string name="invalid_expiration_date">Expiration date must be at most 7 days</string>
<string name="null_expiration_date">You must set an expiration date to share files</string>
<string name="broken_database">Local database is corrupted. Please reinstall this app</string>
<string name="pending_feature">This feature is not implemented yet</string>
<string name="set_bucket_name">Set new bucket name</string>
<string name="bucket_name">Bucket name</string>
<string name="bucket_name_empty">A bucket name is required</string>
<string name="file_share">Share file</string>
<string name="file_external">Open in</string>
<string name="download_file">Download file</string>
<string name="download_in_progress">Download in progress</string>
<string name="download_success">File downloaded successfully</string>
@ -39,6 +41,11 @@
<string name="retry">Retry</string>
<string name="download_failed">Download failed</string>
<string name="success">Success</string>
<string name="object_info">Properties</string>
<string name="file_size">File Size</string>
<string name="folder_size">Folder Size</string>
<string name="bucket_size">Bucket Size</string>
<string name="file_count">Files</string>
<string name="create_bucket">Create new bucket</string>
<string name="create_bucket_success">Bucket created successfully</string>
<string name="upload_file_here">Upload file in current folder</string>