set pdfjs endpoint selector

This commit is contained in:
Page Asgardius 2022-09-17 15:40:26 -07:00
parent c34010680f
commit 4f4bc3b52b
11 changed files with 90 additions and 18 deletions

View file

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

View file

@ -9,8 +9,8 @@ android {
applicationId "asgardius.page.s3manager" applicationId "asgardius.page.s3manager"
minSdk 24 minSdk 24
targetSdk 33 targetSdk 33
versionCode 11 versionCode 12
versionName "0.1.9" versionName "0.1.10"
setProperty("archivesBaseName", "s3-manager-$versionName") setProperty("archivesBaseName", "s3-manager-$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -12,10 +12,13 @@
<li>Amazon Web Services SDK 2.53.0</li> <li>Amazon Web Services SDK 2.53.0</li>
<li>ExoPlayer 2.18.1</li> <li>ExoPlayer 2.18.1</li>
<li>Adwaita Icon Theme for GNOME 43</li> <li>Adwaita Icon Theme for GNOME 43</li>
<li>pdf.js</li>
</ul> </ul>
<H3>This software released under GNU General Public License 3</H3> <H3>This software released under GNU General Public License 3</H3>
<p>You can find source code at https://patrice.asgardius.company/gitea/asgardius/s3manager <p>You can find source code at https://patrice.asgardius.company/gitea/asgardius/s3manager
<br> <br>
You need to setup a pdf.js server to use pdf viewer. Just download latest version from official website and upload to any web server with ssl on same root domain than S3 server (can be same subdomain or a different one). Then set url to pdfjs root folder like https://example.com/pdfjs-dist
<br>
You can find technical support on official forum https://forum.asgardius.company/t/s3-manager</p> You can find technical support on official forum https://forum.asgardius.company/t/s3-manager</p>
</Body> </Body>
</Html> </Html>

View file

@ -24,8 +24,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class AccountAdd extends AppCompatActivity { public class AccountAdd extends AppCompatActivity {
EditText aapick, aupick, appick, aepick, arpick; EditText aapick, aupick, appick, aepick, arpick, pdfpick;
String alias, username, password, endpoint, id, location; String alias, username, password, endpoint, id, location, pdfendpoint;
AWSCredentials myCredentials; AWSCredentials myCredentials;
AmazonS3 s3client; AmazonS3 s3client;
Region region; Region region;
@ -36,6 +36,7 @@ public class AccountAdd extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_add); setContentView(R.layout.activity_account_add);
aapick = (EditText)findViewById(R.id.alias); aapick = (EditText)findViewById(R.id.alias);
pdfpick = (EditText)findViewById(R.id.pdfendpoint);
aepick = (EditText)findViewById(R.id.endpoint); aepick = (EditText)findViewById(R.id.endpoint);
arpick = (EditText)findViewById(R.id.region); arpick = (EditText)findViewById(R.id.region);
aupick = (EditText)findViewById(R.id.username); aupick = (EditText)findViewById(R.id.username);
@ -51,12 +52,14 @@ public class AccountAdd extends AppCompatActivity {
username = getIntent().getStringExtra("username"); username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password"); password = getIntent().getStringExtra("password");
location = getIntent().getStringExtra("region"); location = getIntent().getStringExtra("region");
pdfendpoint = getIntent().getStringExtra("pdfendpoint");
aapick.setText(id); aapick.setText(id);
//aapick.setEnabled(false); //aapick.setEnabled(false);
aepick.setText(endpoint); aepick.setText(endpoint);
aupick.setText(username); aupick.setText(username);
appick.setText(password); appick.setText(password);
arpick.setText(location); arpick.setText(location);
pdfpick.setText(pdfendpoint);
} else{ } else{
getSupportActionBar().setTitle(getResources().getString(R.string.accountadd_button)); getSupportActionBar().setTitle(getResources().getString(R.string.accountadd_button));
} }
@ -68,6 +71,7 @@ public class AccountAdd extends AppCompatActivity {
public void onClick(View view) { public void onClick(View view) {
//buttonaction //buttonaction
alias = aapick.getText().toString(); alias = aapick.getText().toString();
pdfendpoint = pdfpick.getText().toString();
endpoint = aepick.getText().toString(); endpoint = aepick.getText().toString();
location = arpick.getText().toString(); location = arpick.getText().toString();
username = aupick.getText().toString(); username = aupick.getText().toString();
@ -76,11 +80,12 @@ public class AccountAdd extends AppCompatActivity {
if (alias.equals("") && endpoint.equals("") && username.equals(getResources().getString(R.string.access_key))) { if (alias.equals("") && endpoint.equals("") && username.equals(getResources().getString(R.string.access_key))) {
endpoint = getResources().getString(R.string.endpoint_url); endpoint = getResources().getString(R.string.endpoint_url);
alias = "Google Test"; alias = "Google Test";
pdfendpoint = getResources().getString(R.string.pdf_reader);
} }
SQLiteDatabase db = dbHelper.getWritableDatabase(); SQLiteDatabase db = dbHelper.getWritableDatabase();
if (alias.equals("") || endpoint.equals("") || username.equals("") || password.equals("")) { if (alias.equals("") || endpoint.equals("") || username.equals("") || password.equals("")) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_null), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_null), Toast.LENGTH_SHORT).show();
} else if (endpoint.startsWith("http://")) { } else if (endpoint.startsWith("http://") || pdfendpoint.startsWith("http://")) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.nosslwarning), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.nosslwarning), Toast.LENGTH_SHORT).show();
} else if (!endpoint.startsWith("https://")) { } else if (!endpoint.startsWith("https://")) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.invalid_url), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.invalid_url), Toast.LENGTH_SHORT).show();
@ -91,10 +96,10 @@ public class AccountAdd extends AppCompatActivity {
location = "us-east-1"; location = "us-east-1";
} }
if (edit) { if (edit) {
db.execSQL("UPDATE account SET id=\""+id+"\", endpoint=\""+endpoint+"\", username=\""+username+"\", password=\""+password+"\", region=\""+location+"\" WHERE id=\""+id+"\""); db.execSQL("UPDATE account SET id=\""+id+"\", endpoint=\""+endpoint+"\", username=\""+username+"\", password=\""+password+"\", region=\""+location+"\", pdfendpoint=\""+pdfendpoint+"\" WHERE id=\""+id+"\"");
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountsave_success), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountsave_success), Toast.LENGTH_SHORT).show();
} else { } else {
db.execSQL("INSERT INTO account VALUES (\""+alias+"\", \""+endpoint+"\", \""+username+"\", \""+password+"\", \""+location+"\")"); db.execSQL("INSERT INTO account VALUES (\""+alias+"\", \""+endpoint+"\", \""+username+"\", \""+password+"\", \""+location+"\", \""+pdfendpoint+"\")");
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_success), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_success), Toast.LENGTH_SHORT).show();
} }
mainmenu(); mainmenu();

