Skip to content

Commit 209bde6

Browse files
committed
Home UI/UX changes.
Use test net or main server configuration from settings. Bug fixes and performance improvement.
1 parent 625f96b commit 209bde6

24 files changed

Lines changed: 393 additions & 280 deletions

app/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ android {
1010
applicationId "crypto.delta.exchange.openexchange"
1111
minSdkVersion 23
1212
targetSdkVersion 30
13-
versionCode 1
14-
versionName "alpha-1.0"
13+
versionCode 2
14+
versionName "alpha-1.1"
1515
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
1616
externalNativeBuild {
1717
cmake {
1818
cppFlags ""
1919
}
2020
}
21+
resConfigs "en"
2122
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2223
}
2324

@@ -37,8 +38,8 @@ android {
3738
}
3839
debug {
3940
versionNameSuffix '-debug'
40-
minifyEnabled false
41-
shrinkResources false
41+
minifyEnabled true
42+
shrinkResources true
4243
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4344
}
4445
android.applicationVariants.all { variant ->

app/src/main/cpp/native-lib.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
#include <jni.h>
22
#include <string>
33

4+
extern "C" JNIEXPORT jstring JNICALL
5+
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeTestNetBaseUrl(
6+
JNIEnv *env,
7+
jobject /* this */) {
8+
std::string hello = "https://testnet-api.delta.exchange/";
9+
return env->NewStringUTF(hello.c_str());
10+
}
11+
12+
extern "C" JNIEXPORT jstring JNICALL
13+
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeTestNetBaseWebSocketUrl(
14+
JNIEnv *env,
15+
jobject /* this */) {
16+
std::string url = "wss://testnet-api.delta.exchange:2096/";
17+
return env->NewStringUTF(url.c_str());
18+
}
19+
420
extern "C" JNIEXPORT jstring JNICALL
521
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseUrl(
622
JNIEnv *env,
@@ -12,7 +28,7 @@ Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseUrl(
1228
extern "C" JNIEXPORT jstring JNICALL
1329
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseWebSocketUrl(
1430
JNIEnv *env,
15-
jobject /* this */) {
16-
std::string url = "wss://api.delta.exchange:2096/";
17-
return env->NewStringUTF(url.c_str());
31+
jobject /* this */) {
32+
std::string url = "wss://api.delta.exchange:2096/";
33+
return env->NewStringUTF(url.c_str());
1834
}

app/src/main/java/crypto/delta/exchange/openexchange/adapter/HomeAdapter.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@ import android.view.View
55
import android.view.ViewGroup
66
import androidx.appcompat.widget.AppCompatTextView
77
import androidx.fragment.app.FragmentActivity
8+
import androidx.lifecycle.Observer
89
import androidx.navigation.findNavController
910
import androidx.recyclerview.widget.RecyclerView
1011
import crypto.delta.exchange.openexchange.R
12+
import crypto.delta.exchange.openexchange.api.DeltaRepository
1113
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
1214
import crypto.delta.exchange.openexchange.utils.AppPreferenceManager
15+
import crypto.delta.exchange.openexchange.utils.KotlinUtils
16+
1317

1418
class HomeAdapter(
1519
private var productsResponseList: List<ProductsResponse>,
1620
private val requireActivity: FragmentActivity
1721
) : RecyclerView.Adapter<HomeAdapter.ViewHolder>() {
1822

23+
private val deltaRepository = DeltaRepository.getInstance(requireActivity)
24+
1925
override fun getItemCount() = productsResponseList.size
2026

2127
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@@ -26,6 +32,8 @@ class HomeAdapter(
2632

2733
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
2834
internal val symbol: AppCompatTextView = itemView.findViewById(R.id.symbol)
35+
internal val lastPrice: AppCompatTextView = itemView.findViewById(R.id.lastPrice)
36+
internal val dayVolume: AppCompatTextView = itemView.findViewById(R.id.dayVolume)
2937
}
3038

3139
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@@ -34,7 +42,19 @@ class HomeAdapter(
3442
holder.itemView.setOnClickListener {
3543
AppPreferenceManager(requireActivity).setCurrentProductSymbol(product.symbol)
3644
AppPreferenceManager(requireActivity).setCurrentProductId(product.id.toString())
37-
requireActivity.findNavController(R.id.nav_host_fragment).navigate(R.id.navigation_chart)
45+
requireActivity.findNavController(R.id.nav_host_fragment)
46+
.navigate(R.id.navigation_chart, null, KotlinUtils.getNavOptions())
3847
}
48+
deltaRepository!!.getProductsData(product.symbol!!)!!.observe(requireActivity, Observer { tickerResponse ->
49+
if (null != tickerResponse.close) {
50+
holder.lastPrice.text = tickerResponse.close?.toBigDecimal()?.toPlainString()
51+
holder.dayVolume.text = String.format(tickerResponse.volume!!.toString() + " " + product.quotingAsset!!.symbol)
52+
}
53+
})
54+
3955
}
56+
57+
58+
59+
4060
}

app/src/main/java/crypto/delta/exchange/openexchange/adapter/OrderBookAdapter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class OrderBookAdapter(private var orderBookList: DeltaExchangeL2OrderBookRespon
3232
val ask = orderBookList.sell!![position]
3333

3434
holder.sizeBid.text = buy.d_size.toString()
35-
holder.priceBid.text = buy.limitPrice.toString()
35+
holder.priceBid.text = buy.limitPrice?.toBigDecimal()?.toPlainString()
3636
holder.sizeAsk.text = ask.d_size.toString()
37-
holder.priceAsk.text = ask.limitPrice.toString()
37+
holder.priceAsk.text = ask.limitPrice?.toBigDecimal()?.toPlainString()
3838
}
3939

4040
fun updateOrderBook(orderBook: DeltaExchangeL2OrderBookResponse) {

app/src/main/java/crypto/delta/exchange/openexchange/api/DeltaApiClient.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package crypto.delta.exchange.openexchange.api
33
import android.content.Context
44
import com.google.gson.GsonBuilder
55
import crypto.delta.exchange.openexchange.BuildConfig
6+
import crypto.delta.exchange.openexchange.utils.AppPreferenceManager
67
import crypto.delta.exchange.openexchange.utils.Native
78
import okhttp3.OkHttpClient
89
import okhttp3.logging.HttpLoggingInterceptor
@@ -39,8 +40,13 @@ class DeltaApiClient {
3940
httpClient.connectTimeout(400, TimeUnit.SECONDS)
4041
httpClient.followRedirects(true)
4142
httpClient.retryOnConnectionFailure(true)
43+
val baseUrl = if (AppPreferenceManager(mContext).useTestNetServer!!) {
44+
Native.deltaExchangeTestNetBaseUrl
45+
} else {
46+
Native.deltaExchangeBaseUrl
47+
}
4248
retrofit = Retrofit.Builder()
43-
.baseUrl(Native.deltaExchangeBaseUrl)
49+
.baseUrl(baseUrl)
4450
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
4551
.addConverterFactory(GsonConverterFactory.create(gson))
4652
.client(httpClient.build())

app/src/main/java/crypto/delta/exchange/openexchange/api/DeltaExchangeApiEndPoints.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface DeltaExchangeApiEndPoints {
3232
): Call<OrderBookResponse>
3333

3434
@GET("products")
35-
fun getProducts(): Call<List<ProductsResponse>>
35+
fun getProducts(): Observable<List<ProductsResponse>>
3636

3737

3838
@POST("orders")

app/src/main/java/crypto/delta/exchange/openexchange/api/DeltaRepository.kt

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ package crypto.delta.exchange.openexchange.api
33
import android.content.Context
44
import androidx.lifecycle.MutableLiveData
55
import crypto.delta.exchange.openexchange.pojo.DeltaExchangeChartHistoryResponse
6+
import crypto.delta.exchange.openexchange.pojo.DeltaExchangeTickerResponse
67
import crypto.delta.exchange.openexchange.pojo.OrderBookResponse
78
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
9+
import io.reactivex.android.schedulers.AndroidSchedulers
10+
import io.reactivex.disposables.CompositeDisposable
11+
import io.reactivex.observers.DisposableObserver
12+
import io.reactivex.rxkotlin.addTo
13+
import io.reactivex.schedulers.Schedulers
814
import retrofit2.Call
915
import retrofit2.Callback
1016
import retrofit2.Response
11-
import java.util.concurrent.TimeUnit
17+
1218

1319
class DeltaRepository {
1420
companion object {
@@ -31,10 +37,9 @@ class DeltaRepository {
3137
.create(DeltaExchangeApiEndPoints::class.java)
3238
}
3339

34-
fun getChartHistory(resolution: String, symbol: String): MutableLiveData<DeltaExchangeChartHistoryResponse?> {
40+
fun getChartHistory(resolution: String, symbol: String, strFrom: String, strTo: String): MutableLiveData<DeltaExchangeChartHistoryResponse?> {
3541
val data: MutableLiveData<DeltaExchangeChartHistoryResponse?> = MutableLiveData<DeltaExchangeChartHistoryResponse?>()
36-
val currentTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())
37-
deltaExchangeApiEndPoints!!.getChartHistory(symbol, resolution, "1105261585", currentTime.toString()).enqueue(object :
42+
deltaExchangeApiEndPoints!!.getChartHistory(symbol, resolution, strFrom, strTo).enqueue(object :
3843
Callback<DeltaExchangeChartHistoryResponse?> {
3944
override fun onResponse(
4045
call: Call<DeltaExchangeChartHistoryResponse?>?,
@@ -76,22 +81,48 @@ class DeltaRepository {
7681
return data
7782
}
7883

79-
fun getProducts(): MutableLiveData<List<ProductsResponse>> {
84+
fun getProducts(disposables: CompositeDisposable): MutableLiveData<List<ProductsResponse>> {
8085
val data: MutableLiveData<List<ProductsResponse>> = MutableLiveData<List<ProductsResponse>>()
81-
deltaExchangeApiEndPoints!!.getProducts().enqueue(object :
82-
Callback<List<ProductsResponse>> {
83-
override fun onResponse(call: Call<List<ProductsResponse>>?, response: Response<List<ProductsResponse>>) {
84-
if (response.isSuccessful) {
85-
data.value = response.body()
86-
} else {
86+
deltaExchangeApiEndPoints!!.getProducts()
87+
.subscribeOn(Schedulers.io())
88+
.observeOn(AndroidSchedulers.mainThread())
89+
.subscribeWith(object : DisposableObserver<List<ProductsResponse>>() {
90+
override fun onComplete() {
91+
}
92+
93+
override fun onNext(response: List<ProductsResponse>) {
94+
data.value = response
95+
}
96+
97+
override fun onError(e: Throwable) {
98+
e.printStackTrace()
8799
data.value = null
88100
}
89-
}
90101

91-
override fun onFailure(call: Call<List<ProductsResponse>>?, t: Throwable?) {
92-
data.value = null
93-
}
94-
})
102+
}).addTo(disposables)
103+
return data
104+
}
105+
106+
fun getProductsData(symbol: String): MutableLiveData<DeltaExchangeTickerResponse>? {
107+
val data: MutableLiveData<DeltaExchangeTickerResponse> = MutableLiveData<DeltaExchangeTickerResponse>()
108+
deltaExchangeApiEndPoints!!.getTickers24Hrs(symbol)
109+
.enqueue(object :
110+
Callback<DeltaExchangeTickerResponse?> {
111+
override fun onResponse(
112+
call: Call<DeltaExchangeTickerResponse?>?,
113+
response: Response<DeltaExchangeTickerResponse?>
114+
) {
115+
if (response.isSuccessful) {
116+
data.value = response.body()
117+
} else {
118+
data.value = null
119+
}
120+
}
121+
122+
override fun onFailure(call: Call<DeltaExchangeTickerResponse?>?, t: Throwable?) {
123+
data.value = null
124+
}
125+
})
95126
return data
96127
}
97128
}

app/src/main/java/crypto/delta/exchange/openexchange/pojo/Buy.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.google.gson.annotations.SerializedName
88
class Buy {
99
@SerializedName("limit_price")
1010
@Expose
11-
var limitPrice: Double? = null
11+
var limitPrice: Float? = null
1212

1313
@SerializedName("d_size")
1414
@Expose

app/src/main/java/crypto/delta/exchange/openexchange/pojo/DeltaExchangeTickerResponse.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ class DeltaExchangeTickerResponse {
2222

2323
@SerializedName("open")
2424
@Expose
25-
var open: Double? = null
25+
var open: Float? = null
2626

2727
@SerializedName("high")
2828
@Expose
29-
var high: Double? = null
29+
var high: Float? = null
3030

3131
@SerializedName("low")
3232
@Expose
33-
var low: Double? = null
33+
var low: Float? = null
3434

3535
@SerializedName("close")
3636
@Expose
37-
var close: Double? = null
37+
var close: Float? = null
3838

3939
@SerializedName("volume")
4040
@Expose

app/src/main/java/crypto/delta/exchange/openexchange/pojo/Sell.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.google.gson.annotations.SerializedName
88
class Sell {
99
@SerializedName("limit_price")
1010
@Expose
11-
var limitPrice: Double? = null
11+
var limitPrice: Float? = null
1212

1313
@SerializedName("d_size")
1414
@Expose

0 commit comments

Comments
 (0)