Browse Source

图片上传

dxh 6 years ago
parent
commit
313a41b7a1

+ 5 - 0
app/src/main/java/com/electric/chargingpile/activity/PublishItemsActivity.java

61
61
62
    @Override
62
    @Override
63
    public void onClick(View v) {
63
    public void onClick(View v) {
64
        if (!MainApplication.isLogin()){
65
            startActivity(new Intent(this.getApplicationContext(),LoginActivity.class));
66
            ToastUtil.showToast(this.getApplicationContext(),"请先登录", Toast.LENGTH_SHORT);
67
            return;
68
        }
64
        switch (v.getId()) {
69
        switch (v.getId()) {
65
            case R.id.publish_qa:
70
            case R.id.publish_qa:
66
                if (MainApplication.isLogin()){
71
                if (MainApplication.isLogin()){

+ 59 - 4
app/src/main/java/com/electric/chargingpile/activity/PublishPicTopicActivity.java

47
import com.electric.chargingpile.R;
47
import com.electric.chargingpile.R;
48
import com.electric.chargingpile.application.MainApplication;
48
import com.electric.chargingpile.application.MainApplication;
49
import com.electric.chargingpile.data.AuthSignBean;
49
import com.electric.chargingpile.data.AuthSignBean;
50
import com.electric.chargingpile.data.HomePageBean;
50
import com.electric.chargingpile.data.TalkRecommendBean;
51
import com.electric.chargingpile.data.TalkRecommendBean;
51
import com.electric.chargingpile.data.UploadPic;
52
import com.electric.chargingpile.data.UploadPic;
52
import com.electric.chargingpile.util.BarColorUtil;
53
import com.electric.chargingpile.util.BarColorUtil;
124
125
125
    private TextView publishtopic_choose_topic, mPublishtopicChooseTopic;
126
    private TextView publishtopic_choose_topic, mPublishtopicChooseTopic;
126
127
128
    private String topicId = "";
127
    //空间名
129
    //空间名
128
    public static String SPACE = "d1evcom01-fs";
130
    public static String SPACE = "d1evcom01-fs";
129
    private String policy = "";
131
    private String policy = "";
186
                    }
188
                    }
187
                }
189
                }
188
190
191
                dialog.show();
189
                //获取又拍云数据
192
                //获取又拍云数据
190
                getYouPaiData();
193
                getYouPaiData();
191
194
279
                    ArrayList<AuthSignBean> signBeans = (ArrayList<AuthSignBean>) JsonUtils.parseToObjectList(rtnMsg, AuthSignBean.class);
282
                    ArrayList<AuthSignBean> signBeans = (ArrayList<AuthSignBean>) JsonUtils.parseToObjectList(rtnMsg, AuthSignBean.class);
280
283
281
                    if (null != signBeans && signBeans.size() > 0) {
284
                    if (null != signBeans && signBeans.size() > 0) {
282
                       String sign = signBeans.get(0).sign;
283
                       policy = signBeans.get(0).policy;
284
285
                        formUpload(Bimp.tempSelectBitmap.get(0).getImagePath(), sign,  policy);
286
285
286
                        publishCount = signBeans.size();
287
                        for(int i=0;i<publishCount;i++){
288
                            String sign = signBeans.get(i).sign;
289
                            String policy = signBeans.get(i).policy;
290
                            formUpload(Bimp.tempSelectBitmap.get(i).getImagePath(), sign,  policy);
291
                        }
287
292
288
                    }
293
                    }
289
                }
294
                }
292
297
293
    }
298
    }
294
299
300
    private ArrayList<String> publishArray = new ArrayList<>();
301
    private int publishCount = 0;
302
295
    final int reqTopic = -100;
303
    final int reqTopic = -100;
296
304
297
    @Override
305
    @Override
462
            talkRecommendBean = (TalkRecommendBean) data.getSerializableExtra("topic");
470
            talkRecommendBean = (TalkRecommendBean) data.getSerializableExtra("topic");
