1
This commit is contained in:
@@ -98,7 +98,7 @@ android {
|
||||
implementation 'com.android.databinding:library:1.1'
|
||||
implementation 'com.android.databinding:baseLibrary:1.1'
|
||||
implementation 'com.android.databinding:adapters:1.1'
|
||||
|
||||
implementation 'top.zibin:Luban:1.1.8'
|
||||
implementation 'com.hjq:xxpermissions:5.5'
|
||||
implementation 'com.jzj.view:ObservableScrollView:0.0.2'
|
||||
implementation 'com.dalong:refreshlayout:1.0.1'
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.zhihu.matisse.engine.impl.PicassoEngine;
|
||||
import com.zhihu.matisse.internal.entity.CaptureStrategy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -40,9 +41,11 @@ import http.FileUpLoad.retrofit.HttpStaticApi;
|
||||
import http.FileUpLoad.retrofit.RetrofitCallBack;
|
||||
import http.FileUpLoad.retrofit.RetrofitHttpUpLoad;
|
||||
import my_loader.Resultcode;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Response;
|
||||
import tools.Config;
|
||||
import top.zibin.luban.Luban;
|
||||
import utils.Md5;
|
||||
|
||||
public class AddDiscoveryActivity extends BaseActivity<ActivityAddDiscoveryBinding> {
|
||||
@@ -230,20 +233,32 @@ public class AddDiscoveryActivity extends BaseActivity<ActivityAddDiscoveryBindi
|
||||
|
||||
} else if (requestCode == REQUEST_CODE_SELECT_PICTURE && resultCode == RESULT_OK && data != null) {
|
||||
List<String> strings = Matisse.obtainPathResult(data);
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.addAll(additionImageWrapper.getImageList());
|
||||
for (int i = 0; i < strings.size(); i++) {
|
||||
files.add(new File(strings.get(i)));
|
||||
ArrayList<File> files = new ArrayList<>(additionImageWrapper.getImageList());
|
||||
try {
|
||||
List<File> list = Luban.with(AddDiscoveryActivity.this).load(strings)
|
||||
.ignoreBy(100).setTargetDir(getCacheDir().getAbsolutePath()).get();
|
||||
files.addAll(list);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
additionImageWrapper.setData(files);
|
||||
} else if (requestCode == 411 && resultCode == RESULT_OK && data != null) {
|
||||
List<String> strings = Matisse.obtainPathResult(data);
|
||||
|
||||
if (!strings.isEmpty()) {
|
||||
file = new File(strings.get(0));
|
||||
try {
|
||||
List<File> list = Luban.with(AddDiscoveryActivity.this).load(strings).ignoreBy(100).setTargetDir(getCacheDir().getAbsolutePath()).get();
|
||||
if (null != list && list.size() > 0) {
|
||||
file = list.get(0);
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(file.toString());
|
||||
mDataBinding.tvCover.setBackground(new BitmapDrawable(getResources(), bitmap));
|
||||
mDataBinding.tvCover.setText("");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,54 +332,76 @@ public class AddDiscoveryActivity extends BaseActivity<ActivityAddDiscoveryBindi
|
||||
private void submit() {
|
||||
RetrofitHttpUpLoad retrofitHttpUpLoad = RetrofitHttpUpLoad.getInstance();
|
||||
retrofitHttpUpLoad.clear();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
RegisterUser user =
|
||||
Config.getInstance(this).getUser();
|
||||
Map<String, RequestBody> map = new HashMap<>();
|
||||
if (user != null) {
|
||||
map.put("userid", user.getUserid());
|
||||
map.put("userid", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), user.getUserid()));
|
||||
} else {
|
||||
map.put("userid", 0 + "");
|
||||
}
|
||||
map.put("app", "Goods");
|
||||
map.put("class", "AddGoodsInfo");
|
||||
map.put("sign", Md5.md5("Goods" + "AddGoodsInfo" + Md5.secret));
|
||||
map.put("userid", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), 0 + ""));
|
||||
|
||||
}
|
||||
Log.e("userId", user.getUserid());
|
||||
map.put("app", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), "Goods"));
|
||||
|
||||
map.put("class", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), "AddGoodsInfo"));
|
||||
map.put("sign", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), Md5.md5("Goods" + "AddGoodsInfo" + Md5.secret)));
|
||||
Log.e("sign", Md5.md5("Goods" + "AddGoodsInfo" + Md5.secret));
|
||||
map.put("type", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), type + 1 + ""));
|
||||
|
||||
map.put("type", type + 1 + "");
|
||||
if (type == 1) {
|
||||
if (additionImageWrapper.getImageList().size() < 1) {
|
||||
setToast("请添加图片或视频");
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < additionImageWrapper.getImageList().size(); i++) {
|
||||
if (additionImageWrapper.getImageList().get(i) != null) {
|
||||
map.put("pic" + i, additionImageWrapper.getImageList().get(i));
|
||||
}
|
||||
}
|
||||
map.put("file_count", additionImageWrapper.getImageList().size() + "");
|
||||
|
||||
|
||||
String goodsDetail = mDataBinding.etInfo.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(goodsDetail)) {
|
||||
setToast("请输入文字信息");
|
||||
return;
|
||||
}
|
||||
map.put("goods_detail", goodsDetail);
|
||||
map.put("goods_detail", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), goodsDetail));
|
||||
Log.e("goods_detail", goodsDetail);
|
||||
|
||||
if (type == 1) {
|
||||
if (goodsInfo.isEmpty()) {
|
||||
setToast("请添加商品规格");
|
||||
return;
|
||||
}
|
||||
map.put("property", goodsInfo);
|
||||
|
||||
map.put("property", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), goodsInfo));
|
||||
Log.e("property", goodsInfo);
|
||||
|
||||
if (file == null || !file.isFile()) {
|
||||
setToast("请上传商品封面图");
|
||||
return;
|
||||
}
|
||||
}
|
||||
map.put("thumb", file);
|
||||
|
||||
|
||||
for (int i = 0; i < additionImageWrapper.getImageList().size(); i++) {
|
||||
map.put("pic" + i + "\"; filename=\"" + additionImageWrapper.getImageList().get(i).getName() + "", RequestBody.create(MediaType.get("multipart/form-data;charset=UTF-8"), additionImageWrapper.getImageList().get(i)));
|
||||
Log.e("xxxx", additionImageWrapper.getImageList().get(i).getName());
|
||||
}
|
||||
if (file!=null){
|
||||
map.put("pic"+ additionImageWrapper.getImageList().size()+ "\"; filename=\"" + file.getName() + "", RequestBody.create(MediaType.get("multipart/form-data;charset=UTF-8"), file));
|
||||
|
||||
map.put("file_count", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), additionImageWrapper.getImageList().size()+1 + ""));
|
||||
|
||||
}else {
|
||||
map.put("file_count", RequestBody.create(MediaType.get("text/plain;charset=UTF-8"), additionImageWrapper.getImageList().size() + ""));
|
||||
|
||||
}
|
||||
// params.put(key + "\"; filename=\"" + ((File) o).getName() + "", requestBody);
|
||||
progressDialog.setMessage("提交中");
|
||||
progressDialog.show();
|
||||
Map<String, RequestBody> params = retrofitHttpUpLoad.addParameter(map).bulider();
|
||||
retrofitHttpUpLoad.addToEnqueue(retrofitHttpUpLoad.mHttpService.upLoadAgree(ApiConfig.BASE_URL, params),
|
||||
|
||||
|
||||
// Map<String, RequestBody> params = retrofitHttpUpLoad.addParameter(map).bulider();
|
||||
retrofitHttpUpLoad.addToEnqueue(retrofitHttpUpLoad.mHttpService.upLoadAgree(ApiConfig.BASE_URL, map),
|
||||
new RetrofitCallBack() {
|
||||
@Override
|
||||
public void onResponse(Response response, int method) {
|
||||
|
||||
@@ -405,7 +405,8 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> im
|
||||
}
|
||||
}
|
||||
});
|
||||
new XPopup.Builder(baseActivity).hasShadowBg(false).atView(homeGridAdapterItemBinding.ivComment).asCustom(commentDialog)
|
||||
new XPopup.Builder(baseActivity).hasShadowBg(false).atView(homeGridAdapterItemBinding.ivComment)
|
||||
.asCustom(commentDialog)
|
||||
.show();
|
||||
|
||||
}
|
||||
|
||||
@@ -2,13 +2,10 @@ package http.FileUpLoad.retrofit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import com.sl.house_property.MyApplication;
|
||||
import com.sl.house_property.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -33,8 +30,8 @@ public class RetrofitHttpUpLoad {
|
||||
/**
|
||||
* 超时时间60s
|
||||
*/
|
||||
private int progressmes=1000;
|
||||
private static final long DEFAULT_TIMEOUT =10;
|
||||
private int progressmes = 1000;
|
||||
private static final long DEFAULT_TIMEOUT = 10;
|
||||
private volatile static RetrofitHttpUpLoad mInstance;
|
||||
public Retrofit mRetrofit;
|
||||
public IHttpService mHttpService;
|
||||
@@ -121,39 +118,21 @@ public class RetrofitHttpUpLoad {
|
||||
* 添加参数
|
||||
* 根据传进来的Object对象来判断是String还是File类型的参数
|
||||
*/
|
||||
public RetrofitHttpUpLoad addParameter(Map<String ,Object> mymap) {
|
||||
public RetrofitHttpUpLoad addParameter(Map<String, Object> mymap) {
|
||||
Set<Map.Entry<String, Object>> mymap1 = mymap.entrySet();
|
||||
// 遍历键值对对象的集合,得到每一个键值对对象
|
||||
int a=0;
|
||||
|
||||
for (Map.Entry<String, Object> me : mymap1) {
|
||||
|
||||
String key = me.getKey();
|
||||
final Object o = me.getValue();
|
||||
if ( o instanceof String) {
|
||||
if (o instanceof String) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("text/plain;charset=UTF-8"), (String) o);
|
||||
params.put(key, body);
|
||||
} else if (o instanceof File) {
|
||||
a=a+1;
|
||||
final int finalA = a;
|
||||
ProgressRequestBody body = new ProgressRequestBody( (File) o,"multipart/form-data;charset=UTF-8",
|
||||
new ProgressRequestBody.ProgressListener() {
|
||||
@Override
|
||||
public void transferred(long size) {
|
||||
if(handler!=null){
|
||||
File o1= (File) o;
|
||||
long ab= o1.length();
|
||||
double abc=(size*1.0/ab)*100;
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
Message message=new Message();
|
||||
message.what=progressmes;
|
||||
int ii= finalA;
|
||||
message.obj=String.format(MyApplication.getApp().getString(R.string.messages),ii+"")+df.format(abc)+"%";
|
||||
handler.handleMessage(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
params.put(key + "\"; filename=\"" + ((File) o).getName() + "", body);
|
||||
// ProgressRequestBody body = new ProgressRequestBody( (File) o,"multipart/form-data;charset=UTF-8");
|
||||
RequestBody requestBody = RequestBody.create(MediaType.get("multipart/form-data;charset=UTF-8"), (File) o);
|
||||
params.put(key + "\"; filename=\"" + ((File) o).getName() + "", requestBody);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,11 +147,11 @@ public class RetrofitHttpUpLoad {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
public void clear() {
|
||||
params.clear();
|
||||
}
|
||||
|
||||
public void setHandler(Handler handler) {
|
||||
this.handler=handler;
|
||||
this.handler = handler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public class CommentDialog extends HorizontalAttachPopupView {
|
||||
|
||||
public CommentDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
|
||||
tvZan = findViewById(R.id.tv_zan);
|
||||
|
||||
|
||||
@@ -61,6 +62,12 @@ public class CommentDialog extends HorizontalAttachPopupView {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
}
|
||||
|
||||
public void setShowBug(boolean type) {
|
||||
|
||||
if (type) {
|
||||
@@ -75,7 +82,7 @@ public class CommentDialog extends HorizontalAttachPopupView {
|
||||
}
|
||||
|
||||
public void setPraise(boolean type) {
|
||||
isPraise=type;
|
||||
isPraise = type;
|
||||
if (type) {
|
||||
tvZan.setText("取消");
|
||||
} else {
|
||||
|
||||
6
app/src/main/res/drawable/round_blank.xml
Normal file
6
app/src/main/res/drawable/round_blank.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<corners android:radius="8dp" />
|
||||
<solid android:color="#95000000"/>
|
||||
</shape>
|
||||
@@ -2,7 +2,7 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/black"
|
||||
android:background="#4D4B4C"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -82,15 +82,22 @@
|
||||
android:id="@+id/v"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="230dp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/head"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
<FrameLayout
|
||||
android:background="@color/white"
|
||||
android:layout_below="@id/v"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginTop="-30dp"
|
||||
android:layout_marginRight="16dp" />
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:layout_margin="1dp"
|
||||
android:id="@+id/head"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
/>
|
||||
</FrameLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
|
||||
@@ -67,7 +67,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="25dp"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="16dp"
|
||||
android:padding="5dp"
|
||||
android:src="@mipmap/pl" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user