Display Cryptocurrency Prices Using Paging 3 Library and Jetpack Compose | by Victor Roslyakov | Feb, 2022

Construct clear structure primarily based Android apps

Picture by Kanchanara on Unsplash

What utility is about

I’ve chosen one of the crucial fashionable matters at this second. My utility exhibits the listing of cryptocurrencies. As a crypto costs supplier, I’ve used Messari api. Right here the way it seems:

Listing of cryptocurrencies

Add needed dependencies for Compose and Paging to construct.gradle file.

Structure overview

Utility is split for Knowledge, Area and Presentation layers. Essential concept of unpolluted structure is the separation of considerations by preserving the enterprise guidelines not realizing something in any respect in regards to the outdoors world. If you happen to aren’t accustomed to this idea, I extremely suggest to dig into it.

PagingSource

Base class for an abstraction of pageable static data from some source, where loading pages of data is typically an expensive operation.

enjoyable load (params: PagingSource.LoadParams<Int>)
enjoyable getRefreshKey(state: PagingState<Int, AssetDomain>)

Setup paging in Presentation layer

First, let’s transfer to AssetsListViewModel. In getAssets() perform we create a Pager object from GetAssetsSource and convert it into Circulation. In init perform passes a movement of PagingData objects to state.

UI with Jetpack Compose

We will begin from AssetListItem. Right here we are able to discover symbols in inexperienced form, title, and worth.

More Posts