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

View file

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

View file

@ -5,7 +5,7 @@ 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)";
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 int dbversion = 3;
public MyDbHelper(Context context) {

View file

@ -43,7 +43,7 @@ public class ObjectSelect extends AppCompatActivity {
RecyclerView recyclerView;
String username, password, endpoint, bucket, prefix, location;
int treelevel;
String[] filename, path;
String[] filename;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -52,53 +52,21 @@ public class ObjectSelect extends AppCompatActivity {
username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password");
bucket = getIntent().getStringExtra("bucket");
location = getIntent().getStringExtra("region");
prefix = getIntent().getStringExtra("prefix");
treelevel = getIntent().getIntExtra("treelevel", 0);
setContentView(R.layout.activity_object_select);
Region region = Region.getRegion(US_EAST_1);
Region region = Region.getRegion(location);
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
s3ClientOptions.setPathStyleAccess(true);
}
AWSCredentials myCredentials = new BasicAWSCredentials(username, password);
AmazonS3 s3client = new AmazonS3Client(myCredentials, region);
s3client.setEndpoint(endpoint);
s3client.setS3ClientOptions(s3ClientOptions);
if (endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
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();
}
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
s3ClientOptions.setPathStyleAccess(true);
}
s3client.setS3ClientOptions(s3ClientOptions);
recyclerView = findViewById(R.id.olist);
final ProgressBar simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
@ -312,6 +280,7 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("bucket", bucket);
intent.putExtra("prefix", prefix + object);
intent.putExtra("treelevel", treelevel+1);
intent.putExtra("region", location);
startActivity(intent);
}

View file

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

View file

@ -10,6 +10,7 @@
<string name="accounttest_success">Credentials are correct</string>
<string name="accountadd_alias">Account Alias</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_password">S3 Secret Key</string>
<string name="accountadd_success">Account added successfully</string>