copy links

This commit is contained in:
Page Asgardius 2023-01-02 17:03:58 -07:00
parent 51b2f1f783
commit 7223d9333f
8 changed files with 180 additions and 19 deletions

View file

@ -1,8 +1,5 @@
package asgardius.page.s3manager;
import static android.media.MediaExtractor.MetricsConstants.MIME_TYPE;
import static com.amazonaws.regions.Regions.US_EAST_1;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -13,7 +10,6 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
@ -29,7 +25,6 @@ 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.DeleteObjectRequest;
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.ObjectListing;
@ -171,6 +166,8 @@ public class BucketSelect extends AppCompatActivity {
//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.create_link)) {
share(Name.get(position).toString());
} else if (menuItem.getTitle() == getResources().getString(R.string.download_bucket)) {
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
download(Name.get(position).toString());
@ -223,6 +220,23 @@ public class BucketSelect extends AppCompatActivity {
}
private void share(String bucket) {
Intent intent = new Intent(this, Share.class);
//treelevel ++;
intent.putExtra("endpoint", endpoint);
intent.putExtra("username", username);
intent.putExtra("password", password);
intent.putExtra("bucket", bucket);
intent.putExtra("title", bucket);
intent.putExtra("region", location);
intent.putExtra("videotime", videotime);
intent.putExtra("playlisttime", playlisttime);
intent.putExtra("style", style);
startActivity(intent);
}
private void delete(String bucket) {
AlertDialog.Builder builder = new AlertDialog.Builder(BucketSelect.this);
builder.setCancelable(true);
@ -373,7 +387,7 @@ public class BucketSelect extends AppCompatActivity {
ClipData clip = ClipData.newPlainText("name", name);
clipboard.setPrimaryClip(clip);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.copy_name_ok), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),getResources().getString(R.string.copy_ok), Toast.LENGTH_SHORT).show();
}
}
}

View file

@ -396,6 +396,8 @@ public class ObjectSelect extends AppCompatActivity {
} 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);
} else if (menuItem.getTitle() == getResources().getString(R.string.create_link)) {
share( 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)) {
objectInfo(prefix + Name.get(position).toString(), Name.get(position).toString());
} else if (menuItem.getTitle() == getResources().getString(R.string.copy_name)) {
@ -433,7 +435,7 @@ public class ObjectSelect extends AppCompatActivity {
//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));
share(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)) {
objectInfo(prefix + Name.get(position).toString(), Name.get(position).toString());
} else if (menuItem.getTitle() == getResources().getString(R.string.copy_name)) {
@ -565,7 +567,7 @@ public class ObjectSelect extends AppCompatActivity {
}
private void share(String object, String title, boolean mediafile) {
private void share(String object, boolean mediafile) {
Intent intent = new Intent(this, Share.class);
//treelevel ++;
@ -573,11 +575,12 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("username", username);
intent.putExtra("password", password);
intent.putExtra("bucket", bucket);
intent.putExtra("object", object);
intent.putExtra("title", title);
intent.putExtra("object", prefix+object);
intent.putExtra("title", object);
intent.putExtra("region", location);
intent.putExtra("mediafile", mediafile);
intent.putExtra("videotime", videotime);
intent.putExtra("playlisttime", playlisttime);
intent.putExtra("style", style);
startActivity(intent);
@ -739,7 +742,7 @@ public class ObjectSelect extends AppCompatActivity {
}
clipboard.setPrimaryClip(clip);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.copy_name_ok), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),getResources().getString(R.string.copy_ok), Toast.LENGTH_SHORT).show();
}
}

View file

