new release

This commit is contained in:
Page Asgardius 2023-01-22 07:16:09 -07:00
parent 0fe7f7a79b
commit 81693d37db
7 changed files with 146 additions and 50 deletions

View file

@ -9,8 +9,8 @@ android {
applicationId "asgardius.page.s3manager"
minSdk 23
targetSdk 33
versionCode 69
versionName "0.7.7"
versionCode 70
versionName "0.8.0"
setProperty("archivesBaseName", "s3-manager-$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -61,7 +61,7 @@ public class BucketPolicy extends AppCompatActivity {
try {
//Your code goes here
String policy = s3client.getBucketPolicy(bucket).getPolicyText();
System.out.println(policy);
//System.out.println(policy);
runOnUiThread(new Runnable() {

View file

@ -13,6 +13,8 @@ import android.os.Bundle;
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;
@ -34,7 +36,9 @@ import java.util.List;
public class Share extends AppCompatActivity {
String username, password, endpoint, bucket, object, location, title, objectlist;
boolean mediafile, style;
boolean mediafile, style, publicbucket;
TextView expirationtext;
ProgressBar simpleProgressBar;
Region region;
S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials;
@ -84,6 +88,8 @@ public class Share extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share);
simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
expirationtext = (TextView) findViewById(R.id.expirationtext);
mycal = Calendar.getInstance();
datepick = (EditText)findViewById(R.id.Date);
hourpick = (EditText)findViewById(R.id.Hour);
@ -114,13 +120,68 @@ public class Share extends AppCompatActivity {
s3client.setEndpoint(endpoint);
s3ClientOptions.setPathStyleAccess(style);
s3client.setS3ClientOptions(s3ClientOptions);
if(object == null || object.endsWith("/")) {
copylinks.setVisibility(View.VISIBLE);
savelinks.setVisibility(View.VISIBLE);
} else {
share.setVisibility(View.VISIBLE);
copylinks.setVisibility(View.VISIBLE);
}
Thread getPolicy = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
String policy = s3client.getBucketPolicy(bucket).getPolicyText();
//System.out.println(policy);
runOnUiThread(new Runnable() {
@Override
public void run() {
//Your code goes here
if(policy.contains("\"Resource\":[\"arn:aws:s3:::"+bucket+"/*")){
publicbucket = true;
expirationtext.setText(getResources().getString(R.string.expiration_not_required));
} else {
publicbucket = false;
datepick.setEnabled(true);
hourpick.setEnabled(true);
minutepick.setEnabled(true);
expirationtext.setText(getResources().getString(R.string.expiration_time));
}
if(object == null || object.endsWith("/")) {
copylinks.setVisibility(View.VISIBLE);
savelinks.setVisibility(View.VISIBLE);
} else {
share.setVisibility(View.VISIBLE);
copylinks.setVisibility(View.VISIBLE);
}
simpleProgressBar.setVisibility(View.INVISIBLE);
}
});
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
publicbucket = false;
datepick.setEnabled(true);
hourpick.setEnabled(true);
minutepick.setEnabled(true);
expirationtext.setText(getResources().getString(R.string.expiration_time));
if(object == null || object.endsWith("/")) {
copylinks.setVisibility(View.VISIBLE);
savelinks.setVisibility(View.VISIBLE);
} else {
share.setVisibility(View.VISIBLE);
copylinks.setVisibility(View.VISIBLE);
}
simpleProgressBar.setVisibility(View.INVISIBLE);
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
}
}
});
getPolicy.start();
share.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
@ -142,6 +203,9 @@ public class Share extends AppCompatActivity {
@Override
public void onClick(View view) {
//buttonaction
if(object == null || object.endsWith("/")) {
simpleProgressBar.setVisibility(View.VISIBLE);
}
Thread copyLinks = new Thread(new Runnable() {
@Override
@ -155,6 +219,7 @@ public class Share extends AppCompatActivity {
@Override
public void run() {
// Sending reference and data to Adapter
simpleProgressBar.setVisibility(View.INVISIBLE);
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip;
clip = ClipData.newPlainText("name", objectlist);
@ -289,58 +354,71 @@ public class Share extends AppCompatActivity {
objectlist = "";
List<S3ObjectSummary> objects = result.getObjectSummaries();
for (S3ObjectSummary os : objects) {
request = new GeneratePresignedUrlRequest(bucket, os.getKey()).withExpiration(expiration);
objectlist = objectlist+s3client.generatePresignedUrl(request).toString()+"\n";
if(publicbucket) {
objectlist = objectlist+s3client.getUrl(bucket, os.getKey()).toString()+"\n";
} else {
request = new GeneratePresignedUrlRequest(bucket, os.getKey()).withExpiration(expiration);
objectlist = objectlist+s3client.generatePresignedUrl(request).toString()+"\n";
}
}
while (result.isTruncated()) {
result = s3client.listNextBatchOfObjects (result);
objects = result.getObjectSummaries();
for (S3ObjectSummary os : objects) {
request = new GeneratePresignedUrlRequest(bucket, os.getKey()).withExpiration(expiration);
objectlist = objectlist+s3client.generatePresignedUrl(request).toString()+"\n";
if(publicbucket) {
objectlist = objectlist+s3client.getUrl(bucket, os.getKey()).toString()+"\n";
} else {
request = new GeneratePresignedUrlRequest(bucket, os.getKey()).withExpiration(expiration);
objectlist = objectlist+s3client.generatePresignedUrl(request).toString()+"\n";
}
}
}
}
private void sharefile() {
if (datepick.getText().toString().equals("")) {
date = 0;
if(publicbucket) {
objectURL = s3client.getUrl(bucket, object);
} else {
date = Integer.parseInt(datepick.getText().toString());
}
if (hourpick.getText().toString().equals("")) {
hour = 0;
} else {
hour = Integer.parseInt(hourpick.getText().toString());
}
if (minutepick.getText().toString().equals("")) {
minute = 0;
} else {
minute = Integer.parseInt(minutepick.getText().toString());
}
expiration = new Date();
//System.out.println("today is " + mycal.getTime());
mycal.setTime(expiration);
if (date == 0 && hour == 0 && minute == 0) {
if (mediafile) {
mycal.add(Calendar.HOUR, videotime);
if (datepick.getText().toString().equals("")) {
date = 0;
} else {
mycal.add(Calendar.MINUTE, 15);
date = Integer.parseInt(datepick.getText().toString());
}
} else {
mycal.add(Calendar.DATE, date);
mycal.add(Calendar.HOUR, hour);
mycal.add(Calendar.MINUTE, minute);
if (hourpick.getText().toString().equals("")) {
hour = 0;
} else {
hour = Integer.parseInt(hourpick.getText().toString());
}
if (minutepick.getText().toString().equals("")) {
minute = 0;
} else {
minute = Integer.parseInt(minutepick.getText().toString());
}
expiration = new Date();
//System.out.println("today is " + mycal.getTime());
mycal.setTime(expiration);
if (date == 0 && hour == 0 && minute == 0) {
if (mediafile) {
mycal.add(Calendar.HOUR, videotime);
} else {
mycal.add(Calendar.MINUTE, 15);
}
} else {
mycal.add(Calendar.DATE, date);
mycal.add(Calendar.HOUR, hour);
mycal.add(Calendar.MINUTE, minute);
}
//System.out.println("Expiration date: " + mycal.getTime());
expiration = mycal.getTime();
//System.out.println(expiration);
request = new GeneratePresignedUrlRequest(bucket, object).withExpiration(expiration);
objectURL = s3client.generatePresignedUrl(request);
}
//System.out.println("Expiration date: " + mycal.getTime());
expiration = mycal.getTime();
//System.out.println(expiration);
request = new GeneratePresignedUrlRequest(bucket, object).withExpiration(expiration);
objectURL = s3client.generatePresignedUrl(request);
}
private void savelinks() {
simpleProgressBar.setVisibility(View.VISIBLE);
Thread saveLinks = new Thread(new Runnable() {
@Override
@ -356,6 +434,7 @@ public class Share extends AppCompatActivity {
@Override
public void run() {
// Sending reference and data to Adapter
simpleProgressBar.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(),getResources().getString(R.string.save_ok), Toast.LENGTH_SHORT).show();
}
});

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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"
@ -9,7 +9,8 @@
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
tools:ignore="MissingConstraints">
<LinearLayout
android:layout_width="match_parent"
@ -17,9 +18,9 @@
android:orientation="vertical">
<TextView
android:id="@+id/expirationtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/expiration_time"
android:textAlignment="center"
android:textSize="25sp" />
@ -38,6 +39,7 @@
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:enabled="false"
android:hint="@string/share_date"
android:maxLength="1"
android:inputType="date"
@ -50,6 +52,7 @@
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:enabled="false"
android:hint="@string/share_hour"
android:maxLength="2"
android:inputType="date"
@ -62,6 +65,7 @@
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:enabled="false"
android:hint="@string/share_minute"
android:maxLength="2"
android:inputType="date"
@ -97,4 +101,14 @@
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
<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" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -121,4 +121,5 @@
<string name="custom_policy">Política personalizada</string>
<string name="set_public_bucket">Establecer bucket como público</string>
<string name="set_private_bucket">Establecer bucket como privado</string>
<string name="expiration_not_required">Fecha de expiración no requerida</string>
</resources>

View file

@ -122,7 +122,8 @@
<string name="bucket_policy">Access permissions</string>
<string name="public_bucket">Public bucket</string>
<string name="private_bucket">Private bucket</string>
<string name="custom_policy">Private bucket</string>
<string name="custom_policy">Custom policy</string>
<string name="set_public_bucket">Set bucket as public</string>
<string name="set_private_bucket">Set bucket as private</string>
<string name="expiration_not_required">Expiration date not required</string>
</resources>

View file

@ -0,0 +1 @@
* Set bucket as public or private