|
|
@@ -3,6 +3,8 @@ package com.uas.appworks.OA.platform.activity;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Intent;
|
|
|
import android.support.v7.widget.AppCompatButton;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
import android.text.Editable;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
@@ -35,6 +37,8 @@ import com.modular.apputils.listener.OnSmartHttpListener;
|
|
|
import com.modular.apputils.network.Parameter;
|
|
|
import com.modular.apputils.network.Tags;
|
|
|
import com.modular.apputils.utils.TestStr;
|
|
|
+import com.uas.appworks.OA.platform.adapter.PurchaseDetailsAdapter;
|
|
|
+import com.uas.appworks.OA.platform.model.Purchase;
|
|
|
import com.uas.appworks.R;
|
|
|
|
|
|
|
|
|
@@ -48,14 +52,13 @@ import java.util.List;
|
|
|
* Created by Bitlike on 2018/1/15.
|
|
|
*/
|
|
|
|
|
|
-public class PurchaseDetailsActivity extends BaseNetActivity implements View.OnClickListener, OnSmartHttpListener {
|
|
|
+public class PurchaseDetailsActivity extends BaseNetActivity implements OnSmartHttpListener {
|
|
|
|
|
|
private long varId;
|
|
|
private String varStatus;
|
|
|
|
|
|
- private AppCompatButton replyBtn;
|
|
|
- private ListView mListView;
|
|
|
- private DataAdapter mAdapter;
|
|
|
+ private RecyclerView mRecyclerView;
|
|
|
+ private PurchaseDetailsAdapter mAdapter;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
@@ -78,96 +81,19 @@ public class PurchaseDetailsActivity extends BaseNetActivity implements View.OnC
|
|
|
varStatus = "";
|
|
|
}
|
|
|
initView();
|
|
|
+ initData();
|
|
|
}
|
|
|
|
|
|
private void initView() {
|
|
|
- replyBtn = findViewById(R.id.replyBtn);
|
|
|
- mListView = findViewById(R.id.mListView);
|
|
|
- if (varStatus.equals("已结案")) {
|
|
|
- replyBtn.setVisibility(View.GONE);
|
|
|
- replyBtn.setFocusable(false);
|
|
|
- replyBtn.setClickable(false);
|
|
|
- replyBtn.setPressed(true);
|
|
|
- } else {
|
|
|
- replyBtn.setOnClickListener(this);
|
|
|
- }
|
|
|
+ mRecyclerView = findViewById(R.id.mRecyclerView);
|
|
|
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(ct));
|
|
|
|
|
|
- initData();
|
|
|
}
|
|
|
|
|
|
private void initData() {
|
|
|
- ThreadPool.getThreadPool().addTask(new Runnable() {
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- JSONObject object = JSON.parseObject(TestStr.PURCHASE_STR);
|
|
|
- List<Data> dataList = new ArrayList<>();
|
|
|
- //添加头部固定功能
|
|
|
- Data data = new Data();
|
|
|
- Item item = new Item();
|
|
|
- item.field = "客户";
|
|
|
- item.values = JSONUtil.getText(object, "CLIENT");
|
|
|
- data.add(item);
|
|
|
- item = new Item();
|
|
|
- item.field = "收货地址";
|
|
|
- item.values = JSONUtil.getText(object, "ADDRESS");
|
|
|
- data.add(item);
|
|
|
- item = new Item();
|
|
|
- item.field = "订单号";
|
|
|
- item.values = JSONUtil.getText(object, "CODE");
|
|
|
- data.add(item);
|
|
|
- item = new Item();
|
|
|
- item.field = "单据时间";
|
|
|
- item.values = JSONUtil.getText(object, "TIME");
|
|
|
- data.add(item);
|
|
|
- item = new Item();
|
|
|
- item.field = "备注";
|
|
|
- item.values = JSONUtil.getText(object, "REMARKS");
|
|
|
- data.add(item);
|
|
|
- item = new Item();
|
|
|
- item.field = "总额";
|
|
|
- item.values = JSONUtil.getText(object, "ALLS");
|
|
|
- data.add(item);
|
|
|
- dataList.add(data);
|
|
|
- JSONArray dataJSONs = JSONUtil.getJSONArray(object, "DATA");
|
|
|
- JSONArray fields = JSONUtil.getJSONArray(object, "fields");
|
|
|
- if (!ListUtils.isEmpty(dataJSONs) && !ListUtils.isEmpty(fields)) {
|
|
|
- for (int i = 0; i < dataJSONs.size(); i++) {
|
|
|
- JSONObject dataJSON = dataJSONs.getJSONObject(i);
|
|
|
- Data dataIn = new Data();
|
|
|
- for (int j = 0; j < fields.size(); j++) {
|
|
|
- JSONObject field = fields.getJSONObject(j);
|
|
|
- Item it = new Item();
|
|
|
- it.field = JSONUtil.getText(field, "caption");
|
|
|
- it.type = JSONUtil.getText(field, "type");
|
|
|
- it.needInput = JSONUtil.getBoolean(field, "needInput");
|
|
|
- String fiel = JSONUtil.getText(field, "caption");
|
|
|
- it.values = JSONUtil.getText(dataJSON, fiel);
|
|
|
- dataIn.add(it);
|
|
|
- }
|
|
|
- dataList.add(dataIn);
|
|
|
- }
|
|
|
- }
|
|
|
- mAdapter = new DataAdapter(dataList);
|
|
|
- OAHttpHelper.getInstance().post(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- mListView.setAdapter(mAdapter);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
+ handleMessage(TestStr.PURCHASE_STR);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- int id = v.getId();
|
|
|
- if (id == R.id.replyBtn) {
|
|
|
- verifiReply();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
private void verifiReply() {
|
|
|
reply();
|
|
|
@@ -182,214 +108,83 @@ public class PurchaseDetailsActivity extends BaseNetActivity implements View.OnC
|
|
|
requestHttp(builder, this);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSuccess(int what, String message, Tags tag) throws Exception {
|
|
|
-
|
|
|
+ private Purchase getPurchase(int id, JSONObject object, String caption, String field) {
|
|
|
+ Purchase purchase = new Purchase(id);
|
|
|
+ purchase.setCaption(caption);
|
|
|
+ purchase.setField(field);
|
|
|
+ purchase.setValues(JSONUtil.getText(object, purchase.getField()));
|
|
|
+ return purchase;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onFailure(int what, String message, Tags tag) throws Exception {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private class DataAdapter extends BaseAdapter {
|
|
|
- private List<Data> datas;
|
|
|
-
|
|
|
- public DataAdapter(List<Data> datas) {
|
|
|
- this.datas = datas;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getCount() {
|
|
|
- return ListUtils.getSize(datas);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object getItem(int position) {
|
|
|
- return datas.get(position);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public long getItemId(int position) {
|
|
|
- return position;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
- ListView dataListView = null;
|
|
|
- if (convertView == null || !(convertView instanceof ListView)) {
|
|
|
- convertView = LayoutInflater.from(ct).inflate(R.layout.item_ls_purchase, null);
|
|
|
- dataListView = convertView.findViewById(R.id.dataListView);
|
|
|
- convertView.setTag(dataListView);
|
|
|
- } else {
|
|
|
- dataListView = (ListView) convertView;
|
|
|
- }
|
|
|
- dataListView.setAdapter(new ItemAdapter(position, datas.get(position).datas));
|
|
|
- return convertView;
|
|
|
- }
|
|
|
-
|
|
|
- private class ItemAdapter extends BaseAdapter {
|
|
|
- private int group;
|
|
|
- private List<Item> items;
|
|
|
-
|
|
|
- public ItemAdapter(int group, List<Item> items) {
|
|
|
- this.group = group;
|
|
|
- this.items = items;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getCount() {
|
|
|
- return ListUtils.getSize(items);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Item getItem(int position) {
|
|
|
- return items.get(position);
|
|
|
- }
|
|
|
-
|
|
|
+ private void handleMessage(final String message) {
|
|
|
+ ThreadPool.getThreadPool().addTask(new Runnable() {
|
|
|
@Override
|
|
|
- public long getItemId(int position) {
|
|
|
- return position;
|
|
|
- }
|
|
|
+ public void run() {
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ final List<Purchase> dataList = new ArrayList<>();
|
|
|
+ //添加头部固定功能
|
|
|
+ dataList.add(getPurchase(0, object, "客户", "CLIENT"));
|
|
|
+ dataList.add(getPurchase(0, object, "收货地址", "ADDRESS"));
|
|
|
+ dataList.add(getPurchase(0, object, "订单号", "CODE"));
|
|
|
+ dataList.add(getPurchase(0, object, "单据时间", "TIME"));
|
|
|
+ dataList.add(getPurchase(0, object, "备注", "REMARKS"));
|
|
|
+ dataList.add(getPurchase(0, object, "总额", "ALLS"));
|
|
|
|
|
|
- @Override
|
|
|
- public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
- Item item = getItem(position);
|
|
|
- ViewHolder holder = null;
|
|
|
- if (convertView == null) {
|
|
|
- holder = new ViewHolder();
|
|
|
- convertView = LayoutInflater.from(ct).inflate(R.layout.item_purchase, null);
|
|
|
- holder.captionTV = convertView.findViewById(R.id.captionTV);
|
|
|
- holder.valueEt = convertView.findViewById(R.id.valueEt);
|
|
|
- holder.valueTv = convertView.findViewById(R.id.valueTv);
|
|
|
- convertView.setTag(holder);
|
|
|
- } else {
|
|
|
- holder = (ViewHolder) convertView.getTag();
|
|
|
- }
|
|
|
- holder.captionTV.setText(item.field);
|
|
|
- TextChangListener textChangListener = null;
|
|
|
- if (convertView.getTag(R.id.tag_key) != null && convertView.getTag(R.id.tag_key) instanceof TextChangListener) {
|
|
|
- textChangListener = (TextChangListener) convertView.getTag(R.id.tag_key);
|
|
|
- }
|
|
|
- if (item.needInput) {
|
|
|
- holder.valueEt.setBackgroundResource(R.drawable.edit_hint_right_angle);
|
|
|
- holder.valueEt.setClickable(true);
|
|
|
- if (item.type.equals("date")) {
|
|
|
- holder.valueTv.setText(item.values);
|
|
|
- holder.valueTv.setBackgroundResource(R.drawable.edit_hint_right_angle);
|
|
|
- holder.valueEt.setVisibility(View.GONE);
|
|
|
- holder.valueTv.setVisibility(View.VISIBLE);
|
|
|
- holder.valueTv.setTag(position);
|
|
|
- holder.valueTv.setOnClickListener(onClickListener);
|
|
|
- } else {
|
|
|
- holder.valueEt.setText(item.values);
|
|
|
- holder.valueTv.setVisibility(View.GONE);
|
|
|
- holder.valueEt.setVisibility(View.VISIBLE);
|
|
|
- holder.valueEt.setFocusable(true);
|
|
|
- if (textChangListener == null) {
|
|
|
- textChangListener = new TextChangListener(holder, position);
|
|
|
- convertView.setTag(R.id.tag_key, textChangListener);
|
|
|
- }
|
|
|
- holder.valueEt.addTextChangedListener(textChangListener);
|
|
|
- }
|
|
|
- } else {
|
|
|
- holder.valueTv.setText(item.values);
|
|
|
- holder.valueTv.setBackgroundDrawable(null);
|
|
|
- holder.valueEt.setVisibility(View.GONE);
|
|
|
- holder.valueTv.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
- return convertView;
|
|
|
- }
|
|
|
+ JSONArray dataJSONs = JSONUtil.getJSONArray(object, "DATA");
|
|
|
+ JSONArray fields = JSONUtil.getJSONArray(object, "fields");
|
|
|
|
|
|
- private View.OnClickListener onClickListener = new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- if (v != null && v.getTag() != null && v.getTag() instanceof Integer) {
|
|
|
- int position = (int) v.getTag();
|
|
|
- showDateSelect(position);
|
|
|
+ String idField = null;
|
|
|
+ for (int j = 0; j < fields.size(); j++) {
|
|
|
+ if ("ID".equals(JSONUtil.getText(fields.getJSONObject(j), "caption"))) {
|
|
|
+ idField = JSONUtil.getText(fields.getJSONObject(j), "field");
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- };
|
|
|
-
|
|
|
- private class TextChangListener extends EditChangeListener {
|
|
|
- ViewHolder hodler;
|
|
|
- private int position;
|
|
|
-
|
|
|
- public TextChangListener(ViewHolder hodler, int position) {
|
|
|
- this.hodler = hodler;
|
|
|
- this.position = position;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void afterTextChanged(Editable s) {
|
|
|
- if (this.position >= 0 && ListUtils.getSize(items) > this.position) {
|
|
|
- if (this.hodler.valueEt != null && this.hodler.valueEt.getVisibility() == View.VISIBLE) {
|
|
|
- String valueEt = this.hodler.valueEt.getText().toString();
|
|
|
- LogUtil.i("valueEt="+valueEt);
|
|
|
- LogUtil.i("s="+s.toString());
|
|
|
- LogUtil.i("position="+this.position);
|
|
|
- items.get(this.position).values =valueEt == null ? "" : valueEt;
|
|
|
+ if (!ListUtils.isEmpty(dataJSONs) && !ListUtils.isEmpty(fields)) {
|
|
|
+ for (int i = 0; i < dataJSONs.size(); i++) {
|
|
|
+ JSONObject dataJSON = dataJSONs.getJSONObject(i);
|
|
|
+ for (int j = 0; j < fields.size(); j++) {
|
|
|
+ JSONObject fieldJSON = fields.getJSONObject(j);
|
|
|
+ Purchase purchaseItem = new Purchase();
|
|
|
+ purchaseItem.setField(JSONUtil.getText(fieldJSON, "field"));
|
|
|
+ purchaseItem.setCaption(JSONUtil.getText(fieldJSON, "caption"));
|
|
|
+ purchaseItem.setType(JSONUtil.getText(fieldJSON, "type"));
|
|
|
+ purchaseItem.setNeedInput(JSONUtil.getBoolean(fieldJSON, "needInput"));
|
|
|
+ purchaseItem.setValues(JSONUtil.getText(dataJSON, purchaseItem.getField()));
|
|
|
+ purchaseItem.setId(JSONUtil.getInt(dataJSON, idField));
|
|
|
+ dataList.add(purchaseItem);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- private void showDateSelect(final int position) {
|
|
|
- DateTimePicker picker = new DateTimePicker(ct, DateTimePicker.YEAR_MONTH_DAY);
|
|
|
- picker.setRange(2000, 2030);
|
|
|
- int year, month, day;
|
|
|
- Date time = null;
|
|
|
- if (ListUtils.getSize(items) > position && !StringUtil.isEmpty(items.get(position).values)) {
|
|
|
- time = DateFormatUtil.str2date(items.get(position).values, DateFormatUtil.YMD);
|
|
|
- }
|
|
|
- year = CalendarUtil.getYear(time);
|
|
|
- month = CalendarUtil.getMonth(time);
|
|
|
- day = CalendarUtil.getDay(time);
|
|
|
- LogUtil.i("year="+year);
|
|
|
- LogUtil.i("month="+month);
|
|
|
- LogUtil.i("day="+day);
|
|
|
- picker.setSelectedItem(year, month, day);
|
|
|
- picker.setOnDateTimePickListener(new DateTimePicker.OnYearMonthDayTimePickListener() {
|
|
|
+ OAHttpHelper.getInstance().post(new Runnable() {
|
|
|
@Override
|
|
|
- public void onDateTimePicked(String year, String month, String day, String hour, String minute) {
|
|
|
- if (ListUtils.getSize(items) > position) {
|
|
|
- items.get(position).values = year + "-" + month + "-" + day;
|
|
|
- DataAdapter.this.notifyDataSetChanged();
|
|
|
- }
|
|
|
+ public void run() {
|
|
|
+ setData2Adapter(dataList);
|
|
|
}
|
|
|
});
|
|
|
- picker.show();
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- class ViewHolder {
|
|
|
- TextView captionTV, valueTv;
|
|
|
- EditText valueEt;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- private class Data {
|
|
|
- List<Item> datas;
|
|
|
-
|
|
|
- public void add(Item item) {
|
|
|
- if (item == null) return;
|
|
|
- if (datas == null) {
|
|
|
- datas = new ArrayList<>();
|
|
|
+ private void setData2Adapter(List<Purchase> dataList) {
|
|
|
+ mAdapter = new PurchaseDetailsAdapter(ct, varStatus, dataList);
|
|
|
+ mAdapter.setOnReplyLisenter(new PurchaseDetailsAdapter.OnReplyLisenter() {
|
|
|
+ @Override
|
|
|
+ public void reply(List<Purchase> purchases) {
|
|
|
+ LogUtil.prinlnLongMsg("gongpengming","json="+JSON.toJSONString(purchases));
|
|
|
}
|
|
|
- datas.add(item);
|
|
|
- }
|
|
|
+ });
|
|
|
+ mRecyclerView.setAdapter(mAdapter);
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int what, String message, Tags tag) throws Exception {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public class Item {
|
|
|
- String field = "";
|
|
|
- String values = "";
|
|
|
- String type = "";
|
|
|
- boolean needInput = false;
|
|
|
+ @Override
|
|
|
+ public void onFailure(int what, String message, Tags tag) throws Exception {
|
|
|
+
|
|
|
}
|
|
|
}
|