582
if (commentsBean != null) {
childCommentUrl = "&parentid=" + commentsBean.getId() + "&puserid=" + commentsBean.getUserid();
String url = MainApplication.url + "/zhannew/basic/web/index.php/tpappcomments/add";
Map<String,String> map=new HashMap<>();
map.put("userid",MainApplication.userId);
map.put("zhanid",zhan_id);
map.put("comment",URLEncoder.encode(et_pinglun.getText().toString()));
map.put("tel",MainApplication.userPhone);
map.put("token",URLEncoder.encode(DES3.encode(token)));
if (topicText!=null){
map.put("theme",topicText.getText().toString());
}
String url = "";
if (commentType == 1) {
url = MainApplication.url + "/zhannew/basic/web/index.php/tpappcomments/add?userid=" + MainApplication.userId + "&zhanid=" + zhan_id + "&comment=" + URLEncoder.encode(et_pinglun.getText().toString()) + "&tel=" + MainApplication.userPhone + "&token=" + URLEncoder.encode(DES3.encode(token)) + "&fileUrl=" + fileUrl + "&thumUrl=" + thumUrl;
Log.d("url!!!", url);
} else if (commentType == 2) {
url = MainApplication.url + "/zhannew/basic/web/index.php/tpappcomments/add?userid=" + MainApplication.userId + "&zhanid=" + zhan_id + "&comment=" + URLEncoder.encode(et_pinglun.getText().toString()) + "&tel=" + MainApplication.userPhone + "&token=" + URLEncoder.encode(DES3.encode(token)) + childCommentUrl;
// url = "http://59.110.68.162/zhannew/basic/web/index.php/tpappcomments/add?userid=" + MainApplication.userId + "&zhanid=" + zhan_id + "&comment=" + URLEncoder.encode(et_pinglun.getText().toString()) + "&tel=" + MainApplication.userPhone + "&token=" + URLEncoder.encode(DES3.encode(token)) + childCommentUrl;
Log.d("url###", url);
if (commentType == 1){
if (fileUrlList.size()>0){
for (int i = 0; i < fileUrlList.size(); i++) {
String value = fileUrlList.get(i);
if (i == 0){
map.put("fileUrl",value);
}else{
map.put("file"+(i+1)+"Url", value);
}
}
map.put("thumUrl",fileUrlList.get(0));
}
}else if (commentType == 2) {
if (commentsBean != null) {
map.put("parentid",commentsBean.getId());
map.put("puserid", commentsBean.getUserid());
}
}
Log.d("url++++", url);
OkHttpUtils.get()
.params(map)
.url(url)
.build()
.execute(new StringCallback() {
@ -604,7 +693,7 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
@Override
public void onResponse(String response) {
Log.e("comment", response);
// Log.e("comment", response);
String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg");
dialog.cancel();
@ -688,25 +777,37 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
}
if (MainApplication.isLogin()) {
try {
if (Bimp.tempSelectBitmap.size() > 0) {
if (Bimp.tempSelectMedia.size() > 0 && mInsterType == 1) {
dialog.show();
new Thread(new Runnable() {
@Override
public void run() {
try {
// shite("");
shite("");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
} else if (Bimp.tempSelectMedia.size() > 0 && mInsterType == 2) {
//进行视频验证
LocalMedia media = Bimp.tempSelectMedia.get(0);
String path = "";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q)
path = media.getAndroidQToPath();
else {
path = media.getPath();
}
getYouPaiData(path);
} else {
if (containsEmoji(et_pinglun.getText().toString())) {
ToastUtil.showToast(MainApplication.context, "不支持输入表情", Toast.LENGTH_SHORT);
} else {
dialog.show();
addComment("", "");
addComment(new ArrayList<>(), "");
}
}
} catch (Exception e) {
@ -731,7 +832,136 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
}
}
private void addImg(){
private void getYouPaiData(String filePath) {
dialog.show();
// String url = MainApplication.urlNew + "/get-sign-rest";
String url = MainApplication.d1evTestUrl + "/api/topic/get-sign-rest2cdz";
if (TextUtils.isEmpty(filePath)) {
ToastUtil.showToast(getApplicationContext(), "请重新选择视频", Toast.LENGTH_SHORT);
return;
}
String deviceId = JPushInterface.getUdid(MainApplication.context);
String fileName = DateUtils.getSimpleCurrentDate();
if (TextUtils.isEmpty(deviceId)) {
fileName += "_" + Util.getRandom(15);
} else {
fileName += "_" + deviceId;
}
if (TextUtils.isEmpty(filePath)) {
fileName = "";
} else {
String suffix = filePath.substring(filePath.lastIndexOf(".") + 1);
fileName += "." + suffix;
}
Map<String, String> map = new HashMap<>();
map.put("fileName", fileName);
try {
FileInputStream fileInputStream = new FileInputStream(new File(filePath));
map.put("contentLength", String.valueOf(fileInputStream.available()));
} catch (Exception e) {
e.printStackTrace();
}
map.put("targetType", ChatRecommendBean.TARGET_TYPE_VIDEO + "");
CommonParams.addCommonParams(map);
String finalFileName = fileName;
OkHttpUtils.get()
.params(map)
.url(url)
.build()
.connTimeOut(6000)
.readTimeOut(6000)
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
ToastUtil.showToast(getApplicationContext(), "发布失败,请重试", Toast.LENGTH_SHORT);
dialog.dismiss();
}
@Override
public void onResponse(String response) {
Log.e("hyc--", response);
String code = JsonUtils.getKeyResult(response, "code");
String desc = JsonUtils.getKeyResult(response, "desc");
if ("1000".equals(code)) {
String data = JsonUtils.getKeyResult(response, "data");
signBeans = (AuthSignBean) JsonUtils.parseToObjectBean(data, AuthSignBean.class);
if (null != signBeans) {
String sign = signBeans.sign;
String policy = signBeans.policy;
formUpload(filePath, sign, policy, finalFileName);
} else {
ToastUtil.showToast(getApplicationContext(), desc, Toast.LENGTH_SHORT);
}
} else {
ToastUtil.showToast(getApplicationContext(), desc, Toast.LENGTH_SHORT);
dialog.dismiss();
}
}
});
}
/**
* 表单上传
*
* @param SAMPLE_PIC_FILE
* @param sign
* @param policyServer
*/
private void formUpload(String SAMPLE_PIC_FILE, String sign, String policyServer, String fileName) {
if (serialUploader == null) {
serialUploader = new SerialUploader();
}
serialUploader.setCheckMD5(false);
File temp = new File(SAMPLE_PIC_FILE);
serialUploader.setOnProgressListener((bytesWrite, contentLength) -> {
});
String decoder = new String(Base64.decode((policyServer), Base64.DEFAULT));
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(decoder);
} catch (JSONException e) {
e.printStackTrace();
}
String uri = jsonObject.optString("URI");
String date = jsonObject.optString("Date");
String operator = jsonObject.optString("Operator");
String saveKey = jsonObject.optString("save-key");
serialUploader.upload(
temp, uri, date, "UPYUN " + operator + ":" + sign, null, new UpCompleteListener() {
@Override
public void onComplete(boolean isSuccess, String result) {
if (isSuccess) {
try {
ArrayList<String> list = new ArrayList<>();
list.add(saveKey);
addComment(list, saveKey);
} catch (Exception e) {
e.printStackTrace();
}
} else {
ToastUtil.showToast(getApplicationContext(), "发布失败,请重试", Toast.LENGTH_SHORT);
dialog.dismiss();
}
}
});
}
private void addImg() {
PictureSelector.create(this)
.openGallery(PictureMimeType.ofImage())
.maxSelectNum(PIC_NUM)
@ -753,7 +983,8 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
.isAutomaticTitleRecyclerTop(true)//图片列表超过一屏连续点击顶部标题栏快速回滚至顶部
.forResult(REQUEST_CODE_CHOOSE);
}
private void addVideo(){
private void addVideo() {
PictureSelector.create(this)
.openGallery(PictureMimeType.ofVideo())
.selectionMode(PictureConfig.SINGLE)
@ -775,7 +1006,7 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
.recordVideoSecond(15)//录制视频秒数 默认60s
.isPreviewVideo(true)//是否预览视频
.isSingleDirectReturn(true)//PictureConfig.SINGLE模式下是否直接返回
// .filterMaxFileSize(100)//查询指定大小内的图片、视频、音频大小,单位M
// .filterMaxFileSize(100)//查询指定大小内的图片、视频、音频大小,单位M
.forResult(REQUEST_VIDEO_CODE_CHOOSE);
}
@ -820,27 +1051,27 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
@Override
public void add() {
if (mInsterType == 1){
if (mInsterType == 1) {
addImg();
}else if (mInsterType == 2){
} else if (mInsterType == 2) {
addVideo();
}
}
@Override
public void remove(int position) {
if (mAdapter.getItemCount() == 1){
if (mAdapter.getItemCount() == 1) {
setLayoutHintVisible(-1);
mInsterType=-1;
mInsterType = -1;
}
}
@Override
public void open(int position, LocalMedia mLocalMedia) {
if (mInsterType == 1){
ImageDisplayActivity.actionStart(this,position);
}else if (mInsterType == 2){
if (mInsterType == 1) {
ImageDisplayActivity.actionStart(this, position);
} else if (mInsterType == 2) {
PictureSelector.create(ZhanCommentActivity.this)
.themeStyle(R.style.picture_default_style)
.setPictureStyle(Util.getWhiteStyle(ZhanCommentActivity.this))// 动态自定义相册主题
@ -848,6 +1079,7 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
}
}
public class MyTopic extends RObject {
private String id;
@ -877,6 +1109,73 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
Bimp.tempSelectMedia.clear();
}
private String bitmapToBase64(Bitmap bitmap) {
String result = null;
ByteArrayOutputStream baos = null;
try {
if (bitmap != null) {
baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
baos.flush();
baos.close();
byte[] bitmapBytes = baos.toByteArray();
result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (baos != null) {
baos.flush();
baos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
private Bitmap imageZoom(Bitmap bm) {
// 图片允许最大空间 单位:KB
double maxSize = 200.00;
// 将bitmap放至数组中,意在bitmap的大小(与实际读取的原文件要大)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
// 将字节换成KB
double mid = b.length / 1024;
// 判断bitmap占用空间是否大于允许最大空间 如果大于则压缩 小于则不压缩
if (mid > maxSize) {
// 获取bitmap大小 是允许最大大小的多少倍
double i = mid / maxSize;
// 开始压缩 此处用到平方根 将宽带和高度压缩掉对应的平方根倍
// (1.保持刻度和高度和原bitmap比率一致,压缩后也达到了最大大小占用空间的大小)
bm = zoomImage(bm, bm.getWidth() / Math.sqrt(i), bm.getHeight()
/ Math.sqrt(i));
}
return bm;
}
public Bitmap zoomImage(Bitmap bgimage, double newWidth, double newHeight) {
// 获取这个图片的宽和高
float width = bgimage.getWidth();
float height = bgimage.getHeight();
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 计算宽高缩放率
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width,
(int) height, matrix, true);
// iv_2.setImageBitmap(bitmap);
// tv_2.setText(bitmap.getRowBytes() * bitmap.getHeight() + "");
return bitmap;
}
class NetworkChangeReceiver extends BroadcastReceiver {
@ -904,12 +1203,12 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
}
mAdapter.notifyDataSetChanged();
if (mInsterType == 1 && mAdapter.getItemCount() == 1){
if (mInsterType == 1 && mAdapter.getItemCount() == 1) {
setLayoutHintVisible(-1);
mInsterType=-1;
}else if (mInsterType == 2 && mAdapter.getItemCount() == 0){
mInsterType = -1;
} else if (mInsterType == 2 && mAdapter.getItemCount() == 0) {
setLayoutHintVisible(-1);
mInsterType=-1;
mInsterType = -1;
}
}
@ -944,4 +1243,38 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
&& (codePoint <= 0x10FFFF));
}
/**
* 将json 数组转换为Map 对象
*
* @param jsonString
* @return
*/
public static Map<String, Object> getMap(String jsonString) {
JSONObject jsonObject;
Map<String, Object> valueMap = new HashMap<String, Object>();
if (TextUtils.isEmpty(jsonString)) {
return valueMap;
}
try {
jsonObject = new JSONObject(jsonString);
@SuppressWarnings("unchecked")
Iterator<String> keyIter = jsonObject.keys();
String key;
Object value;
while (keyIter.hasNext()) {
key = (String) keyIter.next();
value = jsonObject.get(key);
valueMap.put(key, value);
}
return valueMap;
} catch (JSONException e) {
e.printStackTrace();
}
return valueMap;
}
}
|
||
| 97 | 97 |
|
| 98 | 98 |
|
| 99 | 99 |
|
| 100 |
|
|
| 101 |
|
|
| 100 | 102 |
|
| 101 | 103 |
|
| 102 | 104 |
|