Skip to content

Commit 625f96b

Browse files
committed
Home UI/UX initial working code.
Bug fixes and performance improvement.
1 parent a0865df commit 625f96b

40 files changed

Lines changed: 1200 additions & 70 deletions

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44

55
android {
6-
compileSdkVersion 29
7-
buildToolsVersion "29.0.3"
6+
compileSdkVersion 30
7+
buildToolsVersion "30.0.0"
88

99
defaultConfig {
1010
applicationId "crypto.delta.exchange.openexchange"
1111
minSdkVersion 23
12-
targetSdkVersion 29
12+
targetSdkVersion 30
1313
versionCode 1
1414
versionName "alpha-1.0"
1515
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
@@ -37,8 +37,8 @@ android {
3737
}
3838
debug {
3939
versionNameSuffix '-debug'
40-
minifyEnabled true
41-
shrinkResources true
40+
minifyEnabled false
41+
shrinkResources false
4242
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4343
}
4444
android.applicationVariants.all { variant ->

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ extern "C" JNIEXPORT jstring JNICALL
55
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseUrl(
66
JNIEnv *env,
77
jobject /* this */) {
8-
std::string hello = "https://testnet-api.delta.exchange/";
8+
std::string hello = "https://api.delta.exchange/";
99
return env->NewStringUTF(hello.c_str());
1010
}
1111

1212
extern "C" JNIEXPORT jstring JNICALL
1313
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseWebSocketUrl(
1414
JNIEnv *env,
1515
jobject /* this */) {
16-
std::string url = "wss://testnet-api.delta.exchange:2096/";
16+
std::string url = "wss://api.delta.exchange:2096/";
1717
return env->NewStringUTF(url.c_str());
1818
}

app/src/main/java/crypto/delta/exchange/openexchange/MainActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import android.os.Bundle
44
import com.google.android.material.bottomnavigation.BottomNavigationView
55
import androidx.appcompat.app.AppCompatActivity
66
import androidx.navigation.findNavController
7-
import androidx.navigation.ui.AppBarConfiguration
8-
import androidx.navigation.ui.setupActionBarWithNavController
97
import androidx.navigation.ui.setupWithNavController
108

119
class MainActivity : AppCompatActivity() {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package crypto.delta.exchange.openexchange.adapter
2+
3+
import android.view.LayoutInflater
4+
import android.view.View
5+
import android.view.ViewGroup
6+
import androidx.appcompat.widget.AppCompatTextView
7+
import androidx.fragment.app.FragmentActivity
8+
import androidx.navigation.findNavController
9+
import androidx.recyclerview.widget.RecyclerView
10+
import crypto.delta.exchange.openexchange.R
11+
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
12+
import crypto.delta.exchange.openexchange.utils.AppPreferenceManager
13+
14+
class HomeAdapter(
15+
private var productsResponseList: List<ProductsResponse>,
16+
private val requireActivity: FragmentActivity
17+
) : RecyclerView.Adapter<HomeAdapter.ViewHolder>() {
18+
19+
override fun getItemCount() = productsResponseList.size
20+
21+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
22+
val v = LayoutInflater.from(parent.context)
23+
.inflate(R.layout.adapter_home, parent, false)
24+
return ViewHolder(v)
25+
}
26+
27+
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
28+
internal val symbol: AppCompatTextView = itemView.findViewById(R.id.symbol)
29+
}
30+
31+
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
32+
val product = productsResponseList[position]
33+
holder.symbol.text = product.symbol
34+
holder.itemView.setOnClickListener {
35+
AppPreferenceManager(requireActivity).setCurrentProductSymbol(product.symbol)
36+
AppPreferenceManager(requireActivity).setCurrentProductId(product.id.toString())
37+
requireActivity.findNavController(R.id.nav_host_fragment).navigate(R.id.navigation_chart)
38+
}
39+
}
40+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class OrderBookAdapter(private var orderBookList: DeltaExchangeL2OrderBookRespon
2828
}
2929

3030
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
31-
val buy = orderBookList.buy?.get(position)
32-
val ask = orderBookList.sell?.get(position)
31+
val buy = orderBookList.buy!![position]
32+
val ask = orderBookList.sell!![position]
3333

34-
holder.sizeBid.text = buy!!.d_size.toString()
34+
holder.sizeBid.text = buy.d_size.toString()
3535
holder.priceBid.text = buy.limitPrice.toString()
36-
holder.sizeAsk.text = ask!!.d_size.toString()
36+
holder.sizeAsk.text = ask.d_size.toString()
3737
holder.priceAsk.text = ask.limitPrice.toString()
3838
}
3939

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package crypto.delta.exchange.openexchange.adapter
22

3+
import android.util.Log
34
import android.view.LayoutInflater
45
import android.view.View
56
import android.view.ViewGroup
@@ -34,11 +35,20 @@ class RecentTradesAdapter (private var recentTradesList: ArrayList<RecentTrade>)
3435
holder.tradePrice.text = recentTrade.price.toString()
3536
holder.tradeSize.text = recentTrade.size.toString()
3637
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd hh:mma", Locale.ENGLISH)
37-
holder.tradeTime.text = simpleDateFormat.format(Date(recentTrade.timestamp!!/1000))
38+
holder.tradeTime.text = simpleDateFormat.format(Date(recentTrade.timestamp!! / 1000))
3839
if (recentTrade.sellerRole.equals("taker", true)) {
3940
holder.tradeTaker.text = "S"
4041
} else if (recentTrade.buyerRole.equals("taker", true)) {
4142
holder.tradeTaker.text = "B"
4243
}
44+
45+
if (position != 0) {
46+
val recentPreviousTradePrice = recentTradesList[position - 1].price!!.toDouble()
47+
val currentPrice = recentTrade.price!!.toDouble()
48+
val diff = currentPrice - recentPreviousTradePrice
49+
Log.d("previousPrice", recentPreviousTradePrice.toString())
50+
Log.d("currentPrice", currentPrice.toString())
51+
Log.d("diff", diff.toString())
52+
}
4353
}
4454
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import crypto.delta.exchange.openexchange.pojo.order.ChangeOrderLeverageBody
77
import crypto.delta.exchange.openexchange.pojo.order.CreateOrderRequest
88
import crypto.delta.exchange.openexchange.pojo.order.CreateOrderResponse
99
import crypto.delta.exchange.openexchange.pojo.order.OrderLeverageResponse
10+
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
1011
import io.reactivex.Observable
1112
import retrofit2.Call
1213
import retrofit2.http.*
@@ -30,6 +31,9 @@ interface DeltaExchangeApiEndPoints {
3031
@Path("product_id") product_id: String?
3132
): Call<OrderBookResponse>
3233

