Merge pull request 'account manager' (#3) from account into main

Reviewed-on: https://patrice.asgardius.company/gitea/asgardius/s3manager/pulls/3
This commit is contained in:
Page Asgardius 2022-09-04 16:50:43 -07:00
commit bc0c91b771
10 changed files with 308 additions and 62 deletions

View file

@ -3,6 +3,7 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<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" />
<entry key="app/src/main/res/layout/activity_main.xml" value="0.1" />

View file

@ -15,6 +15,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.AsgardiusS3Manager"
tools:targetApi="31">
<activity
android:name=".AccountAdd"
android:exported="false" />
<activity
android:name=".ObjectSelect"
android:exported="false" />

View file

@ -0,0 +1,53 @@
package asgardius.page.s3manager;
import androidx.appcompat.app.AppCompatActivity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class AccountAdd extends AppCompatActivity {
EditText aapick, aupick, appick, aepick;
String alias, username, password, endpoint;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_add);
aapick = (EditText)findViewById(R.id.alias);
aepick = (EditText)findViewById(R.id.endpoint);
aupick = (EditText)findViewById(R.id.username);
appick = (EditText)findViewById(R.id.password);
Button register = (Button)findViewById(R.id.addaccount);
register.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();
System.out.println("Alias " + alias);
System.out.println("Endpoint " + endpoint);
System.out.println("Username " + username);
System.out.println("Password " + password);
MyDbHelper dbHelper = new MyDbHelper(AccountAdd.this);
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 (db != null) {
// Database Queries
try {
db.execSQL("INSERT INTO account VALUES (\""+alias+"\", \""+endpoint+"\", \""+username+"\", \""+password+"\")");
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_success), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_fail), Toast.LENGTH_SHORT).show();
}
}
}
});
}
}

View file

@ -1,46 +1,130 @@
package asgardius.page.s3manager;
import static com.amazonaws.regions.RegionUtils.getRegion;
import static com.amazonaws.regions.Regions.US_EAST_1;
import static com.amazonaws.services.s3.S3ClientOptions.DEFAULT_PATH_STYLE_ACCESS;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
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.GeneratePresignedUrlRequest;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.net.URL;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
static boolean DEFAULT_PATH_STYLE_ACCESS = true;
String username, password, endpoint;
RecyclerView recyclerView;
ArrayList Name;
ArrayList Img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = getString(R.string.access_key);
password = getResources().getString(R.string.secret_key);
endpoint = getResources().getString(R.string.endpoint_url);
recyclerView = findViewById(R.id.alist);
// layout for vertical orientation
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(linearLayoutManager);
MyDbHelper dbHelper = new MyDbHelper(this);
SQLiteDatabase db = dbHelper.getWritableDatabase();
if (db != null) {
// Database Queries
System.out.println("Database OK");
Name = new ArrayList<String>();
Img = new ArrayList<String>();
String query = "SELECT id FROM account";
Cursor cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){
Name.add(cursor.getString(0));
Img.add(R.drawable.account);
}
} else {
System.out.println("Database Missing");
}
Thread listaccount = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
System.out.println(Name);
runOnUiThread(new Runnable() {
@Override
public void run() {
// Sending reference and data to Adapter
Adapter adapter = new Adapter(MainActivity.this, Img, Name);
// Setting Adapter to RecyclerView
recyclerView.setAdapter(adapter);
}
});
} 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();
}
}
});
listaccount.start();
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), recyclerView, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
//System.out.println("Click on "+Name.get(position).toString());
if (db != null) {
// Database Queries
System.out.println("Database OK");
try {
String query = "SELECT endpoint, username, password 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);
explorer();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void onLongClick(View view, int position) {
System.out.println("Long click on "+Name.get(position).toString());
}
}));
//This is to launch video playback test
Button videotest = (Button)findViewById(R.id.vtest);
videotest.setOnClickListener(new View.OnClickListener(){
Button addaccount = (Button)findViewById(R.id.addaccount);
addaccount.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
s3test();
//videoplayer("https://video.asgardius.company/download/videos/41780585-a935-4d53-84c8-45ce97141231-480.mp4");
addaccount();
}
});
@ -50,35 +134,10 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onClick(View view) {
//buttonaction
explorer();
//videoplayer("https://video.asgardius.company/download/videos/41780585-a935-4d53-84c8-45ce97141231-480.mp4");
}
});
}
private void s3test() {
Region region = Region.getRegion(US_EAST_1);
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
s3ClientOptions.setPathStyleAccess(true);
AWSCredentials myCredentials = new BasicAWSCredentials(username, password);
AmazonS3 s3client = new AmazonS3Client(myCredentials, region);
s3client.setEndpoint(endpoint);
s3client.setS3ClientOptions(s3ClientOptions);
//s3client.setRegion(getRegion("asteroid"));
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(getResources().getString(R.string.bucketname), getResources().getString(R.string.objectname));
URL objectURL = s3client.generatePresignedUrl(request);
videoplayer(objectURL.toString());
}
private void videoplayer(String url) {
Intent intent = new Intent(this, VideoPlayer.class);
intent.putExtra("video_url", url);
startActivity(intent);
}
private void explorer() {
Intent intent = new Intent(this, BucketSelect.class);
@ -89,4 +148,11 @@ public class MainActivity extends AppCompatActivity {
}
private void addaccount() {
Intent intent = new Intent(this, AccountAdd.class);
startActivity(intent);
}
}

