private void uploadImage(final String path) { showDialog(); final PostParams params = new PostParams(); InitUtil.createAdFolder(this, "tempFile"); params.put("file", Utils.saveBitmapFile(this, getSmallBitmap(path), "tempFile")); HttpUtils.postJSONObject( activity, Const.UPLOAD_IMAGE, params, new RespJSONObjectListener(activity) { @Override public void getResp(JSONObject jsonObject) { dismissDialog(); RespVo<UploadFileVo> resp = GsonTools.getVo(jsonObject.toString(), RespVo.class); if (resp.isSuccess()) { final UploadFileVo fileVo = resp.getData(activity, jsonObject, UploadFileVo.class); ids.put(fileVo.getId() + "", fileVo.getId() + ""); final int width = (AppUtils.getWidth(activity) - 80) / 3; final View view = makeView(R.layout.item_photo); ImageView iv_image = (ImageView) view.findViewById(R.id.iv_image); ImageView iv_delete = (ImageView) view.findViewById(R.id.iv_delete); iv_delete.setVisibility(View.VISIBLE); iv_delete.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { fl_pics.removeView(view); ids.remove(fileVo.getId() + ""); if (fl_pics.getChildCount() < 3) { View temp = makeView(R.layout.item_photo); ImageView iv_image = (ImageView) temp.findViewById(R.id.iv_image); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, width); lp.leftMargin = 18; temp.setLayoutParams(lp); iv_image.setImageResource(R.drawable.icon_addzhaopian); temp.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { GalleryConfig.Builder builder = new GalleryConfig.Builder(activity); builder.imageloader(new GlideImageLoader()); builder.singleSelect(); builder.enableEdit(); builder.enableRotate(); builder.showCamera(); GalleryConfig config = builder.build(); GalleryFinal.open(config); } }); fl_pics.addView(temp); } } }); iv_image.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ArrayList<CircleVo.ItemCircle.Cover> list = new ArrayList<CircleVo.ItemCircle.Cover>(); CircleVo.ItemCircle.Cover cover = new CircleVo.ItemCircle.Cover(); cover.setPath(path); list.add(cover); skip(PicScannerActivity.class, list); } }); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, width); lp.leftMargin = 18; view.setLayoutParams(lp); view.setTag(path); iv_image.setImageBitmap(Utils.getSmallBitmap(path)); fl_pics.addView(view, 0); if (fl_pics.getChildCount() == 4) { fl_pics.removeViewAt(3); } } else { toast("获取图片失败,请重试"); } } @Override public void doFailed() { dismissDialog(); } }); }
@OnClick(R.id.tv_publish) void publish(View view) { if (Utils.isEmpty(et_title.getText().toString())) { toast("请输入标题"); return; } if (Utils.isEmpty(et_content.getText().toString())) { toast("请输入内容"); return; } if (Utils.isEmpty(type)) { if (tv_label.getTag(R.id.tag_first) == null && tv_label.getTag(R.id.tag_two) == null) { toast("请选择标签"); return; } } if (!SimpleUtils.isLogin(activity)) { skip(LoginActivity.class); return; } PostParams params = new PostParams(); showDialog(); params.put("title", et_title.getText().toString()); params.put("content", et_content.getText().toString()); params.put("address", tv_address.getText().toString()); if (tv_label.getTag(R.id.tag_two) != null) { params.put("category_id", tv_label.getTag(R.id.tag_two).toString()); // 标签id } if (tv_label.getTag(R.id.tag_first) != null) { params.put("type", tv_label.getTag(R.id.tag_first).toString()); // 标签id params.put("category_id", "2"); // 标签id } if (tb_notify.isChecked()) { params.put("private", "0"); // 标签id } else { params.put("private", "1"); // 标签id } String pics = ""; Set keys = ids.keySet(); Iterator<String> it = keys.iterator(); while (it.hasNext()) { String key = it.next(); String id = ids.get(key); if (Utils.isEmpty(pics)) { pics = id; } else { pics = pics + "," + id; } } params.put("pictures", pics); HttpUtils.postJSONObject( activity, Const.PUBLIC_CIRCLE, SimpleUtils.buildUrl(activity, params), new RespJSONObjectListener(activity) { @Override public void getResp(JSONObject obj) { dismissDialog(); RespVo respVo = GsonTools.getVo(obj.toString(), RespVo.class); if (respVo.isSuccess()) { toast("动态已发布"); EventBus.getDefault().post(new DiseaseRecordActivity.RefreshEvent()); finish(); } else { toast(respVo.getMessage()); } } @Override public void doFailed() { dismissDialog(); } }); }
private void query(final boolean isFirst) { final PostParams params = new PostParams(); params.put("page", pageNum + ""); HttpUtils.postJSONObject( activity, Const.MY_CIRCLE, SimpleUtils.buildUrl(activity, params), new RespJSONObjectListener(activity) { @Override public void getResp(JSONObject jsonObject) { list_circle.setRefreshing(false); RespVo<CircleVo> respVo = GsonTools.getVo(jsonObject.toString(), RespVo.class); if (respVo.isSuccess()) { CircleVo data = respVo.getData(activity, jsonObject, CircleVo.class); if (isFirst && !Utils.isEmpty(data.getHot_tags())) { for (final CircleVo.HotTagsVo tag : data.getHot_tags()) { View view = activity.makeView(R.layout.item_qunzu); ImageView iv_avatar = (ImageView) view.findViewById(R.id.iv_avatar); TextView tv_name = (TextView) view.findViewById(R.id.tv_name); TextView tv_desc = (TextView) view.findViewById(R.id.tv_desc); TextView tv_num = (TextView) view.findViewById(R.id.tv_num); TextView tv_jiaru = (TextView) view.findViewById(R.id.tv_jiaru); tv_num.setVisibility(View.GONE); tv_jiaru.setVisibility(View.GONE); Glide.with(activity.getApplicationContext()) .load(SimpleUtils.getImageUrl(tag.getCover())) .into(iv_avatar); tv_name.setText(tag.getTitle()); tv_desc.setText(tag.getJoined_person() + "人参与"); view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { activity.skip(NewsListActivity.class, tag.getId(), tag.getTitle()); } }); ll_label.addView(view); } } if (pageNum == 1) { adapter.removeAll(); list_circle.setCanLoadMore(); } if (Utils.isEmpty(data.getNews())) { list_circle.setNoMoreData(); } else { if (data.getNews().size() < 10) { list_circle.setNoMoreData(); } else { list_circle.setCanLoadMore(); } adapter.addItems(data.getNews()); } pageNum++; } else { activity.toast(respVo.getMessage()); } } @Override public void doFailed() { list_circle.setRefreshing(false); } }); }