simple layout

minimum number of decimal places
progress at top
This commit is contained in:
m2049r 2017-08-23 22:55:47 +02:00
parent 807d217aac
commit c11d577c5f
6 changed files with 175 additions and 117 deletions

View File

@ -35,6 +35,7 @@ import android.widget.Toast;
import com.m2049r.xmrwallet.model.PendingTransaction; import com.m2049r.xmrwallet.model.PendingTransaction;
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.WalletService; import com.m2049r.xmrwallet.service.WalletService;
import com.m2049r.xmrwallet.util.TxData; import com.m2049r.xmrwallet.util.TxData;
@ -158,6 +159,7 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
String walletId = extras.getString(REQUEST_ID); String walletId = extras.getString(REQUEST_ID);
if (walletId != null) { if (walletId != null) {
setTitle(walletId); setTitle(walletId);
setSubtitle("");
} }
} }
updateProgress(); updateProgress();
@ -172,6 +174,7 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
// see this happen. // see this happen.
mBoundService = null; mBoundService = null;
setTitle(getString(R.string.wallet_activity_name)); setTitle(getString(R.string.wallet_activity_name));
setSubtitle("");
Log.d(TAG, "DISCONNECTED"); Log.d(TAG, "DISCONNECTED");
} }
}; };
@ -270,6 +273,11 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
tbWallet.setTitle(title); tbWallet.setTitle(title);
} }
@Override
public void setSubtitle(String subtitle) {
tbWallet.setSubtitle(subtitle);
}
@Override @Override
public void onSendRequest() { public void onSendRequest() {
replaceFragment(new SendFragment(), null, null); replaceFragment(new SendFragment(), null, null);

View File

@ -22,6 +22,7 @@ import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -29,6 +30,7 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -49,10 +51,10 @@ public class WalletFragment extends Fragment implements TransactionInfoAdapter.O
private NumberFormat formatter = NumberFormat.getInstance(); private NumberFormat formatter = NumberFormat.getInstance();
TextView tvBalance; TextView tvBalance;
TextView tvUnlockedBalance; LinearLayout llUnconfirmedAmount;
TextView tvUnconfirmedAmount;
TextView tvBlockHeightProgress; TextView tvBlockHeightProgress;
TextView tvConnectionStatus; ConstraintLayout clProgress;
LinearLayout llProgress;
TextView tvProgress; TextView tvProgress;
ProgressBar pbProgress; ProgressBar pbProgress;
Button bSend; Button bSend;
@ -64,11 +66,13 @@ public class WalletFragment extends Fragment implements TransactionInfoAdapter.O
tvProgress = (TextView) view.findViewById(R.id.tvProgress); tvProgress = (TextView) view.findViewById(R.id.tvProgress);
pbProgress = (ProgressBar) view.findViewById(R.id.pbProgress); pbProgress = (ProgressBar) view.findViewById(R.id.pbProgress);
llProgress = (LinearLayout) view.findViewById(R.id.llProgress); clProgress = (ConstraintLayout) view.findViewById(R.id.clProgress);
llUnconfirmedAmount = (LinearLayout) view.findViewById(R.id.llUnconfirmedAmount);
tvBalance = (TextView) view.findViewById(R.id.tvBalance); tvBalance = (TextView) view.findViewById(R.id.tvBalance);
tvUnlockedBalance = (TextView) view.findViewById(R.id.tvUnlockedBalance); tvBalance.setText(getDisplayAmount(0));
tvUnconfirmedAmount = (TextView) view.findViewById(R.id.tvUnconfirmedAmount);
tvUnconfirmedAmount.setText(getDisplayAmount(0));
tvBlockHeightProgress = (TextView) view.findViewById(R.id.tvBlockHeightProgress); tvBlockHeightProgress = (TextView) view.findViewById(R.id.tvBlockHeightProgress);
tvConnectionStatus = (TextView) view.findViewById(R.id.tvConnectionStatus);
bSend = (Button) view.findViewById(R.id.bSend); bSend = (Button) view.findViewById(R.id.bSend);
@ -145,11 +149,11 @@ public class WalletFragment extends Fragment implements TransactionInfoAdapter.O
} }
public void showProgress() { public void showProgress() {
llProgress.setVisibility(View.VISIBLE); clProgress.setVisibility(View.VISIBLE);
} }
public void hideProgress() { public void hideProgress() {
llProgress.setVisibility(View.GONE); clProgress.setVisibility(View.GONE);
} }
String setActivityTitle(Wallet wallet) { String setActivityTitle(Wallet wallet) {
@ -158,10 +162,12 @@ public class WalletFragment extends Fragment implements TransactionInfoAdapter.O
if (shortName.length() > 16) { if (shortName.length() > 16) {
shortName = shortName.substring(0, 14) + "..."; shortName = shortName.substring(0, 14) + "...";
} }
String title = "[" + wallet.getAddress().substring(0, 6) + "] " String title = "[" + wallet.getAddress().substring(0, 6) + "] " + shortName;
+ shortName
+ (wallet.isWatchOnly() ? " " + getString(R.string.watchonly_label) : "");
activityCallback.setTitle(title); activityCallback.setTitle(title);
String watchOnly = (wallet.isWatchOnly() ? " " + getString(R.string.watchonly_label) : "");
String net = (wallet.isTestNet() ? getString(R.string.connect_testnet) : getString(R.string.connect_mainnet));
activityCallback.setSubtitle(net + " " + watchOnly);
Log.d(TAG, "wallet title is " + title); Log.d(TAG, "wallet title is " + title);
return title; return title;
} }
@ -169,14 +175,39 @@ public class WalletFragment extends Fragment implements TransactionInfoAdapter.O
private long firstBlock = 0; private long firstBlock = 0;
private String walletTitle = null; private String walletTitle = null;
private String getDisplayAmount(long amount) {
String s = Wallet.getDisplayAmount(amount);
int lastZero = 0;
int decimal = 0;
for (int i = s.length() - 1; i >= 0; i--) {
if ((lastZero == 0) && (s.charAt(i) != '0')) lastZero = i + 1;
// TODO i18n
if (s.charAt(i) == '.') {
decimal = i;
break;
}
}
//Log.d(TAG, decimal + "/" + lastZero + "/" + s);
int cutoff = Math.max(lastZero, decimal + 2);
return s.substring(0, cutoff);
}
private void updateStatus(Wallet wallet) { private void updateStatus(Wallet wallet) {
Log.d(TAG, "updateStatus()"); Log.d(TAG, "updateStatus()");
if (walletTitle == null) { if (walletTitle == null) {
walletTitle = setActivityTitle(wallet); walletTitle = setActivityTitle(wallet);
onProgress(100); // of loading onProgress(100); // of loading
} }
tvBalance.setText(Wallet.getDisplayAmount(wallet.getBalance())); long balance = wallet.getBalance();
tvUnlockedBalance.setText(Wallet.getDisplayAmount(wallet.getUnlockedBalance())); long unlockedBalance = wallet.getUnlockedBalance();
tvBalance.setText(getDisplayAmount(unlockedBalance));
tvUnconfirmedAmount.setText(getDisplayAmount(balance - unlockedBalance));
// balance cannot be less than unlockedBalance
/*if (balance != unlockedBalance) {
llPendingAmount.setVisibility(View.VISIBLE);
} else {
llPendingAmount.setVisibility(View.INVISIBLE);
}*/
String sync = ""; String sync = "";
if (!activityCallback.hasBoundService()) if (!activityCallback.hasBoundService())
throw new IllegalStateException("WalletService not bound."); throw new IllegalStateException("WalletService not bound.");
@ -197,9 +228,10 @@ public class WalletFragment extends Fragment implements TransactionInfoAdapter.O
sync = getString(R.string.status_synced) + ": " + formatter.format(wallet.getBlockChainHeight()); sync = getString(R.string.status_synced) + ": " + formatter.format(wallet.getBlockChainHeight());
} }
} }
String net = (wallet.isTestNet() ? getString(R.string.connect_testnet) : getString(R.string.connect_mainnet));
tvBlockHeightProgress.setText(sync); tvBlockHeightProgress.setText(sync);
tvConnectionStatus.setText(net + " " + daemonConnected.toString().substring(17)); //String net = (wallet.isTestNet() ? getString(R.string.connect_testnet) : getString(R.string.connect_mainnet));
//activityCallback.setSubtitle(net + " " + daemonConnected.toString().substring(17));
// TODO show connected status somewhere
} }
Listener activityCallback; Listener activityCallback;
@ -216,6 +248,8 @@ public class WalletFragment extends Fragment implements TransactionInfoAdapter.O
void setTitle(String title); void setTitle(String title);
void setSubtitle(String subtitle);
void onSendRequest(); void onSendRequest();
void onTxDetailsRequest(TransactionInfo info); void onTxDetailsRequest(TransactionInfo info);

