Graphene Api with equivalent value using a name for the base asset

This commit is contained in:
henry 2017-11-15 21:47:11 -04:00
parent 616e44d59c
commit 8bec42de1a
2 changed files with 42 additions and 2 deletions

View file

@ -559,7 +559,7 @@ public abstract class GrapheneApiGenerator {
* @param context The android context of this application
*/
public static void getEquivalentValue(BitsharesAsset baseAsset,
List<BitsharesAsset> quoteAssets,Context context){
final List<BitsharesAsset> quoteAssets, final Context context){
for(BitsharesAsset quoteAsset : quoteAssets){
WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseAsset.getBitsharesId(),
quoteAsset.getBitsharesId(), 10, new EquivalentValueListener(baseAsset,
@ -568,6 +568,46 @@ public abstract class GrapheneApiGenerator {
}
}
public static void getEquivalenValue(String baseAssetName, final List<BitsharesAsset> quoteAssets, final Context context){
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
final CryptoCurrencyDao cryptoCurrencyDao = db.cryptoCurrencyDao();
final BitsharesAssetDao bitsharesAssetDao = db.bitsharesAssetDao();
CryptoCurrency baseCurrency = cryptoCurrencyDao.getByName(baseAssetName);
BitsharesAssetInfo info = null;
if(baseCurrency != null){
info = db.bitsharesAssetDao().getBitsharesAssetInfo(baseCurrency.getId());
}
if(baseCurrency == null || info == null){
ApiRequest getAssetRequest = new ApiRequest(1, new ApiRequestListener() {
@Override
public void success(Object answer, int idPetition) {
if(answer instanceof BitsharesAsset){
BitsharesAssetInfo info = new BitsharesAssetInfo((BitsharesAsset) answer);
long cryptoCurrencyId = cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency)answer )[0];
info.setCryptoCurrencyId(cryptoCurrencyId);
bitsharesAssetDao.insertBitsharesAssetInfo(info);
GrapheneApiGenerator.getEquivalentValue((BitsharesAsset) answer, quoteAssets, context);
}
}
@Override
public void fail(int idPetition) {
//TODO fail asset petition, the base asset is not an asset in bitshares, or there is no connection to the server
}
});
ArrayList<String> names = new ArrayList<>();
names.add(baseAssetName);
GrapheneApiGenerator.getAssetByName(names,getAssetRequest);
}else {
BitsharesAsset baseAsset = new BitsharesAsset(baseCurrency);
baseAsset.loadInfo(info);
getEquivalentValue(baseAsset,quoteAssets,context);
}
}
/**
* Listener of the equivalent value the answer is stored in the database, for use in conjuntion with LiveData
*/

View file

@ -20,7 +20,7 @@ public interface BitsharesAssetDao {
LiveData<List<BitsharesAssetInfo>> getAll();
@Query("SELECT * FROM bitshares_asset WHERE crypto_curreny_id = :cryptoCurrencyId")
LiveData<BitsharesAssetInfo> getBitsharesAssetInfo(long cryptoCurrencyId);
BitsharesAssetInfo getBitsharesAssetInfo(long cryptoCurrencyId);
@Query("SELECT * FROM bitshares_asset WHERE crypto_curreny_id = :cryptoCurrencyId")
BitsharesAssetInfo getBitsharesAssetInfoFromCurrencyId(long cryptoCurrencyId);