From 2590bb42ed6dbfc165130517d15aa326d1f72471 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Sat, 28 Oct 2017 21:58:00 -0400 Subject: [PATCH] - Adding send and receive buttons to the balances views - Now the transactions view appears as the second Page of the Board Activity --- app/src/main/AndroidManifest.xml | 2 + .../views/CryptoNetBalanceViewHolder.java | 53 +++++++++++++++++-- app/src/main/res/layout/balance_list_item.xml | 12 +++++ .../main/res/layout/fragment_transactions.xml | 7 ++- 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 886b7da..1a2889d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,6 +25,8 @@ + + diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java index 10d49bc..75444ee 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java @@ -1,6 +1,8 @@ package cy.agorise.crystalwallet.views; import android.app.Activity; +import android.content.Context; +import android.content.Intent; import android.support.v4.app.Fragment; import android.arch.lifecycle.LifecycleOwner; import android.arch.lifecycle.LiveData; @@ -9,12 +11,17 @@ import android.arch.lifecycle.ViewModelProviders; import android.arch.paging.PagedList; import android.support.v7.widget.RecyclerView; import android.view.View; +import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import java.util.List; +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.activities.SendTransactionActivity; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoNetBalance; @@ -25,28 +32,68 @@ import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel; */ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder { - private ImageView cryptoNetIcon; - private TextView cryptoNetName; - private CryptoCoinBalanceListView cryptoCoinBalanceListView; + //@BindView(R.id.ivCryptoNetIcon) + ImageView cryptoNetIcon; + + //@BindView(R.id.tvCryptoNetName) + TextView cryptoNetName; + + //@BindView(R.id.cryptoCoinBalancesListView) + CryptoCoinBalanceListView cryptoCoinBalanceListView; + + @BindView(R.id.btnSendFromThisAccount) + Button btnSendFromThisAccount; + + Context context; + + long cryptoNetAccountId; private Fragment fragment; public CryptoNetBalanceViewHolder(View itemView, Fragment fragment) { super(itemView); + this.cryptoNetAccountId = -1; + cryptoNetIcon = (ImageView) itemView.findViewById(R.id.ivCryptoNetIcon); cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName); cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalancesListView); + btnSendFromThisAccount = (Button) itemView.findViewById(R.id.btnSendFromThisAccount); + btnSendFromThisAccount.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + sendFromThisAccount(); + } + }); this.fragment = fragment; + this.context = itemView.getContext(); } public void clear(){ cryptoNetName.setText("loading..."); } + //@OnClick(R.id.btnSendFromThisAccount) + public void sendFromThisAccount(){ + if (this.cryptoNetAccountId >= 0) { + //Intent intent = new Intent(this.context, SendTransactionActivity.class); + //this.context.startActivity(intent); + + Intent startActivity = new Intent(); + startActivity.setClass(context, SendTransactionActivity.class); + startActivity.setAction(SendTransactionActivity.class.getName()); + startActivity.putExtra("CRYPTO_NET_ACCOUNT_ID", this.cryptoNetAccountId); + startActivity.setFlags( + Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + context.startActivity(startActivity); + } + } + public void bindTo(final CryptoNetBalance balance) { if (balance == null){ cryptoNetName.setText("loading..."); } else { + this.cryptoNetAccountId = balance.getAccountId(); cryptoNetName.setText(balance.getCryptoNet().getLabel()); CryptoCoinBalanceListViewModel cryptoCoinBalanceListViewModel = ViewModelProviders.of(this.fragment).get(CryptoCoinBalanceListViewModel.class); diff --git a/app/src/main/res/layout/balance_list_item.xml b/app/src/main/res/layout/balance_list_item.xml index 1ff1487..b2f51fc 100644 --- a/app/src/main/res/layout/balance_list_item.xml +++ b/app/src/main/res/layout/balance_list_item.xml @@ -32,6 +32,18 @@ android:layout_height="wrap_content" android:ems="10" android:text="unknown coin" /> + +