View file

@ -0,0 +1,22 @@
package asgardius.page.s3manager;
import android.content.Context;
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 dbname = "accounts.sqlite3";
private static final int dbversion = 3;
public MyDbHelper(Context context) {
super(context, dbname, null, dbversion);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(atcreate);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AccountAdd">
<EditText
android:id="@+id/alias"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="0dp"
android:focusable="true"
android:hint="@string/accountadd_alias"
android:importantForAutofill="no"
android:inputType="text"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/endpoint"
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"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="94dp"
android:autofillHints="username"
android:focusable="true"
android:hint="@string/accountadd_username"
android:inputType="textNoSuggestions"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="140dp"
android:autofillHints="username"
android:focusable="true"
android:hint="@string/accountadd_password"
android:inputType="textPassword"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="160dp"
android:orientation="horizontal"
android:padding="10dp"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp">
<Button
android:id="@+id/addaccount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/accountadd_button"
tools:ignore="MissingConstraints" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -7,28 +7,30 @@
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="100dp"
android:text="@string/accountselect"
android:textAlignment="center"
android:textSize="25sp"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="20dp"
android:orientation="horizontal"
android:padding="10dp"
tools:ignore="MissingConstraints">
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp">
<Button
android:id="@+id/vtest"
android:id="@+id/addaccount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/video_test_button"
android:text="@string/accountadd_button"
tools:ignore="MissingConstraints" />
<Button
@ -36,9 +38,19 @@
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/explorer_test_button"
android:text="@string/dummy_button"
tools:ignore="MissingConstraints" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/alist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="140dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:layout_editor_absoluteX="27dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,12 +1,15 @@
<resources>
<string name="app_name">Asgardius S3 Manager</string>
<string name="title_activity_video_player">VideoPlayer</string>
<!-- S3 credentials are being used during development process and will become useless when account manager is ready -->
<string name="endpoint_url">https://object.asgardius.company</string>
<string name="access_key">asgardius</string>
<string name="secret_key">DTMp5kftamr49Ke7</string>
<string name="bucketname">asgardiustest</string>
<string name="objectname">peces felices.mp4</string>
<string name="accountselect">Please choose an account</string>
<string name="accountadd_button">Add Account</string>
<string name="accountadd_alias">Account Alias</string>
<string name="accountadd_endpoint">S3 Endpoint URL</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>
<string name="accountadd_fail">This alias is already in use</string>
<string name="accountadd_null">All fields are required</string>
<string name="explorer_test_button">File Explorer Test</string>
<string name="video_test_button">Video Test</string>
<string name="media_conn_fail">Cannot retrieve media file</string>