mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-12 16:41:54 +00:00
Add loading bar
This commit is contained in:
parent
84c740f320
commit
a023260bf2
6 changed files with 95 additions and 1 deletions
|
@ -15,6 +15,7 @@ import com.m2049r.xmrwallet.model.Wallet;
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
import com.m2049r.xmrwallet.service.AddressService;
|
import com.m2049r.xmrwallet.service.AddressService;
|
||||||
import com.m2049r.xmrwallet.service.BalanceService;
|
import com.m2049r.xmrwallet.service.BalanceService;
|
||||||
|
import com.m2049r.xmrwallet.service.BlockchainService;
|
||||||
import com.m2049r.xmrwallet.service.HistoryService;
|
import com.m2049r.xmrwallet.service.HistoryService;
|
||||||
import com.m2049r.xmrwallet.service.MoneroHandlerThread;
|
import com.m2049r.xmrwallet.service.MoneroHandlerThread;
|
||||||
import com.m2049r.xmrwallet.service.PrefService;
|
import com.m2049r.xmrwallet.service.PrefService;
|
||||||
|
@ -30,6 +31,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
private BalanceService balanceService = null;
|
private BalanceService balanceService = null;
|
||||||
private AddressService addressService = null;
|
private AddressService addressService = null;
|
||||||
private HistoryService historyService = null;
|
private HistoryService historyService = null;
|
||||||
|
private BlockchainService blockchainService = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -44,6 +46,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
init(walletFile, "");
|
init(walletFile, "");
|
||||||
} else {
|
} else {
|
||||||
PasswordBottomSheetDialog passwordDialog = new PasswordBottomSheetDialog();
|
PasswordBottomSheetDialog passwordDialog = new PasswordBottomSheetDialog();
|
||||||
|
passwordDialog.setCancelable(false);
|
||||||
passwordDialog.listener = this;
|
passwordDialog.listener = this;
|
||||||
passwordDialog.show(getSupportFragmentManager(), null);
|
passwordDialog.show(getSupportFragmentManager(), null);
|
||||||
}
|
}
|
||||||
|
@ -74,6 +77,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
this.balanceService = new BalanceService(this, thread);
|
this.balanceService = new BalanceService(this, thread);
|
||||||
this.addressService = new AddressService(this, thread);
|
this.addressService = new AddressService(this, thread);
|
||||||
this.historyService = new HistoryService(this, thread);
|
this.historyService = new HistoryService(this, thread);
|
||||||
|
this.blockchainService = new BlockchainService(this, thread);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +86,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
this.historyService.refreshHistory();
|
this.historyService.refreshHistory();
|
||||||
this.balanceService.refreshBalance();
|
this.balanceService.refreshBalance();
|
||||||
this.addressService.refreshAddress();
|
this.addressService.refreshAddress();
|
||||||
|
this.blockchainService.refreshBlockchain();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -30,8 +31,10 @@ import com.m2049r.xmrwallet.fragment.dialog.ReceiveBottomSheetDialog;
|
||||||
import com.m2049r.xmrwallet.fragment.dialog.SendBottomSheetDialog;
|
import com.m2049r.xmrwallet.fragment.dialog.SendBottomSheetDialog;
|
||||||
import com.m2049r.xmrwallet.model.TransactionInfo;
|
import com.m2049r.xmrwallet.model.TransactionInfo;
|
||||||
import com.m2049r.xmrwallet.model.Wallet;
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
import com.m2049r.xmrwallet.service.AddressService;
|
import com.m2049r.xmrwallet.service.AddressService;
|
||||||
import com.m2049r.xmrwallet.service.BalanceService;
|
import com.m2049r.xmrwallet.service.BalanceService;
|
||||||
|
import com.m2049r.xmrwallet.service.BlockchainService;
|
||||||
import com.m2049r.xmrwallet.service.HistoryService;
|
import com.m2049r.xmrwallet.service.HistoryService;
|
||||||
import com.m2049r.xmrwallet.service.PrefService;
|
import com.m2049r.xmrwallet.service.PrefService;
|
||||||
import com.m2049r.xmrwallet.service.TxService;
|
import com.m2049r.xmrwallet.service.TxService;
|
||||||
|
@ -90,6 +93,7 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
|
||||||
|
|
||||||
BalanceService balanceService = BalanceService.getInstance();
|
BalanceService balanceService = BalanceService.getInstance();
|
||||||
HistoryService historyService = HistoryService.getInstance();
|
HistoryService historyService = HistoryService.getInstance();
|
||||||
|
BlockchainService blockchainService = BlockchainService.getInstance();
|
||||||
|
|
||||||
if(balanceService != null) {
|
if(balanceService != null) {
|
||||||
balanceService.balance.observe(getViewLifecycleOwner(), balance -> {
|
balanceService.balance.observe(getViewLifecycleOwner(), balance -> {
|
||||||
|
@ -106,6 +110,22 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProgressBar progressBar = view.findViewById(R.id.sync_progress_bar);
|
||||||
|
if(blockchainService != null) {
|
||||||
|
blockchainService.height.observe(getViewLifecycleOwner(), height -> {
|
||||||
|
long daemonHeight = WalletManager.getInstance().getWallet().getDaemonBlockChainHeight();
|
||||||
|
int syncPct = (int)blockchainService.getSyncPercentage();
|
||||||
|
progressBar.setIndeterminate(height < 1 || daemonHeight <= 0);
|
||||||
|
if(height > 1 && daemonHeight > 1) {
|
||||||
|
progressBar.setProgress(syncPct);
|
||||||
|
|
||||||
|
if(WalletManager.getInstance().getWallet().isSynchronized()) {
|
||||||
|
progressBar.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
TransactionInfoAdapter adapter = new TransactionInfoAdapter(this);
|
TransactionInfoAdapter adapter = new TransactionInfoAdapter(this);
|
||||||
txHistoryRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
txHistoryRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||||
txHistoryRecyclerView.setAdapter(adapter);
|
txHistoryRecyclerView.setAdapter(adapter);
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class OnboardingFragment extends Fragment {
|
||||||
File walletFile = new File(getActivity().getApplicationInfo().dataDir, Constants.WALLET_NAME);
|
File walletFile = new File(getActivity().getApplicationInfo().dataDir, Constants.WALLET_NAME);
|
||||||
Wallet wallet = null;
|
Wallet wallet = null;
|
||||||
if(walletSeed.isEmpty()) {
|
if(walletSeed.isEmpty()) {
|
||||||
wallet = WalletManager.getInstance().createWallet(walletFile, walletPassword, Constants.MNEMONIC_LANGUAGE, -1);
|
wallet = WalletManager.getInstance().createWallet(walletFile, walletPassword, Constants.MNEMONIC_LANGUAGE, 1);
|
||||||
} else {
|
} else {
|
||||||
if(!checkMnemonic(walletSeed)) {
|
if(!checkMnemonic(walletSeed)) {
|
||||||
Toast.makeText(getContext(), getString(R.string.invalid_mnemonic_code), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), getString(R.string.invalid_mnemonic_code), Toast.LENGTH_SHORT).show();
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.m2049r.xmrwallet.service;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.MainActivity;
|
||||||
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
|
|
||||||
|
public class BlockchainService extends ServiceBase {
|
||||||
|
public static BlockchainService instance = null;
|
||||||
|
|
||||||
|
public static BlockchainService getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final MutableLiveData<Long> _currentHeight = new MutableLiveData<>(0L);
|
||||||
|
public LiveData<Long> height = _currentHeight;
|
||||||
|
|
||||||
|
public BlockchainService(MainActivity mainActivity, MoneroHandlerThread thread) {
|
||||||
|
super(mainActivity, thread);
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshBlockchain() {
|
||||||
|
_currentHeight.postValue(getCurrentHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCurrentHeight() {
|
||||||
|
return WalletManager.getInstance().getWallet().getBlockChainHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDaemonHeight() {
|
||||||
|
return WalletManager.getInstance().getWallet().getDaemonBlockChainHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSyncPercentage() {
|
||||||
|
double percentRaw = (double)getCurrentHeight()/(double)getDaemonHeight();
|
||||||
|
return percentRaw * 100d;
|
||||||
|
}
|
||||||
|
}
|
20
app/src/main/res/drawable/sync_progress_bar_drawable.xml
Normal file
20
app/src/main/res/drawable/sync_progress_bar_drawable.xml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:id="@android:id/background">
|
||||||
|
<shape>
|
||||||
|
<solid
|
||||||
|
android:color="@android:color/white" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@android:id/progress">
|
||||||
|
<clip>
|
||||||
|
<shape>
|
||||||
|
<solid
|
||||||
|
android:color="@color/oled_colorSecondary" />
|
||||||
|
</shape>
|
||||||
|
</clip>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
</layer-list>
|
|
@ -6,6 +6,15 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".fragment.home.HomeFragment">
|
tools:context=".fragment.home.HomeFragment">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/sync_progress_bar"
|
||||||
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:layout_height="4dp"
|
||||||
|
android:progressDrawable="@drawable/sync_progress_bar_drawable"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/balance_unlocked_textview"
|
android:id="@+id/balance_unlocked_textview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
Loading…
Reference in a new issue