34+
@GET("products")
35+
fun getProducts(): Call<List<ProductsResponse>>
36+
3337

3438
@POST("orders")
3539
fun createOrder(

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import androidx.lifecycle.MutableLiveData
55
import crypto.delta.exchange.openexchange.pojo.DeltaExchangeChartHistoryResponse
66
import crypto.delta.exchange.openexchange.pojo.OrderBookResponse
7+
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
78
import retrofit2.Call
89
import retrofit2.Callback
910
import retrofit2.Response
@@ -30,17 +31,19 @@ class DeltaRepository {
3031
.create(DeltaExchangeApiEndPoints::class.java)
3132
}
3233

33-
fun getChartHistory(resolution: String): MutableLiveData<DeltaExchangeChartHistoryResponse?> {
34+
fun getChartHistory(resolution: String, symbol: String): MutableLiveData<DeltaExchangeChartHistoryResponse?> {
3435
val data: MutableLiveData<DeltaExchangeChartHistoryResponse?> = MutableLiveData<DeltaExchangeChartHistoryResponse?>()
3536
val currentTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())
36-
deltaExchangeApiEndPoints!!.getChartHistory("BTCUSD", resolution, "1105261585", currentTime.toString()).enqueue(object :
37+
deltaExchangeApiEndPoints!!.getChartHistory(symbol, resolution, "1105261585", currentTime.toString()).enqueue(object :
3738
Callback<DeltaExchangeChartHistoryResponse?> {
3839
override fun onResponse(
3940
call: Call<DeltaExchangeChartHistoryResponse?>?,
4041
response: Response<DeltaExchangeChartHistoryResponse?>
4142
) {
4243
if (response.isSuccessful) {
4344
data.value = response.body()
45+
} else {
46+
data.value = null
4447
}
4548
}
4649

@@ -51,23 +54,44 @@ class DeltaRepository {
5154
return data
5255
}
5356

54-
fun getOrderBook(): MutableLiveData<OrderBookResponse?> {
55-
val newsData: MutableLiveData<OrderBookResponse?> = MutableLiveData<OrderBookResponse?>()
56-
deltaExchangeApiEndPoints!!.getOrderBook("16").enqueue(object :
57+
fun getOrderBook(productId: String): MutableLiveData<OrderBookResponse?> {
58+
val data: MutableLiveData<OrderBookResponse?> = MutableLiveData<OrderBookResponse?>()
59+
deltaExchangeApiEndPoints!!.getOrderBook(productId).enqueue(object :
5760
Callback<OrderBookResponse?> {
5861
override fun onResponse(
5962
call: Call<OrderBookResponse?>?,
6063
response: Response<OrderBookResponse?>
6164
) {
6265
if (response.isSuccessful) {
63-
newsData.value = response.body()
66+
data.value = response.body()
67+
} else {
68+
data.value = null
6469
}
6570
}
6671

6772
override fun onFailure(call: Call<OrderBookResponse?>?, t: Throwable?) {
68-
newsData.value = null
73+
data.value = null
74+
}
75+
})
76+
return data
77+
}
78+
79+
fun getProducts(): MutableLiveData<List<ProductsResponse>> {
80+
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 {
87+
data.value = null
88+
}
89+
}
90+
91+
override fun onFailure(call: Call<List<ProductsResponse>>?, t: Throwable?) {
92+
data.value = null
6993
}
7094
})
71-
return newsData
95+
return data
7296
}
7397
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package crypto.delta.exchange.openexchange.pojo.products
2+
3+
import com.google.gson.annotations.Expose
4+
import com.google.gson.annotations.SerializedName
5+
6+
class ConstituentExchange {
7+
@SerializedName("weight")
8+
@Expose
9+
var weight: Int? = null
10+
11+
@SerializedName("exchange")
12+
@Expose
13+
var exchange: String? = null
14+
15+
@SerializedName("health_interval")
16+
@Expose
17+
var healthInterval: Int? = null
18+
19+
@SerializedName("health_priority")
20+
@Expose
21+
var healthPriority: Int? = null
22+
23+
@SerializedName("toSym")
24+
@Expose
25+
var toSym: String? = null
26+
27+
@SerializedName("fromSym")
28+
@Expose
29+
var fromSym: String? = null
30+
31+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package crypto.delta.exchange.openexchange.pojo.products
2+
3+
import com.google.gson.annotations.Expose
4+
import com.google.gson.annotations.SerializedName
5+
6+
class ProductSpecs {
7+
@SerializedName("fixed_ir_index")
8+
@Expose
9+
var fixedIrIndex: String? = null
10+
11+
@SerializedName("floating_ir_index")
12+
@Expose
13+
var floatingIrIndex: String? = null
14+
15+
@SerializedName("floating_rate_max")
16+
@Expose
17+
var floatingRateMax: String? = null
18+
19+
@SerializedName("floating_rate_min")
20+
@Expose
21+
var floatingRateMin: String? = null
22+
23+
@SerializedName("rate_exchange_interval")
24+
@Expose
25+
var rateExchangeInterval: Int? = null
26+
27+
}

0 commit comments

Comments
 (0)