Browse Source

又拍云sdk

dxh 6 years ago
parent
commit
c6922e5de9

+ 1 - 0
app/build.gradle

279
    compile project(':XRefreshView')
279
    compile project(':XRefreshView')
280
    compile 'com.github.Aspsine:IRecyclerView:0.0.7'
280
    compile 'com.github.Aspsine:IRecyclerView:0.0.7'
281
    compile project(':ijkplayer-java')
281
    compile project(':ijkplayer-java')
282
    compile 'com.upyun:upyun-android-sdk:+'
282
}
283
}

+ 3 - 0
app/src/main/AndroidManifest.xml

1007
        <activity
1007
        <activity
1008
            android:name=".activity.PersonalPageActivity"
1008
            android:name=".activity.PersonalPageActivity"
1009
            android:screenOrientation="portrait" />
1009
            android:screenOrientation="portrait" />
1010
        <activity
1011
            android:name=".activity.TopicDetailsActivity"
1012
            android:screenOrientation="portrait" />
1010
    </application>
1013
    </application>
1011
1014
1012
</manifest>
1015
</manifest>

+ 99 - 47
app/src/main/java/com/electric/chargingpile/activity/PublishPicTopicActivity.java

24
import android.support.v4.app.ActivityCompat;
24
import android.support.v4.app.ActivityCompat;
25
import android.telephony.TelephonyManager;
25
import android.telephony.TelephonyManager;
26
import android.text.Editable;
26
import android.text.Editable;
27
import android.text.TextUtils;
27
import android.text.TextWatcher;
28
import android.text.TextWatcher;
28
import android.util.Base64;
29
import android.util.Base64;
29
import android.util.Log;
30
import android.util.Log;
47
48
48
import com.electric.chargingpile.R;
49
import com.electric.chargingpile.R;
49
import com.electric.chargingpile.application.MainApplication;
50
import com.electric.chargingpile.application.MainApplication;
51
import com.electric.chargingpile.data.AuthSignBean;
52
import com.electric.chargingpile.data.HomePageBean;
50
import com.electric.chargingpile.data.TalkRecommendBean;
53
import com.electric.chargingpile.data.TalkRecommendBean;
51
import com.electric.chargingpile.data.UploadPic;
54
import com.electric.chargingpile.data.UploadPic;
52
import com.electric.chargingpile.util.BarColorUtil;
55
import com.electric.chargingpile.util.BarColorUtil;
59
import com.electric.chargingpile.util.ScreenUtils;
62
import com.electric.chargingpile.util.ScreenUtils;
60
import com.electric.chargingpile.util.ToastUtil;
63
import com.electric.chargingpile.util.ToastUtil;
61
import com.electric.chargingpile.util.UploadUtil;
64
import com.electric.chargingpile.util.UploadUtil;
65
import com.electric.chargingpile.view.footer.LoadMoreFooterView;
62
import com.umeng.analytics.MobclickAgent;
66
import com.umeng.analytics.MobclickAgent;
63
import com.zhy.http.okhttp.OkHttpUtils;
67
import com.zhy.http.okhttp.OkHttpUtils;
64
import com.zhy.http.okhttp.callback.StringCallback;
68
import com.zhy.http.okhttp.callback.StringCallback;
84
import rx.schedulers.Schedulers;
88
import rx.schedulers.Schedulers;
85
89
86
/**
90
/**
87
 *
88
 * @desc : 发布话题
91
 * @desc : 发布话题
89
 *
90
 * */
