diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6dc6e8663..29df753ba 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -49,6 +49,10 @@ + diff --git a/app/src/main/java/com/example/marat/wal/controller/Controller.java b/app/src/main/java/com/example/marat/wal/controller/Controller.java index dcde2b1d8..b6f1a868e 100644 --- a/app/src/main/java/com/example/marat/wal/controller/Controller.java +++ b/app/src/main/java/com/example/marat/wal/controller/Controller.java @@ -8,6 +8,7 @@ import android.os.AsyncTask; import android.util.Log; import android.view.View; import android.widget.TextView; +import android.widget.Toast; import com.example.marat.wal.R; import com.example.marat.wal.model.ESTransaction; @@ -15,6 +16,7 @@ import com.example.marat.wal.model.ESTransactionListResponse; import com.example.marat.wal.model.VMAccount; import com.example.marat.wal.views.AccountListActivity; import com.example.marat.wal.views.CreateAccountActivity; +import com.example.marat.wal.views.ExportAccountActivity; import com.example.marat.wal.views.ImportAccountActivity; import com.example.marat.wal.views.TransactionListActivity; import com.example.marat.wal.views.SendActivity; @@ -244,6 +246,22 @@ public class Controller { loadAccounts(); } + public void navigateToExportAccount(Context context, String address) { + Intent intent = new Intent(context, ExportAccountActivity.class); + intent.putExtra(getString(R.string.address_key), address); + context.startActivity(intent); + } + + public String clickExportAccount(Context context, String address, String password) { + try { + Account account = mEtherStore.getAccount(address); + return mEtherStore.exportAccount(account, password); + } catch (Exception e) { + Toast.makeText(context, "Failed to export account " + e.toString(), Toast.LENGTH_SHORT); + } + return ""; + } + private class GetWeb3ClientVersionTask extends AsyncTask { protected Void doInBackground(Void... params) { try { diff --git a/app/src/main/java/com/example/marat/wal/views/AccountListActivity.java b/app/src/main/java/com/example/marat/wal/views/AccountListActivity.java index 4069e8184..f8b6333e9 100644 --- a/app/src/main/java/com/example/marat/wal/views/AccountListActivity.java +++ b/app/src/main/java/com/example/marat/wal/views/AccountListActivity.java @@ -138,7 +138,8 @@ public class AccountListActivity extends AppCompatActivity implements DeleteAcco public final View mView; public final TextView mIdView; public final TextView mContentView; - public final ImageButton mImageButton; + public final ImageButton mDeleteButton; + public final ImageButton mExportButton; public VMAccount mItem; public ViewHolder(View view) { @@ -146,9 +147,9 @@ public class AccountListActivity extends AppCompatActivity implements DeleteAcco mView = view; mIdView = (TextView) view.findViewById(R.id.id); mContentView = (TextView) view.findViewById(R.id.content); - mImageButton = (ImageButton) view.findViewById(R.id.delete_button); + mDeleteButton = (ImageButton) view.findViewById(R.id.delete_button); - mImageButton.setOnClickListener(new View.OnClickListener() { + mDeleteButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.d(TAG, "Delete " + mItem.getAddress()); Toast.makeText(AccountListActivity.this, "Delete button pressed", Toast.LENGTH_SHORT).show(); @@ -160,6 +161,14 @@ public class AccountListActivity extends AppCompatActivity implements DeleteAcco } }); + mExportButton = (ImageButton) view.findViewById(R.id.export_button); + mExportButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + Log.d(TAG, "Export " + mItem.getAddress()); + Toast.makeText(AccountListActivity.this, "Export button pressed", Toast.LENGTH_SHORT).show(); + mController.navigateToExportAccount(AccountListActivity.this, mItem.getAddress()); + } + }); } @Override diff --git a/app/src/main/java/com/example/marat/wal/views/ExportAccountActivity.java b/app/src/main/java/com/example/marat/wal/views/ExportAccountActivity.java new file mode 100644 index 000000000..31262172c --- /dev/null +++ b/app/src/main/java/com/example/marat/wal/views/ExportAccountActivity.java @@ -0,0 +1,65 @@ +package com.example.marat.wal.views; + +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.marat.wal.R; +import com.example.marat.wal.controller.Controller; + +public class ExportAccountActivity extends AppCompatActivity { + + private Controller mController; + + private String mAddress; + private EditText mPasswordText; + private Button mExportButton; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_export_account); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + mAddress = getIntent().getStringExtra(getString(R.string.address_key)); + + getSupportActionBar().setTitle(getString(R.string.action_export) + mAddress); + + mController = Controller.get(); + + mPasswordText = (EditText) findViewById(R.id.export_password); + mExportButton = (Button) findViewById(R.id.export_account_button); + mExportButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String keystoreJson = mController.clickExportAccount(ExportAccountActivity.this, mAddress, mPasswordText.getText().toString()); + showKeystore(keystoreJson); + } + }); + } + + private void showKeystore(String keystoreJson) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(keystoreJson) + .setTitle(getString(R.string.message_save_this)); + + // Add the button + builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + finish(); + } + }); + + AlertDialog dialog = builder.create(); + dialog.show(); + } + +} diff --git a/app/src/main/java/com/example/marat/wal/views/TransactionListActivity.java b/app/src/main/java/com/example/marat/wal/views/TransactionListActivity.java index b8e9d576a..386a1aafd 100644 --- a/app/src/main/java/com/example/marat/wal/views/TransactionListActivity.java +++ b/app/src/main/java/com/example/marat/wal/views/TransactionListActivity.java @@ -93,7 +93,7 @@ public class TransactionListActivity extends AppCompatActivity implements OnTask mController.loadViewModels(); //Bundle extras = getIntent().getExtras(); - //mAddress = extras.getString("address"); + //mAddressText = extras.getString("address"); init(); diff --git a/app/src/main/res/drawable/ic_code_black_24dp.xml b/app/src/main/res/drawable/ic_code_black_24dp.xml new file mode 100644 index 000000000..6f1ccb6e4 --- /dev/null +++ b/app/src/main/res/drawable/ic_code_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_share_black_24dp.xml b/app/src/main/res/drawable/ic_share_black_24dp.xml new file mode 100644 index 000000000..e3fe874d6 --- /dev/null +++ b/app/src/main/res/drawable/ic_share_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/account_list_content.xml b/app/src/main/res/layout/account_list_content.xml index bdb1f982f..d5535ec94 100644 --- a/app/src/main/res/layout/account_list_content.xml +++ b/app/src/main/res/layout/account_list_content.xml @@ -17,13 +17,23 @@ android:id="@+id/id" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_weight="0.80" + android:layout_weight="0.70" android:layout_margin="@dimen/text_margin" android:ellipsize="middle" android:textIsSelectable="true" android:textSize="12dp" android:textAppearance="?attr/textAppearanceListItem" /> + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/content_export_account.xml b/app/src/main/res/layout/content_export_account.xml new file mode 100644 index 000000000..3b188ea96 --- /dev/null +++ b/app/src/main/res/layout/content_export_account.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + +