Skip to content

Commit

Permalink
Home UI/UX initial working code.
Browse files Browse the repository at this point in the history
Bug fixes and performance improvement.
  • Loading branch information
percy-g2 committed Jun 11, 2020
1 parent a0865df commit 625f96b
Show file tree
Hide file tree
Showing 40 changed files with 1,200 additions and 70 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
compileSdkVersion 30
buildToolsVersion "30.0.0"

defaultConfig {
applicationId "crypto.delta.exchange.openexchange"
minSdkVersion 23
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "alpha-1.0"
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
Expand Down Expand Up @@ -37,8 +37,8 @@ android {
}
debug {
versionNameSuffix '-debug'
minifyEnabled true
shrinkResources true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
android.applicationVariants.all { variant ->
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ extern "C" JNIEXPORT jstring JNICALL
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseUrl(
JNIEnv *env,
jobject /* this */) {
std::string hello = "https://testnet-api.delta.exchange/";
std::string hello = "https://api.delta.exchange/";
return env->NewStringUTF(hello.c_str());
}

extern "C" JNIEXPORT jstring JNICALL
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseWebSocketUrl(
JNIEnv *env,
jobject /* this */) {
std::string url = "wss://testnet-api.delta.exchange:2096/";
std::string url = "wss://api.delta.exchange:2096/";
return env->NewStringUTF(url.c_str());
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import android.os.Bundle
import com.google.android.material.bottomnavigation.BottomNavigationView
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController

class MainActivity : AppCompatActivity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package crypto.delta.exchange.openexchange.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import androidx.fragment.app.FragmentActivity
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import crypto.delta.exchange.openexchange.R
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
import crypto.delta.exchange.openexchange.utils.AppPreferenceManager

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

override fun getItemCount() = productsResponseList.size

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context)
.inflate(R.layout.adapter_home, parent, false)
return ViewHolder(v)
}

inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
internal val symbol: AppCompatTextView = itemView.findViewById(R.id.symbol)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val product = productsResponseList[position]
holder.symbol.text = product.symbol
holder.itemView.setOnClickListener {
AppPreferenceManager(requireActivity).setCurrentProductSymbol(product.symbol)
AppPreferenceManager(requireActivity).setCurrentProductId(product.id.toString())
requireActivity.findNavController(R.id.nav_host_fragment).navigate(R.id.navigation_chart)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class OrderBookAdapter(private var orderBookList: DeltaExchangeL2OrderBookRespon
}

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

holder.sizeBid.text = buy!!.d_size.toString()
holder.sizeBid.text = buy.d_size.toString()
holder.priceBid.text = buy.limitPrice.toString()
holder.sizeAsk.text = ask!!.d_size.toString()
holder.sizeAsk.text = ask.d_size.toString()
holder.priceAsk.text = ask.limitPrice.toString()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package crypto.delta.exchange.openexchange.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -34,11 +35,20 @@ class RecentTradesAdapter (private var recentTradesList: ArrayList<RecentTrade>)
holder.tradePrice.text = recentTrade.price.toString()
holder.tradeSize.text = recentTrade.size.toString()
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd hh:mma", Locale.ENGLISH)
holder.tradeTime.text = simpleDateFormat.format(Date(recentTrade.timestamp!!/1000))
holder.tradeTime.text = simpleDateFormat.format(Date(recentTrade.timestamp!! / 1000))
if (recentTrade.sellerRole.equals("taker", true)) {
holder.tradeTaker.text = "S"
} else if (recentTrade.buyerRole.equals("taker", true)) {
holder.tradeTaker.text = "B"
}

if (position != 0) {
val recentPreviousTradePrice = recentTradesList[position - 1].price!!.toDouble()
val currentPrice = recentTrade.price!!.toDouble()
val diff = currentPrice - recentPreviousTradePrice
Log.d("previousPrice", recentPreviousTradePrice.toString())
Log.d("currentPrice", currentPrice.toString())
Log.d("diff", diff.toString())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import crypto.delta.exchange.openexchange.pojo.order.ChangeOrderLeverageBody
import crypto.delta.exchange.openexchange.pojo.order.CreateOrderRequest
import crypto.delta.exchange.openexchange.pojo.order.CreateOrderResponse
import crypto.delta.exchange.openexchange.pojo.order.OrderLeverageResponse
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
import io.reactivex.Observable
import retrofit2.Call
import retrofit2.http.*
Expand All @@ -30,6 +31,9 @@ interface DeltaExchangeApiEndPoints {
@Path("product_id") product_id: String?
): Call<OrderBookResponse>

@GET("products")
fun getProducts(): Call<List<ProductsResponse>>


@POST("orders")
fun createOrder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import androidx.lifecycle.MutableLiveData
import crypto.delta.exchange.openexchange.pojo.DeltaExchangeChartHistoryResponse
import crypto.delta.exchange.openexchange.pojo.OrderBookResponse
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -30,17 +31,19 @@ class DeltaRepository {
.create(DeltaExchangeApiEndPoints::class.java)
}

fun getChartHistory(resolution: String): MutableLiveData<DeltaExchangeChartHistoryResponse?> {
fun getChartHistory(resolution: String, symbol: String): MutableLiveData<DeltaExchangeChartHistoryResponse?> {
val data: MutableLiveData<DeltaExchangeChartHistoryResponse?> = MutableLiveData<DeltaExchangeChartHistoryResponse?>()
val currentTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())
deltaExchangeApiEndPoints!!.getChartHistory("BTCUSD", resolution, "1105261585", currentTime.toString()).enqueue(object :
deltaExchangeApiEndPoints!!.getChartHistory(symbol, resolution, "1105261585", currentTime.toString()).enqueue(object :
Callback<DeltaExchangeChartHistoryResponse?> {
override fun onResponse(
call: Call<DeltaExchangeChartHistoryResponse?>?,
response: Response<DeltaExchangeChartHistoryResponse?>
) {
if (response.isSuccessful) {
data.value = response.body()
} else {
data.value = null
}
}

Expand All @@ -51,23 +54,44 @@ class DeltaRepository {
return data
}

fun getOrderBook(): MutableLiveData<OrderBookResponse?> {
val newsData: MutableLiveData<OrderBookResponse?> = MutableLiveData<OrderBookResponse?>()
deltaExchangeApiEndPoints!!.getOrderBook("16").enqueue(object :
fun getOrderBook(productId: String): MutableLiveData<OrderBookResponse?> {
val data: MutableLiveData<OrderBookResponse?> = MutableLiveData<OrderBookResponse?>()
deltaExchangeApiEndPoints!!.getOrderBook(productId).enqueue(object :
Callback<OrderBookResponse?> {
override fun onResponse(
call: Call<OrderBookResponse?>?,
response: Response<OrderBookResponse?>
) {
if (response.isSuccessful) {
newsData.value = response.body()
data.value = response.body()
} else {
data.value = null
}
}

override fun onFailure(call: Call<OrderBookResponse?>?, t: Throwable?) {
newsData.value = null
data.value = null
}
})
return data
}

fun getProducts(): MutableLiveData<List<ProductsResponse>> {
val data: MutableLiveData<List<ProductsResponse>> = MutableLiveData<List<ProductsResponse>>()
deltaExchangeApiEndPoints!!.getProducts().enqueue(object :
Callback<List<ProductsResponse>> {
override fun onResponse(call: Call<List<ProductsResponse>>?, response: Response<List<ProductsResponse>>) {
if (response.isSuccessful) {
data.value = response.body()
} else {
data.value = null
}
}

override fun onFailure(call: Call<List<ProductsResponse>>?, t: Throwable?) {
data.value = null
}
})
return newsData
return data
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package crypto.delta.exchange.openexchange.pojo.products

import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

class ConstituentExchange {
@SerializedName("weight")
@Expose
var weight: Int? = null

@SerializedName("exchange")
@Expose
var exchange: String? = null

@SerializedName("health_interval")
@Expose
var healthInterval: Int? = null

@SerializedName("health_priority")
@Expose
var healthPriority: Int? = null

@SerializedName("toSym")
@Expose
var toSym: String? = null

@SerializedName("fromSym")
@Expose
var fromSym: String? = null

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package crypto.delta.exchange.openexchange.pojo.products

import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

class ProductSpecs {
@SerializedName("fixed_ir_index")
@Expose
var fixedIrIndex: String? = null

@SerializedName("floating_ir_index")
@Expose
var floatingIrIndex: String? = null

@SerializedName("floating_rate_max")
@Expose
var floatingRateMax: String? = null

@SerializedName("floating_rate_min")
@Expose
var floatingRateMin: String? = null

@SerializedName("rate_exchange_interval")
@Expose
var rateExchangeInterval: Int? = null

}
Loading

0 comments on commit 625f96b

Please sign in to comment.