View file

@ -40,7 +40,7 @@ public class BucketSelect extends AppCompatActivity {
ArrayList Name; ArrayList Name;
ArrayList Img; ArrayList Img;
RecyclerView recyclerView; RecyclerView recyclerView;
String username, password, endpoint, prefix, location, file; String username, password, endpoint, prefix, location, file, pdfendpoint;
int treelevel; int treelevel;
Region region; Region region;
S3ClientOptions s3ClientOptions; S3ClientOptions s3ClientOptions;
@ -55,6 +55,7 @@ public class BucketSelect extends AppCompatActivity {
username = getIntent().getStringExtra("username"); username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password"); password = getIntent().getStringExtra("password");
location = getIntent().getStringExtra("region"); location = getIntent().getStringExtra("region");
pdfendpoint = getIntent().getStringExtra("pdfendpoint");
prefix = ""; prefix = "";
setContentView(R.layout.activity_bucket_select); setContentView(R.layout.activity_bucket_select);
region = Region.getRegion("us-east-1"); region = Region.getRegion("us-east-1");
@ -189,6 +190,7 @@ public class BucketSelect extends AppCompatActivity {
intent.putExtra("prefix", prefix); intent.putExtra("prefix", prefix);
intent.putExtra("treelevel", treelevel); intent.putExtra("treelevel", treelevel);
intent.putExtra("region", location); intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
startActivity(intent); startActivity(intent);
} }

View file

@ -21,7 +21,7 @@ import java.util.ArrayList;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
static boolean DEFAULT_PATH_STYLE_ACCESS = true; static boolean DEFAULT_PATH_STYLE_ACCESS = true;
String alias, username, password, endpoint, location; String alias, username, password, endpoint, location, pdfendpoint;
RecyclerView recyclerView; RecyclerView recyclerView;
SQLiteDatabase db; SQLiteDatabase db;
ArrayList Name; ArrayList Name;
@ -98,18 +98,20 @@ public class MainActivity extends AppCompatActivity {
if (db != null) { if (db != null) {
// Database Queries // Database Queries
try { try {
String query = "SELECT endpoint, username, password, region FROM account where id=\""+ Name.get(position).toString()+ "\""; String query = "SELECT endpoint, username, password, region, pdfendpoint FROM account where id=\""+ Name.get(position).toString()+ "\"";
Cursor cursor = db.rawQuery(query,null); Cursor cursor = db.rawQuery(query,null);
if (cursor.moveToNext()){ if (cursor.moveToNext()){
endpoint = cursor.getString(0); endpoint = cursor.getString(0);
username = cursor.getString(1); username = cursor.getString(1);
password = cursor.getString(2); password = cursor.getString(2);
location = cursor.getString(3); location = cursor.getString(3);
pdfendpoint = cursor.getString(4);
db.close(); db.close();
explorer(); explorer();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
db.execSQL("ALTER TABLE account add column pdfendpoint text");
} }
} }
@ -131,7 +133,7 @@ public class MainActivity extends AppCompatActivity {
if (menuItem.getTitle() == getResources().getString(R.string.accountedit_button)) { if (menuItem.getTitle() == getResources().getString(R.string.accountedit_button)) {
try { try {
db = dbHelper.getWritableDatabase(); db = dbHelper.getWritableDatabase();
String query = "SELECT id, endpoint, username, password, region FROM account where id=\""+ Name.get(position).toString()+ "\""; String query = "SELECT id, endpoint, username, password, region, pdfendpoint FROM account where id=\""+ Name.get(position).toString()+ "\"";
System.out.println(query); System.out.println(query);
Cursor cursor = db.rawQuery(query,null); Cursor cursor = db.rawQuery(query,null);
if (cursor.moveToNext()){ if (cursor.moveToNext()){
@ -140,12 +142,14 @@ public class MainActivity extends AppCompatActivity {
username = cursor.getString(2); username = cursor.getString(2);
password = cursor.getString(3); password = cursor.getString(3);
location = cursor.getString(4); location = cursor.getString(4);
pdfendpoint = cursor.getString(5);
} }
db.close(); db.close();
addaccount(true); addaccount(true);
//Toast.makeText(MainActivity.this, "This feature is not yet implemented", Toast.LENGTH_SHORT).show(); //Toast.makeText(MainActivity.this, "This feature is not yet implemented", Toast.LENGTH_SHORT).show();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
db.execSQL("ALTER TABLE account add column pdfendpoint text");
} }
} }
else if (menuItem.getTitle() == getResources().getString(R.string.accountdel_button)) { else if (menuItem.getTitle() == getResources().getString(R.string.accountdel_button)) {
@ -218,6 +222,7 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("username", username); intent.putExtra("username", username);
intent.putExtra("password", password); intent.putExtra("password", password);
intent.putExtra("region", location); intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
startActivity(intent); startActivity(intent);
} }
@ -231,6 +236,7 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("username", username); intent.putExtra("username", username);
intent.putExtra("password", password); intent.putExtra("password", password);
intent.putExtra("region", location); intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
} }
intent.putExtra("edit", edit); intent.putExtra("edit", edit);
startActivity(intent); startActivity(intent);

View file

@ -5,7 +5,9 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
public class MyDbHelper extends SQLiteOpenHelper { public class MyDbHelper extends SQLiteOpenHelper {
private static final String atcreate = "CREATE TABLE IF NOT EXISTS account(id text UNIQUE, endpoint text, username text, password text, region text)"; private static final String atcreate = "CREATE TABLE IF NOT EXISTS account(id text UNIQUE, endpoint text, username text, password text, region text, pdfendpoint text)";
private static final String atupgrade = "ALTER TABLE account add column pdfendpoint text";
private static final int DATABASE_VERSION = 1;
private static final String dbname = "accounts.sqlite3"; private static final String dbname = "accounts.sqlite3";
private static final int dbversion = 3; private static final int dbversion = 3;
public MyDbHelper(Context context) { public MyDbHelper(Context context) {
@ -17,6 +19,6 @@ public class MyDbHelper extends SQLiteOpenHelper {
} }
@Override @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(atupgrade);
} }
} }

View file

@ -41,7 +41,7 @@ public class ObjectSelect extends AppCompatActivity {
ArrayList Img; ArrayList Img;
//ArrayList object; //ArrayList object;
RecyclerView recyclerView; RecyclerView recyclerView;
String username, password, endpoint, bucket, prefix, location; String username, password, endpoint, bucket, prefix, location, pdfendpoint;
int treelevel; int treelevel;
String[] filename; String[] filename;
Region region; Region region;
@ -58,6 +58,7 @@ public class ObjectSelect extends AppCompatActivity {
password = getIntent().getStringExtra("password"); password = getIntent().getStringExtra("password");
bucket = getIntent().getStringExtra("bucket"); bucket = getIntent().getStringExtra("bucket");
location = getIntent().getStringExtra("region"); location = getIntent().getStringExtra("region");
pdfendpoint = getIntent().getStringExtra("pdfendpoint");
prefix = getIntent().getStringExtra("prefix"); prefix = getIntent().getStringExtra("prefix");
treelevel = getIntent().getIntExtra("treelevel", 0); treelevel = getIntent().getIntExtra("treelevel", 0);
setContentView(R.layout.activity_object_select); setContentView(R.layout.activity_object_select);
@ -229,7 +230,14 @@ public class ObjectSelect extends AppCompatActivity {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()); GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString());
URL objectURL = s3client.generatePresignedUrl(request); URL objectURL = s3client.generatePresignedUrl(request);
//System.out.println(getResources().getString(R.string.pdf_reader)+ URLEncoder.encode(objectURL.toString(), "UTF-8" )); //System.out.println(getResources().getString(R.string.pdf_reader)+ URLEncoder.encode(objectURL.toString(), "UTF-8" ));
webBrowser(getResources().getString(R.string.pdf_reader)+ URLEncoder.encode(objectURL.toString(), "UTF-8" ), Name.get(position).toString()); if (pdfendpoint == null) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.pdf_reader_notready), Toast.LENGTH_SHORT).show();
} else if (pdfendpoint.endsWith("/")) {
webBrowser(pdfendpoint + "web/viewer.html?file=" + URLEncoder.encode(objectURL.toString(), "UTF-8" ), Name.get(position).toString());
} else {
webBrowser(pdfendpoint + "/web/viewer.html?file=" + URLEncoder.encode(objectURL.toString(), "UTF-8" ), Name.get(position).toString());
}
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
} }
@ -364,6 +372,7 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("prefix", prefix + object); intent.putExtra("prefix", prefix + object);
intent.putExtra("treelevel", treelevel+1); intent.putExtra("treelevel", treelevel+1);
intent.putExtra("region", location); intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
startActivity(intent); startActivity(intent);
} }