91
public class PublishPicTopicActivity extends Activity implements OnClickListener ,EasyPermissions.PermissionCallbacks{
92
 */
93
public class PublishPicTopicActivity extends Activity implements OnClickListener, EasyPermissions.PermissionCallbacks {
92
    private static final String TAG = "PublishPicTopicActivity";
94
    private static final String TAG = "PublishPicTopicActivity";
93
    private static final int PIC_NUM = 9;
95
    private static final int PIC_NUM = 9;
94
    private ImageView ivBack;
96
    private ImageView ivBack;
161
        mPublishTopicDe = (ImageView) findViewById(R.id.publishtopic_choose_topic_de);
163
        mPublishTopicDe = (ImageView) findViewById(R.id.publishtopic_choose_topic_de);
162
        mPublishTopicDe.setOnClickListener(this);
164
        mPublishTopicDe.setOnClickListener(this);
163
        mPublishtopicChooseTopic = (TextView) findViewById(R.id.publishtopic_choose_topic);
165
        mPublishtopicChooseTopic = (TextView) findViewById(R.id.publishtopic_choose_topic);
164
        publishtopic_choose_topic = (TextView)findViewById(R.id.publishtopic_choose_topic);
166
        publishtopic_choose_topic = (TextView) findViewById(R.id.publishtopic_choose_topic);
165
        publishtopic_choose_topic.setOnClickListener(this);
167
        publishtopic_choose_topic.setOnClickListener(this);
166
        insertDialog = new ProgressDialog(this);
168
        insertDialog = new ProgressDialog(this);
167
        insertDialog.setMessage("正在插入图片...");
169
        insertDialog.setMessage("正在插入图片...");
176
                        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
178
                        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
177
                    }
179
                    }
178
                }
180
                }
179
                new Thread(new Runnable() {
180
                    @Override
181
                    public void run() {
182
                        if (Bimp.tempSelectBitmap.size() > 0) {
183
                            uploadFeedbackPic();
184
185
                        } else {
186
181
187
                            uploadFeedbackInfo();
182
                //获取又拍云数据
183
                getYouPaiData();
188
184
189
190
                        }
191
192
                    }
193
                }).start();
185
//                new Thread(new Runnable() {
186
//                    @Override
187
//                    public void run() {
188
//                        if (Bimp.tempSelectBitmap.size() > 0) {
189
                uploadFeedbackPic();
190
//
191
//                        } else {
192
//
193
//                            uploadFeedbackInfo();
194
//
195
//
196
//                        }
197
//
198
//                    }
199
//                }).start();
194
200
195
            }
201
            }
196
        });
202
        });
233
                    tv_right.setEnabled(true);
239
                    tv_right.setEnabled(true);
234
//					tv_right.setTextColor(getResources().getColor(R.color.lvse));
240
//					tv_right.setTextColor(getResources().getColor(R.color.lvse));
235
                    tv_right.setBackgroundColor(Color.parseColor("#02b637"));
241
                    tv_right.setBackgroundColor(Color.parseColor("#02b637"));
236
                }else {
242
                } else {
237
                    tv_right.setEnabled(false);
243
                    tv_right.setEnabled(false);
238
                    tv_right.setBackgroundColor(Color.parseColor("color_9ed3ae"));
244
                    tv_right.setBackgroundColor(Color.parseColor("color_9ed3ae"));
239
                }
245
                }
245
251
246
    }
252
    }
247
253
254
    private void getYouPaiData() {
255
256
        if (null == Bimp.tempSelectBitmap)
257
            return;
258
        String fileNames = "";
259
        for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) {
260
            File tempFile = new File(Bimp.tempSelectBitmap.get(i).imagePath.trim());
261
            String fileName = tempFile.getName();
262
            if (TextUtils.isEmpty(fileNames))
263
                fileNames = fileName;
264
            else
265
                fileNames = "," + fileName;
266
        }
267
        String url = MainApplication.urlNew + "/topic/sign.do";
268
        Map<String, String> map = new HashMap<>();
269
        map.put("fileNames", fileNames);
270
        map.put("expiration", (System.currentTimeMillis() + 1800) + "");
271
        map.put("targetType", "23");
272
        OkHttpUtils.get().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
273
            @Override
274
            public void onError(Call call, Exception e) {
275
            }
276
277
            @Override
278
            public void onResponse(String response) {
279
                Log.i(TAG, response);
280
                String rtnCode = JsonUtils.getKeyResult(response, "code");
281
                if ("1000".equals(rtnCode)) {
282
                    String rtnMsg = JsonUtils.getKeyResult(response, "data");
283
                    ArrayList<AuthSignBean> signBeans = (ArrayList<AuthSignBean>) JsonUtils.parseToObjectList(rtnMsg, AuthSignBean.class);
284
                }
285
            }
