|
@@ -0,0 +1,275 @@
|
|
|
+package com.ynstkz.shitu.android.activity;
|
|
|
+
|
|
|
+import android.app.ProgressDialog;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.provider.MediaStore;
|
|
|
+import android.support.annotation.Nullable;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.GridView;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.common.library.okhttp.callback.Callback;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.ynstkz.shitu.android.R;
|
|
|
+import com.ynstkz.shitu.android.adapter.OrgCommentPicAdapter;
|
|
|
+import com.ynstkz.shitu.android.base.TitleBarActivity;
|
|
|
+import com.ynstkz.shitu.android.bean.OrgCommentSubmintBean;
|
|
|
+import com.ynstkz.shitu.android.data.RequestGroup;
|
|
|
+import com.ynstkz.shitu.android.utils.FileUtils;
|
|
|
+import com.ynstkz.shitu.android.utils.ImageUtils;
|
|
|
+import com.ynstkz.shitu.android.view.SelectPicDialog;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import butterknife.Bind;
|
|
|
+import me.zhanghai.android.materialratingbar.MaterialRatingBar;
|
|
|
+import okhttp3.Call;
|
|
|
+import okhttp3.Response;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 作者:fuchangle on 2018/3/14 15:16
|
|
|
+ */
|
|
|
+
|
|
|
+public class OrgWriteCommentActivity extends TitleBarActivity implements View.OnClickListener{
|
|
|
+
|
|
|
+ /** 请求相册 */
|
|
|
+ public static final int REQUEST_CODE_GETIMAGE_BYSDCARD = 0;
|
|
|
+ /** 请求相机 */
|
|
|
+ public static final int REQUEST_CODE_GETIMAGE_BYCAMERA = 1;
|
|
|
+ /** 请求裁剪 */
|
|
|
+ public static final int REQUEST_CODE_GETIMAGE_BYCROP = 2;
|
|
|
+
|
|
|
+ @Bind(R.id.tv_title)
|
|
|
+ TextView tvTitle;
|
|
|
+ @Bind(R.id.view_title)
|
|
|
+ RelativeLayout viewTitle;
|
|
|
+ @Bind(R.id.rb_score)
|
|
|
+ MaterialRatingBar rbScore;
|
|
|
+ @Bind(R.id.edit_content)
|
|
|
+ EditText editContent;
|
|
|
+ @Bind(R.id.gv_pic)
|
|
|
+ GridView gvPic;
|
|
|
+ @Bind(R.id.btn_submint)
|
|
|
+ Button btnSubmint;
|
|
|
+ private String memberId;
|
|
|
+
|
|
|
+ private List<File> listFiles;
|
|
|
+ private Map<String, File> fileParam;
|
|
|
+ private boolean isTakeFull;
|
|
|
+ private SelectPicDialog selectPicDialog;
|
|
|
+ private OrgCommentPicAdapter orgCommentPicAdapter;
|
|
|
+ private ProgressDialog progressDialog;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ initView();
|
|
|
+ initData();
|
|
|
+ setListener();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getLayoutId() {
|
|
|
+ return R.layout.activity_writecomment;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void initView() {
|
|
|
+ tvTitle.setText(getIntent().getStringExtra("memberTitle"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initData() {
|
|
|
+ memberId = getIntent().getStringExtra("memberId");
|
|
|
+
|
|
|
+ listFiles = new ArrayList<>();
|
|
|
+ fileParam = new HashMap<>();
|
|
|
+ Bitmap bitmap = ImageUtils.drawableToBitmap(getResources().getDrawable(R.drawable.pic_add_icon));
|
|
|
+ listFiles.add(ImageUtils.saveBitmapToPic(bitmap, "pic_add_icon"));
|
|
|
+ orgCommentPicAdapter = new OrgCommentPicAdapter(OrgWriteCommentActivity.this, listFiles);
|
|
|
+ gvPic.setAdapter(orgCommentPicAdapter);
|
|
|
+ orgCommentPicAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void setListener() {
|
|
|
+
|
|
|
+ gvPic.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
|
|
|
+ if (position == listFiles.size() - 1 && !isTakeFull) {
|
|
|
+ if (selectPicDialog == null) {
|
|
|
+ selectPicDialog = new SelectPicDialog(OrgWriteCommentActivity.this, OrgWriteCommentActivity.this);
|
|
|
+ }
|
|
|
+ selectPicDialog.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ btnSubmint.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ String content = editContent.getText().toString().trim();
|
|
|
+ String score = rbScore.getProgress() + "";
|
|
|
+
|
|
|
+ progressDialog = new ProgressDialog(OrgWriteCommentActivity.this);
|
|
|
+ progressDialog.setMessage("正在提交...");
|
|
|
+ progressDialog.show();
|
|
|
+ submintOrgComment(memberId, score, content, fileParam);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提交机构评论
|
|
|
+ *
|
|
|
+ * @param memberId
|
|
|
+ * @param score
|
|
|
+ * @param content
|
|
|
+ * @param files
|
|
|
+ */
|
|
|
+ private void submintOrgComment(String memberId, String score, String content, Map<String, File> files) {
|
|
|
+
|
|
|
+ RequestGroup.submintOrgComment(memberId, score, content, files, new Callback() {
|
|
|
+ @Override
|
|
|
+ public Object parseNetworkResponse(Response response, int id) throws Exception {
|
|
|
+ return new Gson().fromJson(response.body().string(), OrgCommentSubmintBean.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ showToast(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object response, int id) {
|
|
|
+ OrgCommentSubmintBean orgCommentSubmintBean = (OrgCommentSubmintBean)response;
|
|
|
+ if(orgCommentSubmintBean != null){
|
|
|
+ if("200".equals(orgCommentSubmintBean.getCode())){
|
|
|
+ showToast("success");
|
|
|
+ } else {
|
|
|
+ showToast(orgCommentSubmintBean.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ switch (view.getId()) {
|
|
|
+ case R.id.take_photo_layout:
|
|
|
+ closePopDialog();
|
|
|
+ startActionCamera();
|
|
|
+ break;
|
|
|
+ case R.id.choose_from_gallery_layout:
|
|
|
+ closePopDialog();
|
|
|
+ startImagePick();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void closePopDialog() {
|
|
|
+ if (selectPicDialog != null && selectPicDialog.isShowing()) {
|
|
|
+ selectPicDialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 相机拍照
|
|
|
+ */
|
|
|
+ private void startActionCamera() {
|
|
|
+ Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
+ startActivityForResult(intent, REQUEST_CODE_GETIMAGE_BYCAMERA);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 选择图片裁剪
|
|
|
+ */
|
|
|
+ private void startImagePick() {
|
|
|
+ Intent intent = new Intent(Intent.ACTION_PICK);
|
|
|
+ intent.setType("image/*");
|
|
|
+ startActivityForResult(Intent.createChooser(intent, "选择图片"),
|
|
|
+ REQUEST_CODE_GETIMAGE_BYCAMERA);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拍照后裁剪
|
|
|
+ *
|
|
|
+ * @param data 原始图片
|
|
|
+ * 裁剪后图片
|
|
|
+ */
|
|
|
+ private void startActionCrop(Uri data) {
|
|
|
+ Intent intent = new Intent("com.android.camera.action.CROP");
|
|
|
+ intent.setDataAndType(data, "image/*");
|
|
|
+ intent.putExtra("crop", "true");
|
|
|
+ intent.putExtra("aspectX", 1);// 裁剪框比例
|
|
|
+ intent.putExtra("aspectY", 1);
|
|
|
+ intent.putExtra("outputX", 200);// 输出图片大小
|
|
|
+ intent.putExtra("outputY", 200);
|
|
|
+ intent.putExtra("scale", true);// 去黑边
|
|
|
+ intent.putExtra("scaleUpIfNeeded", true);// 去黑边
|
|
|
+ intent.putExtra("return-data", true);
|
|
|
+ startActivityForResult(intent,
|
|
|
+ REQUEST_CODE_GETIMAGE_BYSDCARD);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加图片
|
|
|
+ * @param file
|
|
|
+ */
|
|
|
+ private void addTakeImage(File file) {
|
|
|
+ listFiles.add(listFiles.size() - 1, file);
|
|
|
+ fileParam.put(System.currentTimeMillis() + "", file);
|
|
|
+ if (listFiles.size() > 3) {
|
|
|
+ isTakeFull = true;
|
|
|
+ listFiles.remove(3);
|
|
|
+ }
|
|
|
+ orgCommentPicAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ switch (requestCode){
|
|
|
+ case REQUEST_CODE_GETIMAGE_BYCAMERA:
|
|
|
+ if (data != null) {
|
|
|
+ if (data.getData() != null) {
|
|
|
+ startActionCrop(data.getData());
|
|
|
+ } else {
|
|
|
+ Bitmap bitMap = data.getParcelableExtra("data");
|
|
|
+ if (bitMap != null) {
|
|
|
+ startActionCrop(Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bitMap, null, null)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case REQUEST_CODE_GETIMAGE_BYSDCARD:
|
|
|
+ if (data != null) {
|
|
|
+ if (data.getData() != null) {
|
|
|
+ File takeFile = FileUtils.from(this, data.getData());
|
|
|
+ if (takeFile != null) {
|
|
|
+ addTakeImage(takeFile);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Bitmap bitMap = data.getParcelableExtra("data");
|
|
|
+ File takeFile = ImageUtils.saveBitmapToPic(bitMap, "win_pic" + System.currentTimeMillis());
|
|
|
+ if (takeFile != null) {
|
|
|
+ addTakeImage(takeFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|