View file

@ -7,10 +7,20 @@
android:orientation="vertical" android:orientation="vertical"
tools:context=".AccountAdd"> tools:context=".AccountAdd">
<EditText <LinearLayout
android:id="@+id/alias" android:id="@+id/aliasLayout"
android:layout_width="match_parent" 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/alias"
android:layout_width="wrap_content"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true" android:focusable="true"
android:hint="@string/accountadd_alias" android:hint="@string/accountadd_alias"
android:importantForAutofill="no" android:importantForAutofill="no"
@ -18,6 +28,20 @@
android:textColorHint="?attr/colorOnSecondary" android:textColorHint="?attr/colorOnSecondary"
tools:ignore="MissingConstraints" /> tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/pdfendpoint"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="@string/accountadd_pdfendpoint"
android:importantForAutofill="no"
android:inputType="textUri"
android:textColorHint="?attr/colorOnSecondary"
tools:ignore="MissingConstraints" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/endpointLayout" android:id="@+id/endpointLayout"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -66,4 +66,6 @@
<string name="about_button">Acerca de esta app</string> <string name="about_button">Acerca de esta app</string>
<string name="dummy_button">Botón de prueba</string> <string name="dummy_button">Botón de prueba</string>
<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="pdf_reader_notready">Necesita configurar un servidor pdf.js</string>
</resources> </resources>

