get filesize

This commit is contained in:
Page Asgardius 2022-09-21 11:43:18 -07:00
parent ac1858ba2b
commit 6729688096
2 changed files with 22 additions and 5 deletions

View file

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

View file

@ -16,6 +16,9 @@ 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;
@ -29,6 +32,9 @@ public class ObjectInfo extends AppCompatActivity {
ProgressBar simpleProgressBar;
TextView filesize, filesizeinfo;
boolean isobject, isfolder;
long totalSize = 0;
int totalItems = 0;
ListObjectsRequest orequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -64,6 +70,7 @@ public class ObjectInfo extends AppCompatActivity {
//Your code goes here
if (object == null) {
isobject = false;
orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(8000);
} else {
isobject = true;
if (object.endsWith("/")) {
@ -71,7 +78,16 @@ public class ObjectInfo extends AppCompatActivity {
} 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() {
@ -87,6 +103,7 @@ public class ObjectInfo extends AppCompatActivity {
} else {
filesizeinfo.setText(getResources().getString(R.string.bucket_size));
}
filesize.setText(Long.toString(totalSize));
simpleProgressBar.setVisibility(View.INVISIBLE);
}
});