- Added e-receipts. If the user makes a click to a transaction in the transaction list, that will make appear a e-receipt for that transaction.

This commit is contained in:
Javier Varona 2017-11-21 21:26:24 -04:00
parent 2b638acd89
commit 5946df1885
6 changed files with 679 additions and 1 deletions

View file

@ -29,6 +29,8 @@
</activity>
<activity android:name=".activities.GeneralSettingsActivity" >
</activity>
<activity android:name=".activities.CryptoCoinTransactionReceiptActivity" >
</activity>
<service android:name=".service.CrystalWalletService"
android:exported="false"/>
</application>

View file

@ -0,0 +1,74 @@
package cy.agorise.crystalwallet.activities;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.text.SimpleDateFormat;
import butterknife.BindView;
import butterknife.ButterKnife;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCurrency;
public class CryptoCoinTransactionReceiptActivity extends AppCompatActivity {
@BindView(R.id.tvOtherName)
TextView tvOtherName;
@BindView(R.id.tvUserName)
TextView tvUserName;
@BindView(R.id.tvTime)
TextView tvTime;
@BindView(R.id.tvPaymentAmount)
TextView tvPaymentAmount;
private long cryptoCoinTransactionId;
private LiveData<CryptoCoinTransaction> cryptoCoinTransactionLiveData;
private CrystalDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.e_receipt);
ButterKnife.bind(this);
this.cryptoCoinTransactionId = getIntent().getLongExtra("CRYPTO_COIN_TRANSACTION_ID", -1);
if (this.cryptoCoinTransactionId != -1) {
db = CrystalDatabase.getAppDatabase(this);
this.cryptoCoinTransactionLiveData = db.transactionDao().getById(this.cryptoCoinTransactionId);
this.cryptoCoinTransactionLiveData.observe(this, new Observer<CryptoCoinTransaction>() {
@Override
public void onChanged(@Nullable CryptoCoinTransaction cryptoCoinTransaction) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yy");
CryptoCurrency cryptoCurrency = CrystalDatabase.getAppDatabase(getApplicationContext()).cryptoCurrencyDao().getById(cryptoCoinTransaction.getIdCurrency());
String userAccount = (cryptoCoinTransaction.getInput()?cryptoCoinTransaction.getTo():cryptoCoinTransaction.getFrom());
String otherAccount = (cryptoCoinTransaction.getInput()?cryptoCoinTransaction.getFrom():cryptoCoinTransaction.getTo());
String transactionDateString = dateFormat.format(cryptoCoinTransaction.getDate());
String timezoneString = dateFormat.getTimeZone().getDisplayName();
String amountString = String.format("%.2f",cryptoCoinTransaction.getAmount()/(Math.pow(10,cryptoCurrency.getPrecision())));
tvUserName.setText(userAccount);
tvOtherName.setText(otherAccount);
tvTime.setText(transactionDateString+" "+timezoneString);
tvPaymentAmount.setText(amountString+" "+cryptoCurrency.getName());
}
});
} else {
this.finish();
}
}
}

View file