286
        });
287
//
288
//        //图文路径
289
//        p = "/d/file/liaoliao/img/"+y+"/"+m+"/"+d;
290
//        //视频路径
291
//        p = "/d/file/liaoliao/video/"+y+"/"+m+"/"+d;
292
//        //生产policy传的参数
293
//        Map<String, Object> map = new HashMap<>();
294
//        map.put("bucket","d1evcom01-fs");
295
//        map.put("expiration",expiration);
296
//        map.put("save-key",p+"/"+fname);
297
//        policy =  UpYunUtils.getPolicy(map);
298
    }
299
248
    final int reqTopic = -100;
300
    final int reqTopic = -100;
301
249
    @Override
302
    @Override
250
    public void onClick(View v) {
303
    public void onClick(View v) {
251
        switch (v.getId()) {
304
        switch (v.getId()) {
447
500
448
    /**
501
    /**
449
     * 异步方式插入图片
502
     * 异步方式插入图片
503
     *
450
     * @param data
504
     * @param data
451
     */
505
     */
452
    private void insertImagesSync(final Intent data) {
506
    private void insertImagesSync(final Intent data) {
691
745
692
        }
746
        }
693
        try {
747
        try {
694
            String u = UploadUtil.post(
695
                    MainApplication.url + "/zhannew/basic/web/index.php/fileupload/multi-upload",
748
            String u = UploadUtil.postTopicPicture(
749
                    MainApplication.urlNew + "/topic/sign.do",
696
//                    "http://123.57.6.131/zhannew/basic/web/index.php/zhanlist/add",
750
//                    "http://123.57.6.131/zhannew/basic/web/index.php/zhanlist/add",
697
//					"http://59.110.68.162"+"/zhannew/fileupload/multi-upload",
751
//					"http://59.110.68.162"+"/zhannew/fileupload/multi-upload",
698
                    par, null);
752
                    par, null);
788
            // to handle the case where the user grants the permission. See the documentation
842
            // to handle the case where the user grants the permission. See the documentation
789
            // for ActivityCompat#requestPermissions for more details.
843
            // for ActivityCompat#requestPermissions for more details.
790
            imem = "";
844
            imem = "";
791
        }else {
845
        } else {
792
            imem = telephonyManager.getDeviceId();
846
            imem = telephonyManager.getDeviceId();
793
        }
847
        }
794
        String url;
848
        String url;
795
        if (null != json){
796
            url = MainApplication.url+"/zhannew/basic/web/index.php/advice/add?user_id="+MainApplication.userId+
797
                    "&msg="+et_context.getText().toString()+"&telephone="+MainApplication.userPhone+"&imem="+imem+
798
                    "&main_id=0&url="+json;
799
        }else {
800
            url = MainApplication.url+"/zhannew/basic/web/index.php/advice/add?user_id="+MainApplication.userId+
801
                    "&msg="+et_context.getText().toString()+"&telephone="+MainApplication.userPhone+"&imem="+imem+
849
        if (null != json) {
850
            url = MainApplication.url + "/zhannew/basic/web/index.php/advice/add?user_id=" + MainApplication.userId +
851
                    "&msg=" + et_context.getText().toString() + "&telephone=" + MainApplication.userPhone + "&imem=" + imem +
852
                    "&main_id=0&url=" + json;
853
        } else {
854
            url = MainApplication.url + "/zhannew/basic/web/index.php/advice/add?user_id=" + MainApplication.userId +
855
                    "&msg=" + et_context.getText().toString() + "&telephone=" + MainApplication.userPhone + "&imem=" + imem +
802
                    "&main_id=0&url=";
856
                    "&main_id=0&url=";
803
        }
857
        }
804
858
805
        Log.e(TAG, "uploadFeedbackInfo: url="+url );
859
        Log.e(TAG, "uploadFeedbackInfo: url=" + url);
806
        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
860
        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
807
            @Override
861
            @Override
808
            public void onError(Call call, Exception e) {
862
            public void onError(Call call, Exception e) {
809
//				dialog.cancel();
863
//				dialog.cancel();
810
                ToastUtil.showToast(getApplicationContext(),"请检查当前网络",Toast.LENGTH_SHORT);
864
                ToastUtil.showToast(getApplicationContext(), "请检查当前网络", Toast.LENGTH_SHORT);
811
            }
865
            }
812
866
813
            @Override
867
            @Override
814
            public void onResponse(String response) {
868
            public void onResponse(String response) {
815
                Log.e(TAG, "onResponse: response="+response );
869
                Log.e(TAG, "onResponse: response=" + response);
816
//				dialog.cancel();
870
//				dialog.cancel();
817
                String rtnCode = JsonUtils.getKeyResult(response,"rtnCode");
818
                if (rtnCode.equals("01")){
871
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
872
                if (rtnCode.equals("01")) {
819
//					ToastUtil.showToast(getApplicationContext(),"感谢您的反馈",Toast.LENGTH_SHORT);
873
//					ToastUtil.showToast(getApplicationContext(),"感谢您的反馈",Toast.LENGTH_SHORT);
820
                    String plusScore = JsonUtils.getKeyResult(response,"plusScore");
821
                    if (!plusScore.equals("")){
874
                    String plusScore = JsonUtils.getKeyResult(response, "plusScore");
875
                    if (!plusScore.equals("")) {
822
                        tv_point.setText(plusScore);
876
                        tv_point.setText(plusScore);
823
                        rl_point.setVisibility(View.VISIBLE);
877
                        rl_point.setVisibility(View.VISIBLE);
824
                        rl_point.startAnimation(animation);
878
                        rl_point.startAnimation(animation);
832
                                finish();
886
                                finish();
833
                            }
887
                            }
834
                        }, 1500);
888
                        }, 1500);
835
                    }else {
836
                        ToastUtil.showToast(getApplicationContext(),"感谢您的反馈",Toast.LENGTH_SHORT);
889
                    } else {
890
                        ToastUtil.showToast(getApplicationContext(), "感谢您的反馈", Toast.LENGTH_SHORT);
837
                        finish();
891
                        finish();
838
                    }
892
                    }
839
//					finish();
893
//					finish();
840
                }else if (rtnCode.equals("03")){
841
                    String rtnMsg = JsonUtils.getKeyResult(response,"rtnMsg");
842
                    ToastUtil.showToast(getApplicationContext(),rtnMsg,Toast.LENGTH_SHORT);
843
                }else {
844
                    String rtnMsg = JsonUtils.getKeyResult(response,"rtnMsg");
845
                    ToastUtil.showToast(getApplicationContext(),rtnMsg,Toast.LENGTH_SHORT);
894
                } else if (rtnCode.equals("03")) {
895
                    String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg");
896
                    ToastUtil.showToast(getApplicationContext(), rtnMsg, Toast.LENGTH_SHORT);
897
                } else {
898
                    String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg");
899
                    ToastUtil.showToast(getApplicationContext(), rtnMsg, Toast.LENGTH_SHORT);
846
                }
900
                }
