account edit
This commit is contained in:
parent
f1c1d7d32c
commit
b4a4fc811a
3 changed files with 49 additions and 7 deletions
|
@ -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 {
|
||||
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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
<string name="accountdel_button">Remove Account</string>
|
||||
<string name="accountdel_success">Account removed successfully</string>
|
||||
<string name="accountedit_button">Edit Account</string>
|
||||
<string name="accountsave_button">Save Changes</string>
|
||||
<string name="accountsave_success">Account edited successfully</string>
|
||||
<string name="nosslwarning">Connections without SSL are not allowed</string>
|
||||
<string name="invalid_url">Endpoint URL must start with https://</string>
|
||||
<string name="explorer_test_button">File Explorer Test</string>
|
||||
|
|
Loading…
Reference in a new issue