463
            if (talkRecommendBean != null) {
471
            if (talkRecommendBean != null) {
464
                mPublishtopicChooseTopic.setText("# " + talkRecommendBean.name);
472
                mPublishtopicChooseTopic.setText("# " + talkRecommendBean.name);
473
                topicId = talkRecommendBean.topicId+"";
465
                mPublishTopicDe.setVisibility(View.VISIBLE);
474
                mPublishTopicDe.setVisibility(View.VISIBLE);
466
            }
475
            }
467
        }
476
        }
795
            public void onComplete(boolean isSuccess, String result) {
804
            public void onComplete(boolean isSuccess, String result) {
796
//                tv_form.setText(isSuccess + ":" + result);
805
//                tv_form.setText(isSuccess + ":" + result);
797
                Log.e(TAG, isSuccess + ":" + result);
806
                Log.e(TAG, isSuccess + ":" + result);
807
                if(isSuccess)
808
                    publishArray.add(result);
809
                if(publishCount == publishArray.size()){
810
                    String urls= "";
811
                    for(int i=0;i<publishArray.size();i++){
812
                        if(TextUtils.isEmpty(urls))
813
                            urls = publishArray.get(i);
814
                        else
815
                            urls = urls+","+publishArray.get(i);
816
                    }
817
                    requestPublishServer("["+urls+"]");
818
                }
798
            }
819
            }
799
        };
820
        };
800
821
805
    }
826
    }
806
827
807
828
829
    private void requestPublishServer(String urls){
830
        String url = MainApplication.urlNew + "/topic/publish.do";
831
        Map<String, String> map = new HashMap<>();
832
        map.put("content", et_context.getText().toString());
833
        map.put("urls", urls);
834
        map.put("topicId", topicId);
835
        if (MainApplication.isLogin()) {
836
            map.put("userId", MainApplication.userId);
837
        }
838
        OkHttpUtils.post().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
839
            @Override
840
            public void onError(Call call, Exception e) {
841
                dialog.cancel();
842
                publishArray.clear();
843
                publishCount = 0;
844
                ToastUtil.showToast(getApplicationContext(), "发布失败,请重试", Toast.LENGTH_SHORT);
845
            }
846
847
            @Override
848
            public void onResponse(String response) {
849
                Log.e(TAG, "response:" + response);
850
                dialog.cancel();
851
                publishArray.clear();
852
                publishCount = 0;
853
                String rtnCode = JsonUtils.getKeyResult(response, "code");
854
                if ("1000".equals(rtnCode)) {
855
                    ToastUtil.showToast(getApplicationContext(), "发布成功", Toast.LENGTH_SHORT);
856
                }else {
857
                    String message = JsonUtils.getKeyResult(response, "desc");
858
                    ToastUtil.showToast(getApplicationContext(), message, Toast.LENGTH_SHORT);
859
                }
860
            }
861
        });
862
    }
808
}
863
}

+ 3 - 2
app/src/main/res/layout/activity_publish_picture_content.xml

219

219

220
    <TextView
220
    <TextView
221
        android:id="@+id/publishtopic_choose_preview"
221
        android:id="@+id/publishtopic_choose_preview"
222
        android:layout_width="wrap_content"
222
        android:layout_width="1dp"
223
        android:layout_height="49dp"
223
        android:layout_height="49dp"
224
        android:layout_alignParentEnd="true"
224
        android:layout_alignParentEnd="true"
225
        android:layout_alignParentBottom="true"
225
        android:layout_alignParentBottom="true"
230
        android:paddingEnd="15dp"
230
        android:paddingEnd="15dp"
231
        android:text="预览"
231
        android:text="预览"
232
        android:textColor="#b2b2b2"
232
        android:textColor="#b2b2b2"
233
        android:textSize="14sp" />
233
        android:textSize="14sp"
234
        android:visibility="invisible"/>
234

235

235
    <TextView
236
    <TextView
236
        android:id="@+id/publishtopic_word_num"
237
        android:id="@+id/publishtopic_word_num"