share file frontend

This commit is contained in:
Page Asgardius 2022-09-18 11:37:31 -07:00
parent 89af00ba98
commit fd86936015
7 changed files with 181 additions and 19 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

@ -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,7 +305,7 @@ 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)) {
share(prefix + Name.get(position).toString()); share(prefix + Name.get(position).toString());
} 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)) {

View file

@ -2,7 +2,12 @@ package asgardius.page.s3manager;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSCredentials;
@ -24,6 +29,9 @@ public class Share extends AppCompatActivity {
AWSCredentials myCredentials; AWSCredentials myCredentials;
AmazonS3 s3client; AmazonS3 s3client;
Calendar mycal; Calendar mycal;
EditText datepick, monthpick, yearpick, hourpick, minutepick;
int date, month, year, hour, minute;
Button share;
public static String URLify(String str) { public static String URLify(String str) {
str = str.trim(); str = str.trim();
@ -59,6 +67,12 @@ public class Share extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share); setContentView(R.layout.activity_share);
mycal = Calendar.getInstance(); 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"); endpoint = getIntent().getStringExtra("endpoint");
username = getIntent().getStringExtra("username"); username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password"); password = getIntent().getStringExtra("password");
@ -78,17 +92,36 @@ public class Share extends AppCompatActivity {
s3ClientOptions.setPathStyleAccess(true); s3ClientOptions.setPathStyleAccess(true);
} }
s3client.setS3ClientOptions(s3ClientOptions); s3client.setS3ClientOptions(s3ClientOptions);
mycal.set(Calendar.YEAR, 2022); share.setOnClickListener(new View.OnClickListener(){
mycal.set(Calendar.MONTH, 8); @Override
mycal.set(Calendar.DATE, 18); public void onClick(View view) {
mycal.set(Calendar.HOUR, 14); //buttonaction
mycal.set(Calendar.MINUTE, 15); try {
mycal.set(Calendar.SECOND, 28); date = Integer.parseInt(datepick.getText().toString());
Date expiration = mycal.getTime(); month = Integer.parseInt(monthpick.getText().toString());
System.out.println(expiration); 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();
}
}
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, object).withExpiration(expiration); });
URL objectURL = s3client.generatePresignedUrl(request);
System.out.println(URLify(objectURL.toString()));
} }
} }

View file

@ -1,9 +1,120 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Share"> tools:context=".Share">
</androidx.constraintlayout.widget.ConstraintLayout> <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>