From 247afeefcd23eaa121ec715be7cb930aa9aa3cc5 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 15 Mar 2018 15:38:18 -0400 Subject: [PATCH 1/2] Added Bitshares Contants and added all the current smartcoins Delay the equivalent thread to 1 min pero query --- .../apigenerator/GrapheneApiGenerator.java | 10 +-- .../application/CrystalApplication.java | 52 +---------- .../constant/BitsharesConstant.java | 87 +++++++++++++++++++ .../manager/BitsharesAccountManager.java | 3 +- .../service/EquivalencesThread.java | 2 +- 5 files changed, 98 insertions(+), 56 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/application/constant/BitsharesConstant.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index 0522a9c..6edebed 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -8,6 +8,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; +import cy.agorise.crystalwallet.application.constant.BitsharesConstant; import cy.agorise.crystalwallet.dao.BitsharesAssetDao; import cy.agorise.crystalwallet.dao.CryptoCoinBalanceDao; import cy.agorise.crystalwallet.dao.CryptoCurrencyDao; @@ -58,10 +59,7 @@ import cy.agorise.graphenej.operations.TransferOperation; public abstract class GrapheneApiGenerator { - //TODO network connections //TODO make to work with all Graphene type, not only bitshares - public static String faucetUrl = "http://185.208.208.147:5010"; - private static String equivalentUrl = "wss://bitshares.openledger.info/ws"; // The message broker for bitshares private static SubscriptionMessagesHub bitsharesSubscriptionHub = new SubscriptionMessagesHub("", "", true, new NodeErrorListener() { @@ -570,7 +568,7 @@ public abstract class GrapheneApiGenerator { public void onError(BaseResponse.Error error) { request.getListener().fail(request.getId()); } - }),equivalentUrl); + }), BitsharesConstant.EQUIVALENT_URL); //todo change equivalent url for current server url thread.start(); } @@ -586,7 +584,7 @@ public abstract class GrapheneApiGenerator { for(BitsharesAsset quoteAsset : quoteAssets){ WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseAsset.getBitsharesId(), quoteAsset.getBitsharesId(), 10, new EquivalentValueListener(baseAsset, - quoteAsset,context)),equivalentUrl); + quoteAsset,context)), BitsharesConstant.EQUIVALENT_URL); //todo change equivalent url for current server url thread.start(); } } @@ -666,7 +664,7 @@ public abstract class GrapheneApiGenerator { 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.QUOTE_TO_BASE); + 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; diff --git a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java index 8a1e16c..58282ec 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java +++ b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java @@ -5,6 +5,7 @@ import android.content.Intent; import com.idescout.sql.SqlScoutServer; +import cy.agorise.crystalwallet.application.constant.BitsharesConstant; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.enums.CryptoNet; import cy.agorise.crystalwallet.models.BitsharesAsset; @@ -20,25 +21,6 @@ import cy.agorise.crystalwallet.service.CrystalWalletService; */ public class CrystalApplication extends Application { - public static String BITSHARES_URL[] = - { - "wss://de.palmpay.io/ws", // Custom node - "wss://bitshares.nu/ws", - "wss://dexnode.net/ws", // Dallas, USA - "wss://bitshares.crypto.fans/ws", // Munich, Germany - "wss://bitshares.openledger.info/ws", // Openledger node - "ws://185.208.208.147:8090" // Custom node - }; - - public static String BITSHARES_TESTNET_URL[] = - { - "http://185.208.208.147:11012", // Openledger node - }; - - //This is for testing the equivalent values on the testnet TODO remove - public static BitsharesAsset bitUSDAsset = new BitsharesAsset("USD",4,"1.3.121",BitsharesAsset.Type.SMART_COIN); - //This is for testing the equivalent values on the testnet TODO remove - public static BitsharesAsset bitEURAsset = new BitsharesAsset("EUR",4,"1.3.120",BitsharesAsset.Type.SMART_COIN); @Override public void onCreate() { @@ -48,35 +30,9 @@ public class CrystalApplication extends Application { CrystalDatabase db = CrystalDatabase.getAppDatabase(this.getApplicationContext()); SqlScoutServer.create(this, getPackageName()); - //Using Bitshares Agorise Testnet - CryptoNetManager.addCryptoNetURL(CryptoNet.BITSHARES,BITSHARES_TESTNET_URL); - - //This is for testing the equivalent values on the testnet TODO remove - if(db.bitsharesAssetDao().getBitsharesAssetInfoById(bitEURAsset.getBitsharesId())== null){ - if(db.cryptoCurrencyDao().getByName(bitEURAsset.getName())== null){ - db.cryptoCurrencyDao().insertCryptoCurrency(bitEURAsset); - } - long idCurrency = db.cryptoCurrencyDao().getByName(bitEURAsset.getName()).getId(); - BitsharesAssetInfo info = new BitsharesAssetInfo(bitEURAsset); - info.setCryptoCurrencyId(idCurrency); - db.bitsharesAssetDao().insertBitsharesAssetInfo(info); - - } - - //This is for testing the equivalent values on the testnet TODO remove - if(db.bitsharesAssetDao().getBitsharesAssetInfoById(bitUSDAsset.getBitsharesId())== null){ - if(db.cryptoCurrencyDao().getByName(bitUSDAsset.getName())== null){ - db.cryptoCurrencyDao().insertCryptoCurrency(bitUSDAsset); - } - long idCurrency = db.cryptoCurrencyDao().getByName(bitUSDAsset.getName()).getId(); - BitsharesAssetInfo info = new BitsharesAssetInfo(bitUSDAsset); - info.setCryptoCurrencyId(idCurrency); - db.bitsharesAssetDao().insertBitsharesAssetInfo(info); - - } - - //Next line is for use the bitshares main net - //CryptoNetManager.addCryptoNetURL(CryptoNet.BITSHARES,BITSHARES_URL); + //BitsharesConstant.addMainNetUrls(); + BitsharesConstant.addTestNetUrls(); + BitsharesConstant.addSmartCoins(this.getApplicationContext()); Intent intent = new Intent(getApplicationContext(), CrystalWalletService.class); startService(intent); diff --git a/app/src/main/java/cy/agorise/crystalwallet/application/constant/BitsharesConstant.java b/app/src/main/java/cy/agorise/crystalwallet/application/constant/BitsharesConstant.java new file mode 100644 index 0000000..9021c2f --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/application/constant/BitsharesConstant.java @@ -0,0 +1,87 @@ +package cy.agorise.crystalwallet.application.constant; + +import android.content.Context; + +import java.util.HashSet; + +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.enums.CryptoNet; +import cy.agorise.crystalwallet.models.BitsharesAsset; +import cy.agorise.crystalwallet.models.BitsharesAssetInfo; +import cy.agorise.crystalwallet.network.CryptoNetManager; + +/** + * Created by henry on 15/3/2018. + */ + +public abstract class BitsharesConstant { + public final static String BITSHARES_URL[] = + { + "wss://de.palmpay.io/ws", // Custom node + "wss://bitshares.nu/ws", + "wss://dexnode.net/ws", // Dallas, USA + "wss://bitshares.crypto.fans/ws", // Munich, Germany + "wss://bitshares.openledger.info/ws", // Openledger node + "ws://185.208.208.147:8090" // Custom node + }; + + public final static String BITSHARES_TESTNET_URL[] = + { + "http://185.208.208.147:11012", // Openledger node + }; + + public final static String FAUCET_URL = "http://185.208.208.147:5010"; + public final static String EQUIVALENT_URL = "wss://bitshares.openledger.info/ws"; + + public final static BitsharesAsset[] SMARTCOINS = new BitsharesAsset[]{ + new BitsharesAsset("USD",4,"1.3.121",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("EUR",4,"1.3.120",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("CNY",4,"1.3.113",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("RUBLE",5,"1.3.1325",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("AUD",4,"1.3.117",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("SILVER",4,"1.3.105",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("GOLD",6,"1.3.106",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("JPY",2,"1.3.119",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("CAD",4,"1.3.115",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("MXN",4,"1.3.114",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("GBP",4,"1.3.118",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("ARS",4,"1.3.1017",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("KRW",4,"1.3.102",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("CHF",4,"1.3.116",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("SEK",4,"1.3.111",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("RUB",4,"1.3.110",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("NZD",4,"1.3.112",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("XCD",4,"1.3.2650",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("TRY",4,"1.3.107",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("HKD",4,"1.3.109",BitsharesAsset.Type.SMART_COIN), + new BitsharesAsset("SGD",4,"1.3.108",BitsharesAsset.Type.SMART_COIN) + }; + + public static void addMainNetUrls(){ + for(String url : BITSHARES_URL){ + CryptoNetManager.addCryptoNetURL(CryptoNet.BITSHARES,url); + } + } + + public static void addTestNetUrls(){ + for(String url : BITSHARES_TESTNET_URL){ + CryptoNetManager.addCryptoNetURL(CryptoNet.BITSHARES,url); + } + } + + public static void addSmartCoins(Context context){ + CrystalDatabase db = CrystalDatabase.getAppDatabase(context); + for(BitsharesAsset smartcoin : SMARTCOINS){ + if(db.cryptoCurrencyDao().getByName(smartcoin.getName())== null){ + db.cryptoCurrencyDao().insertCryptoCurrency(smartcoin); + } + long idCurrency = db.cryptoCurrencyDao().getByName(smartcoin.getName()).getId(); + BitsharesAssetInfo info = new BitsharesAssetInfo(smartcoin); + info.setCryptoCurrencyId(idCurrency); + db.bitsharesAssetDao().insertBitsharesAssetInfo(info); + } + + } + +} + diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index 5b1a248..abdd5e4 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -17,6 +17,7 @@ import cy.agorise.crystalwallet.apigenerator.ApiRequest; import cy.agorise.crystalwallet.apigenerator.ApiRequestListener; import cy.agorise.crystalwallet.apigenerator.BitsharesFaucetApiGenerator; import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator; +import cy.agorise.crystalwallet.application.constant.BitsharesConstant; import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetEquivalentRequest; import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest; import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener; @@ -103,7 +104,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI new Address(ECKey.fromPublicOnly(grapheneAccount.getOwnerKey(context).getPubKey())).toString(), new Address(ECKey.fromPublicOnly(grapheneAccount.getActiveKey(context).getPubKey())).toString(), new Address(ECKey.fromPublicOnly(grapheneAccount.getMemoKey(context).getPubKey())).toString(), - GrapheneApiGenerator.faucetUrl, creationRequest); + BitsharesConstant.FAUCET_URL, creationRequest); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/service/EquivalencesThread.java b/app/src/main/java/cy/agorise/crystalwallet/service/EquivalencesThread.java index 9b4cd80..24187ec 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/service/EquivalencesThread.java +++ b/app/src/main/java/cy/agorise/crystalwallet/service/EquivalencesThread.java @@ -32,7 +32,7 @@ public class EquivalencesThread extends Thread{ try { GrapheneApiGenerator.getEquivalenValue(fromAsset, bitsharesAssets, this.service); Log.i("Equivalences Thread", "In loop"); - Thread.sleep(1000); + Thread.sleep(60000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } From 0753a4b43679eb933a6178b8e2e91dfc39f2d0c2 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 15 Mar 2018 14:12:46 -0600 Subject: [PATCH 2/2] Send and Receive FloatingActionButtons hide when scrolling down on the TransactionsFragment --- .../activities/BoardActivity.java | 14 ++----- .../fragments/TransactionsFragment.java | 41 +++++++++++++++++-- .../views/TransactionListView.java | 2 +- app/src/main/res/layout/board.xml | 2 +- .../main/res/layout/fragment_transactions.xml | 23 +++-------- 5 files changed, 48 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java index 95c7fb4..bd5ff97 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java @@ -1,7 +1,6 @@ package cy.agorise.crystalwallet.activities; import android.app.ActivityOptions; -import android.arch.lifecycle.LiveData; import android.arch.lifecycle.ViewModelProviders; import android.content.Intent; import android.content.res.Resources; @@ -23,9 +22,6 @@ import android.view.View; import android.view.animation.LinearInterpolator; import android.widget.ImageView; -import java.util.List; - -import butterknife.BindColor; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -36,7 +32,6 @@ import cy.agorise.crystalwallet.fragments.ReceiveTransactionFragment; import cy.agorise.crystalwallet.fragments.SendTransactionFragment; import cy.agorise.crystalwallet.fragments.TransactionsFragment; import de.hdodenhof.circleimageview.CircleImageView; -import cy.agorise.crystalwallet.models.CryptoNetBalance; import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel; /** @@ -49,9 +44,6 @@ public class BoardActivity extends AppCompatActivity { @BindView(R.id.pager) public ViewPager mPager; - //@BindView(R.id.btnGeneralSettings) - //public ImageButton btnGeneralSettings; - @BindView(R.id.fabSend) public FloatingActionButton fabSend; @@ -182,7 +174,7 @@ public class BoardActivity extends AppCompatActivity { }); } - /* + /** * dispatch the user to the accounts fragment */ @OnClick(R.id.toolbar_user_img) @@ -221,7 +213,7 @@ public class BoardActivity extends AppCompatActivity { } ft.addToBackStack(null); - long receiveCryptoNetAccountId = -1; + long receiveCryptoNetAccountId; if (this.cryptoNetAccountId != -1){ receiveCryptoNetAccountId = this.cryptoNetAccountId; } else { @@ -245,7 +237,7 @@ public class BoardActivity extends AppCompatActivity { } ft.addToBackStack(null); - long sendCryptoNetAccountId = -1; + long sendCryptoNetAccountId; if (this.cryptoNetAccountId != -1){ sendCryptoNetAccountId = this.cryptoNetAccountId; } else { diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java index 7bd7edb..fadbe25 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java @@ -6,7 +6,9 @@ import android.arch.lifecycle.ViewModelProviders; import android.arch.paging.PagedList; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -25,6 +27,10 @@ public class TransactionsFragment extends Fragment { @BindView(R.id.vTransactionListView) TransactionListView transactionListView; + RecyclerView balanceRecyclerView; + FloatingActionButton fabSend; + FloatingActionButton fabReceive; + public TransactionsFragment() { // Required empty public constructor } @@ -45,8 +51,37 @@ public class TransactionsFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View v = inflater.inflate(R.layout.fragment_transactions, container, false); - ButterKnife.bind(this, v); + View view = inflater.inflate(R.layout.fragment_transactions, container, false); + ButterKnife.bind(this, view); + + // Gets the Balance RecyclerView + balanceRecyclerView = view.findViewById(R.id.transactionListView); + fabSend = getActivity().findViewById(R.id.fabSend); + fabReceive = getActivity().findViewById(R.id.fabReceive); + + // TODO move this listener to the activity, to make this fragment reusable + // Adds listener to the RecyclerView to show and hide buttons at the bottom of the screen + balanceRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(RecyclerView recyclerView, int dx,int dy){ + super.onScrolled(recyclerView, dx, dy); + + // Scroll Down + if( dy >0 ) { + if( fabSend.isShown() ) + fabSend.hide(); + if( fabReceive.isShown() ) + fabReceive.hide(); + } + // Scroll Up + else if( dy <0 ) { + if( !fabSend.isShown() ) + fabSend.show(); + if( !fabReceive.isShown() ) + fabReceive.show(); + } + } + }); TransactionListViewModel transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class); LiveData> transactionsLiveData = transactionListViewModel.getTransactionList(); @@ -59,6 +94,6 @@ public class TransactionsFragment extends Fragment { } }); - return v; + return view; } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java index c828de0..c929844 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java @@ -85,7 +85,7 @@ public class TransactionListView extends RelativeLayout { 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); + // this.listView.setNestedScrollingEnabled(false); /*this.listView.addOnScrollListener(new RecyclerView.OnScrollListener() { diff --git a/app/src/main/res/layout/board.xml b/app/src/main/res/layout/board.xml index 49f9d44..c6ae433 100644 --- a/app/src/main/res/layout/board.xml +++ b/app/src/main/res/layout/board.xml @@ -162,7 +162,7 @@ android:layout_height="wrap_content" android:layout_gravity="end|bottom" android:layout_margin="@dimen/fab_margin" - app:backgroundTint="@color/colorPrimaryDark" + app:backgroundTint="@color/colorPrimary" app:srcCompat="@drawable/ic_person_add" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_transactions.xml b/app/src/main/res/layout/fragment_transactions.xml index 881c8da..c847c93 100644 --- a/app/src/main/res/layout/fragment_transactions.xml +++ b/app/src/main/res/layout/fragment_transactions.xml @@ -1,25 +1,12 @@ - - + android:layout_height="wrap_content" + android:id="@+id/vTransactionListView" /> - - - - +