region selector

This commit is contained in:
Page Asgardius 2022-09-08 10:29:01 -07:00
parent 2ab9181a7c
commit 77b8b11fb7
9 changed files with 94 additions and 67 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_31.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-09-08T15:30:22.967249Z" />
</component>
</project>

View file

@ -5,7 +5,7 @@
<map> <map>
<entry key="app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.195" /> <entry key="app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.195" />
<entry key="app/src/main/res/drawable/ic_launcher_background.xml" value="0.195" /> <entry key="app/src/main/res/drawable/ic_launcher_background.xml" value="0.195" />
<entry key="app/src/main/res/layout/activity_account_add.xml" value="0.1" /> <entry key="app/src/main/res/layout/activity_account_add.xml" value="0.25" />
<entry key="app/src/main/res/layout/activity_bucket_select.xml" value="0.2" /> <entry key="app/src/main/res/layout/activity_bucket_select.xml" value="0.2" />
<entry key="app/src/main/res/layout/activity_file_share.xml" value="0.19610507246376813" /> <entry key="app/src/main/res/layout/activity_file_share.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_list_item.xml" value="0.19610507246376813" />

View file

@ -24,10 +24,11 @@ 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; EditText aapick, aupick, appick, aepick, arpick;
String alias, username, password, endpoint, id; String alias, username, password, endpoint, id, location;
AWSCredentials myCredentials; AWSCredentials myCredentials;
AmazonS3 s3client; AmazonS3 s3client;
Region region;
boolean edit; boolean edit;
@Override @Override
@ -36,23 +37,25 @@ public class AccountAdd extends AppCompatActivity {
setContentView(R.layout.activity_account_add); setContentView(R.layout.activity_account_add);
aapick = (EditText)findViewById(R.id.alias); aapick = (EditText)findViewById(R.id.alias);
aepick = (EditText)findViewById(R.id.endpoint); aepick = (EditText)findViewById(R.id.endpoint);
arpick = (EditText)findViewById(R.id.region);
aupick = (EditText)findViewById(R.id.username); aupick = (EditText)findViewById(R.id.username);
appick = (EditText)findViewById(R.id.password); appick = (EditText)findViewById(R.id.password);
Button register = (Button)findViewById(R.id.addaccount); Button register = (Button)findViewById(R.id.addaccount);
Button accounttest = (Button)findViewById(R.id.testaccount); Button accounttest = (Button)findViewById(R.id.testaccount);
edit = getIntent().getBooleanExtra("edit", false); edit = getIntent().getBooleanExtra("edit", false);
Region region = Region.getRegion(US_EAST_1);
if (edit) { if (edit) {
register.setText(getResources().getString(R.string.accountsave_button)); register.setText(getResources().getString(R.string.accountsave_button));
id = getIntent().getStringExtra("alias"); id = getIntent().getStringExtra("alias");
endpoint = getIntent().getStringExtra("endpoint"); endpoint = getIntent().getStringExtra("endpoint");
username = getIntent().getStringExtra("username"); username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password"); password = getIntent().getStringExtra("password");
location = getIntent().getStringExtra("region");
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);
} }
@ -63,6 +66,7 @@ public class AccountAdd extends AppCompatActivity {
//buttonaction //buttonaction
alias = aapick.getText().toString(); alias = aapick.getText().toString();
endpoint = aepick.getText().toString(); endpoint = aepick.getText().toString();
location = arpick.getText().toString();
username = aupick.getText().toString(); username = aupick.getText().toString();
password = appick.getText().toString(); password = appick.getText().toString();
MyDbHelper dbHelper = new MyDbHelper(AccountAdd.this); MyDbHelper dbHelper = new MyDbHelper(AccountAdd.this);
@ -76,11 +80,14 @@ public class AccountAdd extends AppCompatActivity {
} else if (db != null) { } else if (db != null) {
// Database Queries // Database Queries
try { try {
if (location.equals("")) {
location = "us-east-1";
}
if (edit) { if (edit) {
db.execSQL("UPDATE account SET id=\""+id+"\", endpoint=\""+endpoint+"\", username=\""+username+"\", password=\""+password+"\" WHERE id=\""+id+"\""); db.execSQL("UPDATE account SET id=\""+id+"\", endpoint=\""+endpoint+"\", username=\""+username+"\", password=\""+password+"\", region=\""+location+"\" 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+"\")"); db.execSQL("INSERT INTO account VALUES (\""+alias+"\", \""+endpoint+"\", \""+username+"\", \""+password+"\", \""+location+"\")");
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();
@ -100,6 +107,7 @@ public class AccountAdd extends AppCompatActivity {
endpoint = aepick.getText().toString(); endpoint = aepick.getText().toString();
username = aupick.getText().toString(); username = aupick.getText().toString();
password = appick.getText().toString(); password = appick.getText().toString();
location = arpick.getText().toString();
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://")) {
@ -113,6 +121,10 @@ public class AccountAdd extends AppCompatActivity {
public void run() { public void run() {
try { try {
//Your code goes here //Your code goes here
if (location.equals("")) {
location = "us-east-1";
}
region = Region.getRegion(location);
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build(); S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) { if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
s3ClientOptions.setPathStyleAccess(true); s3ClientOptions.setPathStyleAccess(true);

View file

@ -29,7 +29,7 @@ public class BucketSelect extends AppCompatActivity {
ArrayList Name; ArrayList Name;
ArrayList Img; ArrayList Img;
RecyclerView recyclerView; RecyclerView recyclerView;
String username, password, endpoint, prefix; String username, password, endpoint, prefix, location;
int treelevel; int treelevel;
@Override @Override
@ -38,9 +38,10 @@ public class BucketSelect extends AppCompatActivity {
endpoint = getIntent().getStringExtra("endpoint"); endpoint = getIntent().getStringExtra("endpoint");
username = getIntent().getStringExtra("username"); username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password"); password = getIntent().getStringExtra("password");
location = getIntent().getStringExtra("region");
prefix = ""; prefix = "";
setContentView(R.layout.activity_bucket_select); setContentView(R.layout.activity_bucket_select);
Region region = Region.getRegion(US_EAST_1); Region region = Region.getRegion(location);
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build(); S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) { if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
s3ClientOptions.setPathStyleAccess(true); s3ClientOptions.setPathStyleAccess(true);
@ -132,6 +133,7 @@ public class BucketSelect extends AppCompatActivity {
intent.putExtra("bucket", bucket); intent.putExtra("bucket", bucket);
intent.putExtra("prefix", prefix); intent.putExtra("prefix", prefix);
intent.putExtra("treelevel", treelevel); intent.putExtra("treelevel", treelevel);
intent.putExtra("region", location);
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; String alias, username, password, endpoint, location;
RecyclerView recyclerView; RecyclerView recyclerView;
SQLiteDatabase db; SQLiteDatabase db;
ArrayList Name; ArrayList Name;
@ -103,13 +103,14 @@ public class MainActivity extends AppCompatActivity {
// Database Queries // Database Queries
System.out.println("Database OK"); System.out.println("Database OK");
try { try {
String query = "SELECT endpoint, username, password FROM account where id=\""+ Name.get(position).toString()+ "\""; String query = "SELECT endpoint, username, password, region 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()){
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);
db.close(); db.close();
explorer(); explorer();
} }
@ -136,7 +137,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 FROM account where id=\""+ Name.get(position).toString()+ "\""; String query = "SELECT id, endpoint, username, password, region 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()){
@ -144,6 +145,7 @@ public class MainActivity extends AppCompatActivity {
endpoint = cursor.getString(1); endpoint = cursor.getString(1);
username = cursor.getString(2); username = cursor.getString(2);
password = cursor.getString(3); password = cursor.getString(3);
location = cursor.getString(4);
} }
db.close(); db.close();
addaccount(true); addaccount(true);
@ -220,6 +222,7 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("endpoint", endpoint); intent.putExtra("endpoint", endpoint);
intent.putExtra("username", username); intent.putExtra("username", username);
intent.putExtra("password", password); intent.putExtra("password", password);
intent.putExtra("region", location);
startActivity(intent); startActivity(intent);
} }
@ -232,6 +235,7 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("endpoint", endpoint); intent.putExtra("endpoint", endpoint);
intent.putExtra("username", username); intent.putExtra("username", username);
intent.putExtra("password", password); intent.putExtra("password", password);
intent.putExtra("region", location);
} }
intent.putExtra("edit", edit); intent.putExtra("edit", edit);
startActivity(intent); startActivity(intent);

View file

@ -5,7 +5,7 @@ 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)"; 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 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) {

View file

@ -43,7 +43,7 @@ public class ObjectSelect extends AppCompatActivity {
RecyclerView recyclerView; RecyclerView recyclerView;
String username, password, endpoint, bucket, prefix, location; String username, password, endpoint, bucket, prefix, location;
int treelevel; int treelevel;
String[] filename, path; String[] filename;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -52,53 +52,21 @@ public class ObjectSelect extends AppCompatActivity {
username = getIntent().getStringExtra("username"); username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password"); password = getIntent().getStringExtra("password");
bucket = getIntent().getStringExtra("bucket"); bucket = getIntent().getStringExtra("bucket");
location = getIntent().getStringExtra("region");
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);
Region region = Region.getRegion(US_EAST_1); Region region = Region.getRegion(location);
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build(); S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
s3ClientOptions.setPathStyleAccess(true);
}
AWSCredentials myCredentials = new BasicAWSCredentials(username, password); AWSCredentials myCredentials = new BasicAWSCredentials(username, password);
AmazonS3 s3client = new AmazonS3Client(myCredentials, region); AmazonS3 s3client = new AmazonS3Client(myCredentials, region);
s3client.setEndpoint(endpoint); s3client.setEndpoint(endpoint);
s3client.setS3ClientOptions(s3ClientOptions); if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
if (endpoint.contains(getResources().getString(R.string.aws_endpoint))) { s3ClientOptions.setPathStyleAccess(true);
Thread getlocation = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
location = s3client.getBucketLocation(bucket);
System.out.println(location);
Region region = Region.getRegion(location);
s3client.setRegion(region);
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
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();
finish();
}
}
});
getlocation.start();
try {
getlocation.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
s3client.setS3ClientOptions(s3ClientOptions);
recyclerView = findViewById(R.id.olist); recyclerView = findViewById(R.id.olist);
final ProgressBar simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar); final ProgressBar simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
@ -312,6 +280,7 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("bucket", bucket); intent.putExtra("bucket", bucket);
intent.putExtra("prefix", prefix + object); intent.putExtra("prefix", prefix + object);
intent.putExtra("treelevel", treelevel+1); intent.putExtra("treelevel", treelevel+1);
intent.putExtra("region", location);
startActivity(intent); startActivity(intent);
} }

View file

@ -20,19 +20,42 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" /> tools:ignore="MissingConstraints" />
<EditText <LinearLayout
android:id="@+id/endpoint" android:id="@+id/endpointLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="52dp"
android:layout_alignParentStart="true" android:layout_marginTop="44dp"
android:layout_alignParentEnd="true" android:orientation="horizontal"
android:layout_marginTop="48dp" android:padding="10dp"
android:focusable="true"
android:hint="@string/accountadd_endpoint"
android:importantForAutofill="no"
android:inputType="textUri"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" /> tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp">
<EditText
android:id="@+id/endpoint"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_weight="1"
android:focusable="true"
android:hint="@string/accountadd_endpoint"
android:importantForAutofill="no"
android:inputType="textUri"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/region"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_weight="1"
android:focusable="true"
android:hint="@string/accountadd_region"
android:importantForAutofill="no"
android:inputType="textUri"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
</LinearLayout>
<EditText <EditText
android:id="@+id/username" android:id="@+id/username"
@ -40,7 +63,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_marginTop="94dp" android:layout_marginTop="96dp"
android:autofillHints="username" android:autofillHints="username"
android:focusable="true" android:focusable="true"
android:hint="@string/accountadd_username" android:hint="@string/accountadd_username"
@ -54,7 +77,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_marginTop="140dp" android:layout_marginTop="142dp"
android:autofillHints="username" android:autofillHints="username"
android:focusable="true" android:focusable="true"
android:hint="@string/accountadd_password" android:hint="@string/accountadd_password"
@ -65,11 +88,10 @@
<LinearLayout <LinearLayout
android:id="@+id/linearLayout" android:id="@+id/linearLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="80dp"
android:layout_marginTop="160dp"
android:orientation="horizontal" android:orientation="horizontal"
android:padding="10dp" android:padding="10dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toBottomOf="@+id/password"
tools:ignore="MissingConstraints" tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp"> tools:layout_editor_absoluteX="20dp">

View file

@ -10,6 +10,7 @@
<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_endpoint">S3 Endpoint URL</string> <string name="accountadd_endpoint">S3 Endpoint URL</string>
<string name="accountadd_region">S3 Region</string>
<string name="accountadd_username">S3 Access Key</string> <string name="accountadd_username">S3 Access Key</string>
<string name="accountadd_password">S3 Secret Key</string> <string name="accountadd_password">S3 Secret Key</string>
<string name="accountadd_success">Account added successfully</string> <string name="accountadd_success">Account added successfully</string>