@ -2,8 +2,11 @@ package asgardius.page.s3manager;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@ -17,26 +20,32 @@ import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class Share extends AppCompatActivity {
String username, password, endpoint, bucket, object, location, title;
String username, password, endpoint, bucket, object, location, title, objectlist;
boolean mediafile, style;
Region region;
S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials;
AmazonS3 s3client;
ListObjectsRequest orequest;
Calendar mycal;
EditText datepick, hourpick, minutepick;
int date, hour, minute;
Button share;
Button share, copylinks, savelinks;
GeneratePresignedUrlRequest request;
Date expiration;
URL objectURL;
int videotime;
int videotime, playlisttime;
public static String URLify(String str) {
str = str.trim();
@ -76,6 +85,8 @@ public class Share extends AppCompatActivity {
hourpick = (EditText)findViewById(R.id.Hour);
minutepick = (EditText)findViewById(R.id.Minute);
share = (Button)findViewById(R.id.share);
copylinks = (Button)findViewById(R.id.copy_links);
savelinks = (Button)findViewById(R.id.save_links);
endpoint = getIntent().getStringExtra("endpoint");
username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password");
@ -85,6 +96,7 @@ public class Share extends AppCompatActivity {
object = getIntent().getStringExtra("object");
mediafile = getIntent().getBooleanExtra("mediafile", false);
videotime = getIntent().getIntExtra("videotime", 1);
playlisttime = getIntent().getIntExtra("playlisttime", 1);
title = getIntent().getStringExtra("title");
getSupportActionBar().setTitle(title);
region = Region.getRegion(location);
@ -98,6 +110,12 @@ 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);
}
share.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
@ -148,5 +166,102 @@ public class Share extends AppCompatActivity {
}
});
copylinks.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
Thread getLinks = new Thread(new Runnable() {
@Override
public void run() {
try {
//load media file
if (datepick.getText().toString().equals("")) {
date = 0;
} 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, playlisttime);
} 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);
if (object == null) {
orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(1000);
} else {
orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(object).withMaxKeys(1000);
}
ObjectListing result = s3client.listObjects(orequest);
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";
}
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";
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
// Sending reference and data to Adapter
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip;
clip = ClipData.newPlainText("name", objectlist);
clipboard.setPrimaryClip(clip);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.copy_ok), Toast.LENGTH_SHORT).show();
}
}
});
//System.out.println("tree "+treelevel);
//System.out.println("prefix "+prefix);
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.invalid_expiration_date), Toast.LENGTH_SHORT).show();
}
});
}
}
});
getLinks.start();
}
});
}
}

View file

@ -75,6 +75,23 @@
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="@string/file_share"
android:visibility="gone"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/copy_links"
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="@string/copy_links"
android:visibility="gone"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/save_links"
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="@string/save_links"
android:visibility="gone"
tools:ignore="MissingConstraints" />
</LinearLayout>

View file

@ -13,6 +13,10 @@
android:id="@+id/download_bucket"
android:title="@string/download_bucket" />
<item
android:id="@+id/sharefile"
android:title="@string/create_link" />
<item
android:id="@+id/newbucket"
android:title="@string/create_bucket" />

View file

@ -13,6 +13,10 @@
android:id="@+id/download_folder"
android:title="@string/download_folder" />
<item
android:id="@+id/sharefile"
android:title="@string/create_link" />
<item
android:id="@+id/info"
android:title="@string/object_info" />

View file

@ -78,7 +78,7 @@
<string name="share_minute">MM</string>
<string name="expiration_date">Fecha de expiración</string>
<string name="expiration_time">Expira dentro de</string>
<string name="create_link">Crear enlace al archivo</string>
<string name="create_link">Crear enlace</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>
@ -116,7 +116,9 @@
<string name="download_folder">Descargar contenido de la carpeta</string>
<string name="batch_download_success">Archivos descargados exitosamente</string>
<string name="copy_name">Copiar nombre al portapapeles</string>
<string name="copy_name_ok">Nombre copiado al portapapeles</string>
<string name="copy_ok">Copiado al portapapeles</string>
<string name="upload_calculate">Calculando tamaño de la carpeta</string>
<string name="picture_too_big">Imagen demasiado grande</string>
<string name="save_links">Guardar enlaces en archivo</string>
<string name="copy_links">Copiar enlaces al potapapeles</string>
</resources>

View file

@ -13,7 +13,7 @@
<string name="share_hour">HH</string>
<string name="share_minute">MM</string>
<string name="share_date">D</string>
<string name="create_link">Create file link</string>
<string name="create_link">Create 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>
@ -119,7 +119,9 @@
<string name="cors_error">Cannot change CORS policy</string>
<string name="cors_ok">CORS policy changed successfully</string>
<string name="copy_name">Copy name to clipboard</string>
<string name="copy_name_ok">Name copied to clipboard</string>
<string name="copy_ok">Copied to clipboard</string>
<string name="upload_calculate">Calculating folder size</string>
<string name="picture_too_big">Picture too big</string>
<string name="save_links">Save links to file</string>
<string name="copy_links">Copy links to clipboard</string>
</resources>