View File

@ -4,6 +4,20 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
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>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -58,20 +72,6 @@
android:textSize="16sp" /> android:textSize="16sp" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
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>
<TextView <TextView
android:id="@+id/tvWalletMnemonicLabel" android:id="@+id/tvWalletMnemonicLabel"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -103,10 +103,10 @@
android:id="@+id/tvWalletAddress" android:id="@+id/tvWalletAddress"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:selectAllOnFocus="true"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@color/colorPrimaryDark" android:textColor="@color/colorPrimaryDark"
android:textIsSelectable="true" android:textIsSelectable="true"
android:selectAllOnFocus="true"
android:textSize="16sp" /> android:textSize="16sp" />
<TextView <TextView
@ -123,10 +123,10 @@
android:id="@+id/tvWalletViewKey" android:id="@+id/tvWalletViewKey"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:selectAllOnFocus="true"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@color/colorPrimaryDark" android:textColor="@color/colorPrimaryDark"
android:textIsSelectable="true" android:textIsSelectable="true"
android:selectAllOnFocus="true"
android:textSize="16sp" /> android:textSize="16sp" />
<TextView <TextView
@ -143,10 +143,10 @@
android:id="@+id/tvWalletSpendKey" android:id="@+id/tvWalletSpendKey"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:selectAllOnFocus="true"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@color/colorPrimaryDark" android:textColor="@color/colorPrimaryDark"
android:textIsSelectable="true" android:textIsSelectable="true"
android:selectAllOnFocus="true"
android:textSize="16sp" /> android:textSize="16sp" />
<Button <Button

