Skip to content

Commit

Permalink
PocketChange (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2049r authored Jun 5, 2023
1 parent bc4aa0f commit bf1829f
Show file tree
Hide file tree
Showing 64 changed files with 1,179 additions and 320 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.m2049r.xmrwallet"
minSdkVersion 21
targetSdkVersion 31
versionCode 3200
versionName "3.2.0 'Decoy Selection'"
versionCode 3307
versionName "3.3.7 'Pocket Change'"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down
195 changes: 177 additions & 18 deletions app/src/main/cpp/monerujo.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,11 @@ private void showNet(NetworkType net) {
break;
case NetworkType_Testnet:
toolbar.setSubtitle(getString(R.string.connect_testnet));
toolbar.setBackgroundResource(ThemeHelper.getThemedResourceId(this, R.attr.colorPrimaryDark));
toolbar.setBackgroundResource(ThemeHelper.getThemedResourceId(this, androidx.appcompat.R.attr.colorPrimaryDark));
break;
case NetworkType_Stagenet:
toolbar.setSubtitle(getString(R.string.connect_stagenet));
toolbar.setBackgroundResource(ThemeHelper.getThemedResourceId(this, R.attr.colorPrimaryDark));
toolbar.setBackgroundResource(ThemeHelper.getThemedResourceId(this, androidx.appcompat.R.attr.colorPrimaryDark));
break;
default:
throw new IllegalStateException("NetworkType unknown: " + net);
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/m2049r/xmrwallet/TxFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public TxFragment() {
private TextView tvTxPaymentId;
private TextView tvTxBlockheight;
private TextView tvTxAmount;
private TextView tvTxPocketChangeAmount;
private TextView tvTxFee;
private TextView tvTxTransfers;
private TextView etTxNotes;
Expand Down Expand Up @@ -116,6 +117,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
tvTxPaymentId = view.findViewById(R.id.tvTxPaymentId);
tvTxBlockheight = view.findViewById(R.id.tvTxBlockheight);
tvTxAmount = view.findViewById(R.id.tvTxAmount);
tvTxPocketChangeAmount = view.findViewById(R.id.tvTxPocketChangeAmount);
tvTxFee = view.findViewById(R.id.tvTxFee);
tvTxTransfers = view.findViewById(R.id.tvTxTransfers);
etTxNotes = view.findViewById(R.id.etTxNotes);
Expand Down Expand Up @@ -249,8 +251,10 @@ private void show() {
}
String sign = (info.direction == TransactionInfo.Direction.Direction_In ? "+" : "-");

long realAmount = info.amount;
tvTxAmount.setText(sign + Wallet.getDisplayAmount(realAmount));
tvTxAmount.setText(sign + Wallet.getDisplayAmount(info.amount));
final long pcAmount = info.getPocketChangeAmount();
tvTxPocketChangeAmount.setVisibility(pcAmount > 0 ? View.VISIBLE : View.GONE);
tvTxPocketChangeAmount.setText(getString(R.string.pocketchange_tx_detail, Wallet.getDisplayAmount(pcAmount)));

if ((info.fee > 0)) {
String fee = Wallet.getDisplayAmount(info.fee);
Expand Down
28 changes: 23 additions & 5 deletions app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
import com.m2049r.xmrwallet.data.Subaddress;
import com.m2049r.xmrwallet.data.TxData;
import com.m2049r.xmrwallet.data.UserNotes;
import com.m2049r.xmrwallet.dialog.CreditsFragment;
import com.m2049r.xmrwallet.dialog.HelpFragment;
import com.m2049r.xmrwallet.dialog.PocketChangeFragment;
import com.m2049r.xmrwallet.fragment.send.SendAddressWizardFragment;
import com.m2049r.xmrwallet.fragment.send.SendFragment;
import com.m2049r.xmrwallet.ledger.LedgerProgressDialog;
Expand Down Expand Up @@ -82,7 +82,8 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
WalletFragment.DrawerLocker,
NavigationView.OnNavigationItemSelectedListener,
SubaddressFragment.Listener,
SubaddressInfoFragment.Listener {
SubaddressInfoFragment.Listener,
PocketChangeFragment.Listener {

public static final String REQUEST_ID = "id";
public static final String REQUEST_PW = "pw";
Expand Down Expand Up @@ -285,8 +286,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
onWalletRescan();
} else if (itemId == R.id.action_info) {
onWalletDetails();
} else if (itemId == R.id.action_credits) {
CreditsFragment.display(getSupportFragmentManager());
} else if (itemId == R.id.action_share) {
onShareTxInfo();
} else if (itemId == R.id.action_help_tx_info) {
Expand All @@ -301,6 +300,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
HelpFragment.display(getSupportFragmentManager(), R.string.help_send);
} else if (itemId == R.id.action_rename) {
onAccountRename();
} else if (itemId == R.id.action_pocketchange) {
PocketChangeFragment.display(getSupportFragmentManager(), getWallet().getPocketChangeSetting());
} else if (itemId == R.id.action_subaddresses) {
showSubaddresses(true);
} else if (itemId == R.id.action_streetmode) {
Expand Down Expand Up @@ -422,7 +423,7 @@ public void showNet() {
break;
case NetworkType_Stagenet:
case NetworkType_Testnet:
toolbar.setBackgroundResource(ThemeHelper.getThemedResourceId(this, R.attr.colorPrimaryDark));
toolbar.setBackgroundResource(ThemeHelper.getThemedResourceId(this, androidx.appcompat.R.attr.colorPrimaryDark));
break;
default:
throw new IllegalStateException("Unsupported Network: " + WalletManager.getInstance().getNetworkType());
Expand Down Expand Up @@ -628,6 +629,7 @@ public void onWalletOpen(final Wallet.Device device) {

@Override
public void onWalletStarted(final Wallet.Status walletStatus) {
loadPocketChangeSettings();
runOnUiThread(() -> {
dismissProgressDialog();
if (walletStatus == null) {
Expand Down Expand Up @@ -1104,6 +1106,7 @@ public void onAccountRename() {

public void setAccountIndex(int accountIndex) {
getWallet().setAccountIndex(accountIndex);
loadPocketChangeSettings();
selectedSubaddressIndex = 0;
}

Expand Down Expand Up @@ -1214,4 +1217,19 @@ public void showSubaddress(View view, final int subaddressIndex) {
b.putInt("subaddressIndex", subaddressIndex);
replaceFragmentWithTransition(view, new SubaddressInfoFragment(), null, b);
}

@Override
public void setPocketChange(Wallet.PocketChangeSetting setting) {
SharedPreferences.Editor editor = getPrefs().edit();
editor.putString(getWallet().getAddress() + "_PC", setting.toPrefString());
editor.apply();
getWallet().setPocketChangeSetting(setting);
}


public void loadPocketChangeSettings() {
final String settings = getPrefs().getString(getWallet().getAddress() + "_PC", "0");
getWallet().setPocketChangeSetting(Wallet.PocketChangeSetting.from(settings));
}

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
flExchange = view.findViewById(R.id.flExchange);
((ProgressBar) view.findViewById(R.id.pbExchange)).getIndeterminateDrawable().
setColorFilter(
ThemeHelper.getThemedColor(getContext(), R.attr.colorPrimaryVariant),
ThemeHelper.getThemedColor(getContext(), com.google.android.material.R.attr.colorPrimaryVariant),
android.graphics.PorterDuff.Mode.MULTIPLY);

tvProgress = view.findViewById(R.id.tvProgress);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/m2049r/xmrwallet/data/NodeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void showInfo(TextView view, String info, boolean isError) {
(hostAddress.isOnion() ? " .onion  " : ""), " " + info));
view.setText(text);
if (isError)
view.setTextColor(ThemeHelper.getThemedColor(ctx, R.attr.colorError));
view.setTextColor(ThemeHelper.getThemedColor(ctx, androidx.appcompat.R.attr.colorError));
else
view.setTextColor(ThemeHelper.getThemedColor(ctx, android.R.attr.textColorSecondary));
}
Expand Down
Loading

0 comments on commit bf1829f

Please sign in to comment.