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"
minSdk 24
targetSdk 33
versionCode 11
versionName "0.1.9"
versionCode 12
versionName "0.1.10"
setProperty("archivesBaseName", "s3-manager-$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -12,10 +12,13 @@
<li>Amazon Web Services SDK 2.53.0</li>
<li>ExoPlayer 2.18.1</li>
<li>Adwaita Icon Theme for GNOME 43</li>
<li>pdf.js</li>
</ul>
<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
<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>
</Body>
</Html>

View file

@ -24,8 +24,8 @@ import java.util.ArrayList;
import java.util.List;
public class AccountAdd extends AppCompatActivity {
EditText aapick, aupick, appick, aepick, arpick;
String alias, username, password, endpoint, id, location;
EditText aapick, aupick, appick, aepick, arpick, pdfpick;
String alias, username, password, endpoint, id, location, pdfendpoint;
AWSCredentials myCredentials;
AmazonS3 s3client;
Region region;
@ -36,6 +36,7 @@ public class AccountAdd extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_add);
aapick = (EditText)findViewById(R.id.alias);
pdfpick = (EditText)findViewById(R.id.pdfendpoint);
aepick = (EditText)findViewById(R.id.endpoint);
arpick = (EditText)findViewById(R.id.region);
aupick = (EditText)findViewById(R.id.username);
@ -51,12 +52,14 @@ public class AccountAdd extends AppCompatActivity {
username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password");
location = getIntent().getStringExtra("region");
pdfendpoint = getIntent().getStringExtra("pdfendpoint");
aapick.setText(id);
//aapick.setEnabled(false);
aepick.setText(endpoint);
aupick.setText(username);
appick.setText(password);
arpick.setText(location);
pdfpick.setText(pdfendpoint);
} else{
getSupportActionBar().setTitle(getResources().getString(R.string.accountadd_button));
}
@ -68,6 +71,7 @@ public class AccountAdd extends AppCompatActivity {
public void onClick(View view) {
//buttonaction
alias = aapick.getText().toString();
pdfendpoint = pdfpick.getText().toString();
endpoint = aepick.getText().toString();
location = arpick.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))) {
endpoint = getResources().getString(R.string.endpoint_url);
alias = "Google Test";
pdfendpoint = getResources().getString(R.string.pdf_reader);
}
SQLiteDatabase db = dbHelper.getWritableDatabase();
if (alias.equals("") || endpoint.equals("") || username.equals("") || password.equals("")) {
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();
} else if (!endpoint.startsWith("https://")) {
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";
}
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();
} 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();
}
mainmenu();

View file

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

View file

@ -21,7 +21,7 @@ import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
static boolean DEFAULT_PATH_STYLE_ACCESS = true;
String alias, username, password, endpoint, location;
String alias, username, password, endpoint, location, pdfendpoint;
RecyclerView recyclerView;
SQLiteDatabase db;
ArrayList Name;
@ -98,18 +98,20 @@ public class MainActivity extends AppCompatActivity {
if (db != null) {
// Database Queries
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);
if (cursor.moveToNext()){
endpoint = cursor.getString(0);
username = cursor.getString(1);
password = cursor.getString(2);
location = cursor.getString(3);
pdfendpoint = cursor.getString(4);
db.close();
explorer();
}
} catch (Exception e) {
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)) {
try {
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);
Cursor cursor = db.rawQuery(query,null);
if (cursor.moveToNext()){
@ -140,12 +142,14 @@ public class MainActivity extends AppCompatActivity {
username = cursor.getString(2);
password = cursor.getString(3);
location = cursor.getString(4);
pdfendpoint = cursor.getString(5);
}
db.close();
addaccount(true);
//Toast.makeText(MainActivity.this, "This feature is not yet implemented", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
db.execSQL("ALTER TABLE account add column pdfendpoint text");
}
}
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("password", password);
intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
startActivity(intent);
}
@ -231,6 +236,7 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("username", username);
intent.putExtra("password", password);
intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
}
intent.putExtra("edit", edit);
startActivity(intent);

View file

@ -5,7 +5,9 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.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 int dbversion = 3;
public MyDbHelper(Context context) {
@ -17,6 +19,6 @@ public class MyDbHelper extends SQLiteOpenHelper {
}
@Override
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 object;
RecyclerView recyclerView;
String username, password, endpoint, bucket, prefix, location;
String username, password, endpoint, bucket, prefix, location, pdfendpoint;
int treelevel;
String[] filename;
Region region;
@ -58,6 +58,7 @@ public class ObjectSelect extends AppCompatActivity {
password = getIntent().getStringExtra("password");
bucket = getIntent().getStringExtra("bucket");
location = getIntent().getStringExtra("region");
pdfendpoint = getIntent().getStringExtra("pdfendpoint");
prefix = getIntent().getStringExtra("prefix");
treelevel = getIntent().getIntExtra("treelevel", 0);
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());
URL objectURL = s3client.generatePresignedUrl(request);
//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) {
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("treelevel", treelevel+1);
intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
startActivity(intent);
}

View file

@ -7,10 +7,20 @@
android:orientation="vertical"
tools:context=".AccountAdd">
<EditText
android:id="@+id/alias"
<LinearLayout
android:id="@+id/aliasLayout"
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_weight="1"
android:focusable="true"
android:hint="@string/accountadd_alias"
android:importantForAutofill="no"
@ -18,6 +28,20 @@
android:textColorHint="?attr/colorOnSecondary"
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
android:id="@+id/endpointLayout"
android:layout_width="match_parent"

View file

@ -66,4 +66,6 @@
<string name="about_button">Acerca de esta app</string>
<string name="dummy_button">Botón 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>

View file

@ -2,7 +2,8 @@
<string name="app_name" translatable="false">S3 Manager</string>
<string name="aws_endpoint" translatable="false">.amazonaws.com</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="account_list">Account list</string>
<string name="bucket_list">Bucket list</string>
@ -46,6 +47,7 @@
<string name="accounttest_button">Test credentials</string>
<string name="accounttest_success">Credentials are correct</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_region">S3 Region</string>
<string name="accountadd_username">S3 Access Key</string>