|
|
@@ -0,0 +1,368 @@
|
|
|
+package cn.muchinfo.rma.view.base.yrdzpurchase.adapter;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.ViewTreeObserver;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+
|
|
|
+import com.blankj.utilcode.util.ActivityUtils;
|
|
|
+import com.blankj.utilcode.util.ToastUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import cn.muchinfo.rma.R;
|
|
|
+import cn.muchinfo.rma.global.GlobalDataCollection;
|
|
|
+import cn.muchinfo.rma.global.data.ContractTradePositionData;
|
|
|
+import cn.muchinfo.rma.global.data.GoodsInfoAndQuotes;
|
|
|
+import cn.muchinfo.rma.global.data.QuoteDayData;
|
|
|
+import cn.muchinfo.rma.global.data.account.loginQeruy.GoodsInfo;
|
|
|
+import cn.muchinfo.rma.global.database.DataBase;
|
|
|
+import cn.muchinfo.rma.global.utils.TimeUtils;
|
|
|
+import cn.muchinfo.rma.view.autoWidget.CustomHorizontalScrollView;
|
|
|
+import cn.muchinfo.rma.view.autoWidget.utils.NumberUtils;
|
|
|
+import cn.muchinfo.rma.view.base.chart.ChartActivity;
|
|
|
+import cn.muchinfo.rma.view.base.platinumtreasure.PlatinumTrasureDetailsActivity;
|
|
|
+import cn.muchinfo.rma.view.base.platinumtreasure.adapter.QHjRightData;
|
|
|
+import cn.muchinfo.rma.view.base.platinumtreasure.adapter.QhjRightScrollAdapter;
|
|
|
+import cn.muchinfo.rma.view.base.platinumtreasure.trade.PlatinumTradeActivity;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用于千海金铂金宝页面额adapter
|
|
|
+ */
|
|
|
+public class TransferAdapter extends RecyclerView.Adapter<TransferAdapter.ItemViewHolder> {
|
|
|
+
|
|
|
+
|
|
|
+ private Context context;
|
|
|
+ private List<GoodsInfo> datas;
|
|
|
+ private int index = -1;
|
|
|
+ private int position = -1;
|
|
|
+ private List<ItemViewHolder> mViewHolderList = new ArrayList<>();
|
|
|
+ public int offestX = 0;
|
|
|
+ private OnContentScrollListener onContentScrollListener;
|
|
|
+
|
|
|
+
|
|
|
+ public interface OnContentScrollListener {
|
|
|
+ void onScroll(MotionEvent event);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setOnContentScrollListener(OnContentScrollListener onContentScrollListener) {
|
|
|
+ this.onContentScrollListener = onContentScrollListener;
|
|
|
+ }
|
|
|
+
|
|
|
+ public TransferAdapter(Context context) {
|
|
|
+ this.context = context;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setDatas(List<GoodsInfo> datas) {
|
|
|
+ this.datas = datas;
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setPosition(int position) {
|
|
|
+ if (this.position == position) {
|
|
|
+ this.position = -1;
|
|
|
+ notifyItemChanged(index);
|
|
|
+ } else {
|
|
|
+ this.position = position;
|
|
|
+ notifyItemChanged(position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @NonNull
|
|
|
+ @Override
|
|
|
+ public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
|
|
+ View view = LayoutInflater.from(context).inflate(R.layout.layout_item_transfer_content, viewGroup, false);
|
|
|
+ return new ItemViewHolder(view);
|
|
|
+ }
|
|
|
+
|
|
|
+ //回购 买一价 销售 卖一价
|
|
|
+ @SuppressLint("SetTextI18n")
|
|
|
+ @Override
|
|
|
+ public void onBindViewHolder(@NonNull final ItemViewHolder itemViewHolder, int i) {
|
|
|
+ this.index = i;
|
|
|
+ GoodsInfo data = datas.get(i);
|
|
|
+ itemViewHolder.tvLeftTitle.setText(datas.get(i).getGoodsname());
|
|
|
+ //右边滑动部分
|
|
|
+ LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
|
|
|
+ linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
+ itemViewHolder.rvItemRight.setLayoutManager(linearLayoutManager);
|
|
|
+ itemViewHolder.rvItemRight.setHasFixedSize(true);
|
|
|
+ QhjRightScrollAdapter qhjRightScrollAdapter = new QhjRightScrollAdapter(context);
|
|
|
+ List<QHjRightData> rightData = new ArrayList<>();
|
|
|
+ //获取盘面信息
|
|
|
+ QuoteDayData quoteDayData = null;//当前商品的盘面信息(有用的只有买一卖一价即回购销售价,其他信息用关联商品的)
|
|
|
+
|
|
|
+ GoodsInfo relateGoodsInfo = null;//关联商品实体
|
|
|
+ relateGoodsInfo = DataBase.Companion.getInstance().goodsInfoDao().getGoodsInfo(data.getRelatedgoodsid());//获取关联商品的商品详情
|
|
|
+ List<GoodsInfoAndQuotes> quotesList = GlobalDataCollection.Companion.getInstance().getGoodsInfoAndQuotesList();//获取盘面信息列表
|
|
|
+ for (int j = 0;j < quotesList.size();j++){
|
|
|
+ if (data.getOutgoodscode().equals(quotesList.get(j).getOutgoodscode())){
|
|
|
+ quoteDayData = quotesList.get(j).getQuoteDayData();//赋值当前商品的盘面信息
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (quoteDayData != null){
|
|
|
+ QHjRightData bidData = new QHjRightData();
|
|
|
+ bidData.setValue(NumberUtils.roundNum(NumberUtils.doubleDistortion(String.valueOf(quoteDayData.getBid())),2));//加入回购价买一价
|
|
|
+ bidData.setColorType("1");
|
|
|
+ rightData.add(bidData);
|
|
|
+
|
|
|
+ QHjRightData askData = new QHjRightData();
|
|
|
+ askData.setValue(NumberUtils.roundNum(NumberUtils.doubleDistortion(String.valueOf(quoteDayData.getAsk())),2));//加入销售价卖一价
|
|
|
+ askData.setColorType("1");
|
|
|
+ rightData.add(askData);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (quoteDayData != null){
|
|
|
+ //涨跌幅
|
|
|
+ QHjRightData appliesData = new QHjRightData();
|
|
|
+ //涨跌
|
|
|
+ QHjRightData riseFallData = new QHjRightData();
|
|
|
+ //今开
|
|
|
+ QHjRightData openRightData = new QHjRightData();
|
|
|
+ openRightData.setValue(NumberUtils.roundNum(NumberUtils.doubleDistortion(String.valueOf(quoteDayData.getOpened())),2));
|
|
|
+ double openRightDatColor = quoteDayData.getOpened() - quoteDayData.getPreclose();
|
|
|
+ if (openRightDatColor > 0){
|
|
|
+ openRightData.setColorType("3");
|
|
|
+ }else if (openRightDatColor < 0){
|
|
|
+ openRightData.setColorType("2");
|
|
|
+ }else {
|
|
|
+ openRightData.setColorType("1");
|
|
|
+ }
|
|
|
+ //最高价
|
|
|
+ QHjRightData highRightData = new QHjRightData();
|
|
|
+ highRightData.setValue(NumberUtils.roundNum(NumberUtils.doubleDistortion(String.valueOf(quoteDayData.getHighest())),2));
|
|
|
+ double highRightDatColor = quoteDayData.getHighest() - quoteDayData.getPreclose();
|
|
|
+ if (highRightDatColor > 0){
|
|
|
+ highRightData.setColorType("3");
|
|
|
+ }else if (highRightDatColor < 0){
|
|
|
+ highRightData.setColorType("2");
|
|
|
+ }else {
|
|
|
+ highRightData.setColorType("1");
|
|
|
+ }
|
|
|
+ highRightData.setColorType("1");
|
|
|
+ //最低价
|
|
|
+ QHjRightData lowestRightData = new QHjRightData();
|
|
|
+ lowestRightData.setValue(NumberUtils.roundNum(NumberUtils.doubleDistortion(String.valueOf(quoteDayData.getLowest())),data.getDecimalplace()));
|
|
|
+ double lowestRightDatColor = quoteDayData.getLowest() - quoteDayData.getPreclose();
|
|
|
+ if (lowestRightDatColor > 0){
|
|
|
+ lowestRightData.setColorType("3");
|
|
|
+ }else if (lowestRightDatColor < 0){
|
|
|
+ lowestRightData.setColorType("2");
|
|
|
+ }else {
|
|
|
+ lowestRightData.setColorType("1");
|
|
|
+ }
|
|
|
+ lowestRightData.setColorType("1");
|
|
|
+ //昨收价
|
|
|
+ QHjRightData yesCloseRightData = new QHjRightData();
|
|
|
+ yesCloseRightData.setValue(NumberUtils.roundNum(NumberUtils.doubleDistortion(String.valueOf(quoteDayData.getPreclose())),data.getDecimalplace()));
|
|
|
+ yesCloseRightData.setColorType("1");
|
|
|
+ //行情时间
|
|
|
+ QHjRightData timeRightData = new QHjRightData();
|
|
|
+ if (quoteDayData.getLasttime().isEmpty()){
|
|
|
+ timeRightData.setValue("--");
|
|
|
+ }else {
|
|
|
+ timeRightData.setValue(TimeUtils.formatTime2(quoteDayData.getLasttime(),"HH:mm:ss"));
|
|
|
+ }
|
|
|
+ timeRightData.setColorType("1");
|
|
|
+ if (quoteDayData.getLast() != 0 && quoteDayData.getPreclose() != 0) {
|
|
|
+ String textApplies = "";
|
|
|
+ String textUpDown = NumberUtils.roundNum(NumberUtils.doubleDistortion(String.valueOf((quoteDayData.getPrice() - quoteDayData.getPresettle()))),2);//涨跌
|
|
|
+ if (quoteDayData.getPresettle() == 0){
|
|
|
+ textApplies = "--";
|
|
|
+ }else {
|
|
|
+ textApplies = NumberUtils.roundNum(String.valueOf((((quoteDayData.getPrice() - quoteDayData.getPresettle()) / quoteDayData.getPresettle()) * 100)),2);//涨跌幅
|
|
|
+ }
|
|
|
+ riseFallData.setValue(textUpDown);
|
|
|
+ appliesData.setValue(textApplies + "%");
|
|
|
+ if (Double.valueOf(textUpDown) > 0){
|
|
|
+ riseFallData.setColorType("3");
|
|
|
+ appliesData.setColorType("3");
|
|
|
+ }else if (Double.valueOf(textUpDown) < 0){
|
|
|
+ riseFallData.setColorType("2");
|
|
|
+ appliesData.setColorType("2");
|
|
|
+ }else {
|
|
|
+ riseFallData.setColorType("1");
|
|
|
+ appliesData.setColorType("1");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ appliesData.setValue("--");
|
|
|
+ appliesData.setColorType("1");
|
|
|
+ riseFallData.setValue("--");
|
|
|
+ riseFallData.setColorType("1");
|
|
|
+ }
|
|
|
+ rightData.add(appliesData);//涨跌幅
|
|
|
+ rightData.add(riseFallData);//涨跌
|
|
|
+ rightData.add(openRightData);//今开
|
|
|
+ rightData.add(highRightData);//最高
|
|
|
+ rightData.add(lowestRightData);//最低
|
|
|
+ rightData.add(yesCloseRightData);//昨收
|
|
|
+ rightData.add(timeRightData);//时间
|
|
|
+ }
|
|
|
+ ContractTradePositionData positionData = null;
|
|
|
+ List<ContractTradePositionData> positionDataList = GlobalDataCollection.Companion.getInstance().getContractTradePositionDataArrayList();
|
|
|
+ for (int j = 0;j < positionDataList.size();j++){
|
|
|
+ if (String.valueOf(data.getGoodsid()).equals(positionDataList.get(j).getGoodsid())){
|
|
|
+ positionData = positionDataList.get(j);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ qhjRightScrollAdapter.setDatas(rightData);
|
|
|
+ itemViewHolder.rvItemRight.setAdapter(qhjRightScrollAdapter);
|
|
|
+ //缓存当前holder
|
|
|
+ if (!mViewHolderList.contains(itemViewHolder)) {
|
|
|
+ mViewHolderList.add(itemViewHolder);
|
|
|
+ }
|
|
|
+ if (i == this.position) {
|
|
|
+ itemViewHolder.roots_view.setBackgroundColor(context.getResources().getColor(R.color.qhj_click_bg));
|
|
|
+ itemViewHolder.allView.setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ itemViewHolder.roots_view.setBackgroundColor(context.getResources().getColor(R.color.white));
|
|
|
+ itemViewHolder.allView.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ itemViewHolder.all_click_View.setOnClickListener(view -> setPosition(i));
|
|
|
+ itemViewHolder.horItemScrollview.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ setPosition(i);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //买入点击
|
|
|
+ itemViewHolder.transfer_buy.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("goodsId",String.valueOf(data.getGoodsid()));
|
|
|
+ intent.putExtra("outGoodsCode",data.getGoodscode());
|
|
|
+ intent.putExtra("index",0);
|
|
|
+ intent.setClass(context, PlatinumTradeActivity.class);
|
|
|
+ ActivityUtils.startActivity(intent);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //图表点击
|
|
|
+ itemViewHolder.platnum_chart.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ GoodsInfo goodsInfo = DataBase.Companion.getInstance().goodsInfoDao().getGoodsInfo(data.getRelatedgoodsid());
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("outGoodsCode", goodsInfo.getOutgoodscode());
|
|
|
+ intent.putExtra("goodsCode", goodsInfo.getGoodscode());
|
|
|
+ intent.putExtra("goodsId", String.valueOf(goodsInfo.getGoodsid()));
|
|
|
+// intent.putExtra("goodsGroupId", list?.get(position)?.goodsgroupid)
|
|
|
+ intent.putExtra("marketId", String.valueOf(goodsInfo.getMarketid()));
|
|
|
+ intent.setClass(context, ChartActivity.class);
|
|
|
+ ActivityUtils.startActivity(intent);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (data.getPictureurl().isEmpty()){
|
|
|
+ itemViewHolder.platnum_details.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ //详情点击
|
|
|
+ itemViewHolder.platnum_details.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("goodsname",data.getGoodsname());
|
|
|
+ intent.putExtra("imageString",data.getPictureurl());
|
|
|
+ intent.setClass(context, PlatinumTrasureDetailsActivity.class);
|
|
|
+ ActivityUtils.startActivity(intent);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ itemViewHolder.rvItemRight.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ ToastUtils.showLong("ahhahahha");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ itemViewHolder.horItemScrollview.setEventListener(new CustomHorizontalScrollView.EventListener() {
|
|
|
+ @Override
|
|
|
+ public void onEvent(MotionEvent ev) {
|
|
|
+
|
|
|
+ if (null != onContentScrollListener) onContentScrollListener.onScroll(ev);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //由于viewHolder的缓存,在1级缓存取出来是2个viewholder,并且不会被重新赋值,所以这里需要处理缓存的viewholder的位移
|
|
|
+ itemViewHolder.horItemScrollview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
+ @Override
|
|
|
+ public void onGlobalLayout() {
|
|
|
+ if (!itemViewHolder.isLayoutFinish()) {
|
|
|
+ itemViewHolder.horItemScrollview.scrollTo(offestX, 0);
|
|
|
+ itemViewHolder.setLayoutFinish(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ float start, end;
|
|
|
+ float distance = 0;
|
|
|
+ boolean isclick = false;
|
|
|
+ boolean isFirst = false;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getItemCount() {
|
|
|
+ return null == datas ? 0 : datas.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ItemViewHolder> getViewHolderCacheList() {
|
|
|
+ return mViewHolderList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getOffestX() {
|
|
|
+ return offestX;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class ItemViewHolder extends RecyclerView.ViewHolder {
|
|
|
+ LinearLayout roots_view;//根部布局
|
|
|
+ TextView transfer_buy;//买卖大厅
|
|
|
+ TextView platnum_chart;//图表
|
|
|
+ TextView platnum_details;//详情
|
|
|
+ LinearLayout allView;//隐藏的底部操作空间
|
|
|
+ LinearLayout all_click_View;//item左侧点击控件
|
|
|
+ RelativeLayout item_onclick;
|
|
|
+ TextView tvLeftTitle;//左边销售方字段
|
|
|
+ RecyclerView rvItemRight;//右方的列表
|
|
|
+ ImageView click_icon;//图标
|
|
|
+ public CustomHorizontalScrollView horItemScrollview;//右方的滑动控件
|
|
|
+ private boolean isLayoutFinish;//自定义字段,用于标记layout
|
|
|
+
|
|
|
+ public boolean isLayoutFinish() {
|
|
|
+ return isLayoutFinish;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setLayoutFinish(boolean layoutFinish) {
|
|
|
+ isLayoutFinish = layoutFinish;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ItemViewHolder(@NonNull View itemView) {
|
|
|
+ super(itemView);
|
|
|
+ item_onclick = itemView.findViewById(R.id.item_onclick);
|
|
|
+ click_icon = itemView.findViewById(R.id.click_icon);
|
|
|
+ transfer_buy = itemView.findViewById(R.id.transfer_buy);
|
|
|
+ platnum_chart = itemView.findViewById(R.id.platnum_chart);
|
|
|
+ platnum_details = itemView.findViewById(R.id.platnum_details);
|
|
|
+ tvLeftTitle = itemView.findViewById(R.id.tv_left_title);
|
|
|
+ rvItemRight = itemView.findViewById(R.id.rv_item_right);
|
|
|
+ horItemScrollview = itemView.findViewById(R.id.hor_item_scrollview);
|
|
|
+ allView = itemView.findViewById(R.id.all_view);
|
|
|
+ all_click_View = itemView.findViewById(R.id.all_click_View);
|
|
|
+ roots_view = itemView.findViewById(R.id.roots_view);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|