Merge pull request 'file share' (#5) from share into main

Reviewed-on: https://patrice.asgardius.company/gitea/asgardius/s3manager/pulls/5
This commit is contained in:
Page Asgardius 2022-09-18 11:41:15 -07:00
commit f16f1e1154
8 changed files with 283 additions and 20 deletions

View file

@ -14,6 +14,7 @@
<entry key="app/src/main/res/layout/activity_list_item.xml" value="0.19610507246376813" /> <entry key="app/src/main/res/layout/activity_list_item.xml" value="0.19610507246376813" />
<entry key="app/src/main/res/layout/activity_main.xml" value="0.20260416666666667" /> <entry key="app/src/main/res/layout/activity_main.xml" value="0.20260416666666667" />
<entry key="app/src/main/res/layout/activity_object_select.xml" value="0.1" /> <entry key="app/src/main/res/layout/activity_object_select.xml" value="0.1" />
<entry key="app/src/main/res/layout/activity_share.xml" value="0.17119565217391305" />
<entry key="app/src/main/res/layout/activity_text_viewer.xml" value="0.19610507246376813" /> <entry key="app/src/main/res/layout/activity_text_viewer.xml" value="0.19610507246376813" />
<entry key="app/src/main/res/layout/activity_uploader.xml" value="0.20260416666666667" /> <entry key="app/src/main/res/layout/activity_uploader.xml" value="0.20260416666666667" />
<entry key="app/src/main/res/layout/activity_video_player.xml" value="0.1" /> <entry key="app/src/main/res/layout/activity_video_player.xml" value="0.1" />

View file

@ -19,6 +19,9 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.AsgardiusS3Manager" android:theme="@style/Theme.AsgardiusS3Manager"
tools:targetApi="31"> tools:targetApi="31">
<activity
android:name=".Share"
android:exported="false" />
<activity <activity
android:name=".Downloader" android:name=".Downloader"
android:configChanges="orientation|keyboardHidden|screenSize|uiMode|keyboardHidden" android:configChanges="orientation|keyboardHidden|screenSize|uiMode|keyboardHidden"

View file

@ -7,7 +7,6 @@ import androidx.recyclerview.widget.RecyclerView;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -306,14 +305,8 @@ public class ObjectSelect extends AppCompatActivity {
} else if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) { } 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(); //Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
upload(); upload();
} else if (menuItem.getTitle() == getResources().getString(R.string.file_external)) { } else if (menuItem.getTitle() == getResources().getString(R.string.file_share)) {
try { share(prefix + Name.get(position).toString());
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString());
URL objectURL = s3client.generatePresignedUrl(request);
share(objectURL.toString());
} catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
}
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) { } else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
if (menuItem.getTitle() == getResources().getString(R.string.file_del)) { if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
if (Name.size() == 1 && treelevel >= 1) { if (Name.size() == 1 && treelevel >= 1) {
@ -383,14 +376,15 @@ public class ObjectSelect extends AppCompatActivity {
private void share(String object) { private void share(String object) {
try { Intent intent = new Intent(this, Share.class);
//treelevel ++;
Intent shareIntent = new Intent(Intent.ACTION_VIEW); intent.putExtra("endpoint", endpoint);
shareIntent.setData(Uri.parse(object)); intent.putExtra("username", username);
startActivity(Intent.createChooser(shareIntent, "choose one")); intent.putExtra("password", password);
} catch(Exception e) { intent.putExtra("bucket", bucket);
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); intent.putExtra("object", object);
} intent.putExtra("region", location);
startActivity(intent);
} }

View file

@ -0,0 +1,127 @@
package asgardius.page.s3manager;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
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.GeneratePresignedUrlRequest;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
public class Share extends AppCompatActivity {
String username, password, endpoint, bucket, object, location;
Region region;
S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials;
AmazonS3 s3client;
Calendar mycal;
EditText datepick, monthpick, yearpick, hourpick, minutepick;
int date, month, year, hour, minute;
Button share;
public static String URLify(String str) {
str = str.trim();
int length = str.length();
int trueL = length;
if(str.contains(" ")) {
for(int i = 0; i < length; i++) {
if(str.charAt(i) == ' ') {
trueL = trueL + 2;
}
}
char[] oldArr = str.toCharArray();
char[] newArr = new char[trueL];
int x = 0;
for(int i = 0; i < length; i++) {
if(oldArr[i] == ' ') {
newArr[x] = '%';
newArr[x+1] = '2';
newArr[x+2] = '0';
x += 3;
} else {
newArr[x] = oldArr[i];
x++;
}
}
str = new String(newArr, 0, trueL);
}
return str;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share);
mycal = Calendar.getInstance();
datepick = (EditText)findViewById(R.id.Date);
monthpick = (EditText)findViewById(R.id.Month);
yearpick = (EditText)findViewById(R.id.Year);
hourpick = (EditText)findViewById(R.id.Hour);
minutepick = (EditText)findViewById(R.id.Minute);
share = (Button)findViewById(R.id.share);
endpoint = getIntent().getStringExtra("endpoint");
username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password");
bucket = getIntent().getStringExtra("bucket");
location = getIntent().getStringExtra("region");
object = getIntent().getStringExtra("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);
share.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
try {
date = Integer.parseInt(datepick.getText().toString());
month = Integer.parseInt(monthpick.getText().toString());
year = Integer.parseInt(yearpick.getText().toString());
hour = Integer.parseInt(hourpick.getText().toString());
minute = Integer.parseInt(minutepick.getText().toString());
mycal.set(Calendar.YEAR, year);
mycal.set(Calendar.MONTH, month-1);
mycal.set(Calendar.DATE, date);
mycal.set(Calendar.HOUR, hour);
mycal.set(Calendar.MINUTE, minute);
mycal.set(Calendar.SECOND, 0);
Date expiration = mycal.getTime();
//System.out.println(expiration);
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, object).withExpiration(expiration);
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,120 @@
<?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=".Share">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/expiration_date"
android:textAlignment="center"
android:textSize="25sp" />
<LinearLayout
android:id="@+id/linearLayoutDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp">
<EditText
android:id="@+id/Date"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="@string/share_date"
android:inputType="date"
android:textColorHint="?attr/colorOnSecondary"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/Month"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="@string/share_month"
android:inputType="date"
android:textColorHint="?attr/colorOnSecondary"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/Year"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="@string/share_year"
android:inputType="date"
android:textColorHint="?attr/colorOnSecondary"
tools:ignore="MissingConstraints" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/expiration_time"
android:textAlignment="center"
android:textSize="25sp" />
<LinearLayout
android:id="@+id/linearLayoutTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp">
<EditText
android:id="@+id/Hour"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="@string/share_hour"
android:inputType="date"
android:textColorHint="?attr/colorOnSecondary"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/Minute"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="@string/share_minute"
android:inputType="date"
android:textColorHint="?attr/colorOnSecondary"
tools:ignore="MissingConstraints" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutSubmit"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="20dp"
android:orientation="horizontal"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp">
<Button
android:id="@+id/share"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/create_link"
tools:ignore="MissingConstraints" />
</LinearLayout>
</LinearLayout>

View file

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

View file

@ -9,7 +9,7 @@
<string name="set_bucket_name">Establezca el nombre del nuevo bucket</string> <string name="set_bucket_name">Establezca el nombre del nuevo bucket</string>
<string name="bucket_name">Nombre del bucket</string> <string name="bucket_name">Nombre del bucket</string>
<string name="bucket_name_empty">Se requiere un nombre para el bucket</string> <string name="bucket_name_empty">Se requiere un nombre para el bucket</string>
<string name="file_external">Abrir en</string> <string name="file_share">Compartir archivo</string>
<string name="download_file">Descargar archivo</string> <string name="download_file">Descargar archivo</string>
<string name="download_in_progress">Descarga en proceso</string> <string name="download_in_progress">Descarga en proceso</string>
<string name="download_success">Archivo descargado exitosamente</string> <string name="download_success">Archivo descargado exitosamente</string>
@ -68,4 +68,13 @@
<string name="dummy_content">Contenido de prueba</string> <string name="dummy_content">Contenido de prueba</string>
<string name="accountadd_pdfendpoint">servidor pdfjs</string> <string name="accountadd_pdfendpoint">servidor pdfjs</string>
<string name="pdf_reader_notready">Necesita configurar un servidor pdf.js</string> <string name="pdf_reader_notready">Necesita configurar un servidor pdf.js</string>
<string name="share_date">DD</string>
<string name="share_month">MM</string>
<string name="share_year">AAAA</string>
<string name="share_hour">HH</string>
<string name="share_minute">MM</string>
<string name="expiration_date">Fecha de expiración</string>
<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>
</resources> </resources>

View file

@ -9,12 +9,21 @@
<string name="bucket_list">Bucket list</string> <string name="bucket_list">Bucket list</string>
<string name="object_list">Object list</string> <string name="object_list">Object list</string>
<string name="Image">Image</string> <string name="Image">Image</string>
<string name="expiration_date">Expiration date</string>
<string name="expiration_time">Expiration time</string>
<string name="share_hour">HH</string>
<string name="share_minute">MM</string>
<string name="share_date">DD</string>
<string name="share_month">MM</string>
<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="broken_database">Local database is corrupted. Please reinstall this app</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="pending_feature">This feature is not implemented yet</string>
<string name="set_bucket_name">Set new bucket name</string> <string name="set_bucket_name">Set new bucket name</string>
<string name="bucket_name">Bucket name</string> <string name="bucket_name">Bucket name</string>
<string name="bucket_name_empty">A bucket name is required</string> <string name="bucket_name_empty">A bucket name is required</string>
<string name="file_external">Open in</string> <string name="file_share">Share file</string>
<string name="download_file">Download file</string> <string name="download_file">Download file</string>
<string name="download_in_progress">Download in progress</string> <string name="download_in_progress">Download in progress</string>
<string name="download_success">File downloaded successfully</string> <string name="download_success">File downloaded successfully</string>