Adds import and export functionality

pull/2/head
Marat Subkhankulov 7 years ago
parent 4ccd7484dc
commit 5f06a07674
  1. 4
      app/src/main/AndroidManifest.xml
  2. 18
      app/src/main/java/com/example/marat/wal/controller/Controller.java
  3. 15
      app/src/main/java/com/example/marat/wal/views/AccountListActivity.java
  4. 65
      app/src/main/java/com/example/marat/wal/views/ExportAccountActivity.java
  5. 2
      app/src/main/java/com/example/marat/wal/views/TransactionListActivity.java
  6. 9
      app/src/main/res/drawable/ic_code_black_24dp.xml
  7. 9
      app/src/main/res/drawable/ic_share_black_24dp.xml
  8. 12
      app/src/main/res/layout/account_list_content.xml
  9. 26
      app/src/main/res/layout/activity_export_account.xml
  10. 46
      app/src/main/res/layout/content_export_account.xml
  11. 5
      app/src/main/res/values/strings.xml

@ -49,6 +49,10 @@
<activity
android:name=".views.ImportAccountActivity"
android:label="@string/title_activity_import_account"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".views.ExportAccountActivity"
android:label="@string/title_activity_export_account"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

@ -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<Void, Void, Void> {
protected Void doInBackground(Void... params) {
try {

@ -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

@ -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();
}
}

@ -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();

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M9.4,16.6L4.8,12l4.6,-4.6L8,6l-6,6 6,6 1.4,-1.4zM14.6,16.6l4.6,-4.6 -4.6,-4.6L16,6l6,6 -6,6 -1.4,-1.4z"/>
</vector>

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>

@ -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" />
<ImageButton
android:id="@+id/export_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:src="@drawable/ic_share_black_24dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageButton
android:id="@+id/delete_button"
android:layout_width="0dp"

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="com.example.marat.wal.views.ExportAccountActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:title="@string/action_export"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_export_account" />
</android.support.design.widget.CoordinatorLayout>

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.marat.wal.views.ExportAccountActivity"
tools:showIn="@layout/activity_export_account">
<LinearLayout
android:id="@+id/import_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/export_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="@+id/login"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/export_account_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/action_export"
android:textStyle="bold" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>

@ -137,4 +137,9 @@
<string name="title_activity_import_account">ImportAccountActivity</string>
<string name="hint_keystore">keystore</string>
<string name="action_import">Import</string>
<string name="title_activity_export_account">ExportAccountActivity</string>
<string name="action_export">Export</string>
<string name="address_key">ADDRESS</string>
<string name="message_save_this">Keep this someplace safe</string>
<string name="ok">ok</string>
</resources>

Loading…
Cancel
Save