From b4a4fc811aa634e3e2f93bb5f4e4efd7f4597a6e Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Tue, 6 Sep 2022 12:03:43 -0700 Subject: [PATCH] account edit --- .../asgardius/page/s3manager/AccountAdd.java | 25 ++++++++++++++-- .../page/s3manager/MainActivity.java | 29 ++++++++++++++++--- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/AccountAdd.java b/app/src/main/java/asgardius/page/s3manager/AccountAdd.java index f33bc50..f9e9223 100644 --- a/app/src/main/java/asgardius/page/s3manager/AccountAdd.java +++ b/app/src/main/java/asgardius/page/s3manager/AccountAdd.java @@ -12,7 +12,8 @@ import android.widget.Toast; public class AccountAdd extends AppCompatActivity { EditText aapick, aupick, appick, aepick; - String alias, username, password, endpoint; + String alias, username, password, endpoint, id; + boolean edit; @Override protected void onCreate(Bundle savedInstanceState) { @@ -23,6 +24,19 @@ public class AccountAdd extends AppCompatActivity { aupick = (EditText)findViewById(R.id.username); appick = (EditText)findViewById(R.id.password); Button register = (Button)findViewById(R.id.addaccount); + edit = getIntent().getBooleanExtra("edit", false); + 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"); + aapick.setText(id); + //aapick.setEnabled(false); + aepick.setText(endpoint); + aupick.setText(username); + appick.setText(password); + } register.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view) { @@ -42,8 +56,13 @@ public class AccountAdd extends AppCompatActivity { } 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(); + if (edit) { + db.execSQL("UPDATE account SET id=\""+id+"\", endpoint=\""+endpoint+"\", username=\""+username+"\", password=\""+password+"\" 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+"\")"); + Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_success), Toast.LENGTH_SHORT).show(); + } mainmenu(); } catch (Exception e) { Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_fail), Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/asgardius/page/s3manager/MainActivity.java b/app/src/main/java/asgardius/page/s3manager/MainActivity.java index 26d96b1..a299997 100644 --- a/app/src/main/java/asgardius/page/s3manager/MainActivity.java +++ b/app/src/main/java/asgardius/page/s3manager/MainActivity.java @@ -19,7 +19,7 @@ import java.util.ArrayList; public class MainActivity extends AppCompatActivity { static boolean DEFAULT_PATH_STYLE_ACCESS = true; - String username, password, endpoint; + String alias, username, password, endpoint; RecyclerView recyclerView; ArrayList Name; ArrayList Img; @@ -128,7 +128,21 @@ public class MainActivity extends AppCompatActivity { // Toast message on menu item clicked //Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); if (menuItem.getTitle() == getResources().getString(R.string.accountedit_button)) { - Toast.makeText(MainActivity.this, "This feature is not yet implemented", Toast.LENGTH_SHORT).show(); + try { + String query = "SELECT id, endpoint, username, password FROM account where id=\""+ Name.get(position).toString()+ "\""; + System.out.println(query); + Cursor cursor = db.rawQuery(query,null); + if (cursor.moveToNext()){ + alias = cursor.getString(0); + endpoint = cursor.getString(1); + username = cursor.getString(2); + password = cursor.getString(3); + } + addaccount(true); + //Toast.makeText(MainActivity.this, "This feature is not yet implemented", Toast.LENGTH_SHORT).show(); + } catch (Exception e) { + e.printStackTrace(); + } } else if (menuItem.getTitle() == getResources().getString(R.string.accountdel_button)) { if (db != null) { @@ -157,7 +171,7 @@ public class MainActivity extends AppCompatActivity { @Override public void onClick(View view) { //buttonaction - addaccount(); + addaccount(false); } }); @@ -181,9 +195,16 @@ public class MainActivity extends AppCompatActivity { } - private void addaccount() { + private void addaccount(boolean edit) { Intent intent = new Intent(this, AccountAdd.class); + if (edit) { + intent.putExtra("alias", alias); + intent.putExtra("endpoint", endpoint); + intent.putExtra("username", username); + intent.putExtra("password", password); + } + intent.putExtra("edit", edit); startActivity(intent); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3a48468..946dfed 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,6 +13,8 @@ Remove Account Account removed successfully Edit Account + Save Changes + Account edited successfully Connections without SSL are not allowed Endpoint URL must start with https:// File Explorer Test