account tester
This commit is contained in:
parent
b4a4fc811a
commit
ff332f3449
4 changed files with 88 additions and 0 deletions
|
@ -3,6 +3,8 @@
|
|||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<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_bucket_select.xml" value="0.2" />
|
||||
<entry key="app/src/main/res/layout/activity_list_item.xml" value="0.19610507246376813" />
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package asgardius.page.s3manager;
|
||||
|
||||
import static com.amazonaws.regions.Regions.US_EAST_1;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
|
@ -10,9 +12,22 @@ import android.widget.Button;
|
|||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.regions.Region;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.S3ClientOptions;
|
||||
import com.amazonaws.services.s3.model.Bucket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AccountAdd extends AppCompatActivity {
|
||||
EditText aapick, aupick, appick, aepick;
|
||||
String alias, username, password, endpoint, id;
|
||||
AWSCredentials myCredentials;
|
||||
AmazonS3 s3client;
|
||||
boolean edit;
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +39,11 @@ public class AccountAdd extends AppCompatActivity {
|
|||
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);
|
||||
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
|
||||
s3ClientOptions.setPathStyleAccess(true);
|
||||
if (edit) {
|
||||
register.setText(getResources().getString(R.string.accountsave_button));
|
||||
id = getIntent().getStringExtra("alias");
|
||||
|
@ -37,6 +56,9 @@ public class AccountAdd extends AppCompatActivity {
|
|||
aupick.setText(username);
|
||||
appick.setText(password);
|
||||
}
|
||||
|
||||
|
||||
|
||||
register.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -71,6 +93,60 @@ public class AccountAdd extends AppCompatActivity {
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
accounttest.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//buttonaction
|
||||
alias = aapick.getText().toString();
|
||||
endpoint = aepick.getText().toString();
|
||||
username = aupick.getText().toString();
|
||||
password = appick.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://")) {
|
||||
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();
|
||||
} else {
|
||||
Thread servertest = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//Your code goes here
|
||||
myCredentials = new BasicAWSCredentials(username, password);
|
||||
s3client = new AmazonS3Client(myCredentials, region);
|
||||
s3client.setEndpoint(endpoint);
|
||||
s3client.setS3ClientOptions(s3ClientOptions);
|
||||
List<Bucket> buckets = s3client.listBuckets();
|
||||
//System.out.println(Name);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Sending reference and data to Adapter
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accounttest_success), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
} 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
servertest.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void mainmenu() {
|
||||
|
|
|
@ -81,6 +81,14 @@
|
|||
android:text="@string/accountadd_button"
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/testaccount"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/accounttest_button"
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -3,6 +3,8 @@
|
|||
<string name="title_activity_video_player">VideoPlayer</string>
|
||||
<string name="accountselect">Please choose an account</string>
|
||||
<string name="accountadd_button">Add Account</string>
|
||||
<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_endpoint">S3 Endpoint URL</string>
|
||||
<string name="accountadd_username">S3 Access Key</string>
|
||||
|
|
Loading…
Reference in a new issue