@ -29,6 +29,9 @@ public interface TransactionDao {
@Query("SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date DESC")
List<CryptoCoinTransaction> getByIdAccount(long idAccount);
@Query("SELECT * FROM crypto_coin_transaction WHERE id = :id")
LiveData<CryptoCoinTransaction> getById(long id);
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertTransaction(CryptoCoinTransaction... transactions);

View file

@ -2,12 +2,16 @@ package cy.agorise.crystalwallet.views;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.Intent;
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 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.viewmodels.CryptoCurrencyViewModel;
@ -31,19 +35,50 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
* The view holding the transaction amount
*/
private TextView transactionAmount;
private TextView tvTransactionDate;
private View rootView;
private Fragment fragment;
private long cryptoCoinTransactionId;
public TransactionViewHolder(View itemView, Fragment fragment) {
super(itemView);
//TODO: use ButterKnife to load this
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);
tvTransactionDate = (TextView) itemView.findViewById(R.id.tvTransactionDate);
this.fragment = fragment;
rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ereceiptOfThisTransaction();
}
});
}
/*
* dispatch the user to the receipt activity using this transaction
*/
public void ereceiptOfThisTransaction(){
//if the transaction was loaded
if (this.cryptoCoinTransactionId >= 0) {
Context context = fragment.getContext();
Intent startActivity = new Intent();
startActivity.setClass(context, CryptoCoinTransactionReceiptActivity.class);
startActivity.setAction(CryptoCoinTransactionReceiptActivity.class.getName());
//Pass the transaction id as an extra parameter to the receipt activity
startActivity.putExtra("CRYPTO_COIN_TRANSACTION_ID", this.cryptoCoinTransactionId);
startActivity.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(startActivity);
}
}
/*
@ -64,6 +99,7 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
transactionTo.setText("");
transactionAmount.setText("");
} else {
this.cryptoCoinTransactionId = transaction.getId();
CryptoCurrencyViewModel cryptoCurrencyViewModel = ViewModelProviders.of(this.fragment).get(CryptoCurrencyViewModel.class);
CryptoCurrency cryptoCurrency = cryptoCurrencyViewModel.getCryptoCurrencyById(transaction.getIdCurrency());
String amountString = String.format("%.2f",transaction.getAmount()/Math.pow(10,cryptoCurrency.getPrecision()));

View file

@ -0,0 +1,562 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/receiptScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_horizontal_margin">
<RelativeLayout
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="right">
<ImageButton
android:id="@+id/buttonSend"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@color/white"
android:src="@drawable/share"
android:text="@string/email_pdf" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:indeterminateDrawable="@drawable/loader_homescreen"></ProgressBar>
</RelativeLayout>
<LinearLayout
android:id="@+id/llall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edittext_bg"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/rlbuttonSend"
android:layout_width="50dp"
android:layout_height="10dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"></RelativeLayout>
<ImageView
android:id="@+id/ivOtherGravatar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="@+id/rlbuttonSend"
android:layout_centerInParent="true"
android:src="@drawable/default_gravatar_image" />
<LinearLayout
android:id="@+id/llOtherAccount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@+id/ivOtherGravatar"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/tvOtherCompany"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=""
android:textColor="@color/black"
android:textSize="20dp" />
<TextView
android:id="@+id/tvOtherStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="18dp" />
<TextView
android:id="@+id/tvOtherName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/black"
android:textSize="15dp" />
<TextView
android:id="@+id/tvAddress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text=""
android:textColor="@color/black"
android:textSize="12dp" />
<TextView
android:id="@+id/tvContact"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text=""
android:textColor="@color/black"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llUserAccount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/llOtherAccount"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/tvUserStatus"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/black"
android:textSize="18dp" />
<TextView
android:id="@+id/tvUserName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/black"
android:textSize="15dp" />
<TextView
android:id="@+id/tvUserId"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/black"
android:textSize="13dp" />
<TextView
android:id="@+id/tvTime"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:textColor="@color/black"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llDetailsTable"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="@+id/llUserAccount"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:weightSum="5">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/simple_line"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left|center"
android:text="Item 1" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
android:paddingTop="3dp"
android:weightSum="2">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center_vertical|right"
android:text="----"
android:textColor="@color/black"
android:textSize="13dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/simple_line"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left|center"
android:text="Item 2" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
android:paddingTop="3dp"
android:weightSum="2">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center_vertical|right"
android:text="----"
android:textColor="@color/black"
android:textSize="13dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/simple_line"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left|center"
android:text="@string/amount" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
android:paddingTop="3dp"
android:weightSum="2">
<TextView
android:id="@+id/tvAmount"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical|right"
android:text="+1E"
android:textColor="@color/black"
android:textSize="13dp" />
<TextView
android:id="@+id/tvAmountEquivalent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="clip_vertical|right"
android:text="+1E"
android:textColor="@color/black"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/simple_line"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left|center"
android:text="@string/fee_capital" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
android:paddingTop="3dp"
android:weightSum="2">
<TextView
android:id="@+id/tvFee"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical|right"
android:text="+1E"
android:textColor="@color/black"
android:textSize="13dp" />
<TextView
android:id="@+id/tvFeeEquivalent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="clip_vertical|right"
android:text="+1E"
android:textColor="@color/black"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/simple_line"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left|center"
android:text="@string/total" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
android:paddingTop="3dp"
android:weightSum="2">
<TextView
android:id="@+id/tvTotal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical|right"
android:text="+1E"
android:textColor="@color/black"
android:textSize="13dp" />
<TextView
android:id="@+id/tvTotalEquivalent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="clip_vertical|right"
android:text="+1E"
android:textColor="@color/black"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/llPaymentMethod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/llDetailsTable"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:weightSum="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/payment_method" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30sp"
android:gravity="left|center"
android:text=" : " />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:weightSum="3">
<ImageView
android:id="@+id/ivImageTag"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_weight="1"
android:src="@drawable/sendicon" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical"
android:paddingTop="3dp"
android:weightSum="3">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="left|center"
android:text="@string/app_name"
android:textColor="@color/black"
android:textSize="15dp" />
<TextView
android:id="@+id/tvPaymentAmount"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="left|center"
android:text=""
android:textColor="@color/black"
android:textSize="13dp" />
<TextView
android:id="@+id/tvPaymentEquivalent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="left|center"
android:text=""
android:textColor="@color/black"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/llMemo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/llPaymentMethod"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/memo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:text="@string/memo_template" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/llMemo"
android:layout_margin="3dp"
android:background="@android:color/darker_gray" />
<LinearLayout
android:id="@+id/llThankyou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/llMemo"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/thankyou_string" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_below="@+id/llThankyou"
android:layout_gravity="bottom"
android:layout_marginTop="10dp"
android:gravity="bottom"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:weightSum="6">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="block#" />
<TextView
android:id="@+id/tvBlockNumber"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="trx id#" />
<TextView
android:id="@+id/tvTrxInBlock"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -8,6 +8,7 @@
android:paddingTop="10dp">
<RelativeLayout
android:id="@+id/rlTransactionItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"