1
mirror of https://github.com/m2049r/xmrwallet synced 2025-06-01 10:24:13 +02:00

tweaks + get address from wallet (and not from file)

This commit is contained in:
m2049r 2017-09-02 12:51:57 +02:00
parent fe84bae9ed
commit 68abaec6cb
8 changed files with 117 additions and 35 deletions

@ -11,7 +11,7 @@
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@drawable/ic_monero_32dp"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">

@ -99,7 +99,7 @@ public class LoginActivity extends AppCompatActivity
} }
@Override @Override
public void onWalletDetails(final String walletName) { public void onWalletDetails(String walletName) {
Log.d(TAG, "details for wallet ." + walletName + "."); Log.d(TAG, "details for wallet ." + walletName + ".");
final File walletFile = Helper.getWalletFile(this, walletName); final File walletFile = Helper.getWalletFile(this, walletName);
if (WalletManager.getInstance().walletExists(walletFile)) { if (WalletManager.getInstance().walletExists(walletFile)) {
@ -115,12 +115,16 @@ public class LoginActivity extends AppCompatActivity
} }
@Override @Override
public void onWalletReceive(final String walletName) { public void onWalletReceive(String walletName) {
Log.d(TAG, "receive for wallet ." + walletName + "."); Log.d(TAG, "receive for wallet ." + walletName + ".");
final File walletFile = Helper.getWalletFile(this, walletName); final File walletFile = Helper.getWalletFile(this, walletName);
if (WalletManager.getInstance().walletExists(walletFile)) { if (WalletManager.getInstance().walletExists(walletFile)) {
String address = WalletManager.getInstance().getWalletInfo(walletFile).address; promptPassword(walletName, new PasswordAction() {
startReceive(address); @Override
public void action(String walletName, String password) {
startReceive(walletFile, password);
}
});
} else { // this cannot really happen as we prefilter choices } else { // this cannot really happen as we prefilter choices
Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show(); Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show();
} }
@ -263,7 +267,7 @@ public class LoginActivity extends AppCompatActivity
startActivity(intent); startActivity(intent);
} }
void startDetails(final File walletFile, final String password, String type) { void startDetails(File walletFile, String password, String type) {
Log.d(TAG, "startDetails()"); Log.d(TAG, "startDetails()");
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putString("path", walletFile.getAbsolutePath()); b.putString("path", walletFile.getAbsolutePath());
@ -272,10 +276,11 @@ public class LoginActivity extends AppCompatActivity
startReviewFragment(b); startReviewFragment(b);
} }
void startReceive(String address) { void startReceive(File walletFile, String password) {
Log.d(TAG, "startReceive()"); Log.d(TAG, "startReceive()");
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putString("address", address); b.putString("path", walletFile.getAbsolutePath());
b.putString("password", password);
startReceiveFragment(b); startReceiveFragment(b);
} }

@ -119,7 +119,7 @@ public class LoginFragment extends Fragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
Log.d(TAG, "onPause()"); Log.d(TAG, "onResume()");
activityCallback.setTitle(getString(R.string.login_activity_name)); activityCallback.setTitle(getString(R.string.login_activity_name));
} }
@ -453,6 +453,8 @@ public class LoginFragment extends Fragment {
return true; return true;
} }
checkAndSetWalletDaemon("", !isMainNet()); // just set selected net
activityCallback.onWalletReceive(wallet); activityCallback.onWalletReceive(wallet);
return true; return true;
} }

