- Change the look of the transactions.

- Change text of "from" and "to" when it's the user account. Instead of bitshares id, the name of the account will appear.
This commit is contained in:
Javier Varona 2018-02-27 21:11:10 -04:00
parent 6c81d74deb
commit 8464ee18ec
6 changed files with 154 additions and 45 deletions

View file

@ -24,7 +24,7 @@ public class CryptoNetAccountViewModel extends AndroidViewModel {
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
}
public void loadCryptoNetAccount(int accountId){
public void loadCryptoNetAccount(long accountId){
this.cryptoNetAccount = this.db.cryptoNetAccountDao().getByIdLiveData(accountId);
}
@ -36,5 +36,4 @@ public class CryptoNetAccountViewModel extends AndroidViewModel {
public LiveData<CryptoNetAccount> getCryptoNetAccount(){
return this.cryptoNetAccount;
}
}

View file

@ -1,20 +1,30 @@
package cy.agorise.crystalwallet.views;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.TimeZone;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.activities.CryptoCoinTransactionReceiptActivity;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.viewmodels.CryptoCurrencyViewModel;
import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel;
/**
* Created by Henry Varona on 17/9/2017.
@ -26,16 +36,18 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
/*
* The view holding the transaction "from"
*/
private TextView transactionFrom;
private TextView tvFrom;
/*
* The view holding the transaction "to"
*/
private TextView transactionTo;
private TextView tvTo;
/*
* The view holding the transaction amount
*/
private TextView transactionAmount;
private TextView tvAmount;
private TextView tvEquivalent;
private TextView tvTransactionDate;
private TextView tvTransactionHour;
private View rootView;
private Fragment fragment;
@ -48,10 +60,12 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
this.cryptoCoinTransactionId = -1;
rootView = itemView.findViewById(R.id.rlTransactionItem);
transactionFrom = (TextView) itemView.findViewById(R.id.fromText);
transactionTo = (TextView) itemView.findViewById(R.id.toText);
transactionAmount = (TextView) itemView.findViewById(R.id.amountText);
tvFrom = (TextView) itemView.findViewById(R.id.fromText);
tvTo = (TextView) itemView.findViewById(R.id.toText);
tvAmount = (TextView) itemView.findViewById(R.id.tvAmount);
tvEquivalent = (TextView) itemView.findViewById(R.id.tvEquivalent);
tvTransactionDate = (TextView) itemView.findViewById(R.id.tvTransactionDate);
tvTransactionHour = (TextView) itemView.findViewById(R.id.tvTransactionHour);
this.fragment = fragment;
rootView.setOnClickListener(new View.OnClickListener() {
@ -85,9 +99,12 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
* Clears all info in this element view
*/
public void clear(){
transactionFrom.setText("loading...");
transactionTo.setText("");
transactionAmount.setText("");
tvFrom.setText("loading...");
tvTo.setText("");
tvAmount.setText("");
tvEquivalent.setText("");
tvTransactionDate.setText("");
tvTransactionHour.setText("");
}
/*
@ -95,28 +112,53 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
*/
public void bindTo(final CryptoCoinTransaction transaction/*, final OnTransactionClickListener listener*/) {
if (transaction == null){
transactionFrom.setText("loading...");
transactionTo.setText("");
transactionAmount.setText("");
clear();
} else {
this.cryptoCoinTransactionId = transaction.getId();
CryptoCurrencyViewModel cryptoCurrencyViewModel = ViewModelProviders.of(this.fragment).get(CryptoCurrencyViewModel.class);
CryptoCurrency cryptoCurrency = cryptoCurrencyViewModel.getCryptoCurrencyById(transaction.getIdCurrency());
CryptoNetAccountViewModel cryptoNetAccountViewModel = ViewModelProviders.of(this.fragment).get(CryptoNetAccountViewModel.class);
cryptoNetAccountViewModel.loadCryptoNetAccount(transaction.getAccountId());
String amountString = String.format("%.2f",transaction.getAmount()/Math.pow(10,cryptoCurrency.getPrecision()));
tvTransactionDate.setText(transaction.getDate().toString());
transactionFrom.setText(transaction.getFrom());
transactionTo.setText(transaction.getTo());
DateFormat dateFormat = new SimpleDateFormat("dd MMM");
dateFormat.setTimeZone(TimeZone.getTimeZone("cet"));
DateFormat hourFormat = new SimpleDateFormat("HH:mm:ss");
hourFormat.setTimeZone(TimeZone.getTimeZone("cet"));
if (transaction.getInput()) {
transactionAmount.setTextColor(itemView.getContext().getResources().getColor(R.color.green));
tvTransactionDate.setText(dateFormat.format(transaction.getDate()));
tvTransactionHour.setText(hourFormat.format(transaction.getDate())+" CET");
tvFrom.setText(transaction.getFrom());
tvTo.setText(transaction.getTo());
LiveData<CryptoNetAccount> cryptoNetAccountLiveData = cryptoNetAccountViewModel.getCryptoNetAccount();
cryptoNetAccountLiveData.observe(this.fragment, new Observer<CryptoNetAccount>() {
@Override
public void onChanged(@Nullable CryptoNetAccount cryptoNetAccount) {
if (transaction.getInput()){
tvTo.setText(cryptoNetAccount.getName());
} else {
transactionAmount.setTextColor(itemView.getContext().getResources().getColor(R.color.red));
tvFrom.setText(cryptoNetAccount.getName());
}
transactionAmount.setText(
amountString
}
});
String finalAmountText = "";
if (transaction.getInput()) {
tvAmount.setTextColor(itemView.getContext().getResources().getColor(R.color.green));
finalAmountText = "+ "+amountString
+ " "
+ cryptoCurrency.getName());
+ cryptoCurrency.getName();
} else {
tvAmount.setTextColor(itemView.getContext().getResources().getColor(R.color.red));
finalAmountText = amountString
+ " "
+ cryptoCurrency.getName();
}
tvAmount.setText(finalAmountText);
//This will load the transaction receipt when the user clicks this view
/*itemView.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:color="#5FBD8A" android:width="4dp"/>
</shape>
</item>
<item android:left="3dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>

View file

@ -37,13 +37,15 @@
android:id="@+id/btnSendFromThisAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"/>
android:text="send"
android:visibility="gone" />
<Button
android:id="@+id/btnReceiveWithThisAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="receive"/>
android:text="receive"
android:visibility="gone" />
</LinearLayout>
<cy.agorise.crystalwallet.views.CryptoCoinBalanceListView

View file

@ -34,7 +34,8 @@
android:layout_below="@+id/tvContactName"
android:layout_toRightOf="@+id/ivContactThumbnail"
android:text="Paid: Jan 1, 2001, 01:01"
android:textColor="@android:color/darker_gray" />
android:textColor="@android:color/darker_gray"
android:visibility="gone" />
<ImageView
android:id="@+id/ivDeleteContact"

View file

@ -1,59 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
android:paddingTop="5dp">
<RelativeLayout
android:id="@+id/rlTransactionItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<TextView
android:id="@+id/tvTransactionDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:ems="10"
android:gravity="center"
android:text="date" />
android:layout_alignParentTop="true"
android:background="@drawable/transaction_list_item_background">
<TextView
android:id="@+id/fromText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvTransactionDate"
android:layout_alignParentStart="true"
android:layout_marginLeft="5dp"
android:layout_toStartOf="@+id/ivArrowFromTo"
android:ems="10"
android:inputType="text"
android:text="from" />
<ImageView
android:id="@+id/ivArrowFromTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:tint="@color/black"
app:srcCompat="@drawable/ic_arrow_forward" />
<TextView
android:id="@+id/toText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvTransactionDate"
android:layout_alignParentBottom="false"
android:layout_alignParentRight="true"
android:layout_toEndOf="@+id/ivArrowFromTo"
android:ems="10"
android:inputType="text"
android:text="to"
android:textAlignment="textEnd" />
<Space
android:id="@+id/sAfterFromTo"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/fromText"/>
<TextView
android:id="@+id/amountText"
android:id="@+id/tvTransactionDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/sAfterFromTo"
android:layout_marginLeft="5dp"
android:layout_toStartOf="@+id/ivArrowFromTo"
android:ems="10"
android:text="02 Oct"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvTransactionHour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tvTransactionDate"
android:layout_marginLeft="5dp"
android:layout_toStartOf="@+id/ivArrowFromTo"
android:ems="10"
android:text="15:01:18 CET" />
<TextView
android:id="@+id/tvAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignWithParentIfMissing="false"
android:layout_below="@+id/fromText"
android:layout_centerHorizontal="true"
android:layout_below="@id/sAfterFromTo"
android:layout_toEndOf="@+id/ivArrowFromTo"
android:ems="10"
android:gravity="center"
android:inputType="text"
android:text="amount" />
android:text="+ 1 BTS"
android:textAlignment="textEnd"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvEquivalent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignWithParentIfMissing="false"
android:layout_below="@id/tvAmount"
android:layout_toEndOf="@+id/ivArrowFromTo"
android:ems="10"
android:inputType="text"
android:text="0.005€"
android:textAlignment="textEnd" />
</RelativeLayout>
</LinearLayout>