847
            }
901
            }
848
        });
902
        });
898
        } else {
952
        } else {
899
            // Ask for one permission
953
            // Ask for one permission
900
            EasyPermissions.requestPermissions(
954
            EasyPermissions.requestPermissions(
901
                    this,"充电桩想要获取您的图片读取权限,是否允许?",
955
                    this, "充电桩想要获取您的图片读取权限,是否允许?",
902
                    RC_ALBUM_PERM,
956
                    RC_ALBUM_PERM,
903
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
957
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
904
                    Manifest.permission.READ_EXTERNAL_STORAGE);
958
                    Manifest.permission.READ_EXTERNAL_STORAGE);
913
    }
967
    }
914
968
915
969
916
917
918
}
970
}

+ 10 - 0
app/src/main/java/com/electric/chargingpile/adapter/LayoutAdapter.java

1
package com.electric.chargingpile.adapter;
1
package com.electric.chargingpile.adapter;
2
2
3
import android.content.Context;
3
import android.content.Context;
4
import android.content.Intent;
4
import android.support.v7.widget.LinearLayoutManager;
5
import android.support.v7.widget.LinearLayoutManager;
5
import android.support.v7.widget.RecyclerView;
6
import android.support.v7.widget.RecyclerView;
6
import android.support.v7.widget.StaggeredGridLayoutManager;
7
import android.support.v7.widget.StaggeredGridLayoutManager;
15
16
16
import com.aspsine.irecyclerview.IViewHolder;
17
import com.aspsine.irecyclerview.IViewHolder;
17
import com.electric.chargingpile.R;
18
import com.electric.chargingpile.R;
19
import com.electric.chargingpile.activity.TopicDetailsActivity;
18
import com.electric.chargingpile.data.TalkRecommendBean;
20
import com.electric.chargingpile.data.TalkRecommendBean;
19
import com.electric.chargingpile.iview.RecyclerItemTypeClickListener;
21
import com.electric.chargingpile.iview.RecyclerItemTypeClickListener;
20
import com.electric.chargingpile.util.CircleTransform;
22
import com.electric.chargingpile.util.CircleTransform;
192
        TalkRecommendHeaderAdapter talkRecommendHeaderAdapter = new TalkRecommendHeaderAdapter(context);