View file

@ -2,7 +2,8 @@
<string name="app_name" translatable="false">S3 Manager</string> <string name="app_name" translatable="false">S3 Manager</string>
<string name="aws_endpoint" translatable="false">.amazonaws.com</string> <string name="aws_endpoint" translatable="false">.amazonaws.com</string>
<string name="endpoint_url" translatable="false">https://object.asgardius.company</string> <string name="endpoint_url" translatable="false">https://object.asgardius.company</string>
<string name="pdf_reader" translatable="false">https://office.asgardius.company/pdfjs/web/viewer.html?file=</string> <string name="pdf_reader" translatable="false">https://office.asgardius.company/pdfjs</string>
<string name="pdf_reader_notready">You need to setup a pdf.js server</string>
<string name="access_key" translatable="false">google</string> <string name="access_key" translatable="false">google</string>
<string name="account_list">Account list</string> <string name="account_list">Account list</string>
<string name="bucket_list">Bucket list</string> <string name="bucket_list">Bucket list</string>
@ -46,6 +47,7 @@
<string name="accounttest_button">Test credentials</string> <string name="accounttest_button">Test credentials</string>
<string name="accounttest_success">Credentials are correct</string> <string name="accounttest_success">Credentials are correct</string>
<string name="accountadd_alias">Account Alias</string> <string name="accountadd_alias">Account Alias</string>
<string name="accountadd_pdfendpoint">pdfjs server</string>
<string name="accountadd_endpoint">S3 Endpoint URL</string> <string name="accountadd_endpoint">S3 Endpoint URL</string>
<string name="accountadd_region">S3 Region</string> <string name="accountadd_region">S3 Region</string>
<string name="accountadd_username">S3 Access Key</string> <string name="accountadd_username">S3 Access Key</string>