Skip to content

Commit

Permalink
Home UI/UX changes.
Browse files Browse the repository at this point in the history
Use test net or main server configuration from settings.
Bug fixes and performance improvement.
  • Loading branch information
percy-g2 committed Jun 12, 2020
1 parent 625f96b commit 209bde6
Show file tree
Hide file tree
Showing 24 changed files with 393 additions and 280 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ android {
applicationId "crypto.delta.exchange.openexchange"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "alpha-1.0"
versionCode 2
versionName "alpha-1.1"
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
externalNativeBuild {
cmake {
cppFlags ""
}
}
resConfigs "en"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand All @@ -37,8 +38,8 @@ android {
}
debug {
versionNameSuffix '-debug'
minifyEnabled false
shrinkResources false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
android.applicationVariants.all { variant ->
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
#include <jni.h>
#include <string>

extern "C" JNIEXPORT jstring JNICALL
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeTestNetBaseUrl(
JNIEnv *env,
jobject /* this */) {
std::string hello = "https://testnet-api.delta.exchange/";
return env->NewStringUTF(hello.c_str());
}

extern "C" JNIEXPORT jstring JNICALL
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeTestNetBaseWebSocketUrl(
JNIEnv *env,
jobject /* this */) {
std::string url = "wss://testnet-api.delta.exchange:2096/";
return env->NewStringUTF(url.c_str());
}

extern "C" JNIEXPORT jstring JNICALL
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseUrl(
JNIEnv *env,
Expand All @@ -12,7 +28,7 @@ Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseUrl(
extern "C" JNIEXPORT jstring JNICALL
Java_crypto_delta_exchange_openexchange_utils_Native_getDeltaExchangeBaseWebSocketUrl(
JNIEnv *env,
jobject /* this */) {
std::string url = "wss://api.delta.exchange:2096/";
return env->NewStringUTF(url.c_str());
jobject /* this */) {
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 @@ -5,17 +5,23 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import crypto.delta.exchange.openexchange.R
import crypto.delta.exchange.openexchange.api.DeltaRepository
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
import crypto.delta.exchange.openexchange.utils.AppPreferenceManager
import crypto.delta.exchange.openexchange.utils.KotlinUtils


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

private val deltaRepository = DeltaRepository.getInstance(requireActivity)

override fun getItemCount() = productsResponseList.size

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

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

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
Expand All @@ -34,7 +42,19 @@ class HomeAdapter(
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)
requireActivity.findNavController(R.id.nav_host_fragment)
.navigate(R.id.navigation_chart, null, KotlinUtils.getNavOptions())
}
deltaRepository!!.getProductsData(product.symbol!!)!!.observe(requireActivity, Observer { tickerResponse ->
if (null != tickerResponse.close) {
holder.lastPrice.text = tickerResponse.close?.toBigDecimal()?.toPlainString()
holder.dayVolume.text = String.format(tickerResponse.volume!!.toString() + " " + product.quotingAsset!!.symbol)
}
})

}




}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class OrderBookAdapter(private var orderBookList: DeltaExchangeL2OrderBookRespon
val ask = orderBookList.sell!![position]

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

fun updateOrderBook(orderBook: DeltaExchangeL2OrderBookResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package crypto.delta.exchange.openexchange.api
import android.content.Context
import com.google.gson.GsonBuilder
import crypto.delta.exchange.openexchange.BuildConfig
import crypto.delta.exchange.openexchange.utils.AppPreferenceManager
import crypto.delta.exchange.openexchange.utils.Native
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand Down Expand Up @@ -39,8 +40,13 @@ class DeltaApiClient {
httpClient.connectTimeout(400, TimeUnit.SECONDS)
httpClient.followRedirects(true)
httpClient.retryOnConnectionFailure(true)
val baseUrl = if (AppPreferenceManager(mContext).useTestNetServer!!) {
Native.deltaExchangeTestNetBaseUrl
} else {
Native.deltaExchangeBaseUrl
}
retrofit = Retrofit.Builder()
.baseUrl(Native.deltaExchangeBaseUrl)
.baseUrl(baseUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.client(httpClient.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface DeltaExchangeApiEndPoints {
): Call<OrderBookResponse>

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


@POST("orders")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ package crypto.delta.exchange.openexchange.api
import android.content.Context
import androidx.lifecycle.MutableLiveData
import crypto.delta.exchange.openexchange.pojo.DeltaExchangeChartHistoryResponse
import crypto.delta.exchange.openexchange.pojo.DeltaExchangeTickerResponse
import crypto.delta.exchange.openexchange.pojo.OrderBookResponse
import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.observers.DisposableObserver
import io.reactivex.rxkotlin.addTo
import io.reactivex.schedulers.Schedulers
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.util.concurrent.TimeUnit


class DeltaRepository {
companion object {
Expand All @@ -31,10 +37,9 @@ class DeltaRepository {
.create(DeltaExchangeApiEndPoints::class.java)
}

fun getChartHistory(resolution: String, symbol: String): MutableLiveData<DeltaExchangeChartHistoryResponse?> {
fun getChartHistory(resolution: String, symbol: String, strFrom: String, strTo: String): MutableLiveData<DeltaExchangeChartHistoryResponse?> {
val data: MutableLiveData<DeltaExchangeChartHistoryResponse?> = MutableLiveData<DeltaExchangeChartHistoryResponse?>()
val currentTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())
deltaExchangeApiEndPoints!!.getChartHistory(symbol, resolution, "1105261585", currentTime.toString()).enqueue(object :
deltaExchangeApiEndPoints!!.getChartHistory(symbol, resolution, strFrom, strTo).enqueue(object :
Callback<DeltaExchangeChartHistoryResponse?> {
override fun onResponse(
call: Call<DeltaExchangeChartHistoryResponse?>?,
Expand Down Expand Up @@ -76,22 +81,48 @@ class DeltaRepository {
return data
}

fun getProducts(): MutableLiveData<List<ProductsResponse>> {
fun getProducts(disposables: CompositeDisposable): 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 {
deltaExchangeApiEndPoints!!.getProducts()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver<List<ProductsResponse>>() {
override fun onComplete() {
}

override fun onNext(response: List<ProductsResponse>) {
data.value = response
}

override fun onError(e: Throwable) {
e.printStackTrace()
data.value = null
}
}

override fun onFailure(call: Call<List<ProductsResponse>>?, t: Throwable?) {
data.value = null
}
})
}).addTo(disposables)
return data
}

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

override fun onFailure(call: Call<DeltaExchangeTickerResponse?>?, t: Throwable?) {
data.value = null
}
})
return data
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.google.gson.annotations.SerializedName
class Buy {
@SerializedName("limit_price")
@Expose
var limitPrice: Double? = null
var limitPrice: Float? = null

@SerializedName("d_size")
@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ class DeltaExchangeTickerResponse {

@SerializedName("open")
@Expose
var open: Double? = null
var open: Float? = null

@SerializedName("high")
@Expose
var high: Double? = null
var high: Float? = null

@SerializedName("low")
@Expose
var low: Double? = null
var low: Float? = null

@SerializedName("close")
@Expose
var close: Double? = null
var close: Float? = null

@SerializedName("volume")
@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.google.gson.annotations.SerializedName
class Sell {
@SerializedName("limit_price")
@Expose
var limitPrice: Double? = null
var limitPrice: Float? = null

@SerializedName("d_size")
@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.google.gson.annotations.SerializedName
class ConstituentExchange {
@SerializedName("weight")
@Expose
var weight: Int? = null
var weight: Double? = null

@SerializedName("exchange")
@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ChartFragment : BaseFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
chartViewModel = ViewModelProvider(this).get(ChartViewModel::class.java)
chartViewModel.init(requireActivity())
chartViewModel.getChartHistory("15", appPreferenceManager!!.currentProductSymbol!!)!!.observe(viewLifecycleOwner, Observer {
val currentTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())
chartViewModel.getChartHistory("15", appPreferenceManager!!.currentProductSymbol!!, "1105261585", currentTime.toString())!!.observe(viewLifecycleOwner, Observer {
try {
if (it != null) {
val responseData = it
Expand Down Expand Up @@ -121,7 +122,8 @@ class ChartFragment : BaseFragment() {

chartViewModel = ViewModelProvider(requireActivity()).get(ChartViewModel::class.java)
chartViewModel.init(requireActivity())
chartViewModel.getChartHistory(resolution, appPreferenceManager!!.currentProductSymbol!!)!!.observe(viewLifecycleOwner, Observer {
val currentTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())
chartViewModel.getChartHistory(resolution, appPreferenceManager!!.currentProductSymbol!!, "1105261585", currentTime.toString())!!.observe(viewLifecycleOwner, Observer {
try {
if (it != null) {
if (it.s.equals("ok")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ChartViewModel : ViewModel() {
deltaRepository = DeltaRepository.getInstance(context)
}

fun getChartHistory(resolution: String, symbol: String): LiveData<DeltaExchangeChartHistoryResponse?>? {
mutableLiveData = deltaRepository!!.getChartHistory(resolution, symbol)
fun getChartHistory(resolution: String, symbol: String, strFrom: String, strTo: String): LiveData<DeltaExchangeChartHistoryResponse?>? {
mutableLiveData = deltaRepository!!.getChartHistory(resolution, symbol, strFrom, strTo)
return mutableLiveData
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class HomeFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
): View? {
homeViewModel = ViewModelProvider(this).get(HomeViewModel::class.java)
homeViewModel.init(requireActivity())

homeViewModel.getProducts()!!.observe(viewLifecycleOwner, Observer { list ->
if (null != list) {
productsResponseList = list
Expand All @@ -42,6 +43,7 @@ class HomeFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
},
requireActivity()
)
progressSpinner.visibility = View.GONE
}
})
return inflater.inflate(R.layout.fragment_home, container, false)
Expand Down Expand Up @@ -144,7 +146,7 @@ class HomeFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
)
}
}
tab.text.toString() == resources.getString(R.string.interest_rate_swipes) -> {
tab.text.toString() == resources.getString(R.string.interest_rate_swaps) -> {
futuresSettled.visibility = View.GONE
if (null != productsResponseList) {
filteredProductsResponseList = productsResponseList
Expand Down Expand Up @@ -200,7 +202,7 @@ class HomeFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
)
}
}
tab.text.toString() == resources.getString(R.string.interest_rate_swipes) -> {
tab.text.toString() == resources.getString(R.string.interest_rate_swaps) -> {
futuresSettled.visibility = View.GONE
if (null != productsResponseList) {
filteredProductsResponseList = productsResponseList
Expand Down Expand Up @@ -272,7 +274,7 @@ class HomeFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
}
}
productType.getTabAt(productType.selectedTabPosition)!!.text.toString() == resources.getString(
R.string.interest_rate_swipes
R.string.interest_rate_swaps
) -> {
if (null != productsResponseList) {
homeRecyclerView.adapter = HomeAdapter(
Expand Down
Loading

0 comments on commit 209bde6

Please sign in to comment.