194
        TalkRecommendHeaderAdapter talkRecommendHeaderAdapter = new TalkRecommendHeaderAdapter(context);
193
        simpleHeaderViewHolder.header_recy.setAdapter(talkRecommendHeaderAdapter);
195
        simpleHeaderViewHolder.header_recy.setAdapter(talkRecommendHeaderAdapter);
194
        talkRecommendHeaderAdapter.setData(talkHeaderRecommendBeans);
196
        talkRecommendHeaderAdapter.setData(talkHeaderRecommendBeans);
197
198
        talkRecommendHeaderAdapter.setOnRecyclerItemClickListener(new RecyclerItemTypeClickListener() {
199
            @Override
200
            public void onItemClickListener(int position, int index) {
201
                String topicId = talkHeaderRecommendBeans.get(position).topicId+"";
202
                context.startActivity(new Intent(context, TopicDetailsActivity.class).putExtra("topicId", topicId));
203
            }
204
        });
195
    }
205
    }
196
206
197
    class SimpleViewHolder extends IViewHolder {
207
    class SimpleViewHolder extends IViewHolder {

+ 1 - 1
app/src/main/java/com/electric/chargingpile/adapter/WaterFallAdapter.java

94
            simpleViewHolder.info_bg_icon.setLayoutParams(lpImg);
94
            simpleViewHolder.info_bg_icon.setLayoutParams(lpImg);
95
        }
95
        }
96
96
97
        TalkRecommendBean talkRecommendBean = talkRecommendBeans.get(position - 1);
97
        TalkRecommendBean talkRecommendBean = talkRecommendBeans.get(position);
98
        simpleViewHolder.recycler_view_title.setText(talkRecommendBean.title);
98
        simpleViewHolder.recycler_view_title.setText(talkRecommendBean.title);
99
        simpleViewHolder.recycler_view_zan.setText(talkRecommendBean.likeNums + "");
99
        simpleViewHolder.recycler_view_zan.setText(talkRecommendBean.likeNums + "");
100
        simpleViewHolder.user_avater_name.setText(talkRecommendBean.nickName);
100
        simpleViewHolder.user_avater_name.setText(talkRecommendBean.nickName);

+ 14 - 0
app/src/main/java/com/electric/chargingpile/data/HomePageBean.java

13
        public String headImgUrl;
13
        public String headImgUrl;
14
        public String carName;
14
        public String carName;
15
        public int topicNums;
15
        public int topicNums;
16
17
        public long targetId;
18
        public long addUserId;
19
        public int targetType;
20
        public String title;
21
        public String topicName;
22
        public String coverImgUrl;
23
        public String[] imgUrls;
24
        public int topicId;
25
        public int likeNums;
26
        public int commentNums;
27
        public int isTop;
28
        public int likeFlg;
29
        public int source;
16
    }
30
    }
17
}
31
}

