|
|
@@ -8,28 +8,38 @@ import android.view.ViewGroup
|
|
|
import android.widget.ImageView
|
|
|
import android.widget.RelativeLayout
|
|
|
import android.widget.TextView
|
|
|
+import androidx.lifecycle.MutableLiveData
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import cn.muchinfo.rma.R
|
|
|
+import cn.muchinfo.rma.business.future.FutureManager
|
|
|
+import cn.muchinfo.rma.global.GlobalDataCollection
|
|
|
+import cn.muchinfo.rma.global.data.FutureDetailsData
|
|
|
+import cn.muchinfo.rma.global.data.futureOrders.FutureEntrustData
|
|
|
+import cn.muchinfo.rma.global.data.futureOrders.FutureHoldData
|
|
|
import cn.muchinfo.rma.view.base.BaseViewModel
|
|
|
+import cn.muchinfo.rma.view.base.app.Constant
|
|
|
+import com.blankj.utilcode.util.SPUtils
|
|
|
|
|
|
/**
|
|
|
* 持仓的ViewModel
|
|
|
*/
|
|
|
class HoldViewModel : BaseViewModel() {
|
|
|
|
|
|
- var list: ArrayList<HoldData>? = null
|
|
|
+ val holdLiveData: MutableLiveData<List<FutureHoldData>> = MutableLiveData() // 持仓单
|
|
|
|
|
|
+ var list: ArrayList<FutureHoldData>? = null
|
|
|
+ var marketID: String? = null
|
|
|
/**
|
|
|
* 获取配置器。
|
|
|
*/
|
|
|
fun getAdapter(): RecyclerView.Adapter<HoldAdapter.HoldHolder> {
|
|
|
- return HoldAdapter(context, list)
|
|
|
+ return HoldAdapter(context)
|
|
|
}
|
|
|
/**
|
|
|
* 通用的适配器。
|
|
|
*/
|
|
|
- class HoldAdapter(context: Context?, list: ArrayList<HoldData>?) : RecyclerView.Adapter<HoldAdapter.HoldHolder>() {
|
|
|
- private var list: ArrayList<HoldData>? = null
|
|
|
+ inner class HoldAdapter(context: Context?) : RecyclerView.Adapter<HoldAdapter.HoldHolder>() {
|
|
|
+ private var list: ArrayList<FutureHoldData>? = null
|
|
|
private var inflater: LayoutInflater? = null
|
|
|
private var context: Context? = null
|
|
|
private var pink: Drawable? = null
|
|
|
@@ -37,7 +47,7 @@ class HoldViewModel : BaseViewModel() {
|
|
|
private var priceRed: Int = 0
|
|
|
private var priceGreen: Int = 0
|
|
|
init {
|
|
|
- this.list = list
|
|
|
+ this.list = GlobalDataCollection.instance?.futureHoldData
|
|
|
this.inflater = LayoutInflater.from(context)
|
|
|
this.context = context
|
|
|
|
|
|
@@ -51,7 +61,12 @@ class HoldViewModel : BaseViewModel() {
|
|
|
return list?.size ?: 0
|
|
|
}
|
|
|
|
|
|
- class HoldHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
|
|
|
+ fun update(list: ArrayList<FutureHoldData>?) {
|
|
|
+ this.list = list
|
|
|
+ notifyDataSetChanged()
|
|
|
+ }
|
|
|
+
|
|
|
+ inner class HoldHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
|
|
|
var idGoodsName = itemView?.findViewById<TextView>(R.id.id_goods_name)
|
|
|
var idTransDirection = itemView?.findViewById<TextView>(R.id.id_trans_direction)
|
|
|
var idAvailable = itemView?.findViewById<TextView>(R.id.id_available)
|
|
|
@@ -64,14 +79,14 @@ class HoldViewModel : BaseViewModel() {
|
|
|
}
|
|
|
|
|
|
override fun onBindViewHolder(holder: HoldHolder, position: Int) {
|
|
|
- holder.idGoodsName?.text = list?.get(position)?.goodsName
|
|
|
- holder.idAvailable?.text = list?.get(position)?.available.toString()
|
|
|
- holder.idHoldTotal?.text = list?.get(position)?.totals.toString()
|
|
|
- holder.idLastPrice?.text = list?.get(position)?.lastPrice.toString()
|
|
|
- holder.idCost?.text = list?.get(position)?.cost.toString()
|
|
|
- holder.idPl?.text = list?.get(position)?.pl.toString()
|
|
|
- holder.idPlp?.text = list?.get(position)?.plp.toString()
|
|
|
- if (list?.get(position)?.direction == 0) {
|
|
|
+ holder.idGoodsName?.text = list?.get(position)?.goodsname
|
|
|
+ holder.idAvailable?.text = list?.get(position)?.enableqty.toString() // 可用(总仓可用)
|
|
|
+ holder.idHoldTotal?.text = list?.get(position)?.curpositionqty.toString() // 持仓(总仓数量, 期末头寸)
|
|
|
+ holder.idLastPrice?.text = list?.get(position)?.last.toString() // 现价
|
|
|
+ holder.idCost?.text = list?.get(position)?.positioncost.toString() // 持仓成本
|
|
|
+// holder.idPl?.text = list?.get(position)?.pl.toString() //
|
|
|
+// holder.idPlp?.text = list?.get(position)?.plp.toString() // 持仓盈亏比例
|
|
|
+ if (list?.get(position)?.buyorsell == 0) {
|
|
|
holder.idTransDirection?.text = context?.resources?.getString(R.string.str_buy)
|
|
|
} else {
|
|
|
holder.idTransDirection?.text = context?.resources?.getString(R.string.str_sell)
|
|
|
@@ -84,4 +99,24 @@ class HoldViewModel : BaseViewModel() {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询持仓单
|
|
|
+ */
|
|
|
+ fun queryHold() {
|
|
|
+ val params = mutableMapOf<String, String>()
|
|
|
+ params["accountID "] = SPUtils.getInstance().getLong(Constant.SELECT_ACCOUNT_ID).toString()
|
|
|
+ if (marketID != null) {
|
|
|
+ params["marketID"] = marketID!!
|
|
|
+ }
|
|
|
+ FutureManager().queryErmcpTradePosition(params) { isSuccess, respData, _ ->
|
|
|
+ if (isSuccess && !respData!!.isNullOrEmpty()) {
|
|
|
+ list = respData as ArrayList<FutureHoldData>
|
|
|
+ holdLiveData.value = list
|
|
|
+ } else {
|
|
|
+ // 没有数据或者接口返回错误的时候,通知界面没有获取到数据
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|