|
|
@@ -0,0 +1,353 @@
|
|
|
+package com.sheishuo.app.core_module.trade.view.ui.activity;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.ArrayAdapter;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.CompoundButton;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.RadioButton;
|
|
|
+import android.widget.SeekBar;
|
|
|
+import android.widget.Spinner;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.netease.nim.uikit.activity.GiftRechargeActivity;
|
|
|
+import com.netease.nim.uikit.common.media.picker.PickImageHelper;
|
|
|
+import com.netease.nim.uikit.common.media.picker.model.PhotoInfo;
|
|
|
+import com.sheishuo.app.R;
|
|
|
+import com.sheishuo.app.cache.AccountCache;
|
|
|
+import com.sheishuo.app.common.util.img.ImgUtil;
|
|
|
+import com.sheishuo.app.common.util.net.NetImpl;
|
|
|
+import com.sheishuo.app.common.util.net.ResponseCallback;
|
|
|
+import com.sheishuo.app.core_module.trade.model.TradeModel;
|
|
|
+import com.sheishuo.app.core_module.trade.presenter.TradePresenter;
|
|
|
+import com.sheishuo.app.core_module.trade.view.adapter.TradeItemAdapter;
|
|
|
+import com.sheishuo.app.impl.SheishuoUI;
|
|
|
+
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import jp.wasabeef.glide.transformations.ColorFilterTransformation;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by KN on 2017/8/23.
|
|
|
+ */
|
|
|
+
|
|
|
+public class TradePublishActivity extends SheishuoUI {
|
|
|
+
|
|
|
+ public final static String TEAM_ID = "team_id";
|
|
|
+
|
|
|
+ private String TAG = this.getClass().getSimpleName();
|
|
|
+ private Context context = this;
|
|
|
+
|
|
|
+ private TradePresenter presenter = new TradePresenter(this);
|
|
|
+
|
|
|
+ private EditText tradeContentET;
|
|
|
+
|
|
|
+ private Button publishBtn;
|
|
|
+
|
|
|
+ private RadioButton sellRadioBtn, buyRadioBtn;
|
|
|
+
|
|
|
+ private SeekBar prioritySeekbar;
|
|
|
+
|
|
|
+ private TextView priorityTV,emptyTipTV,balanceTV,rechargeTV;
|
|
|
+
|
|
|
+ private LinearLayout photosLayout,tradeLayout,parentLayout;
|
|
|
+
|
|
|
+ private String photosStr = "";
|
|
|
+
|
|
|
+ private List<String> selectedPhotoPathList = new ArrayList<>();
|
|
|
+
|
|
|
+ private List<String> photoIds = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ //Spinner
|
|
|
+ private Spinner spinner;
|
|
|
+ private List<String> priorityTypeList = new ArrayList<>();
|
|
|
+ private ArrayAdapter<String> adapter;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //FLAGS
|
|
|
+ private String teamId = "";
|
|
|
+ private String PRIORITY_TYPE = TradeItemAdapter.PRIORITY_COUNTRY;
|
|
|
+ private int TRADE_TYPE = TradeModel.TYPE_SELL;
|
|
|
+ private int RADIO_CHECKED;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ if (getIntent().getStringExtra(TEAM_ID) != null)
|
|
|
+ teamId = getIntent().getStringExtra(TEAM_ID);
|
|
|
+ setContentView(R.layout.trade_publish_activity);
|
|
|
+ findViews();
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void findViews() {
|
|
|
+ parentLayout = findView(R.id.trade_publish_parent_layout);
|
|
|
+ tradeLayout = findView(R.id.gift_panel_trade_layout);
|
|
|
+ emptyTipTV = findView(R.id.gift_panel_empty_tip_TV);
|
|
|
+ tradeContentET = findView(R.id.gift_panel_gift_message_ET);
|
|
|
+ publishBtn = findView(R.id.gift_panel_publish_btn);
|
|
|
+ sellRadioBtn = findView(R.id.gift_panel_sell_radio_btn);
|
|
|
+ buyRadioBtn = findView(R.id.gift_panel_buy_radio_btn);
|
|
|
+ spinner = findView(R.id.gift_panel_spinner);
|
|
|
+ prioritySeekbar = findView(R.id.gift_panel_num_seekbar);
|
|
|
+ priorityTV = findView(R.id.gift_panel_num_TV);
|
|
|
+ photosLayout = findView(R.id.gift_panel_photos_layout);
|
|
|
+ balanceTV = findView(R.id.gift_panel_balance_TV);
|
|
|
+ rechargeTV = findView(R.id.gift_panel_recharge_TV);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void init() {
|
|
|
+
|
|
|
+ //设置父Layout
|
|
|
+ parentLayout.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //初始化余额
|
|
|
+ balanceTV.setText(AccountCache.getAccount().getCoin());
|
|
|
+
|
|
|
+ //初始化充值
|
|
|
+ rechargeTV.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ startActivity(new Intent(context,GiftRechargeActivity.class));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //设置Spinner
|
|
|
+ priorityTypeList.add("国家道具");
|
|
|
+ priorityTypeList.add("省份道具");
|
|
|
+ priorityTypeList.add("城市道具");
|
|
|
+ priorityTypeList.add("地区道具");
|
|
|
+ adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, priorityTypeList);
|
|
|
+ spinner.setAdapter(adapter);
|
|
|
+ spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ PRIORITY_TYPE = String.valueOf(position);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNothingSelected(AdapterView<?> parent) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ //设置seekbar
|
|
|
+ prioritySeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
|
|
+ priorityTV.setText(String.valueOf(progress));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStartTrackingTouch(SeekBar seekBar) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStopTrackingTouch(SeekBar seekBar) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ //设置RadioButton
|
|
|
+ sellRadioBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
+ if(RADIO_CHECKED == R.id.gift_panel_sell_radio_btn){
|
|
|
+ sellRadioBtn.setChecked(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isChecked) {
|
|
|
+ tradeLayout.setVisibility(View.VISIBLE);
|
|
|
+ emptyTipTV.setVisibility(View.GONE);
|
|
|
+ TRADE_TYPE = TradeModel.TYPE_SELL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ buyRadioBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
+ if(RADIO_CHECKED == R.id.gift_panel_buy_radio_btn){
|
|
|
+ buyRadioBtn.setChecked(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isChecked) {
|
|
|
+ tradeLayout.setVisibility(View.VISIBLE);
|
|
|
+ emptyTipTV.setVisibility(View.GONE);
|
|
|
+ TRADE_TYPE = TradeModel.TYPE_BUY;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //初始化发布按钮
|
|
|
+ publishBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ publishBtn.setEnabled(false);
|
|
|
+ for (int i = 0;i < photoIds.size() ; i ++){
|
|
|
+ if (i == photoIds.size() - 1){
|
|
|
+ photosStr += photoIds.get(i);
|
|
|
+ }else {
|
|
|
+ photosStr += photoIds.get(i) + ",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Log.e(TAG,photosStr);
|
|
|
+
|
|
|
+ new NetImpl().publishTrade(TRADE_TYPE
|
|
|
+ , tradeContentET.getText().toString()
|
|
|
+ , photosStr
|
|
|
+ , Integer.valueOf(priorityTV.getText().toString())
|
|
|
+ , Integer.valueOf(PRIORITY_TYPE)
|
|
|
+ , teamId
|
|
|
+ , new ResponseCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object object) {
|
|
|
+ try {
|
|
|
+ int code = new JSONObject((String) object).getInt("c");
|
|
|
+ if (1 == code){
|
|
|
+ showToast(context,new JSONObject((String) object).getString("d"));
|
|
|
+ }else {
|
|
|
+ showToast(context,"发布成功");
|
|
|
+ }
|
|
|
+ finish();
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailed() {
|
|
|
+ showToast(context,"发布失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ //初始化photosLayout
|
|
|
+ photosLayout.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ PickImageHelper.PickImageOption option = new PickImageHelper.PickImageOption();
|
|
|
+ PickImageHelper.pickImage(context, 0, option);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ for (String key : data.getExtras().keySet()) {
|
|
|
+ Log.e("key", key);
|
|
|
+ }
|
|
|
+
|
|
|
+ Bundle result = data.getExtras();
|
|
|
+ if (!result.getBoolean("from_local")) {
|
|
|
+ //照相机
|
|
|
+ String filePath = result.getString("file_path");
|
|
|
+ //移除添加图片按钮
|
|
|
+ photosLayout.removeAllViews();
|
|
|
+
|
|
|
+ ImageView imageView = new ImageView(this);
|
|
|
+ imageView.setAdjustViewBounds(true);
|
|
|
+ int toDp = (int) ImgUtil.convertDpToPixel(128, context);
|
|
|
+ imageView.setLayoutParams(new LinearLayout.LayoutParams(toDp, toDp));
|
|
|
+ Glide.with(context).load(filePath)
|
|
|
+ .centerCrop()
|
|
|
+ .bitmapTransform(new ColorFilterTransformation(context, 0x7900CCCC))
|
|
|
+ .into(imageView);
|
|
|
+ photosLayout.addView(imageView);
|
|
|
+ selectedPhotoPathList.add(filePath);
|
|
|
+ presenter.uploadPhoto(filePath);
|
|
|
+ } else {
|
|
|
+ //相册
|
|
|
+
|
|
|
+ //移除添加图片按钮
|
|
|
+ photosLayout.removeAllViews();
|
|
|
+
|
|
|
+ List<PhotoInfo> photoInfoList = (List<PhotoInfo>) result.getSerializable("photo_list");
|
|
|
+ for (PhotoInfo info : photoInfoList) {
|
|
|
+ ImageView imageView = new ImageView(this);
|
|
|
+ imageView.setAdjustViewBounds(true);
|
|
|
+ int toDp = (int) ImgUtil.convertDpToPixel(128, context);
|
|
|
+ imageView.setLayoutParams(new LinearLayout.LayoutParams(toDp, toDp));
|
|
|
+ Glide.with(context).load(info.getFilePath())
|
|
|
+ .centerCrop()
|
|
|
+ .bitmapTransform(new ColorFilterTransformation(context, 0x7900CCCC))
|
|
|
+ .into(imageView);
|
|
|
+ photosLayout.addView(imageView);
|
|
|
+ selectedPhotoPathList.add(info.getAbsolutePath());
|
|
|
+ }
|
|
|
+
|
|
|
+ presenter.uploadPhoto(selectedPhotoPathList);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开放调用方法
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //当一张照片上传完成后回调
|
|
|
+ public void onOnePhotoUploaded(final int index, final int photoId){
|
|
|
+ getHandler().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ ImageView imageView = (ImageView) photosLayout.getChildAt(index);
|
|
|
+ String filePath = selectedPhotoPathList.get(index);
|
|
|
+ Glide.with(context).load(filePath).into(imageView);
|
|
|
+ Collections.synchronizedList(photoIds);
|
|
|
+ photoIds.add(String.valueOf(photoId));
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //全部照片上传完成
|
|
|
+ public void onAllPhotosUploaded(){
|
|
|
+ publishBtn.setEnabled(true);
|
|
|
+ }
|
|
|
+}
|