+ 1 - 0
app/src/main/java/com/electric/chargingpile/data/TalkRecommendBean.java

25
    public long addTime;
25
    public long addTime;
26
    public int topicId;
26
    public int topicId;
27
    public int joinNums;
27
    public int joinNums;
28
    public int visitNums;
28
    public String coverImgUrl;
29
    public String coverImgUrl;
29
    public String headImgUrl;
30
    public String headImgUrl;
30
    public String nickName;
31
    public String nickName;

+ 79 - 0
app/src/main/java/com/electric/chargingpile/util/UploadUtil.java

157
        return sb2.toString();
157
        return sb2.toString();
158
    }
158
    }
159

159

160
    public static String postTopicPicture(String url, Map<String, String> params,
161
                              Map<String, File> files) throws IOException {
162

163
        String expiration = System.currentTimeMillis()+"30";
164
        String BOUNDARY = java.util.UUID.randomUUID().toString();
165
        String PREFIX = "--", LINEND = "\r\n";
166
        String MULTIPART_FROM_DATA = "multipart/form-data";
167
        String CHARSET = "UTF-8";
168

169
        URL uri = new URL(url);
170
        HttpURLConnection conn = (HttpURLConnection) uri.openConnection();
171
        conn.setReadTimeout(10 * 1000);
172
        conn.setDoInput(true);
173
        conn.setDoOutput(true);
174
        conn.setUseCaches(false);
175
        conn.setRequestMethod("POST");
176
        conn.setRequestProperty("connection", "keep-alive");
177
        conn.setRequestProperty("Charsert", "UTF-8");
178
        conn.setRequestProperty("Content-Type", MULTIPART_FROM_DATA
179
                + ";boundary=" + BOUNDARY);
180

181
        StringBuilder sb = new StringBuilder();
182
        for (Map.Entry<String, String> entry : params.entrySet()) {
183
            sb.append(PREFIX);
184
            sb.append(BOUNDARY);
185
            sb.append(LINEND);
186
            sb.append("Content-Disposition: form-data; name=\""
187
                    + entry.getKey() + "\"" + LINEND);
188
            sb.append("Content-Type: text/plain; charset=" + CHARSET + LINEND);
189
            sb.append("Content-Transfer-Encoding: 8bit" + LINEND);
190
            sb.append(LINEND);
191
            sb.append(entry.getValue());
192
            sb.append(LINEND);
193
        }
194

195
        DataOutputStream outStream = new DataOutputStream(
196
                conn.getOutputStream());
197
        outStream.write(sb.toString().getBytes());
198
        if (files != null)
199
            for (Map.Entry<String, File> file : files.entrySet()) {
200
                StringBuilder sb1 = new StringBuilder();
201
                sb1.append(PREFIX);
202
                sb1.append(BOUNDARY);
203
                sb1.append(LINEND);
204
                sb1.append("Content-Disposition: form-data; name=\"uploadfile\"; targetType=24;fileNames=\""
205
                        + file.getValue().getName() + "\"" + LINEND);
206
                sb1.append("Content-Type: application/octet-stream; charset="
207
                        + CHARSET + LINEND);
208
                sb1.append(LINEND);
209
                outStream.write(sb1.toString().getBytes());
210

211
                InputStream is = new FileInputStream(file.getValue());
212
                byte[] buffer = new byte[1024];
213
                int len = 0;
214
                while ((len = is.read(buffer)) != -1) {
215
                    outStream.write(buffer, 0, len);
216
                }
217

218
                is.close();
219
                outStream.write(LINEND.getBytes());
220
            }
221

222
        byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINEND).getBytes();
223
        outStream.write(end_data);
224
        outStream.flush();
225
        int res = conn.getResponseCode();
226
        InputStream in = conn.getInputStream();
227
        StringBuilder sb2 = new StringBuilder();
228
        if (res == 200) {
229
            int ch;
230
            while ((ch = in.read()) != -1) {
231
                sb2.append((char) ch);
232
            }
233
        }
234
        outStream.close();
235
        conn.disconnect();
236
        return sb2.toString();
237
    }
238

160
}
239
}