From d92631cfdc7100f0676b508f3f93a459fb992aa2 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 4 Dec 2018 17:25:47 -0500 Subject: [PATCH 1/3] Add new file structure for Retrofit --- .../activities/AddAssetActivity.kt | 2 +- .../activities/AssetsActivity.kt | 24 ++++++++--------- .../activities/InflationActivity.kt | 2 +- .../stellarwallet/activities/SendActivity.kt | 2 +- .../activities/WalletActivity.kt | 2 +- .../adapters/AssetsRecyclerViewAdapter.kt | 12 ++++----- .../fragments/tabs/MyOffersTabFragment.kt | 2 +- .../fragments/tabs/OrderBookTabFragment.kt | 2 +- .../fragments/tabs/TradeTabFragment.kt | 2 +- .../stellarwallet/models/SupportedAsset.kt | 26 ------------------- .../{remote => networking}/Horizon.kt | 2 +- .../{remote => networking}/HorizonTasks.kt | 2 +- .../responses/SupportedAssetResponse.kt | 26 +++++++++++++++++++ .../stellarwallet/vmodels/TradingViewModel.kt | 5 +--- 14 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 app/src/main/java/com/blockeq/stellarwallet/models/SupportedAsset.kt rename app/src/main/java/com/blockeq/stellarwallet/{remote => networking}/Horizon.kt (99%) rename app/src/main/java/com/blockeq/stellarwallet/{remote => networking}/HorizonTasks.kt (97%) create mode 100644 app/src/main/java/com/blockeq/stellarwallet/responses/SupportedAssetResponse.kt diff --git a/app/src/main/java/com/blockeq/stellarwallet/activities/AddAssetActivity.kt b/app/src/main/java/com/blockeq/stellarwallet/activities/AddAssetActivity.kt index 807c5731..62eae59f 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/activities/AddAssetActivity.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/activities/AddAssetActivity.kt @@ -6,7 +6,7 @@ import android.widget.Toast import com.blockeq.stellarwallet.R import com.blockeq.stellarwallet.interfaces.SuccessErrorCallback import com.blockeq.stellarwallet.models.HorizonException -import com.blockeq.stellarwallet.remote.Horizon +import com.blockeq.stellarwallet.networking.Horizon import com.blockeq.stellarwallet.utils.AccountUtils import com.blockeq.stellarwallet.utils.NetworkUtils import kotlinx.android.synthetic.main.activity_add_asset.* diff --git a/app/src/main/java/com/blockeq/stellarwallet/activities/AssetsActivity.kt b/app/src/main/java/com/blockeq/stellarwallet/activities/AssetsActivity.kt index 0129f16d..ed8ab7ab 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/activities/AssetsActivity.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/activities/AssetsActivity.kt @@ -18,9 +18,9 @@ import com.blockeq.stellarwallet.interfaces.ChangeTrustlineListener import com.blockeq.stellarwallet.interfaces.OnLoadAccount import com.blockeq.stellarwallet.interfaces.SuccessErrorCallback import com.blockeq.stellarwallet.models.HorizonException -import com.blockeq.stellarwallet.models.SupportedAsset -import com.blockeq.stellarwallet.models.SupportedAssetType -import com.blockeq.stellarwallet.remote.Horizon +import com.blockeq.stellarwallet.responses.SupportedAssetResponse +import com.blockeq.stellarwallet.responses.SupportedAssetType +import com.blockeq.stellarwallet.networking.Horizon import com.blockeq.stellarwallet.utils.AccountUtils import com.blockeq.stellarwallet.utils.NetworkUtils import com.google.gson.GsonBuilder @@ -32,7 +32,7 @@ import org.stellar.sdk.responses.AccountResponse class AssetsActivity : BasePopupActivity(), ChangeTrustlineListener { - private var map: Map? = null + private var map: Map? = null private var assetsList: ArrayList = ArrayList() private lateinit var context : Context private lateinit var adapter : AssetsRecyclerViewAdapter @@ -83,13 +83,13 @@ class AssetsActivity : BasePopupActivity(), ChangeTrustlineListener { //endregion private fun convertBalanceToSupportedAsset(balances: Array, - supportedAssetsMap: Map) : List { + supportedAssetsMap: Map) : List { - val lumenSupportedAsset = SupportedAsset(0, Constants.LUMENS_ASSET_CODE, Constants.LUMENS_IMAGE_URL, + val lumenSupportedAsset = SupportedAssetResponse(0, Constants.LUMENS_ASSET_CODE, Constants.LUMENS_IMAGE_URL, "", "", Constants.LUMENS_ASSET_NAME, "", "", "0", SupportedAssetType.ADDED, null) - val list = ArrayList() + val list = ArrayList() list.add(lumenSupportedAsset) if (balances.isNotEmpty()) { @@ -107,7 +107,7 @@ class AssetsActivity : BasePopupActivity(), ChangeTrustlineListener { return@map asset } else -> { - val asset = SupportedAsset(0, it.assetCode.toLowerCase(), "", + val asset = SupportedAssetResponse(0, it.assetCode.toLowerCase(), "", it.assetIssuer.accountId, it.limit, it.assetCode, "", "", it.balance, SupportedAssetType.ADDED, it.asset) return@map asset @@ -117,13 +117,13 @@ class AssetsActivity : BasePopupActivity(), ChangeTrustlineListener { // This cast is guaranteed to succeed @Suppress("UNCHECKED_CAST") - list.addAll((nullableAssets.filter { it != null }) as List) + list.addAll((nullableAssets.filter { it != null }) as List) } return list } - private fun getFilteredSupportedAssets(map: Map): List { + private fun getFilteredSupportedAssets(map: Map): List { return map.values.filter { it -> it.code.toUpperCase() !in WalletApplication.localStore.balances!!.map { it.assetCode } } @@ -137,9 +137,9 @@ class AssetsActivity : BasePopupActivity(), ChangeTrustlineListener { Response.Listener { response -> // display response val gson = GsonBuilder().create() - val token = object : TypeToken>(){}.type + val token = object : TypeToken>(){}.type - map = gson.fromJson>(response.toString(), token) + map = gson.fromJson>(response.toString(), token) updateAdapter() }, Response.ErrorListener { diff --git a/app/src/main/java/com/blockeq/stellarwallet/activities/InflationActivity.kt b/app/src/main/java/com/blockeq/stellarwallet/activities/InflationActivity.kt index 79cc48c8..3de9f9c4 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/activities/InflationActivity.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/activities/InflationActivity.kt @@ -7,7 +7,7 @@ import com.blockeq.stellarwallet.R import com.blockeq.stellarwallet.helpers.Constants import com.blockeq.stellarwallet.interfaces.SuccessErrorCallback import com.blockeq.stellarwallet.models.HorizonException -import com.blockeq.stellarwallet.remote.Horizon +import com.blockeq.stellarwallet.networking.Horizon import com.blockeq.stellarwallet.utils.AccountUtils import com.blockeq.stellarwallet.utils.NetworkUtils import kotlinx.android.synthetic.main.activity_inflation.* diff --git a/app/src/main/java/com/blockeq/stellarwallet/activities/SendActivity.kt b/app/src/main/java/com/blockeq/stellarwallet/activities/SendActivity.kt index fb76b15e..324fd589 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/activities/SendActivity.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/activities/SendActivity.kt @@ -20,7 +20,7 @@ import com.blockeq.stellarwallet.interfaces.SuccessErrorCallback import com.blockeq.stellarwallet.models.ExchangeApiModel import com.blockeq.stellarwallet.models.HorizonException import com.blockeq.stellarwallet.models.PinType -import com.blockeq.stellarwallet.remote.Horizon +import com.blockeq.stellarwallet.networking.Horizon import com.blockeq.stellarwallet.utils.AccountUtils import com.blockeq.stellarwallet.utils.NetworkUtils import com.blockeq.stellarwallet.utils.StringFormat.Companion.getNumDecimals diff --git a/app/src/main/java/com/blockeq/stellarwallet/activities/WalletActivity.kt b/app/src/main/java/com/blockeq/stellarwallet/activities/WalletActivity.kt index 85512c3a..cf32ac1c 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/activities/WalletActivity.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/activities/WalletActivity.kt @@ -13,7 +13,7 @@ import com.blockeq.stellarwallet.fragments.WalletFragment import com.blockeq.stellarwallet.interfaces.OnLoadAccount import com.blockeq.stellarwallet.interfaces.OnLoadEffects import com.blockeq.stellarwallet.models.MinimumBalance -import com.blockeq.stellarwallet.remote.Horizon +import com.blockeq.stellarwallet.networking.Horizon import com.blockeq.stellarwallet.utils.AccountUtils import com.blockeq.stellarwallet.utils.KeyboardUtils import com.blockeq.stellarwallet.utils.NetworkUtils diff --git a/app/src/main/java/com/blockeq/stellarwallet/adapters/AssetsRecyclerViewAdapter.kt b/app/src/main/java/com/blockeq/stellarwallet/adapters/AssetsRecyclerViewAdapter.kt index 3d61fe46..1bdbbf41 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/adapters/AssetsRecyclerViewAdapter.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/adapters/AssetsRecyclerViewAdapter.kt @@ -17,8 +17,8 @@ import com.blockeq.stellarwallet.WalletApplication import com.blockeq.stellarwallet.activities.InflationActivity import com.blockeq.stellarwallet.helpers.Constants import com.blockeq.stellarwallet.interfaces.ChangeTrustlineListener -import com.blockeq.stellarwallet.models.SupportedAsset -import com.blockeq.stellarwallet.models.SupportedAssetType +import com.blockeq.stellarwallet.responses.SupportedAssetResponse +import com.blockeq.stellarwallet.responses.SupportedAssetType import com.blockeq.stellarwallet.utils.AccountUtils import com.blockeq.stellarwallet.utils.StringFormat import com.squareup.picasso.Picasso @@ -53,8 +53,8 @@ class AssetsRecyclerViewAdapter(var context: Context, private var listener: Chan override fun getItemViewType(position: Int): Int { return when { - items[position] is SupportedAsset && (items[position] as SupportedAsset).type == SupportedAssetType.ADDED -> TYPE_ASSET - items[position] is SupportedAsset -> TYPE_SUPPORTED_ASSET + items[position] is SupportedAssetResponse && (items[position] as SupportedAssetResponse).type == SupportedAssetType.ADDED -> TYPE_ASSET + items[position] is SupportedAssetResponse -> TYPE_SUPPORTED_ASSET else -> TYPE_HEADER } } @@ -107,7 +107,7 @@ class AssetsRecyclerViewAdapter(var context: Context, private var listener: Chan //region Bind View Holders private fun configureAssetViewHolder(viewHolder : AssetViewHolder, position : Int) { - val asset = items[position] as SupportedAsset + val asset = items[position] as SupportedAssetResponse viewHolder.assetButton.visibility = View.VISIBLE viewHolder.assetName.text = asset.name @@ -165,7 +165,7 @@ class AssetsRecyclerViewAdapter(var context: Context, private var listener: Chan } private fun configureSupportedAssetViewHolder(viewHolder: SupportedAssetViewHolder, position: Int) { - val asset = items[position] as SupportedAsset + val asset = items[position] as SupportedAssetResponse val trustLineAsset = Asset.createNonNativeAsset(asset.code.toUpperCase(), KeyPair.fromAccountId(asset.issuer)) viewHolder.assetName.text = String.format(context.getString(R.string.asset_template), diff --git a/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/MyOffersTabFragment.kt b/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/MyOffersTabFragment.kt index 809d8be1..753aaefa 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/MyOffersTabFragment.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/MyOffersTabFragment.kt @@ -16,7 +16,7 @@ import com.blockeq.stellarwallet.interfaces.OnDeleteRequest import com.blockeq.stellarwallet.models.AssetUtil import com.blockeq.stellarwallet.models.Currency import com.blockeq.stellarwallet.models.MyOffer -import com.blockeq.stellarwallet.remote.Horizon +import com.blockeq.stellarwallet.networking.Horizon import kotlinx.android.synthetic.main.fragment_tab_my_offers.* import org.stellar.sdk.responses.OfferResponse import timber.log.Timber diff --git a/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/OrderBookTabFragment.kt b/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/OrderBookTabFragment.kt index 02abb1b6..96a32aaf 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/OrderBookTabFragment.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/OrderBookTabFragment.kt @@ -15,7 +15,7 @@ import com.blockeq.stellarwallet.R import com.blockeq.stellarwallet.adapters.OrderBooksAdapter import com.blockeq.stellarwallet.interfaces.OnUpdateTradingCurrencies import com.blockeq.stellarwallet.models.* -import com.blockeq.stellarwallet.remote.Horizon +import com.blockeq.stellarwallet.networking.Horizon import kotlinx.android.synthetic.main.fragment_tab_order_book.* import org.stellar.sdk.responses.OrderBookResponse import timber.log.Timber diff --git a/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/TradeTabFragment.kt b/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/TradeTabFragment.kt index 282980fc..77b0eed6 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/TradeTabFragment.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/fragments/tabs/TradeTabFragment.kt @@ -15,7 +15,7 @@ import com.blockeq.stellarwallet.R import com.blockeq.stellarwallet.WalletApplication import com.blockeq.stellarwallet.interfaces.OnTradeCurrenciesChanged import com.blockeq.stellarwallet.models.* -import com.blockeq.stellarwallet.remote.Horizon +import com.blockeq.stellarwallet.networking.Horizon import com.blockeq.stellarwallet.utils.AccountUtils import com.blockeq.stellarwallet.vmodels.TradingViewModel import kotlinx.android.synthetic.main.fragment_tab_trade.* diff --git a/app/src/main/java/com/blockeq/stellarwallet/models/SupportedAsset.kt b/app/src/main/java/com/blockeq/stellarwallet/models/SupportedAsset.kt deleted file mode 100644 index 9969155e..00000000 --- a/app/src/main/java/com/blockeq/stellarwallet/models/SupportedAsset.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.blockeq.stellarwallet.models - -import org.stellar.sdk.Asset - -/** - * Class which provides a model for SupportedAsset - * @constructor Sets all properties of the SupportedAsset - * @property id the unique identifier of this asset - * @property code the asset code - * @property image the link to icon of asset - * @property issuer the public address of the issuer of this asset - * @property createdAt the iso instant time stamp of when the asset was created - * @property updatedAt the iso instant time stamp of when the asset was updated - * @property amount the amount of balance of asset - * @property type either added or not added asset - */ - -enum class SupportedAssetType { - ADDED, NOT_ADDED -} - -data class SupportedAsset (var id: Int, var code: String, var image: String, var issuer: String, - var limit: String, var name: String, var createdAt: String, - var updatedAt: String, var amount: String?, - var type: SupportedAssetType? = SupportedAssetType.NOT_ADDED, - var asset: Asset?) diff --git a/app/src/main/java/com/blockeq/stellarwallet/remote/Horizon.kt b/app/src/main/java/com/blockeq/stellarwallet/networking/Horizon.kt similarity index 99% rename from app/src/main/java/com/blockeq/stellarwallet/remote/Horizon.kt rename to app/src/main/java/com/blockeq/stellarwallet/networking/Horizon.kt index 31b7d9e2..dcc4f930 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/remote/Horizon.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/networking/Horizon.kt @@ -1,4 +1,4 @@ -package com.blockeq.stellarwallet.remote +package com.blockeq.stellarwallet.networking import android.os.AsyncTask import android.os.Handler diff --git a/app/src/main/java/com/blockeq/stellarwallet/remote/HorizonTasks.kt b/app/src/main/java/com/blockeq/stellarwallet/networking/HorizonTasks.kt similarity index 97% rename from app/src/main/java/com/blockeq/stellarwallet/remote/HorizonTasks.kt rename to app/src/main/java/com/blockeq/stellarwallet/networking/HorizonTasks.kt index 70c214ca..e5f7b3a1 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/remote/HorizonTasks.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/networking/HorizonTasks.kt @@ -1,4 +1,4 @@ -package com.blockeq.stellarwallet.remote +package com.blockeq.stellarwallet.networking import android.os.AsyncTask import com.blockeq.stellarwallet.interfaces.OnLoadAccount diff --git a/app/src/main/java/com/blockeq/stellarwallet/responses/SupportedAssetResponse.kt b/app/src/main/java/com/blockeq/stellarwallet/responses/SupportedAssetResponse.kt new file mode 100644 index 00000000..f92000c7 --- /dev/null +++ b/app/src/main/java/com/blockeq/stellarwallet/responses/SupportedAssetResponse.kt @@ -0,0 +1,26 @@ +package com.blockeq.stellarwallet.responses + +import org.stellar.sdk.Asset + +/** + * Class which provides a model for SupportedAssetResponse + * @constructor Sets all properties of the SupportedAssetResponse + * @property id the unique identifier of this asset + * @property code the asset code + * @property image the link to icon of asset + * @property issuer the public address of the issuer of this asset + * @property createdAt the iso instant time stamp of when the asset was created + * @property updatedAt the iso instant time stamp of when the asset was updated + * @property amount the amount of balance of asset + * @property type either added or not added asset + */ + +enum class SupportedAssetType { + ADDED, NOT_ADDED +} + +data class SupportedAssetResponse (var id: Int, var code: String, var image: String, var issuer: String, + var limit: String, var name: String, var createdAt: String, + var updatedAt: String, var amount: String?, + var type: SupportedAssetType? = SupportedAssetType.NOT_ADDED, + var asset: Asset?) diff --git a/app/src/main/java/com/blockeq/stellarwallet/vmodels/TradingViewModel.kt b/app/src/main/java/com/blockeq/stellarwallet/vmodels/TradingViewModel.kt index 98260dc6..2d30b842 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/vmodels/TradingViewModel.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/vmodels/TradingViewModel.kt @@ -3,12 +3,9 @@ package com.blockeq.stellarwallet.vmodels import android.app.Application import android.arch.lifecycle.AndroidViewModel import android.arch.lifecycle.MutableLiveData -import android.os.Handler -import android.os.Looper import android.widget.Toast import com.blockeq.stellarwallet.models.* -import com.blockeq.stellarwallet.remote.Horizon -import org.stellar.sdk.requests.RequestBuilder +import com.blockeq.stellarwallet.networking.Horizon import org.stellar.sdk.responses.OrderBookResponse import timber.log.Timber import java.util.* From b8ce93653993dc35327708b974c186ef56bb4b35 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Wed, 5 Dec 2018 11:19:21 -0500 Subject: [PATCH 2/3] Add retrofit and okhttp dependencies --- app/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index ba6c4f30..13ddc4bb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -126,4 +126,8 @@ dependencies { implementation "android.arch.persistence.room:runtime:$lifecycleVersion" annotationProcessor "android.arch.persistence.room:compiler:$lifecycleVersion" kapt "android.arch.persistence.room:compiler:$lifecycleVersion" + + // Retrofit + implementation 'com.squareup.retrofit2:retrofit:2.5.0' + implementation 'com.squareup.okhttp3:okhttp:3.12.0' } From 74298271e7f449b8082f1ce0a03622d87c812bc1 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Wed, 5 Dec 2018 16:00:08 -0500 Subject: [PATCH 3/3] Add retrofit instance and call --- app/build.gradle | 9 ++++- .../activities/AssetsActivity.kt | 39 ++++++++++--------- .../stellarwallet/helpers/Constants.kt | 3 +- .../networking/RetrofitClient.kt | 16 ++++++++ .../networking/api/SupportedAssetAPI.kt | 12 ++++++ 5 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 app/src/main/java/com/blockeq/stellarwallet/networking/RetrofitClient.kt create mode 100644 app/src/main/java/com/blockeq/stellarwallet/networking/api/SupportedAssetAPI.kt diff --git a/app/build.gradle b/app/build.gradle index 13ddc4bb..301382b6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -128,6 +128,11 @@ dependencies { kapt "android.arch.persistence.room:compiler:$lifecycleVersion" // Retrofit - implementation 'com.squareup.retrofit2:retrofit:2.5.0' - implementation 'com.squareup.okhttp3:okhttp:3.12.0' + implementation('com.squareup.retrofit2:retrofit:2.5.0') { + exclude group: 'com.squareup.okhttp3', module: 'okhttp' + } + implementation('com.squareup.retrofit2:converter-gson:2.5.0') { + exclude group: 'com.squareup.okhttp3', module: 'okhttp' + exclude group: 'com.google.code.gson', module: 'gson' + } } diff --git a/app/src/main/java/com/blockeq/stellarwallet/activities/AssetsActivity.kt b/app/src/main/java/com/blockeq/stellarwallet/activities/AssetsActivity.kt index ed8ab7ab..09b43833 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/activities/AssetsActivity.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/activities/AssetsActivity.kt @@ -21,14 +21,16 @@ import com.blockeq.stellarwallet.models.HorizonException import com.blockeq.stellarwallet.responses.SupportedAssetResponse import com.blockeq.stellarwallet.responses.SupportedAssetType import com.blockeq.stellarwallet.networking.Horizon +import com.blockeq.stellarwallet.networking.RetrofitClient +import com.blockeq.stellarwallet.networking.api.SupportedAssetAPI import com.blockeq.stellarwallet.utils.AccountUtils import com.blockeq.stellarwallet.utils.NetworkUtils -import com.google.gson.GsonBuilder -import com.google.gson.reflect.TypeToken import kotlinx.android.synthetic.main.content_assets_activity.* import org.stellar.sdk.Asset import org.stellar.sdk.requests.ErrorResponse import org.stellar.sdk.responses.AccountResponse +import retrofit2.Call +import retrofit2.Callback class AssetsActivity : BasePopupActivity(), ChangeTrustlineListener { @@ -130,23 +132,22 @@ class AssetsActivity : BasePopupActivity(), ChangeTrustlineListener { } private fun loadSupportedAssets() { - val queue = Volley.newRequestQueue(this) - - // TODO: Use retrofit and dagger - val request = JsonObjectRequest(Request.Method.GET, Constants.BLOCKEQ_BASE_URL, null, - Response.Listener { response -> - // display response - val gson = GsonBuilder().create() - val token = object : TypeToken>(){}.type - - map = gson.fromJson>(response.toString(), token) - updateAdapter() - }, - Response.ErrorListener { - Toast.makeText(this, getString(R.string.error_supported_assets_message), Toast.LENGTH_SHORT).show() - }) - - queue.add(request) + val retrofitClient = RetrofitClient.getRetrofitClient(Constants.BLOCKEQ_BASE_URL) + val service = retrofitClient.create(SupportedAssetAPI::class.java) + + val call = service.requestSupportedAssets() + + call.enqueue(object : Callback>{ + override fun onFailure(call: Call>, t: Throwable) { + Toast.makeText(this@AssetsActivity, getString(R.string.error_supported_assets_message), Toast.LENGTH_SHORT).show() + } + + override fun onResponse(call: Call>, response: retrofit2.Response>) { + map = response.body() + updateAdapter() + } + + }) } //region Call backs diff --git a/app/src/main/java/com/blockeq/stellarwallet/helpers/Constants.kt b/app/src/main/java/com/blockeq/stellarwallet/helpers/Constants.kt index a7d0e499..04fc6abf 100644 --- a/app/src/main/java/com/blockeq/stellarwallet/helpers/Constants.kt +++ b/app/src/main/java/com/blockeq/stellarwallet/helpers/Constants.kt @@ -20,7 +20,8 @@ class Constants { const val INFLATION_DESTINATION = "GCCD6AJOYZCUAQLX32ZJF2MKFFAUJ53PVCFQI3RHWKL3V47QYE2BNAUT" const val LUMENS_IMAGE_URL = "https://firebasestorage.googleapis.com/v0/b/blockeq-wallet.appspot.com/o/icon-stellar.png?alt=media&token=38b70165-5255-4113-a15e-3c72bd4fab9f" - const val BLOCKEQ_BASE_URL = "https://api.blockeq.com/directory/assets" + const val BLOCKEQ_BASE_URL = "https://api.blockeq.com" + const val BLOCKEQ_ASSETS_URL = "https://api.blockeq.com/directory/assets" const val BLOCKEQ_EXCHANGES_URL = "https://api.blockeq.com/directory/exchanges?asArray" const val BLOCKEQ_DIAGNOSTIC_URL = "https://api.blockeq.com/diagnostic" diff --git a/app/src/main/java/com/blockeq/stellarwallet/networking/RetrofitClient.kt b/app/src/main/java/com/blockeq/stellarwallet/networking/RetrofitClient.kt new file mode 100644 index 00000000..dddfe401 --- /dev/null +++ b/app/src/main/java/com/blockeq/stellarwallet/networking/RetrofitClient.kt @@ -0,0 +1,16 @@ +package com.blockeq.stellarwallet.networking + +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory + +class RetrofitClient { + + companion object { + fun getRetrofitClient(baseUrl : String) : Retrofit { + return Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(GsonConverterFactory.create()) + .build() + } + } +} diff --git a/app/src/main/java/com/blockeq/stellarwallet/networking/api/SupportedAssetAPI.kt b/app/src/main/java/com/blockeq/stellarwallet/networking/api/SupportedAssetAPI.kt new file mode 100644 index 00000000..847cec3b --- /dev/null +++ b/app/src/main/java/com/blockeq/stellarwallet/networking/api/SupportedAssetAPI.kt @@ -0,0 +1,12 @@ +package com.blockeq.stellarwallet.networking.api + +import com.blockeq.stellarwallet.responses.SupportedAssetResponse +import retrofit2.Call +import retrofit2.http.GET + +interface SupportedAssetAPI { + + @GET("/directory/assets") + fun requestSupportedAssets() : Call> + +}