Merge pull request #1 from Agorise/master

need latest commits
This commit is contained in:
Severiano Jaramillo Quintanar 2017-11-14 21:04:48 -06:00 committed by GitHub
commit 5207bd9118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 282 additions and 49 deletions

View file

@ -57,8 +57,11 @@ public abstract class GrapheneApiGenerator {
//TODO network connections //TODO network connections
//TODO make to work with all Graphene type, not only bitshares //TODO make to work with all Graphene type, not only bitshares
public static String url = "http://128.0.69.157:8090"; //public static String url = "http://128.0.69.157:8090";
private static String equivalentUrl = "http://128.0.69.157:8090"; //private static String equivalentUrl = "http://128.0.69.157:8090";
public static String url = "wss://bitshares.openledger.info/ws";
private static String equivalentUrl = "wss://bitshares.openledger.info/ws";
// The message broker for bitshares // The message broker for bitshares
private static SubscriptionMessagesHub bitsharesSubscriptionHub = new SubscriptionMessagesHub("", "", true, new NodeErrorListener() { private static SubscriptionMessagesHub bitsharesSubscriptionHub = new SubscriptionMessagesHub("", "", true, new NodeErrorListener() {
@ -595,12 +598,18 @@ public abstract class GrapheneApiGenerator {
//TODO indirect equivalent value //TODO indirect equivalent value
} }
for(LimitOrder order : orders){ for(LimitOrder order : orders){
if(order.getSellPrice().base.getAsset().getBitassetId().equals(baseAsset.getBitsharesId())) { try {
Converter converter = new Converter(); //if (order.getSellPrice().base.getAsset().getBitassetId().equals(baseAsset.getBitsharesId())) {
double equiValue = converter.getConversionRate(order.getSellPrice(), Converter.BASE_TO_QUOTE); Converter converter = new Converter();
CryptoCurrencyEquivalence equivalence = new CryptoCurrencyEquivalence(baseAsset.getId(), quoteAsset.getId(), (int) (Math.pow(10, baseAsset.getPrecision()) * equiValue), new Date()); order.getSellPrice().base.getAsset().setPrecision(baseAsset.getPrecision());
CrystalDatabase.getAppDatabase(context).cryptoCurrencyEquivalenceDao().insertCryptoCurrencyEquivalence(equivalence); order.getSellPrice().quote.getAsset().setPrecision(quoteAsset.getPrecision());
break; double equiValue = converter.getConversionRate(order.getSellPrice(), Converter.BASE_TO_QUOTE);
CryptoCurrencyEquivalence equivalence = new CryptoCurrencyEquivalence(baseAsset.getId(), quoteAsset.getId(), (int) (Math.pow(10, baseAsset.getPrecision()) * equiValue), new Date());
CrystalDatabase.getAppDatabase(context).cryptoCurrencyEquivalenceDao().insertCryptoCurrencyEquivalence(equivalence);
break;
//}
}catch(Exception e){
e.printStackTrace();
} }
} }
} }

View file

@ -16,9 +16,9 @@ import cy.agorise.crystalwallet.enums.CryptoNet;
import static android.arch.persistence.room.ColumnInfo.INTEGER; import static android.arch.persistence.room.ColumnInfo.INTEGER;
/** /**
* Represents a generic CryptoNet Account Balance
*
* Created by Henry Varona on 6/9/2017. * Created by Henry Varona on 6/9/2017.
*
* Represents a generic Account Balance from a specific CryptoNet
*/ */
@Entity @Entity
@ -31,7 +31,7 @@ public class CryptoNetBalance {
private long mAccountId; private long mAccountId;
/** /**
* The cryptonet of the account * The crypto net of the account
*/ */
@ColumnInfo(name = "crypto_net") @ColumnInfo(name = "crypto_net")
private CryptoNet mCryptoNet; private CryptoNet mCryptoNet;

View file

@ -41,7 +41,7 @@ public class CrystalWalletService extends LifecycleService {
private ServiceHandler mServiceHandler; private ServiceHandler mServiceHandler;
private BitsharesAccountManager bitsharesAccountManager; private BitsharesAccountManager bitsharesAccountManager;
private Thread LoadAccountTransactionsThread; private Thread LoadAccountTransactionsThread;
private Thread LoadEquivalencesThread; private EquivalencesThread LoadEquivalencesThread;
private boolean keepLoadingAccountTransactions; private boolean keepLoadingAccountTransactions;
private boolean keepLoadingEquivalences; private boolean keepLoadingEquivalences;
private CryptoNetInfoRequests cryptoNetInfoRequests; private CryptoNetInfoRequests cryptoNetInfoRequests;
@ -106,22 +106,15 @@ public class CrystalWalletService extends LifecycleService {
bitsharesAssets.add(nextAsset); bitsharesAssets.add(nextAsset);
} }
while (keepLoadingEquivalences) { if (LoadEquivalencesThread != null){LoadEquivalencesThread.stopLoadingEquivalences();};
try { LoadEquivalencesThread = new EquivalencesThread(service, preferredCurrencyBitshareAsset, bitsharesAssets);
GrapheneApiGenerator.getEquivalentValue(preferredCurrencyBitshareAsset, bitsharesAssets, service); LoadEquivalencesThread.start();
Thread.sleep(60000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
} }
}); });
} }
} }
} }
}); });
} }
public void loadAccountTransactions(){ public void loadAccountTransactions(){
@ -177,6 +170,7 @@ public class CrystalWalletService extends LifecycleService {
if (LoadAccountTransactionsThread == null) { if (LoadAccountTransactionsThread == null) {
LoadAccountTransactionsThread = new Thread() { LoadAccountTransactionsThread = new Thread() {
@Override
public void run() { public void run() {
loadAccountTransactions(); loadAccountTransactions();
} }
@ -184,14 +178,15 @@ public class CrystalWalletService extends LifecycleService {
LoadAccountTransactionsThread.start(); LoadAccountTransactionsThread.start();
} }
if (LoadEquivalencesThread == null) { //if (LoadEquivalencesThread == null) {
LoadEquivalencesThread = new Thread() { // LoadEquivalencesThread = new Thread() {
public void run() { // @Override
// public void run() {
loadEquivalentsValues(); loadEquivalentsValues();
} // }
}; // };
LoadEquivalencesThread.start(); // LoadEquivalencesThread.start();
} //}
// If we get killed, after returning from here, restart // If we get killed, after returning from here, restart
return START_STICKY; return START_STICKY;

View file

@ -0,0 +1,46 @@
package cy.agorise.crystalwallet.service;
import android.arch.lifecycle.LifecycleService;
import android.util.Log;
import java.util.List;
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
import cy.agorise.crystalwallet.models.BitsharesAsset;
/**
* Created by Henry Varona on 14/11/2017.
*/
public class EquivalencesThread extends Thread{
private boolean keepLoadingEquivalences = true;
private LifecycleService service;
private BitsharesAsset fromAsset;
private List<BitsharesAsset> bitsharesAssets;
public EquivalencesThread(LifecycleService service, BitsharesAsset fromAsset, List<BitsharesAsset> bitsharesAssets){
this.service = service;
this.fromAsset = fromAsset;
this.bitsharesAssets = bitsharesAssets;
}
@Override
public void run() {
super.run();
while(this.keepLoadingEquivalences){
try {
GrapheneApiGenerator.getEquivalentValue(fromAsset, bitsharesAssets, this.service);
Log.i("Equivalences Thread", "In loop");
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
public void stopLoadingEquivalences(){
this.keepLoadingEquivalences = false;
}
}

View file

@ -11,6 +11,8 @@ import cy.agorise.crystalwallet.models.CryptoCoinBalance;
/** /**
* Created by Henry Varona on 11/9/2017. * Created by Henry Varona on 11/9/2017.
*
* An adapter to show the elements of a list of crypto coin balances
*/ */
public class CryptoCoinBalanceListAdapter extends ListAdapter<CryptoCoinBalance, CryptoCoinBalanceViewHolder> { public class CryptoCoinBalanceListAdapter extends ListAdapter<CryptoCoinBalance, CryptoCoinBalanceViewHolder> {

View file

@ -16,54 +16,81 @@ import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
/** /**
* Created by Henry Varona on 10/9/2017. * Created by Henry Varona on 10/9/2017.
*
* A list view of crypto coin balances of a crypto net account
*/ */
public class CryptoCoinBalanceListView extends RelativeLayout { public class CryptoCoinBalanceListView extends RelativeLayout {
LayoutInflater mInflater; LayoutInflater mInflater;
/*
* The root view of this view
*/
View rootView; View rootView;
/*
* The list view that holds every crypto coin balance item
*/
RecyclerView listView; RecyclerView listView;
/*
* The adapter for the previous list view
*/
CryptoCoinBalanceListAdapter listAdapter; CryptoCoinBalanceListAdapter listAdapter;
CryptoCoinBalanceListViewModel cryptoCoinBalanceListViewModel;
private int visibleThreshold = 5;
private boolean loading = true;
/*
* One of three constructors needed to be inflated from a layout
*/
public CryptoCoinBalanceListView(Context context){ public CryptoCoinBalanceListView(Context context){
super(context); super(context);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
/*
* One of three constructors needed to be inflated from a layout
*/
public CryptoCoinBalanceListView(Context context, AttributeSet attrs) { public CryptoCoinBalanceListView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
/*
* One of three constructors needed to be inflated from a layout
*/
public CryptoCoinBalanceListView(Context context, AttributeSet attrs, int defStyle){ public CryptoCoinBalanceListView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle); super(context, attrs, defStyle);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
/*
* Initializes this view
*/
public void init(){ public void init(){
rootView = mInflater.inflate(R.layout.crypto_coin_balance_list, this, true); rootView = mInflater.inflate(R.layout.crypto_coin_balance_list, this, true);
this.listView = (RecyclerView) rootView.findViewById(R.id.cryptoCoinBalanceListView); this.listView = (RecyclerView) rootView.findViewById(R.id.cryptoCoinBalanceListView);
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext()); final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
this.listView.setLayoutManager(linearLayoutManager); this.listView.setLayoutManager(linearLayoutManager);
//Prevents the UI from an infinite scrolling of balances
this.listView.setNestedScrollingEnabled(false); this.listView.setNestedScrollingEnabled(false);
} }
/*
* Sets the data for the list of balances.
*
* @param data the list of crypto coin balances that will be show to the user
*/
public void setData(List<CryptoCoinBalance> data){ public void setData(List<CryptoCoinBalance> data){
//initializes the list adapter
if (this.listAdapter == null) { if (this.listAdapter == null) {
this.listAdapter = new CryptoCoinBalanceListAdapter(); this.listAdapter = new CryptoCoinBalanceListAdapter();
this.listView.setAdapter(this.listAdapter); this.listView.setAdapter(this.listAdapter);
} }
//sets the data of the list adapter
if (data != null) { if (data != null) {
this.listAdapter.setList(data); this.listAdapter.setList(data);
} }

View file

@ -19,16 +19,29 @@ import cy.agorise.crystalwallet.models.GeneralSetting;
/** /**
* Created by Henry Varona on 17/9/2017. * Created by Henry Varona on 17/9/2017.
*
* Represents an element view from a Crypto Coin Balance List
*/ */
public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder { public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
/*
* the view holding the crypto coin name
*/
private TextView cryptoCoinName; private TextView cryptoCoinName;
/*
* the view holding the crypto coin balance amount
*/
private TextView cryptoCoinBalance; private TextView cryptoCoinBalance;
/*
* the view holding the crypto coin balance equivalent value
*/
private TextView cryptoCoinBalanceEquivalence; private TextView cryptoCoinBalanceEquivalence;
private Context context; private Context context;
public CryptoCoinBalanceViewHolder(View itemView) { public CryptoCoinBalanceViewHolder(View itemView) {
super(itemView); super(itemView);
//TODO: use ButterKnife to load this
cryptoCoinName = (TextView) itemView.findViewById(R.id.tvCryptoCoinName); cryptoCoinName = (TextView) itemView.findViewById(R.id.tvCryptoCoinName);
cryptoCoinBalance = (TextView) itemView.findViewById(R.id.tvCryptoCoinBalanceAmount); cryptoCoinBalance = (TextView) itemView.findViewById(R.id.tvCryptoCoinBalanceAmount);
cryptoCoinBalanceEquivalence = (TextView) itemView.findViewById(R.id.tvCryptoCoinBalanceEquivalence); cryptoCoinBalanceEquivalence = (TextView) itemView.findViewById(R.id.tvCryptoCoinBalanceEquivalence);
@ -36,35 +49,46 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
} }
/*
* Clears the information in this element view
*/
public void clear(){ public void clear(){
cryptoCoinName.setText("loading..."); cryptoCoinName.setText("loading...");
cryptoCoinBalance.setText(""); cryptoCoinBalance.setText("");
cryptoCoinBalanceEquivalence.setText(""); cryptoCoinBalanceEquivalence.setText("");
} }
/*
* Binds this view with the data of an element of the list
*/
public void bindTo(final CryptoCoinBalance balance/*, final OnTransactionClickListener listener*/) { public void bindTo(final CryptoCoinBalance balance/*, final OnTransactionClickListener listener*/) {
if (balance == null){ if (balance == null){
cryptoCoinName.setText("loading..."); this.clear();
cryptoCoinBalance.setText("");
cryptoCoinBalanceEquivalence.setText("");
} else { } else {
//Retrieves the preferred currency selected by the user
LiveData<GeneralSetting> preferedCurrencySetting = CrystalDatabase.getAppDatabase(this.context).generalSettingDao().getByName(GeneralSetting.SETTING_NAME_PREFERED_CURRENCY); LiveData<GeneralSetting> preferedCurrencySetting = CrystalDatabase.getAppDatabase(this.context).generalSettingDao().getByName(GeneralSetting.SETTING_NAME_PREFERED_CURRENCY);
//Retrieves the currency of this balance
final CryptoCurrency currencyFrom = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId()); final CryptoCurrency currencyFrom = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId());
//Sets the name and amount of the balance in the view
cryptoCoinName.setText(currencyFrom.getName()); cryptoCoinName.setText(currencyFrom.getName());
cryptoCoinBalance.setText("" + balance.getBalance()); cryptoCoinBalance.setText("" + balance.getBalance());
//Observes the preferred currency of the user. If the user changes it, this will change the equivalent value
preferedCurrencySetting.observe((LifecycleOwner) this.context, new Observer<GeneralSetting>() { preferedCurrencySetting.observe((LifecycleOwner) this.context, new Observer<GeneralSetting>() {
@Override @Override
public void onChanged(@Nullable GeneralSetting generalSetting) { public void onChanged(@Nullable GeneralSetting generalSetting) {
if (generalSetting != null) { if (generalSetting != null) {
//Gets the currency object of the preferred currency
CryptoCurrency currencyTo = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getByName(generalSetting.getValue()); CryptoCurrency currencyTo = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getByName(generalSetting.getValue());
//Retrieves the equivalent value of this balance using the "From" currency and the "To" currency
LiveData<CryptoCurrencyEquivalence> currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(context) LiveData<CryptoCurrencyEquivalence> currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(context)
.cryptoCurrencyEquivalenceDao().getByFromTo( .cryptoCurrencyEquivalenceDao().getByFromTo(
currencyFrom.getId(), currencyFrom.getId(),
currencyTo.getId() currencyTo.getId()
); );
//Observes the equivalent value. If the equivalent value changes, this will keep the value showed correct
currencyEquivalenceLiveData.observe((LifecycleOwner) context, new Observer<CryptoCurrencyEquivalence>() { currencyEquivalenceLiveData.observe((LifecycleOwner) context, new Observer<CryptoCurrencyEquivalence>() {
@Override @Override
public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) { public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) {

View file

@ -14,6 +14,8 @@ import cy.agorise.crystalwallet.models.CryptoCurrency;
/** /**
* Created by Henry Varona on 25/10/2017. * Created by Henry Varona on 25/10/2017.
*
* The adapter to show a list of crypto currencies in a spinner.
*/ */
public class CryptoCurrencyAdapter extends ArrayAdapter<CryptoCurrency> { public class CryptoCurrencyAdapter extends ArrayAdapter<CryptoCurrency> {
@ -29,6 +31,9 @@ public class CryptoCurrencyAdapter extends ArrayAdapter<CryptoCurrency> {
return getView(position, convertView, parent); return getView(position, convertView, parent);
} }
/*
* Creates the view for every element of the spinner
*/
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View file

@ -13,10 +13,15 @@ import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
/** /**
* Created by Henry Varona on 11/9/2017. * Created by Henry Varona on 11/9/2017.
*
* An adapter to show the elements of a list of crypto net balances
*/ */
public class CryptoNetBalanceListAdapter extends ListAdapter<CryptoNetBalance, CryptoNetBalanceViewHolder> { public class CryptoNetBalanceListAdapter extends ListAdapter<CryptoNetBalance, CryptoNetBalanceViewHolder> {
/*
* A LifecycleOwner fragment that will be used to call the ViewModelProviders
*/
Fragment fragment; Fragment fragment;
public CryptoNetBalanceListAdapter(Fragment fragment) { public CryptoNetBalanceListAdapter(Fragment fragment) {
@ -28,7 +33,6 @@ public class CryptoNetBalanceListAdapter extends ListAdapter<CryptoNetBalance, C
public CryptoNetBalanceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public CryptoNetBalanceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.balance_list_item,parent,false); View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.balance_list_item,parent,false);
return new CryptoNetBalanceViewHolder(v, fragment); return new CryptoNetBalanceViewHolder(v, fragment);
} }

View file

@ -18,54 +18,86 @@ import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel;
/** /**
* Created by Henry Varona on 10/9/2017. * Created by Henry Varona on 10/9/2017.
*
* A view that show the list of crypto net balances of the user.
* Each crypto net has its own list of crypto coin balances.
*
* With this view the user can see all of his/her account balances of
* every crypto coin.
*/ */
public class CryptoNetBalanceListView extends RelativeLayout { public class CryptoNetBalanceListView extends RelativeLayout {
LayoutInflater mInflater; LayoutInflater mInflater;
/*
* The root container of this view. Its a relative layout
*/
View rootView; View rootView;
/*
* The list view that holds every crypto net balance item
*/
RecyclerView listView; RecyclerView listView;
/*
* The adapter for the previous list view
*/
CryptoNetBalanceListAdapter listAdapter; CryptoNetBalanceListAdapter listAdapter;
CryptoNetBalanceListViewModel cryptoNetBalanceListViewModel; /*
* One of three constructors needed to be inflated from a layout
private int visibleThreshold = 5; */
private boolean loading = true;
public CryptoNetBalanceListView(Context context){ public CryptoNetBalanceListView(Context context){
super(context); super(context);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
/*
* One of three constructors needed to be inflated from a layout
*/
public CryptoNetBalanceListView(Context context, AttributeSet attrs) { public CryptoNetBalanceListView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
/*
* One of three constructors needed to be inflated from a layout
*/
public CryptoNetBalanceListView(Context context, AttributeSet attrs, int defStyle){ public CryptoNetBalanceListView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle); super(context, attrs, defStyle);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
/**
* Initialize the list view holding the crypto net balances
*/
public void init(){ public void init(){
//inflates the corresponding view
rootView = mInflater.inflate(R.layout.balance_list, this, true); rootView = mInflater.inflate(R.layout.balance_list, this, true);
this.listView = rootView.findViewById(R.id.balanceListView); this.listView = rootView.findViewById(R.id.balanceListView);
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext()); final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
this.listView.setLayoutManager(linearLayoutManager); this.listView.setLayoutManager(linearLayoutManager);
//Prevents the UI from an infinite scrolling of balances
this.listView.setNestedScrollingEnabled(false); this.listView.setNestedScrollingEnabled(false);
} }
/*
* Sets the data for the list of balances.
*
* @param data the list of crypto net balances that will be show to the user
* @param fragment a LifecycleOwner fragment to allow the inners views to use the ViewModels
*/
public void setData(List<CryptoNetBalance> data, Fragment fragment){ public void setData(List<CryptoNetBalance> data, Fragment fragment){
//initializes the list adapter
if (this.listAdapter == null) { if (this.listAdapter == null) {
this.listAdapter = new CryptoNetBalanceListAdapter(fragment); this.listAdapter = new CryptoNetBalanceListAdapter(fragment);
this.listView.setAdapter(this.listAdapter); this.listView.setAdapter(this.listAdapter);
} }
//sets the data of the list adapter
if (data != null) { if (data != null) {
this.listAdapter.setList(data); this.listAdapter.setList(data);
} }

View file

@ -30,35 +30,57 @@ import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
/** /**
* Created by Henry Varona on 17/9/2017. * Created by Henry Varona on 17/9/2017.
*
* Represents an element view from a Crypto Net Balance List
*/ */
public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder { public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
//@BindView(R.id.ivCryptoNetIcon) /*
* the view holding the icon of the crypto net
*/
ImageView cryptoNetIcon; ImageView cryptoNetIcon;
//@BindView(R.id.tvCryptoNetName) /*
* the view holding the name of the crypto net
*/
TextView cryptoNetName; TextView cryptoNetName;
//@BindView(R.id.cryptoCoinBalancesListView) /*
* The list view of the crypto coins balances of this crypto net balance
*/
CryptoCoinBalanceListView cryptoCoinBalanceListView; CryptoCoinBalanceListView cryptoCoinBalanceListView;
/*
* The button for sending transactions from this crypto net balance account
*/
@BindView(R.id.btnSendFromThisAccount) @BindView(R.id.btnSendFromThisAccount)
Button btnSendFromThisAccount; Button btnSendFromThisAccount;
Context context; Context context;
/*
* the id of the account of this crypto net balance. It will be loaded
* when the element is bounded.
*/
long cryptoNetAccountId; long cryptoNetAccountId;
/*
* A LifecycleOwner fragment. It will be used to call the ViewModelProviders
*/
private Fragment fragment; private Fragment fragment;
public CryptoNetBalanceViewHolder(View itemView, Fragment fragment) { public CryptoNetBalanceViewHolder(View itemView, Fragment fragment) {
super(itemView); super(itemView);
//-1 represents a crypto net account not loaded yet
this.cryptoNetAccountId = -1; this.cryptoNetAccountId = -1;
//TODO: use ButterKnife to load the views
cryptoNetIcon = (ImageView) itemView.findViewById(R.id.ivCryptoNetIcon); cryptoNetIcon = (ImageView) itemView.findViewById(R.id.ivCryptoNetIcon);
cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName); cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName);
cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalancesListView); cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalancesListView);
btnSendFromThisAccount = (Button) itemView.findViewById(R.id.btnSendFromThisAccount); btnSendFromThisAccount = (Button) itemView.findViewById(R.id.btnSendFromThisAccount);
//Setting the send button
btnSendFromThisAccount.setOnClickListener(new View.OnClickListener() { btnSendFromThisAccount.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -73,15 +95,16 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
cryptoNetName.setText("loading..."); cryptoNetName.setText("loading...");
} }
//@OnClick(R.id.btnSendFromThisAccount) /*
* dispatch the user to the send activity using this account
*/
public void sendFromThisAccount(){ public void sendFromThisAccount(){
//if the crypto net account was loaded
if (this.cryptoNetAccountId >= 0) { if (this.cryptoNetAccountId >= 0) {
//Intent intent = new Intent(this.context, SendTransactionActivity.class);
//this.context.startActivity(intent);
Intent startActivity = new Intent(); Intent startActivity = new Intent();
startActivity.setClass(context, SendTransactionActivity.class); startActivity.setClass(context, SendTransactionActivity.class);
startActivity.setAction(SendTransactionActivity.class.getName()); startActivity.setAction(SendTransactionActivity.class.getName());
//Pass the account id as an extra parameter to the send activity
startActivity.putExtra("CRYPTO_NET_ACCOUNT_ID", this.cryptoNetAccountId); startActivity.putExtra("CRYPTO_NET_ACCOUNT_ID", this.cryptoNetAccountId);
startActivity.setFlags( startActivity.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_NEW_TASK
@ -90,6 +113,9 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
} }
} }
/*
* Binds this view with the data of an element of the list
*/
public void bindTo(final CryptoNetBalance balance) { public void bindTo(final CryptoNetBalance balance) {
if (balance == null){ if (balance == null){
cryptoNetName.setText("loading..."); cryptoNetName.setText("loading...");
@ -97,12 +123,14 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
this.cryptoNetAccountId = balance.getAccountId(); this.cryptoNetAccountId = balance.getAccountId();
cryptoNetName.setText(balance.getCryptoNet().getLabel()); cryptoNetName.setText(balance.getCryptoNet().getLabel());
//Loads the crypto coin balance list of this account using a ViewModel and retrieving a LiveData List
CryptoCoinBalanceListViewModel cryptoCoinBalanceListViewModel = ViewModelProviders.of(this.fragment).get(CryptoCoinBalanceListViewModel.class); CryptoCoinBalanceListViewModel cryptoCoinBalanceListViewModel = ViewModelProviders.of(this.fragment).get(CryptoCoinBalanceListViewModel.class);
cryptoCoinBalanceListViewModel.init(balance.getAccountId()); cryptoCoinBalanceListViewModel.init(balance.getAccountId());
LiveData<List<CryptoCoinBalance>> cryptoCoinBalanceData = cryptoCoinBalanceListViewModel.getCryptoCoinBalanceList(); LiveData<List<CryptoCoinBalance>> cryptoCoinBalanceData = cryptoCoinBalanceListViewModel.getCryptoCoinBalanceList();
cryptoCoinBalanceListView.setData(null); cryptoCoinBalanceListView.setData(null);
//Observes the livedata, so any of its changes on the database will be reloaded here
cryptoCoinBalanceData.observe((LifecycleOwner)this.itemView.getContext(), new Observer<List<CryptoCoinBalance>>() { cryptoCoinBalanceData.observe((LifecycleOwner)this.itemView.getContext(), new Observer<List<CryptoCoinBalance>>() {
@Override @Override
public void onChanged(List<CryptoCoinBalance> cryptoCoinBalances) { public void onChanged(List<CryptoCoinBalance> cryptoCoinBalances) {

View file

@ -21,6 +21,11 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
/** /**
* Created by Henry Varona on 11/9/2017. * Created by Henry Varona on 11/9/2017.
*
* An adapter to show the elements of a list of crypto net account transactions.
*
* Extends from a paged list, so not all transactions will be loaded immediately, but only a segment
* that will be extended with the scroll of the user
*/ */
public class TransactionListAdapter extends PagedListAdapter<CryptoCoinTransaction, TransactionViewHolder> { public class TransactionListAdapter extends PagedListAdapter<CryptoCoinTransaction, TransactionViewHolder> {

View file

@ -15,45 +15,75 @@ import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
/** /**
* Created by Henry Varona on 10/9/2017. * Created by Henry Varona on 10/9/2017.
*
* A list view showing many crypto net account transactions elements
*/ */
public class TransactionListView extends RelativeLayout { public class TransactionListView extends RelativeLayout {
LayoutInflater mInflater; LayoutInflater mInflater;
/*
* The root view of this view
*/
View rootView; View rootView;
/*
* The list view that holds every transaction item
*/
RecyclerView listView; RecyclerView listView;
/*
* The adapter for the previous list view
*/
TransactionListAdapter listAdapter; TransactionListAdapter listAdapter;
TransactionListViewModel transactionListViewModel; TransactionListViewModel transactionListViewModel;
/*
* how much transactions will remain to show before the list loads more
*/
private int visibleThreshold = 5; private int visibleThreshold = 5;
/*
* if true, the transaction list will be loading new data
*/
private boolean loading = true; private boolean loading = true;
/*
* One of three constructors needed to be inflated from a layout
*/
public TransactionListView(Context context){ public TransactionListView(Context context){
super(context); super(context);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
/*
* One of three constructors needed to be inflated from a layout
*/
public TransactionListView(Context context, AttributeSet attrs) { public TransactionListView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
/*
* One of three constructors needed to be inflated from a layout
*/
public TransactionListView(Context context, AttributeSet attrs, int defStyle){ public TransactionListView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle); super(context, attrs, defStyle);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
/*
* Initializes this view
*/
public void init(){ public void init(){
rootView = mInflater.inflate(R.layout.transaction_list, this, true); rootView = mInflater.inflate(R.layout.transaction_list, this, true);
this.listView = rootView.findViewById(R.id.transactionListView); this.listView = rootView.findViewById(R.id.transactionListView);
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext()); final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
this.listView.setLayoutManager(linearLayoutManager); this.listView.setLayoutManager(linearLayoutManager);
//Prevents the list to start again when scrolling to the end
this.listView.setNestedScrollingEnabled(false); this.listView.setNestedScrollingEnabled(false);
@ -74,12 +104,19 @@ public class TransactionListView extends RelativeLayout {
//} //}
/*
* Sets the elements data of this view
*
* @param data the transactions that will be showed to the user
*/
public void setData(PagedList<CryptoCoinTransaction> data){ public void setData(PagedList<CryptoCoinTransaction> data){
//Initializes the adapter of the transaction list
if (this.listAdapter == null) { if (this.listAdapter == null) {
this.listAdapter = new TransactionListAdapter(); this.listAdapter = new TransactionListAdapter();
this.listView.setAdapter(this.listAdapter); this.listView.setAdapter(this.listAdapter);
} }
//Sets the data of the transaction list
if (data != null) { if (data != null) {
this.listAdapter.setList(data); this.listAdapter.setList(data);
} }

View file

@ -9,28 +9,46 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
/** /**
* Created by Henry Varona on 17/9/2017. * Created by Henry Varona on 17/9/2017.
*
* Represents a transaction view in the crypto net account transaction list
*/ */
public class TransactionViewHolder extends RecyclerView.ViewHolder { public class TransactionViewHolder extends RecyclerView.ViewHolder {
/*
* The view holding the transaction "from"
*/
private TextView transactionFrom; private TextView transactionFrom;
/*
* The view holding the transaction "to"
*/
private TextView transactionTo; private TextView transactionTo;
/*
* The view holding the transaction amount
*/
private TextView transactionAmount; private TextView transactionAmount;
public TransactionViewHolder(View itemView) { public TransactionViewHolder(View itemView) {
super(itemView); super(itemView);
//TODO: use ButterKnife to load this
transactionFrom = (TextView) itemView.findViewById(R.id.fromText); transactionFrom = (TextView) itemView.findViewById(R.id.fromText);
transactionTo = (TextView) itemView.findViewById(R.id.toText); transactionTo = (TextView) itemView.findViewById(R.id.toText);
transactionAmount = (TextView) itemView.findViewById(R.id.amountText); transactionAmount = (TextView) itemView.findViewById(R.id.amountText);
} }
/*
* Clears all info in this element view
*/
public void clear(){ public void clear(){
transactionFrom.setText("loading..."); transactionFrom.setText("loading...");
transactionTo.setText(""); transactionTo.setText("");
transactionAmount.setText(""); transactionAmount.setText("");
} }
/*
* Binds a transaction object with this element view
*/
public void bindTo(final CryptoCoinTransaction transaction/*, final OnTransactionClickListener listener*/) { public void bindTo(final CryptoCoinTransaction transaction/*, final OnTransactionClickListener listener*/) {
if (transaction == null){ if (transaction == null){
transactionFrom.setText("loading..."); transactionFrom.setText("loading...");
@ -40,6 +58,7 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
transactionFrom.setText(transaction.getFrom()); transactionFrom.setText(transaction.getFrom());
transactionTo.setText(transaction.getTo()); transactionTo.setText(transaction.getTo());
transactionAmount.setText("" + transaction.getAmount()); transactionAmount.setText("" + transaction.getAmount());
//This will load the transaction receipt when the user clicks this view
/*itemView.setOnClickListener(new View.OnClickListener() { /*itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {