commit
5207bd9118
14 changed files with 282 additions and 49 deletions
|
@ -57,8 +57,11 @@ public abstract class GrapheneApiGenerator {
|
|||
|
||||
//TODO network connections
|
||||
//TODO make to work with all Graphene type, not only bitshares
|
||||
public static String url = "http://128.0.69.157:8090";
|
||||
private static String equivalentUrl = "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";
|
||||
public static String url = "wss://bitshares.openledger.info/ws";
|
||||
private static String equivalentUrl = "wss://bitshares.openledger.info/ws";
|
||||
|
||||
|
||||
// The message broker for bitshares
|
||||
private static SubscriptionMessagesHub bitsharesSubscriptionHub = new SubscriptionMessagesHub("", "", true, new NodeErrorListener() {
|
||||
|
@ -595,12 +598,18 @@ public abstract class GrapheneApiGenerator {
|
|||
//TODO indirect equivalent value
|
||||
}
|
||||
for(LimitOrder order : orders){
|
||||
if(order.getSellPrice().base.getAsset().getBitassetId().equals(baseAsset.getBitsharesId())) {
|
||||
try {
|
||||
//if (order.getSellPrice().base.getAsset().getBitassetId().equals(baseAsset.getBitsharesId())) {
|
||||
Converter converter = new Converter();
|
||||
order.getSellPrice().base.getAsset().setPrecision(baseAsset.getPrecision());
|
||||
order.getSellPrice().quote.getAsset().setPrecision(quoteAsset.getPrecision());
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ import cy.agorise.crystalwallet.enums.CryptoNet;
|
|||
import static android.arch.persistence.room.ColumnInfo.INTEGER;
|
||||
|
||||
/**
|
||||
* Represents a generic CryptoNet Account Balance
|
||||
*
|
||||
* Created by Henry Varona on 6/9/2017.
|
||||
*
|
||||
* Represents a generic Account Balance from a specific CryptoNet
|
||||
*/
|
||||
|
||||
@Entity
|
||||
|
|
|
@ -41,7 +41,7 @@ public class CrystalWalletService extends LifecycleService {
|
|||
private ServiceHandler mServiceHandler;
|
||||
private BitsharesAccountManager bitsharesAccountManager;
|
||||
private Thread LoadAccountTransactionsThread;
|
||||
private Thread LoadEquivalencesThread;
|
||||
private EquivalencesThread LoadEquivalencesThread;
|
||||
private boolean keepLoadingAccountTransactions;
|
||||
private boolean keepLoadingEquivalences;
|
||||
private CryptoNetInfoRequests cryptoNetInfoRequests;
|
||||
|
@ -106,22 +106,15 @@ public class CrystalWalletService extends LifecycleService {
|
|||
bitsharesAssets.add(nextAsset);
|
||||
}
|
||||
|
||||
while (keepLoadingEquivalences) {
|
||||
try {
|
||||
GrapheneApiGenerator.getEquivalentValue(preferredCurrencyBitshareAsset, bitsharesAssets, service);
|
||||
Thread.sleep(60000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
if (LoadEquivalencesThread != null){LoadEquivalencesThread.stopLoadingEquivalences();};
|
||||
LoadEquivalencesThread = new EquivalencesThread(service, preferredCurrencyBitshareAsset, bitsharesAssets);
|
||||
LoadEquivalencesThread.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void loadAccountTransactions(){
|
||||
|
@ -177,6 +170,7 @@ public class CrystalWalletService extends LifecycleService {
|
|||
|
||||
if (LoadAccountTransactionsThread == null) {
|
||||
LoadAccountTransactionsThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadAccountTransactions();
|
||||
}
|
||||
|
@ -184,14 +178,15 @@ public class CrystalWalletService extends LifecycleService {
|
|||
LoadAccountTransactionsThread.start();
|
||||
}
|
||||
|
||||
if (LoadEquivalencesThread == null) {
|
||||
LoadEquivalencesThread = new Thread() {
|
||||
public void run() {
|
||||
//if (LoadEquivalencesThread == null) {
|
||||
// LoadEquivalencesThread = new Thread() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
loadEquivalentsValues();
|
||||
}
|
||||
};
|
||||
LoadEquivalencesThread.start();
|
||||
}
|
||||
// }
|
||||
// };
|
||||
// LoadEquivalencesThread.start();
|
||||
//}
|
||||
|
||||
// If we get killed, after returning from here, restart
|
||||
return START_STICKY;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,8 @@ import cy.agorise.crystalwallet.models.CryptoCoinBalance;
|
|||
|
||||
/**
|
||||
* 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> {
|
||||
|
|
|
@ -16,54 +16,81 @@ import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
|
|||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
LayoutInflater mInflater;
|
||||
|
||||
/*
|
||||
* The root view of this view
|
||||
*/
|
||||
View rootView;
|
||||
/*
|
||||
* The list view that holds every crypto coin balance item
|
||||
*/
|
||||
RecyclerView listView;
|
||||
/*
|
||||
* The adapter for the previous list view
|
||||
*/
|
||||
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){
|
||||
super(context);
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* One of three constructors needed to be inflated from a layout
|
||||
*/
|
||||
public CryptoCoinBalanceListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* One of three constructors needed to be inflated from a layout
|
||||
*/
|
||||
public CryptoCoinBalanceListView(Context context, AttributeSet attrs, int defStyle){
|
||||
super(context, attrs, defStyle);
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes this view
|
||||
*/
|
||||
public void init(){
|
||||
rootView = mInflater.inflate(R.layout.crypto_coin_balance_list, this, true);
|
||||
this.listView = (RecyclerView) rootView.findViewById(R.id.cryptoCoinBalanceListView);
|
||||
|
||||
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
|
||||
this.listView.setLayoutManager(linearLayoutManager);
|
||||
//Prevents the UI from an infinite scrolling of balances
|
||||
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){
|
||||
//initializes the list adapter
|
||||
if (this.listAdapter == null) {
|
||||
this.listAdapter = new CryptoCoinBalanceListAdapter();
|
||||
this.listView.setAdapter(this.listAdapter);
|
||||
}
|
||||
|
||||
//sets the data of the list adapter
|
||||
if (data != null) {
|
||||
this.listAdapter.setList(data);
|
||||
}
|
||||
|
|
|
@ -19,16 +19,29 @@ import cy.agorise.crystalwallet.models.GeneralSetting;
|
|||
|
||||
/**
|
||||
* Created by Henry Varona on 17/9/2017.
|
||||
*
|
||||
* Represents an element view from a Crypto Coin Balance List
|
||||
*/
|
||||
|
||||
public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
|
||||
/*
|
||||
* the view holding the crypto coin name
|
||||
*/
|
||||
private TextView cryptoCoinName;
|
||||
/*
|
||||
* the view holding the crypto coin balance amount
|
||||
*/
|
||||
private TextView cryptoCoinBalance;
|
||||
/*
|
||||
* the view holding the crypto coin balance equivalent value
|
||||
*/
|
||||
private TextView cryptoCoinBalanceEquivalence;
|
||||
|
||||
private Context context;
|
||||
|
||||
public CryptoCoinBalanceViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
//TODO: use ButterKnife to load this
|
||||
cryptoCoinName = (TextView) itemView.findViewById(R.id.tvCryptoCoinName);
|
||||
cryptoCoinBalance = (TextView) itemView.findViewById(R.id.tvCryptoCoinBalanceAmount);
|
||||
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(){
|
||||
cryptoCoinName.setText("loading...");
|
||||
cryptoCoinBalance.setText("");
|
||||
cryptoCoinBalanceEquivalence.setText("");
|
||||
}
|
||||
|
||||
/*
|
||||
* Binds this view with the data of an element of the list
|
||||
*/
|
||||
public void bindTo(final CryptoCoinBalance balance/*, final OnTransactionClickListener listener*/) {
|
||||
if (balance == null){
|
||||
cryptoCoinName.setText("loading...");
|
||||
cryptoCoinBalance.setText("");
|
||||
cryptoCoinBalanceEquivalence.setText("");
|
||||
this.clear();
|
||||
} else {
|
||||
//Retrieves the preferred currency selected by the user
|
||||
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());
|
||||
//Sets the name and amount of the balance in the view
|
||||
cryptoCoinName.setText(currencyFrom.getName());
|
||||
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>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable GeneralSetting generalSetting) {
|
||||
if (generalSetting != null) {
|
||||
//Gets the currency object of the preferred currency
|
||||
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)
|
||||
.cryptoCurrencyEquivalenceDao().getByFromTo(
|
||||
currencyFrom.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>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) {
|
||||
|
|
|
@ -14,6 +14,8 @@ import cy.agorise.crystalwallet.models.CryptoCurrency;
|
|||
|
||||
/**
|
||||
* 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> {
|
||||
|
@ -29,6 +31,9 @@ public class CryptoCurrencyAdapter extends ArrayAdapter<CryptoCurrency> {
|
|||
return getView(position, convertView, parent);
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates the view for every element of the spinner
|
||||
*/
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
|
|
@ -13,10 +13,15 @@ import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
|
|||
|
||||
/**
|
||||
* 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> {
|
||||
|
||||
/*
|
||||
* A LifecycleOwner fragment that will be used to call the ViewModelProviders
|
||||
*/
|
||||
Fragment fragment;
|
||||
|
||||
public CryptoNetBalanceListAdapter(Fragment fragment) {
|
||||
|
@ -28,7 +33,6 @@ public class CryptoNetBalanceListAdapter extends ListAdapter<CryptoNetBalance, C
|
|||
public CryptoNetBalanceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.balance_list_item,parent,false);
|
||||
|
||||
|
||||
return new CryptoNetBalanceViewHolder(v, fragment);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,54 +18,86 @@ import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel;
|
|||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
LayoutInflater mInflater;
|
||||
|
||||
/*
|
||||
* The root container of this view. Its a relative layout
|
||||
*/
|
||||
View rootView;
|
||||
/*
|
||||
* The list view that holds every crypto net balance item
|
||||
*/
|
||||
RecyclerView listView;
|
||||
/*
|
||||
* The adapter for the previous list view
|
||||
*/
|
||||
CryptoNetBalanceListAdapter listAdapter;
|
||||
|
||||
CryptoNetBalanceListViewModel cryptoNetBalanceListViewModel;
|
||||
|
||||
private int visibleThreshold = 5;
|
||||
private boolean loading = true;
|
||||
|
||||
/*
|
||||
* One of three constructors needed to be inflated from a layout
|
||||
*/
|
||||
public CryptoNetBalanceListView(Context context){
|
||||
super(context);
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* One of three constructors needed to be inflated from a layout
|
||||
*/
|
||||
public CryptoNetBalanceListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* One of three constructors needed to be inflated from a layout
|
||||
*/
|
||||
public CryptoNetBalanceListView(Context context, AttributeSet attrs, int defStyle){
|
||||
super(context, attrs, defStyle);
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the list view holding the crypto net balances
|
||||
*/
|
||||
public void init(){
|
||||
//inflates the corresponding view
|
||||
rootView = mInflater.inflate(R.layout.balance_list, this, true);
|
||||
this.listView = rootView.findViewById(R.id.balanceListView);
|
||||
|
||||
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
|
||||
this.listView.setLayoutManager(linearLayoutManager);
|
||||
//Prevents the UI from an infinite scrolling of balances
|
||||
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){
|
||||
//initializes the list adapter
|
||||
if (this.listAdapter == null) {
|
||||
this.listAdapter = new CryptoNetBalanceListAdapter(fragment);
|
||||
this.listView.setAdapter(this.listAdapter);
|
||||
}
|
||||
|
||||
//sets the data of the list adapter
|
||||
if (data != null) {
|
||||
this.listAdapter.setList(data);
|
||||
}
|
||||
|
|
|
@ -30,35 +30,57 @@ import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
|
|||
|
||||
/**
|
||||
* Created by Henry Varona on 17/9/2017.
|
||||
*
|
||||
* Represents an element view from a Crypto Net Balance List
|
||||
*/
|
||||
|
||||
public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
|
||||
//@BindView(R.id.ivCryptoNetIcon)
|
||||
/*
|
||||
* the view holding the icon of the crypto net
|
||||
*/
|
||||
ImageView cryptoNetIcon;
|
||||
|
||||
//@BindView(R.id.tvCryptoNetName)
|
||||
/*
|
||||
* the view holding the name of the crypto net
|
||||
*/
|
||||
TextView cryptoNetName;
|
||||
|
||||
//@BindView(R.id.cryptoCoinBalancesListView)
|
||||
/*
|
||||
* The list view of the crypto coins balances of this crypto net balance
|
||||
*/
|
||||
CryptoCoinBalanceListView cryptoCoinBalanceListView;
|
||||
|
||||
/*
|
||||
* The button for sending transactions from this crypto net balance account
|
||||
*/
|
||||
@BindView(R.id.btnSendFromThisAccount)
|
||||
Button btnSendFromThisAccount;
|
||||
|
||||
Context context;
|
||||
|
||||
/*
|
||||
* the id of the account of this crypto net balance. It will be loaded
|
||||
* when the element is bounded.
|
||||
*/
|
||||
long cryptoNetAccountId;
|
||||
|
||||
/*
|
||||
* A LifecycleOwner fragment. It will be used to call the ViewModelProviders
|
||||
*/
|
||||
private Fragment fragment;
|
||||
|
||||
public CryptoNetBalanceViewHolder(View itemView, Fragment fragment) {
|
||||
super(itemView);
|
||||
//-1 represents a crypto net account not loaded yet
|
||||
this.cryptoNetAccountId = -1;
|
||||
|
||||
//TODO: use ButterKnife to load the views
|
||||
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);
|
||||
|
||||
//Setting the send button
|
||||
btnSendFromThisAccount.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -73,15 +95,16 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
|
|||
cryptoNetName.setText("loading...");
|
||||
}
|
||||
|
||||
//@OnClick(R.id.btnSendFromThisAccount)
|
||||
/*
|
||||
* dispatch the user to the send activity using this account
|
||||
*/
|
||||
public void sendFromThisAccount(){
|
||||
//if the crypto net account was loaded
|
||||
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());
|
||||
//Pass the account id as an extra parameter to the send activity
|
||||
startActivity.putExtra("CRYPTO_NET_ACCOUNT_ID", this.cryptoNetAccountId);
|
||||
startActivity.setFlags(
|
||||
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) {
|
||||
if (balance == null){
|
||||
cryptoNetName.setText("loading...");
|
||||
|
@ -97,12 +123,14 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
|
|||
this.cryptoNetAccountId = balance.getAccountId();
|
||||
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.init(balance.getAccountId());
|
||||
LiveData<List<CryptoCoinBalance>> cryptoCoinBalanceData = cryptoCoinBalanceListViewModel.getCryptoCoinBalanceList();
|
||||
|
||||
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>>() {
|
||||
@Override
|
||||
public void onChanged(List<CryptoCoinBalance> cryptoCoinBalances) {
|
||||
|
|
|
@ -21,6 +21,11 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
|||
|
||||
/**
|
||||
* 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> {
|
||||
|
|
|
@ -15,45 +15,75 @@ import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
|
|||
|
||||
/**
|
||||
* Created by Henry Varona on 10/9/2017.
|
||||
*
|
||||
* A list view showing many crypto net account transactions elements
|
||||
*/
|
||||
|
||||
public class TransactionListView extends RelativeLayout {
|
||||
|
||||
LayoutInflater mInflater;
|
||||
|
||||
/*
|
||||
* The root view of this view
|
||||
*/
|
||||
View rootView;
|
||||
/*
|
||||
* The list view that holds every transaction item
|
||||
*/
|
||||
RecyclerView listView;
|
||||
/*
|
||||
* The adapter for the previous list view
|
||||
*/
|
||||
TransactionListAdapter listAdapter;
|
||||
|
||||
TransactionListViewModel transactionListViewModel;
|
||||
|
||||
/*
|
||||
* how much transactions will remain to show before the list loads more
|
||||
*/
|
||||
private int visibleThreshold = 5;
|
||||
/*
|
||||
* if true, the transaction list will be loading new data
|
||||
*/
|
||||
private boolean loading = true;
|
||||
|
||||
/*
|
||||
* One of three constructors needed to be inflated from a layout
|
||||
*/
|
||||
public TransactionListView(Context context){
|
||||
super(context);
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* One of three constructors needed to be inflated from a layout
|
||||
*/
|
||||
public TransactionListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* One of three constructors needed to be inflated from a layout
|
||||
*/
|
||||
public TransactionListView(Context context, AttributeSet attrs, int defStyle){
|
||||
super(context, attrs, defStyle);
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes this view
|
||||
*/
|
||||
public void init(){
|
||||
rootView = mInflater.inflate(R.layout.transaction_list, this, true);
|
||||
this.listView = rootView.findViewById(R.id.transactionListView);
|
||||
|
||||
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
|
||||
this.listView.setLayoutManager(linearLayoutManager);
|
||||
//Prevents the list to start again when scrolling to the end
|
||||
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){
|
||||
//Initializes the adapter of the transaction list
|
||||
if (this.listAdapter == null) {
|
||||
this.listAdapter = new TransactionListAdapter();
|
||||
this.listView.setAdapter(this.listAdapter);
|
||||
}
|
||||
|
||||
//Sets the data of the transaction list
|
||||
if (data != null) {
|
||||
this.listAdapter.setList(data);
|
||||
}
|
||||
|
|
|
@ -9,28 +9,46 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
|||
|
||||
/**
|
||||
* 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 {
|
||||
/*
|
||||
* The view holding the transaction "from"
|
||||
*/
|
||||
private TextView transactionFrom;
|
||||
/*
|
||||
* The view holding the transaction "to"
|
||||
*/
|
||||
private TextView transactionTo;
|
||||
/*
|
||||
* The view holding the transaction amount
|
||||
*/
|
||||
private TextView transactionAmount;
|
||||
|
||||
|
||||
public TransactionViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
//TODO: use ButterKnife to load this
|
||||
transactionFrom = (TextView) itemView.findViewById(R.id.fromText);
|
||||
transactionTo = (TextView) itemView.findViewById(R.id.toText);
|
||||
transactionAmount = (TextView) itemView.findViewById(R.id.amountText);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Clears all info in this element view
|
||||
*/
|
||||
public void clear(){
|
||||
transactionFrom.setText("loading...");
|
||||
transactionTo.setText("");
|
||||
transactionAmount.setText("");
|
||||
}
|
||||
|
||||
/*
|
||||
* Binds a transaction object with this element view
|
||||
*/
|
||||
public void bindTo(final CryptoCoinTransaction transaction/*, final OnTransactionClickListener listener*/) {
|
||||
if (transaction == null){
|
||||
transactionFrom.setText("loading...");
|
||||
|
@ -40,6 +58,7 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
|
|||
transactionFrom.setText(transaction.getFrom());
|
||||
transactionTo.setText(transaction.getTo());
|
||||
transactionAmount.setText("" + transaction.getAmount());
|
||||
//This will load the transaction receipt when the user clicks this view
|
||||
/*itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
Loading…
Reference in a new issue