View File

@ -5,111 +5,121 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<android.support.constraint.ConstraintLayout <android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp"> android:layout_marginBottom="4sp"
android:layout_marginLeft="4sp"
<TextView android:layout_marginRight="4sp">
android:id="@+id/tvBalanceLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="@string/label_balance"
android:textSize="10sp"
app:layout_constraintBaseline_toBaselineOf="@+id/tvBalance"
app:layout_constraintRight_toLeftOf="@+id/tvBalance" />
<TextView
android:id="@+id/tvBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:text="00000000.000000000000"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvUnlockedBalanceLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="@string/label_unlockedBalance"
android:textColor="@color/colorAccent"
android:textSize="10sp"
app:layout_constraintBaseline_toBaselineOf="@+id/tvUnlockedBalance"
app:layout_constraintRight_toLeftOf="@+id/tvUnlockedBalance" />
<TextView
android:id="@+id/tvUnlockedBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="00000000.000000000000"
android:textColor="@color/colorAccent"
app:layout_constraintRight_toRightOf="@+id/tvBalance"
app:layout_constraintTop_toBottomOf="@+id/tvBalance" />
<TextView
android:id="@+id/tvConnectionStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Loading..."
android:textSize="10sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBaseline_toBaselineOf="@+id/tvBalance" />
<TextView <TextView
android:id="@+id/tvBlockHeightProgress" android:id="@+id/tvBlockHeightProgress"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Loading..." android:text="Loading..."
android:textSize="10sp" android:textSize="16sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/clProgress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBaseline_toBaselineOf="@+id/tvUnlockedBalance"/> app:layout_constraintRight_toRightOf="parent">
</android.support.constraint.ConstraintLayout> <ProgressBar
android:id="@+id/pbProgress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:progress="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<LinearLayout <TextView
android:id="@+id/llProgress" android:id="@+id/tvProgress"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:text="Loading..."
android:layout_marginTop="8dp" android:textSize="16sp"
android:gravity="center" android:textColor="@color/white"
android:orientation="vertical" app:layout_constraintBottom_toBottomOf="parent"
android:visibility="gone"> app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
<TextView <LinearLayout
android:id="@+id/tvProgress" android:id="@+id/llBalance"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Loading..." android:layout_marginTop="4dp"
android:textSize="16sp" /> android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvBlockHeightProgress">
<ProgressBar <TextView
android:id="@+id/pbProgress" android:id="@+id/tvBalance"
style="@android:style/Widget.ProgressBar.Horizontal" android:layout_width="wrap_content"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="00000000.000000000000"
android:textColor="@color/moneroOrange"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4sp"
android:text="@string/label_xmr"
android:textColor="@color/moneroOrange"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llUnconfirmedAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:progress="0" /> android:orientation="horizontal"
</LinearLayout> android:visibility="visible"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/llBalance">
<android.support.constraint.ConstraintLayout <TextView
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4sp"
android:text="+"
android:textSize="16sp" />
<TextView
android:id="@+id/tvUnconfirmedAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00000000.000000000000"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4sp"
android:text="@string/label_unconfirmed_alance"
android:textSize="16sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list" android:id="@+id/list"
android:layout_width="0dp" android:layout_width="0dp"
@ -125,7 +135,6 @@
android:id="@+id/bSend" android:id="@+id/bSend"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorPrimary" android:background="@color/colorPrimary"
android:enabled="true" android:enabled="true"
android:text="@string/wallet_send_hint" android:text="@string/wallet_send_hint"
@ -133,5 +142,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" /> app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
</LinearLayout> </LinearLayout>

View File

@ -11,4 +11,7 @@
<color name="tx_red">#ff4f41</color> <color name="tx_red">#ff4f41</color>
<color name="tx_pending">#FF4081</color> <color name="tx_pending">#FF4081</color>
<color name="moneroOrange">#fa6600</color>
<color name="white">#ffffff</color>
</resources> </resources>

View File

@ -34,7 +34,9 @@
<string name="title_amount">Amount</string> <string name="title_amount">Amount</string>
<string name="title_date">Date</string> <string name="title_date">Date</string>
<string name="label_balance">Balance</string> <string name="label_balance">Unconfirmed</string>
<string name="label_unconfirmed_alance">unconfirmed</string>
<string name="label_xmr">XMR</string>
<string name="label_unlockedBalance">Available</string> <string name="label_unlockedBalance">Available</string>
<string name="label_transactions">Transactions</string> <string name="label_transactions">Transactions</string>
<string name="text_daemonConnected">Daemon connected!</string> <string name="text_daemonConnected">Daemon connected!</string>