wownero
/
wownerujo
Archived
4
0
Fork 0

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

upstream
m2049r 7 years ago
parent fe84bae9ed
commit 68abaec6cb

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

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

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

@ -23,6 +23,7 @@ import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@ -31,6 +32,7 @@ import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
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.decoder.ErrorCorrectionLevel;
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 java.util.HashMap;
@ -48,12 +52,14 @@ import java.util.Map;
public class ReceiveFragment extends Fragment {
static final String TAG = "ReceiveFragment";
ProgressBar pbProgress;
TextView tvAddress;
EditText etPaymentId;
EditText etAmount;
Button bPaymentId;
Button bGenerate;
ImageView qrCode;
EditText etDummy;
@Override
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);
pbProgress = (ProgressBar) view.findViewById(R.id.pbProgress);
tvAddress = (TextView) view.findViewById(R.id.tvAddress);
etPaymentId = (EditText) view.findViewById(R.id.etPaymentId);
etAmount = (EditText) view.findViewById(R.id.etAmount);
bPaymentId = (Button) view.findViewById(R.id.bPaymentId);
qrCode = (ImageView) view.findViewById(R.id.qrCode);
bGenerate = (Button) view.findViewById(R.id.bGenerate);
etDummy = (EditText) view.findViewById(R.id.etDummy);
etPaymentId.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
etDummy.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Helper.showKeyboard(getActivity());
etPaymentId.requestFocus();
@ -86,7 +95,7 @@ public class ReceiveFragment extends Fragment {
etPaymentId.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
qrCode.setImageBitmap(null);
qrCode.setImageBitmap(getMoneroLogo());
if (paymentIdOk() && amountOk()) {
bGenerate.setEnabled(true);
} else {
@ -118,7 +127,7 @@ public class ReceiveFragment extends Fragment {
etAmount.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
qrCode.setImageBitmap(null);
qrCode.setImageBitmap(getMoneroLogo());
if (paymentIdOk() && amountOk()) {
bGenerate.setEnabled(true);
} else {
@ -156,12 +165,58 @@ public class ReceiveFragment extends Fragment {
}
});
showProgress();
qrCode.setImageBitmap(getMoneroLogo());
Bundle b = getArguments();
String address = b.getString("address", "");
tvAddress.setText(address);
String address = b.getString("address");
if (address == null) {
String path = b.getString("path");
String password = b.getString("password");
show(path, password);
} else {
show(address);
}
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() {
String amountEntry = etAmount.getText().toString();
if (amountEntry.isEmpty()) return true;
@ -179,7 +234,7 @@ public class ReceiveFragment extends Fragment {
String paymentId = etPaymentId.getText().toString();
String enteredAmount = etAmount.getText().toString();
// 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();
sb.append(ScannerFragment.QR_SCHEME).append(address);
boolean first = true;
@ -201,7 +256,9 @@ public class ReceiveFragment extends Fragment {
String text = sb.toString();
Bitmap qr = generate(text, 500, 500);
if (qr != null) {
etAmount.setText(amount);
qrCode.setImageBitmap(qr);
etDummy.requestFocus();
}
}
@ -263,4 +320,13 @@ public class ReceiveFragment extends Fragment {
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"
android:width="50dp"
android:height="50dp"
android:width="100dp"
android:height="100dp"
android:viewportHeight="75.0"
android:viewportWidth="75.0">
<path

@ -4,19 +4,13 @@
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
<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:orientation="vertical">
<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>
android:visibility="invisible" />
<LinearLayout
android:layout_width="match_parent"

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

@ -1,6 +1,6 @@
<resources>
<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="menu_info">Details</string>
@ -152,7 +152,7 @@
<string name="tx_pending">PENDING</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_label">PaymentID</string>
<string name="receive_paymentid_hint">(optional)</string>