@ -23,6 +23,7 @@ import android.support.v4.app.Fragment;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -31,6 +32,7 @@ import android.view.inputmethod.EditorInfo;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
@ -40,6 +42,8 @@ import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.m2049r.xmrwallet.model.Wallet; import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.model.WalletManager;
import com.m2049r.xmrwallet.service.MoneroHandlerThread;
import com.m2049r.xmrwallet.util.Helper; import com.m2049r.xmrwallet.util.Helper;
import java.util.HashMap; import java.util.HashMap;
@ -48,12 +52,14 @@ import java.util.Map;
public class ReceiveFragment extends Fragment { public class ReceiveFragment extends Fragment {
static final String TAG = "ReceiveFragment"; static final String TAG = "ReceiveFragment";
ProgressBar pbProgress;
TextView tvAddress; TextView tvAddress;
EditText etPaymentId; EditText etPaymentId;
EditText etAmount; EditText etAmount;
Button bPaymentId; Button bPaymentId;
Button bGenerate; Button bGenerate;
ImageView qrCode; ImageView qrCode;
EditText etDummy;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -61,14 +67,17 @@ public class ReceiveFragment extends Fragment {
View view = inflater.inflate(R.layout.receive_fragment, container, false); View view = inflater.inflate(R.layout.receive_fragment, container, false);
pbProgress = (ProgressBar) view.findViewById(R.id.pbProgress);
tvAddress = (TextView) view.findViewById(R.id.tvAddress); tvAddress = (TextView) view.findViewById(R.id.tvAddress);
etPaymentId = (EditText) view.findViewById(R.id.etPaymentId); etPaymentId = (EditText) view.findViewById(R.id.etPaymentId);
etAmount = (EditText) view.findViewById(R.id.etAmount); etAmount = (EditText) view.findViewById(R.id.etAmount);
bPaymentId = (Button) view.findViewById(R.id.bPaymentId); bPaymentId = (Button) view.findViewById(R.id.bPaymentId);
qrCode = (ImageView) view.findViewById(R.id.qrCode); qrCode = (ImageView) view.findViewById(R.id.qrCode);
bGenerate = (Button) view.findViewById(R.id.bGenerate); bGenerate = (Button) view.findViewById(R.id.bGenerate);
etDummy = (EditText) view.findViewById(R.id.etDummy);
etPaymentId.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); etPaymentId.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
etDummy.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Helper.showKeyboard(getActivity()); Helper.showKeyboard(getActivity());
etPaymentId.requestFocus(); etPaymentId.requestFocus();
@ -86,7 +95,7 @@ public class ReceiveFragment extends Fragment {
etPaymentId.addTextChangedListener(new TextWatcher() { etPaymentId.addTextChangedListener(new TextWatcher() {
@Override @Override
public void afterTextChanged(Editable editable) { public void afterTextChanged(Editable editable) {
qrCode.setImageBitmap(null); qrCode.setImageBitmap(getMoneroLogo());
if (paymentIdOk() && amountOk()) { if (paymentIdOk() && amountOk()) {
bGenerate.setEnabled(true); bGenerate.setEnabled(true);
} else { } else {
@ -118,7 +127,7 @@ public class ReceiveFragment extends Fragment {
etAmount.addTextChangedListener(new TextWatcher() { etAmount.addTextChangedListener(new TextWatcher() {
@Override @Override
public void afterTextChanged(Editable editable) { public void afterTextChanged(Editable editable) {
qrCode.setImageBitmap(null); qrCode.setImageBitmap(getMoneroLogo());
if (paymentIdOk() && amountOk()) { if (paymentIdOk() && amountOk()) {
bGenerate.setEnabled(true); bGenerate.setEnabled(true);
} else { } else {
@ -156,12 +165,58 @@ public class ReceiveFragment extends Fragment {
} }
}); });
showProgress();
qrCode.setImageBitmap(getMoneroLogo());
Bundle b = getArguments(); Bundle b = getArguments();
String address = b.getString("address", ""); String address = b.getString("address");
tvAddress.setText(address); if (address == null) {
String path = b.getString("path");
String password = b.getString("password");
show(path, password);
} else {
show(address);
}
return view; return view;
} }
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onResume()");
if (paymentIdOk() && amountOk() && tvAddress.getText().length() > 0) {
generateQr();
}
}
private void show(String address) {
tvAddress.setText(address);
etPaymentId.setEnabled(true);
etAmount.setEnabled(true);
bPaymentId.setEnabled(true);
bGenerate.setEnabled(true);
hideProgress();
generateQr();
}
private void show(final String walletPath, final String password) {
new Thread(null,
new Runnable() {
@Override
public void run() {
final Wallet wallet = WalletManager.getInstance().openWallet(walletPath, password);
getActivity().runOnUiThread(new Runnable() {
public void run() {
show(wallet.getAddress());
wallet.close();
}
});
}
}
, "Receive", MoneroHandlerThread.THREAD_STACK_SIZE).start();
}
private boolean amountOk() { private boolean amountOk() {
String amountEntry = etAmount.getText().toString(); String amountEntry = etAmount.getText().toString();
if (amountEntry.isEmpty()) return true; if (amountEntry.isEmpty()) return true;
@ -179,7 +234,7 @@ public class ReceiveFragment extends Fragment {
String paymentId = etPaymentId.getText().toString(); String paymentId = etPaymentId.getText().toString();
String enteredAmount = etAmount.getText().toString(); String enteredAmount = etAmount.getText().toString();
// that's a lot of converting ... // that's a lot of converting ...
String amount = (enteredAmount.isEmpty()?enteredAmount:Helper.getDisplayAmount(Wallet.getAmountFromString(enteredAmount))); String amount = (enteredAmount.isEmpty() ? enteredAmount : Helper.getDisplayAmount(Wallet.getAmountFromString(enteredAmount)));
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(ScannerFragment.QR_SCHEME).append(address); sb.append(ScannerFragment.QR_SCHEME).append(address);
boolean first = true; boolean first = true;
@ -201,7 +256,9 @@ public class ReceiveFragment extends Fragment {
String text = sb.toString(); String text = sb.toString();
Bitmap qr = generate(text, 500, 500); Bitmap qr = generate(text, 500, 500);
if (qr != null) { if (qr != null) {
etAmount.setText(amount);
qrCode.setImageBitmap(qr); qrCode.setImageBitmap(qr);
etDummy.requestFocus();
} }
} }
@ -263,4 +320,13 @@ public class ReceiveFragment extends Fragment {
return logo; return logo;
} }
public void showProgress() {
pbProgress.setIndeterminate(true);
pbProgress.setVisibility(View.VISIBLE);
}
public void hideProgress() {
pbProgress.setVisibility(View.GONE);
}
} }

@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="50dp" android:width="100dp"
android:height="50dp" android:height="100dp"
android:viewportHeight="75.0" android:viewportHeight="75.0"
android:viewportWidth="75.0"> android:viewportWidth="75.0">
<path <path

@ -4,19 +4,13 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <ProgressBar
android:id="@+id/pbProgress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8sp" android:layout_marginBottom="8sp"
android:orientation="vertical"> android:visibility="invisible" />
<ProgressBar
android:id="@+id/pbProgress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

@ -4,6 +4,14 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<ProgressBar
android:id="@+id/pbProgress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8sp"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/tvAddress" android:id="@+id/tvAddress"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -36,6 +44,7 @@
android:layout_width="0sp" android:layout_width="0sp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="5" android:layout_weight="5"
android:enabled="false"
android:hint="@string/receive_paymentid_hint" android:hint="@string/receive_paymentid_hint"
android:imeOptions="actionNext" android:imeOptions="actionNext"
android:inputType="textMultiLine" android:inputType="textMultiLine"
@ -49,7 +58,7 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_weight="2" android:layout_weight="2"
android:background="@color/colorPrimary" android:background="@color/colorPrimary"
android:enabled="true" android:enabled="false"
android:minHeight="36sp" android:minHeight="36sp"
android:text="@string/receive_paymentid_button" android:text="@string/receive_paymentid_button"
android:textSize="12sp" /> android:textSize="12sp" />
@ -58,9 +67,9 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="4sp" android:layout_marginBottom="4sp"
android:layout_marginTop="4sp" android:layout_marginTop="4sp"
android:orientation="horizontal"
android:weightSum="10"> android:weightSum="10">
<TextView <TextView
@ -76,10 +85,11 @@
android:id="@+id/etAmount" android:id="@+id/etAmount"
android:layout_width="0sp" android:layout_width="0sp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="7"
android:enabled="false"
android:hint="@string/receive_amount_hint" android:hint="@string/receive_amount_hint"
android:imeOptions="actionNext" android:imeOptions="actionNext"
android:inputType="numberDecimal" android:inputType="numberDecimal"
android:layout_weight="7"
android:textAlignment="textStart" android:textAlignment="textStart"
android:textSize="24sp" /> android:textSize="24sp" />
</LinearLayout> </LinearLayout>
@ -90,16 +100,21 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="4sp" android:layout_marginBottom="4sp"
android:layout_marginTop="4sp" android:layout_marginTop="4sp"
android:minHeight="36sp"
android:background="@color/colorPrimary" android:background="@color/colorPrimary"
android:enabled="false"
android:minHeight="36sp"
android:text="@string/receive_generate_hint" /> android:text="@string/receive_generate_hint" />
<ImageView <ImageView
android:id="@+id/qrCode" android:id="@+id/qrCode"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="fill_parent"
android:layout_margin="16sp" android:layout_margin="16sp"
android:adjustViewBounds="true" android:adjustViewBounds="true" />
android:src="@drawable/ic_monero_32dp" />
<EditText
android:id="@+id/etDummy"
android:layout_width="0sp"
android:layout_height="0sp" />
</LinearLayout> </LinearLayout>

@ -1,6 +1,6 @@
<resources> <resources>
<string name="app_name">Monerujo</string> <string name="app_name">Monerujo</string>
<string name="login_activity_name">Select Wallet</string> <string name="login_activity_name">Monerujo</string>
<string name="wallet_activity_name">Wallet</string> <string name="wallet_activity_name">Wallet</string>
<string name="menu_info">Details</string> <string name="menu_info">Details</string>
@ -152,7 +152,7 @@
<string name="tx_pending">PENDING</string> <string name="tx_pending">PENDING</string>
<string name="tx_failed">FAILED</string> <string name="tx_failed">FAILED</string>
<string name="receive_generate_hint">Generate QR Code</string> <string name="receive_generate_hint">Show me the QR Code</string>
<string name="receive_paymentid_button">Generate</string> <string name="receive_paymentid_button">Generate</string>
<string name="receive_paymentid_label">PaymentID</string> <string name="receive_paymentid_label">PaymentID</string>
<string name="receive_paymentid_hint">(optional)</string> <string name="receive_paymentid_hint">(optional)</string>