Open Source Project- Cryptocur App (UPDATE #1: Swipe to Refresh Functionality)

in #utopian-io7 years ago (edited)

The Cryptocur App is an android application that is based on the constantly changing cryptocurrency market prices and its exchange rates with the top 20 leading currencies of the world.

About 6 leading cryptocurrencies can be selected for exchange rate comparison, they include Bitcoin (BTC), Ethereum (ETH), Litecoin (LTC), Ripple (XRP), Bitcoin Cash (BCH) and Steem Backed Dollars (SBD).

Image Source

Previous Updates

Updated APK file

Cryptocur App Version 1.1

New Features

  • Swipe to Refresh functionality

Asides making the application compatible with android Oreo 8.0, to increase the user experience and application interaction, a swipe to refresh rates functionality has been added.

In the previous version, in order to see the latest exchange rates, a user had to create a new card that reflected the new changes even though an initial card of the same cryptocurrency and base currency already existed.

With this new update, the exchange rates are automatically refreshed on starting the app and a simple swipe down gesture from the top of the screen automatically refreshes the exchange rates and immediately updates the UI with the latest values.

To see this in action, click on the youtube link to see a recording showing this functionality

Cryptocur App Functionality Recording

How i implemented this

I added a SwipeRefreshLayout from the android support library to the conversion_layout.xml file. I added the RecyclerView layout of the cards as a child view to the SwipeRefreshLayout.

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_exchange_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

</android.support.v7.widget.RecyclerView>

Thereafter, i created a SwipeRefreshLayout object in the UserExchangeActivity.java which is referenced to the view in the xml file and then in its onRefresh() listener method, i restarted the loader which gets the latest rates from the web API and called a method updateList() in the onLoadFinished() method of the loader.

A part of the code of the updateList() method is shown below,

            updatedExchange = new ArrayList<>();
            for (int i=0; i<baseText.size();i++){
                updatedExchange.add(showExchangeRate(cryptoText.get(i), baseText.get(i)));
            }
            exchangeRateObservable = fromArray(updatedExchange);
            exchangeRateObserver = new Observer<ArrayList<String>>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(ArrayList<String> strings) {
                    exchangeRateAdapter = new ExchangeRateAdapter(cryptoText, baseText,UserExchangeActivity.this, updatedExchange);
                    recyclerView.setAdapter(exchangeRateAdapter);
                    exchangeRateAdapter.notifyDataSetChanged();
                }

                @Override
                public void onError(Throwable e) {
                    Toast.makeText(UserExchangeActivity.this, "Could not update rates, check internet connection", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onComplete() {
                    Toast.makeText(UserExchangeActivity.this, "Prices Updated", Toast.LENGTH_SHORT).show();

                }
            };
exchangeRateObservable.subscribe(exchangeRateObserver);

In the updateList() method, i used RXJava and RXAndroid to create an Observable of an arraylist of strings which adds the latest exchange rates received after reloading as strings to an arraylist called updatedExchange.

An observer is then created which updates the ExchangeRateAdapter with the data emitted from the observable in the onNext() method. The ExchangeRateAdapter then feeds this new data to the recycler view and the recycler view is notified of changes to its data set with the notifyDataSetChanged() method of the adapter which then updates the UI.

Finally, the observer is subscribed to the observable so as to monitor further changes in streams emitted by the Observable.

Further modifications to the application can be seen on the git commit linked below.

Important Links

Github commit https://github.com/demistry/CryptoCur_App/commit/5c652b54566ac96a77684b216fa7687114f78469

Android APK File https://drive.google.com/open?id=1aENY8sPLEWAuSgDPnAl6zk2K6DZgOo9l



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @davidemi I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x