diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..c3ebb80 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 4c93319..79b787b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,7 @@ - + diff --git a/app/src/main/java/asgardius/page/s3manager/AccountAdd.java b/app/src/main/java/asgardius/page/s3manager/AccountAdd.java index f965fb4..e86edc6 100644 --- a/app/src/main/java/asgardius/page/s3manager/AccountAdd.java +++ b/app/src/main/java/asgardius/page/s3manager/AccountAdd.java @@ -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); diff --git a/app/src/main/java/asgardius/page/s3manager/BucketSelect.java b/app/src/main/java/asgardius/page/s3manager/BucketSelect.java index 6ebcd8f..954f8dc 100644 --- a/app/src/main/java/asgardius/page/s3manager/BucketSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/BucketSelect.java @@ -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); } diff --git a/app/src/main/java/asgardius/page/s3manager/MainActivity.java b/app/src/main/java/asgardius/page/s3manager/MainActivity.java index cf1defc..d32fc10 100644 --- a/app/src/main/java/asgardius/page/s3manager/MainActivity.java +++ b/app/src/main/java/asgardius/page/s3manager/MainActivity.java @@ -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); diff --git a/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java b/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java index c366ca0..34d144f 100644 --- a/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java +++ b/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java @@ -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) { diff --git a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java index 9766c32..636eb1a 100644 --- a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java @@ -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); } diff --git a/app/src/main/res/layout/activity_account_add.xml b/app/src/main/res/layout/activity_account_add.xml index 60f259b..8373475 100644 --- a/app/src/main/res/layout/activity_account_add.xml +++ b/app/src/main/res/layout/activity_account_add.xml @@ -20,19 +20,42 @@ app:layout_constraintTop_toTopOf="parent" tools:ignore="MissingConstraints" /> - + tools:ignore="MissingConstraints" + tools:layout_editor_absoluteX="20dp"> + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 062b40b..67d49d3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,7 @@ Credentials are correct Account Alias S3 Endpoint URL + S3 Region S3 Access Key S3 Secret Key Account added successfully