mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-11-22 07:22:26 +00:00
Refresh latest address index periodically, and fetch latest subaddress for receive popup
This commit is contained in:
parent
069970ea23
commit
4674e81040
4 changed files with 42 additions and 17 deletions
|
@ -6,13 +6,11 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
|
||||
import com.m2049r.xmrwallet.fragment.dialog.PasswordBottomSheetDialog;
|
||||
import com.m2049r.xmrwallet.fragment.dialog.SendBottomSheetDialog;
|
||||
import com.m2049r.xmrwallet.livedata.SingleLiveEvent;
|
||||
import com.m2049r.xmrwallet.model.Wallet;
|
||||
import com.m2049r.xmrwallet.model.WalletManager;
|
||||
|
@ -24,8 +22,6 @@ import com.m2049r.xmrwallet.service.MoneroHandlerThread;
|
|||
import com.m2049r.xmrwallet.service.PrefService;
|
||||
import com.m2049r.xmrwallet.service.TxService;
|
||||
import com.m2049r.xmrwallet.util.Constants;
|
||||
import com.m2049r.xmrwallet.util.DayNightMode;
|
||||
import com.m2049r.xmrwallet.util.NightmodeHelper;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
@ -33,6 +29,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||
public final SingleLiveEvent restartEvents = new SingleLiveEvent();
|
||||
private MoneroHandlerThread thread = null;
|
||||
private BalanceService balanceService = null;
|
||||
private AddressService addressService = null;
|
||||
private HistoryService historyService = null;
|
||||
private BlockchainService blockchainService = null;
|
||||
|
||||
|
@ -79,7 +76,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||
thread = new MoneroHandlerThread("WalletService", this, wallet);
|
||||
new TxService(thread);
|
||||
this.balanceService = new BalanceService(thread);
|
||||
new AddressService(thread);
|
||||
this.addressService = new AddressService(thread);
|
||||
this.historyService = new HistoryService(thread);
|
||||
this.blockchainService = new BlockchainService(thread);
|
||||
thread.start();
|
||||
|
@ -90,6 +87,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||
this.historyService.refreshHistory();
|
||||
this.balanceService.refreshBalance();
|
||||
this.blockchainService.refreshBlockchain();
|
||||
this.addressService.refreshAddresses();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.google.zxing.common.BitMatrix;
|
|||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import com.m2049r.xmrwallet.R;
|
||||
import com.m2049r.xmrwallet.data.Subaddress;
|
||||
import com.m2049r.xmrwallet.service.AddressService;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -39,9 +40,9 @@ public class ReceiveBottomSheetDialog extends BottomSheetDialogFragment {
|
|||
ImageView addressImageView = view.findViewById(R.id.monero_qr_imageview);
|
||||
TextView addressTextView = view.findViewById(R.id.address_textview);
|
||||
|
||||
String addr = AddressService.getInstance().getAddress();
|
||||
addressTextView.setText(addr);
|
||||
addressImageView.setImageBitmap(generate(addr, 256, 256));
|
||||
Subaddress addr = AddressService.getInstance().getLatestSubaddress();
|
||||
addressTextView.setText(addr.getAddress());
|
||||
addressImageView.setImageBitmap(generate(addr.getAddress(), 256, 256));
|
||||
}
|
||||
|
||||
public Bitmap generate(String text, int width, int height) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.m2049r.xmrwallet.service;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.m2049r.xmrwallet.MainActivity;
|
||||
import com.m2049r.xmrwallet.data.Subaddress;
|
||||
import com.m2049r.xmrwallet.model.TransactionInfo;
|
||||
import com.m2049r.xmrwallet.model.Wallet;
|
||||
import com.m2049r.xmrwallet.model.WalletManager;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class AddressService extends ServiceBase {
|
||||
public static AddressService instance = null;
|
||||
|
@ -13,12 +13,42 @@ public class AddressService extends ServiceBase {
|
|||
return instance;
|
||||
}
|
||||
|
||||
private final HashMap<String, Integer> subAddresses = new HashMap<>();
|
||||
private int latestAddressIndex = 1;
|
||||
|
||||
public AddressService(MoneroHandlerThread thread) {
|
||||
super(thread);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
public void refreshAddresses() {
|
||||
Wallet wallet = WalletManager.getInstance().getWallet();
|
||||
int issuedAddressesSize = WalletManager.getInstance().getWallet().getNumSubaddresses();
|
||||
if(subAddresses.size() != issuedAddressesSize) {
|
||||
for (int i = 0; i < issuedAddressesSize; i++) {
|
||||
if(!subAddresses.containsValue(i)) {
|
||||
subAddresses.put(wallet.getSubaddress(i), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (TransactionInfo info : HistoryService.getInstance().getHistory()) {
|
||||
if(info.addressIndex > latestAddressIndex) {
|
||||
latestAddressIndex = info.addressIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getPrimaryAddress() {
|
||||
return WalletManager.getInstance().getWallet().getAddress();
|
||||
}
|
||||
|
||||
public Subaddress getLatestSubaddress() {
|
||||
Wallet wallet = WalletManager.getInstance().getWallet();
|
||||
return wallet.getSubaddressObject(latestAddressIndex);
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getIssuedSubaddresses() {
|
||||
return subAddresses;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,8 @@ package com.m2049r.xmrwallet.service;
|
|||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.m2049r.xmrwallet.MainActivity;
|
||||
import com.m2049r.xmrwallet.model.TransactionInfo;
|
||||
import com.m2049r.xmrwallet.model.WalletManager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HistoryService extends ServiceBase {
|
||||
|
|
Loading…
Reference in a new issue