mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-09 20:53:47 +01:00
Refresh latest address index periodically, and fetch latest subaddress for receive popup
This commit is contained in:
parent
069970ea23
commit
4674e81040
@ -6,13 +6,11 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.fragment.dialog.PasswordBottomSheetDialog;
|
import com.m2049r.xmrwallet.fragment.dialog.PasswordBottomSheetDialog;
|
||||||
import com.m2049r.xmrwallet.fragment.dialog.SendBottomSheetDialog;
|
|
||||||
import com.m2049r.xmrwallet.livedata.SingleLiveEvent;
|
import com.m2049r.xmrwallet.livedata.SingleLiveEvent;
|
||||||
import com.m2049r.xmrwallet.model.Wallet;
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
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.PrefService;
|
||||||
import com.m2049r.xmrwallet.service.TxService;
|
import com.m2049r.xmrwallet.service.TxService;
|
||||||
import com.m2049r.xmrwallet.util.Constants;
|
import com.m2049r.xmrwallet.util.Constants;
|
||||||
import com.m2049r.xmrwallet.util.DayNightMode;
|
|
||||||
import com.m2049r.xmrwallet.util.NightmodeHelper;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -33,6 +29,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||||||
public final SingleLiveEvent restartEvents = new SingleLiveEvent();
|
public final SingleLiveEvent restartEvents = new SingleLiveEvent();
|
||||||
private MoneroHandlerThread thread = null;
|
private MoneroHandlerThread thread = null;
|
||||||
private BalanceService balanceService = null;
|
private BalanceService balanceService = null;
|
||||||
|
private AddressService addressService = null;
|
||||||
private HistoryService historyService = null;
|
private HistoryService historyService = null;
|
||||||
private BlockchainService blockchainService = null;
|
private BlockchainService blockchainService = null;
|
||||||
|
|
||||||
@ -79,7 +76,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||||||
thread = new MoneroHandlerThread("WalletService", this, wallet);
|
thread = new MoneroHandlerThread("WalletService", this, wallet);
|
||||||
new TxService(thread);
|
new TxService(thread);
|
||||||
this.balanceService = new BalanceService(thread);
|
this.balanceService = new BalanceService(thread);
|
||||||
new AddressService(thread);
|
this.addressService = new AddressService(thread);
|
||||||
this.historyService = new HistoryService(thread);
|
this.historyService = new HistoryService(thread);
|
||||||
this.blockchainService = new BlockchainService(thread);
|
this.blockchainService = new BlockchainService(thread);
|
||||||
thread.start();
|
thread.start();
|
||||||
@ -90,6 +87,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||||||
this.historyService.refreshHistory();
|
this.historyService.refreshHistory();
|
||||||
this.balanceService.refreshBalance();
|
this.balanceService.refreshBalance();
|
||||||
this.blockchainService.refreshBlockchain();
|
this.blockchainService.refreshBlockchain();
|
||||||
|
this.addressService.refreshAddresses();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,6 +19,7 @@ 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.R;
|
import com.m2049r.xmrwallet.R;
|
||||||
|
import com.m2049r.xmrwallet.data.Subaddress;
|
||||||
import com.m2049r.xmrwallet.service.AddressService;
|
import com.m2049r.xmrwallet.service.AddressService;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -39,9 +40,9 @@ public class ReceiveBottomSheetDialog extends BottomSheetDialogFragment {
|
|||||||
ImageView addressImageView = view.findViewById(R.id.monero_qr_imageview);
|
ImageView addressImageView = view.findViewById(R.id.monero_qr_imageview);
|
||||||
TextView addressTextView = view.findViewById(R.id.address_textview);
|
TextView addressTextView = view.findViewById(R.id.address_textview);
|
||||||
|
|
||||||
String addr = AddressService.getInstance().getAddress();
|
Subaddress addr = AddressService.getInstance().getLatestSubaddress();
|
||||||
addressTextView.setText(addr);
|
addressTextView.setText(addr.getAddress());
|
||||||
addressImageView.setImageBitmap(generate(addr, 256, 256));
|
addressImageView.setImageBitmap(generate(addr.getAddress(), 256, 256));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap generate(String text, int width, int height) {
|
public Bitmap generate(String text, int width, int height) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.m2049r.xmrwallet.service;
|
package com.m2049r.xmrwallet.service;
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
import com.m2049r.xmrwallet.data.Subaddress;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import com.m2049r.xmrwallet.model.TransactionInfo;
|
||||||
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
import com.m2049r.xmrwallet.MainActivity;
|
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class AddressService extends ServiceBase {
|
public class AddressService extends ServiceBase {
|
||||||
public static AddressService instance = null;
|
public static AddressService instance = null;
|
||||||
@ -13,12 +13,42 @@ public class AddressService extends ServiceBase {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final HashMap<String, Integer> subAddresses = new HashMap<>();
|
||||||
|
private int latestAddressIndex = 1;
|
||||||
|
|
||||||
public AddressService(MoneroHandlerThread thread) {
|
public AddressService(MoneroHandlerThread thread) {
|
||||||
super(thread);
|
super(thread);
|
||||||
instance = this;
|
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();
|
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.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.MainActivity;
|
|
||||||
import com.m2049r.xmrwallet.model.TransactionInfo;
|
import com.m2049r.xmrwallet.model.TransactionInfo;
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class HistoryService extends ServiceBase {
|
public class HistoryService extends ServiceBase {
|
||||||
|
Loading…
Reference in New Issue
Block a user