|
@@ -1,54 +1,76 @@
|
|
|
package com.fxy.putIn;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
+import android.app.AlertDialog;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
|
|
|
+import android.net.ConnectivityManager;
|
|
|
+import android.net.Network;
|
|
|
+import android.net.NetworkCapabilities;
|
|
|
+import android.net.NetworkInfo;
|
|
|
+import android.net.NetworkRequest;
|
|
|
+import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
import android.os.Message;
|
|
|
-import android.support.v7.widget.RecyclerView;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.View;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.LinearLayout;
|
|
|
+import android.widget.ProgressBar;
|
|
|
+import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
+import androidx.annotation.RequiresApi;
|
|
|
+
|
|
|
import com.elvishew.xlog.XLog;
|
|
|
import com.fxy.R;
|
|
|
+import com.fxy.base.NetworkChangeReceiver;
|
|
|
import com.fxy.baselibrary.base.BaseActivity;
|
|
|
import com.fxy.baselibrary.bean.BaseEventBusBean;
|
|
|
import com.fxy.baselibrary.interfaces.OnRxScanerListener;
|
|
|
-import com.fxy.baselibrary.qrcode.RxQrBarTool;
|
|
|
+import com.fxy.baselibrary.util.DateUtil;
|
|
|
+import com.fxy.baselibrary.util.HideUtil;
|
|
|
import com.fxy.baselibrary.util.JsonUtil;
|
|
|
-import com.fxy.baselibrary.util.RxToast;
|
|
|
import com.fxy.bean.ActionBean;
|
|
|
import com.fxy.bean.ScanBean;
|
|
|
-import com.fxy.common.PictureSelectorUpload;
|
|
|
+import com.fxy.common.FiledUpload;
|
|
|
import com.fxy.constant.BaseConfig;
|
|
|
import com.fxy.constant.EventCode;
|
|
|
import com.fxy.net.MyDialogCallback;
|
|
|
import com.fxy.net.Urls;
|
|
|
+import com.fxy.putIn.bean.realm.TakePhotosRealm;
|
|
|
+import com.fxy.tool.OrderToolMainActivity;
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
import com.google.zxing.Result;
|
|
|
|
|
|
+import com.luck.picture.lib.PictureSelector;
|
|
|
import com.luck.picture.lib.config.PictureConfig;
|
|
|
+import com.luck.picture.lib.config.PictureMimeType;
|
|
|
+import com.luck.picture.lib.entity.LocalMedia;
|
|
|
import com.lzy.okgo.OkGo;
|
|
|
import com.lzy.okgo.model.Response;
|
|
|
|
|
|
-import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
|
import butterknife.OnClick;
|
|
|
import butterknife.Unbinder;
|
|
|
+import io.realm.RealmResults;
|
|
|
import sto.android.app.StoJNI;
|
|
|
import sto.android.app.StoPdaKeyEvent;
|
|
|
import sto.android.app.StoTongJNI;
|
|
@@ -63,10 +85,29 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
@BindView(R.id.ll_take_picture)
|
|
|
LinearLayout llTakePicture;
|
|
|
|
|
|
+ @BindView(R.id.tv_photos)
|
|
|
+ TextView tvPhotos;
|
|
|
+
|
|
|
+ @BindView(R.id.tv_uploaded)
|
|
|
+ TextView tvUploaded;
|
|
|
+
|
|
|
+ @BindView(R.id.tv_upload_exception)
|
|
|
+ TextView tvUploadedException;
|
|
|
+
|
|
|
+ @BindView(R.id.pb_progressbar)
|
|
|
+ ProgressBar pbProgressbar;
|
|
|
+ @BindView(R.id.percentage_text_view)
|
|
|
+ TextView tvPercentageTextView;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
private ArrayList photoList =new ArrayList<>();
|
|
|
|
|
|
- private PictureSelectorUpload pictureSelectorUpload;
|
|
|
+ private FiledUpload filedUpload;
|
|
|
+
|
|
|
+ private ArrayList<String> uploadMapSort =new ArrayList<>();
|
|
|
+
|
|
|
//
|
|
|
//扫码扫码动作
|
|
|
private ScanBean scanBean;
|
|
@@ -80,7 +121,22 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
|
|
|
private JSONObject postParam = new JSONObject();
|
|
|
|
|
|
+ //private RealmResults awaitUploadList;
|
|
|
+ private List<TakePhotosRealm> awaitUploadList=new ArrayList<>();
|
|
|
+
|
|
|
+ //总数
|
|
|
+ private int totalPhoto = 0;
|
|
|
+ //上传数量
|
|
|
+ private int totalUpload = 0;
|
|
|
+ //异常数量
|
|
|
+ private int totalAbnormal = 0;
|
|
|
+
|
|
|
+ //当前网络
|
|
|
+ private static Boolean currentNetwork = false;
|
|
|
|
|
|
+
|
|
|
+ //检查网络
|
|
|
+ private BroadcastReceiver networkReceiver;
|
|
|
@Override
|
|
|
public int getContentViewResId() {
|
|
|
return R.layout.activity_fxy_putin_photos;
|
|
@@ -98,7 +154,7 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
|
|
|
@Override
|
|
|
protected void getBundleExtras(Bundle bundle) {
|
|
|
- XLog.e("接收数据解析:",bundle);
|
|
|
+ //XLog.e("接收数据解析:",bundle);
|
|
|
action = bundle.getString("action","add");
|
|
|
}
|
|
|
|
|
@@ -115,13 +171,32 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
if (requestCode == PictureConfig.CHOOSE_REQUEST) {// 图片选择结果回调
|
|
|
- pictureSelectorUpload.getSelectImg(data);
|
|
|
+ List<LocalMedia> images = PictureSelector.obtainMultipleResult(data);
|
|
|
+ addTakePhotos(images.get(0));
|
|
|
+ authCamera();
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ private void authCamera(){
|
|
|
+ //拍照
|
|
|
+ com.luck.picture.lib.PictureSelector.create(this)
|
|
|
+ .openCamera(PictureMimeType.ofImage())
|
|
|
+ //只需要拍照
|
|
|
+ //.selectionMode(PictureConfig.SINGLE)
|
|
|
+ //.isCamera(true)
|
|
|
+ //.compressMaxKB()//压缩最大值kb compressGrade()为Luban.CUSTOM_GEAR有效
|
|
|
+// .compress(true) // 压缩
|
|
|
+// .cropCompressQuality(100)// 裁剪压缩质量 默认100
|
|
|
+// .minimumCompressSize(100) //最新压缩图片 默认100
|
|
|
+ .forResult(PictureConfig.CHOOSE_REQUEST);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* EventBus接收信息的方法,开启后才会调用(非粘性事件)
|
|
|
*
|
|
@@ -146,47 +221,16 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
protected void initView() {
|
|
|
unbinder = ButterKnife.bind(this);
|
|
|
setTitleName("快递入库");
|
|
|
-
|
|
|
+ //注册监听网络
|
|
|
+ registerNetReceiver();
|
|
|
initEdit();
|
|
|
iniData();
|
|
|
-
|
|
|
- RecyclerView rvShowImg = (RecyclerView)llTakePicture.findViewById(R.id.rv_show_img);
|
|
|
- pictureSelectorUpload = setItemPicture("photo",rvShowImg,9,PictureConfig.TYPE_IMAGE);
|
|
|
-
|
|
|
+ setTotalData();
|
|
|
+ filedUpload = new FiledUpload(PutinPhotosMainActivity.this,"work");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 设置多个上传文件
|
|
|
- * @param actionType String
|
|
|
- * @param showImg RecyclerView
|
|
|
- */
|
|
|
- private PictureSelectorUpload setItemPicture(String actionType,RecyclerView showImg,int maxNum,int pictureType){
|
|
|
- PictureSelectorUpload pictureUpload = new PictureSelectorUpload(PutinPhotosMainActivity.this,showImg,"work",maxNum,pictureType);
|
|
|
- pictureUpload.setActionType(actionType);
|
|
|
- pictureUpload.setCompress(true,100,500);
|
|
|
- pictureUpload.setOnlyCamera(true);
|
|
|
- //showImg.onTouchEvent()
|
|
|
-
|
|
|
- pictureUpload.setOnChangeListener(new PictureSelectorUpload.UploadChangeListener() {
|
|
|
- @Override
|
|
|
- public void uploadResult(boolean State,String actionType) {
|
|
|
- if (State) {
|
|
|
- pictureInbound();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void uploadActionType(String actionType) {
|
|
|
-
|
|
|
- System.out.println("actionType:"+actionType);
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- return pictureUpload;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
|
@@ -194,7 +238,7 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
if ((event.getKeyCode()==KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode()==KeyEvent.KEYCODE_ENTER ) && event.getAction() == KeyEvent.ACTION_DOWN){
|
|
|
//按确定键
|
|
|
if(this.validate()){
|
|
|
- pictureSelectorUpload.authCamera();
|
|
|
+// authCamera();
|
|
|
}
|
|
|
}
|
|
|
return super.dispatchKeyEvent(event);
|
|
@@ -217,7 +261,6 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
|
|
|
@SuppressLint("HandlerLeak")
|
|
|
Handler scanHandler = new Handler() {
|
|
|
-
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
// TODO Auto-generated method stub
|
|
@@ -238,13 +281,10 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
msg.obj = str;
|
|
|
scanHandler.sendMessage(msg);
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void onScanResults(String str, int type) {
|
|
|
-
|
|
|
}
|
|
|
/**
|
|
|
* 定义广播接受
|
|
@@ -312,6 +352,310 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
|
|
|
private void iniData(){
|
|
|
|
|
|
+ //检查已上传未推送成功数据
|
|
|
+ RealmResults<TakePhotosRealm> realmResults = mRealm.where(TakePhotosRealm.class)
|
|
|
+ .equalTo("isDelete",0)
|
|
|
+ .equalTo("pushStatus",2)
|
|
|
+ .notEqualTo("isFinish",1)
|
|
|
+ .sort("pushStatus").findAll();
|
|
|
+ realmResults.load();
|
|
|
+ if (realmResults.size()>0){
|
|
|
+ for (int i=0;i<realmResults.size();i++){
|
|
|
+ if (!realmResults.get(i).getOssUrl().isEmpty() && !realmResults.get(i).getId().isEmpty()){
|
|
|
+ pictureInbound(realmResults.get(i).getId(),realmResults.get(i).getOssUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void showBack() {
|
|
|
+ super.showBack();
|
|
|
+ tb_iv_left.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ int num = awaitUploadList.size();
|
|
|
+
|
|
|
+ if (num>0){
|
|
|
+
|
|
|
+ new AlertDialog.Builder(mContext).setTitle(R.string.dl_hint)
|
|
|
+ .setMessage("返回会取消上传还有"+num+"条数据未上传,确定要返回吗")
|
|
|
+ .setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
+ dialogInterface.dismiss();
|
|
|
+ }
|
|
|
+ }).setPositiveButton(R.string.str_submit, new DialogInterface.OnClickListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
+ doBack();
|
|
|
+ }
|
|
|
+ }).show();
|
|
|
+
|
|
|
+ }else{
|
|
|
+ doBack();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ private void doBack(){
|
|
|
+ HideUtil.hideSoftKeyboard(PutinPhotosMainActivity.this);
|
|
|
+ if (isShowBackDialog) {
|
|
|
+ onBackPressedSupport();
|
|
|
+ } else {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void setTotalData(){
|
|
|
+ // 获取当前日期
|
|
|
+ long timestamp = getCurrentDayStartTimestamp();
|
|
|
+
|
|
|
+ long countPhotos = mRealm.where(TakePhotosRealm.class)
|
|
|
+ .equalTo("isDelete",0)
|
|
|
+ .greaterThan("createTime", timestamp)
|
|
|
+ .count();
|
|
|
+ totalPhoto = (int)countPhotos;
|
|
|
+ tvPhotos.setText(String.valueOf(totalPhoto));
|
|
|
+
|
|
|
+ //上传数量
|
|
|
+ long countUpload = mRealm.where(TakePhotosRealm.class)
|
|
|
+ .equalTo("isDelete",0)
|
|
|
+ .equalTo("pushStatus",2)
|
|
|
+ .greaterThan("createTime", timestamp)
|
|
|
+ .count();
|
|
|
+ totalUpload = (int)countUpload;
|
|
|
+ tvUploaded.setText(String.valueOf(totalUpload));
|
|
|
+
|
|
|
+
|
|
|
+ //异常
|
|
|
+ long countAbnormal = mRealm.where(TakePhotosRealm.class)
|
|
|
+ .equalTo("isDelete",0)
|
|
|
+ .equalTo("pushStatus",1)
|
|
|
+ .greaterThan("createTime", timestamp)
|
|
|
+ .count();
|
|
|
+ totalAbnormal = (int) countAbnormal;
|
|
|
+ tvUploadedException.setText(String.valueOf(totalAbnormal));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static long getCurrentDayStartTimestamp() {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ return calendar.getTimeInMillis();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加拍照记录
|
|
|
+ * @param localMedia
|
|
|
+ */
|
|
|
+ private void addTakePhotos(LocalMedia localMedia){
|
|
|
+ String realmId = UUID.randomUUID().toString();
|
|
|
+ String scan_date = DateUtil.getCurDateStr(DateUtil.FORMAT_YMDHMS);
|
|
|
+ //同步操作写法一:
|
|
|
+ mRealm.beginTransaction();
|
|
|
+ //会创建对象和user表
|
|
|
+ TakePhotosRealm takePhotosRealm = mRealm.createObject(TakePhotosRealm.class,realmId);
|
|
|
+ //会自动更新表
|
|
|
+ takePhotosRealm.setLocalPath(localMedia.getPath());
|
|
|
+ takePhotosRealm.setMimeType(localMedia.getMimeType());
|
|
|
+ takePhotosRealm.setOssUrl("");
|
|
|
+ takePhotosRealm.setScanDate(scan_date);
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ takePhotosRealm.setCreateTime(date.getTime());
|
|
|
+ takePhotosRealm.setPushStatus(0);
|
|
|
+ //提交事务,操作就被执行
|
|
|
+ mRealm.commitTransaction();
|
|
|
+ totalPhoto++;
|
|
|
+ tvPhotos.setText(String.valueOf(totalPhoto));
|
|
|
+
|
|
|
+ //无正在执行的
|
|
|
+ if (awaitUploadList==null || awaitUploadList.size()==0){
|
|
|
+ asyncUpload();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void asyncUpload(){
|
|
|
+
|
|
|
+ if (!currentNetwork){
|
|
|
+ //无网络时在请求检查是否有网络
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (awaitUploadList==null || awaitUploadList.size()==0){
|
|
|
+ RealmResults<TakePhotosRealm> realmResults = mRealm.where(TakePhotosRealm.class)
|
|
|
+ .equalTo("isDelete",0)
|
|
|
+ .equalTo("pushStatus",0)
|
|
|
+ .sort("pushStatus").findAll();
|
|
|
+ realmResults.load();
|
|
|
+ awaitUploadList.addAll(realmResults);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (awaitUploadList.size()>0){
|
|
|
+ TakePhotosRealm tmpRealm= awaitUploadList.get(0);
|
|
|
+ int sort = uploadMapSort.size();
|
|
|
+ setUploadProgress(0);
|
|
|
+ uploadMapSort.add(tmpRealm.getId());
|
|
|
+ filedUpload.filedUpload(tmpRealm.getLocalPath(),uploadHandler,sort);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传结果
|
|
|
+ * @param tmpRealmId
|
|
|
+ * @param status
|
|
|
+ * @param photo_list
|
|
|
+ */
|
|
|
+ private void resultUpload(String tmpRealmId,Integer status,String photo_list){
|
|
|
+ if (tmpRealmId!=null && !tmpRealmId.isEmpty()){
|
|
|
+ int rePush = 0;
|
|
|
+ //遍历删除
|
|
|
+ if (awaitUploadList.size()>0){
|
|
|
+ for (int i=0;i<awaitUploadList.size();i++){
|
|
|
+ if (awaitUploadList.get(i).getId().equals(tmpRealmId)){
|
|
|
+ rePush = awaitUploadList.get(i).getRePush();
|
|
|
+ awaitUploadList.remove(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int pushStatus = 2;
|
|
|
+ if (status==0){
|
|
|
+ pushStatus = rePush>4 ? 1 : 0;
|
|
|
+ totalAbnormal++;
|
|
|
+ tvUploadedException.setText(String.valueOf(totalAbnormal));
|
|
|
+ }else{
|
|
|
+ totalUpload++;
|
|
|
+ tvUploaded.setText(String.valueOf(totalUpload));
|
|
|
+ }
|
|
|
+ //更新值
|
|
|
+ mRealm.beginTransaction();
|
|
|
+ TakePhotosRealm myObject = mRealm.where(TakePhotosRealm.class).equalTo("id",tmpRealmId).findFirst();
|
|
|
+ myObject.setPushStatus(pushStatus);
|
|
|
+ myObject.setOssUrl(photo_list);
|
|
|
+ mRealm.commitTransaction();
|
|
|
+ pictureInbound(tmpRealmId,photo_list);
|
|
|
+ }
|
|
|
+ //上传完,继续执行
|
|
|
+ asyncUpload();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //必须在主线程更新
|
|
|
+ protected void setUploadProgress(int diff){
|
|
|
+ if (pbProgressbar!=null){
|
|
|
+ pbProgressbar.setProgress(diff);
|
|
|
+ tvPercentageTextView.setText(String.valueOf(diff).concat("%"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @SuppressLint("HandlerLeak")
|
|
|
+ private Handler uploadHandler = new android.os.Handler() {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ try {
|
|
|
+ //XLog.e(msg);
|
|
|
+
|
|
|
+ String tmpRealmId;
|
|
|
+ switch (msg.what){
|
|
|
+ case 0:
|
|
|
+ Toast.makeText(mContext, "error", Toast.LENGTH_SHORT).show();
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ //失败 arg2 1、网络异常 2、服务异常
|
|
|
+ //String message = (String) msg.obj;
|
|
|
+
|
|
|
+ //网络异常不算进失败
|
|
|
+ currentNetwork = getIsNetwork();
|
|
|
+ if (currentNetwork){
|
|
|
+ resultUpload(uploadMapSort.get(msg.arg1),0,"");
|
|
|
+ }else{
|
|
|
+ awaitUploadList.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 2://成功
|
|
|
+
|
|
|
+ //表示数据存在
|
|
|
+ //Toast.makeText(mContext, "上传成功", Toast.LENGTH_SHORT).show();
|
|
|
+ tmpRealmId = uploadMapSort.get(msg.arg1);
|
|
|
+ ArrayList<String> list =new ArrayList<>();
|
|
|
+ list.add((String) msg.obj);
|
|
|
+ resultUpload(tmpRealmId,1,(new Gson()).toJson(list));
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+
|
|
|
+ //XLog.e("上传进度"+msg.arg1);
|
|
|
+ setUploadProgress(msg.arg1);
|
|
|
+ //设置进度条
|
|
|
+ //progressDialog.show();
|
|
|
+ return;
|
|
|
+ case 4:
|
|
|
+ //获取上传状态
|
|
|
+
|
|
|
+ return;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ XLog.e("上传回调",e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置是否完成
|
|
|
+ * @param realmId
|
|
|
+ * @param isFinish
|
|
|
+ */
|
|
|
+ private void setIsFinish(String realmId,Integer isFinish){
|
|
|
+ //更新值
|
|
|
+ mRealm.beginTransaction();
|
|
|
+ TakePhotosRealm myObject = mRealm.where(TakePhotosRealm.class).equalTo("id",realmId).findFirst();
|
|
|
+ myObject.setIsFinish(isFinish);
|
|
|
+ mRealm.commitTransaction();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前网络
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Boolean getIsNetwork(){
|
|
|
+ ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
+ boolean isNetwork = false;
|
|
|
+ if (connectivityManager != null) {
|
|
|
+ NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
|
|
|
+ if (networkInfo != null) {
|
|
|
+ XLog.d( "当前网络状态:" + networkInfo.getState());
|
|
|
+ isNetwork = true;
|
|
|
+ } else {
|
|
|
+ XLog.d( "当前无网络连接");
|
|
|
+ isNetwork = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ XLog.d( "无法获取ConnectivityManager实例");
|
|
|
+ }
|
|
|
+ return isNetwork;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -351,41 +695,42 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //拍照上传
|
|
|
+ private void pictureInbound(String tmpRealmId, String labelImg){
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("realm_id",tmpRealmId);
|
|
|
+ jsonObject.put("label_img",labelImg);
|
|
|
+
|
|
|
+ final String tmpRealmId1 = tmpRealmId;
|
|
|
+ OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_PICTURE_INBOUND).upJson(jsonObject)
|
|
|
+ .execute(new MyDialogCallback(this, true, false) {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Response<String> response) {
|
|
|
+ super.onSuccess(response);
|
|
|
+ try {
|
|
|
+ ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
|
|
|
+ if(bean.code == 1){
|
|
|
+ //showSuccessToast(bean.msg);
|
|
|
+ JSONObject data = new JSONObject(bean.data);
|
|
|
+ if (data.has("realm_id")){
|
|
|
+ setIsFinish(data.getString("realm_id"),1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ XLog.e("添加理货数据结果返回错误",e.getMessage());
|
|
|
+ setIsFinish(tmpRealmId1,2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
|
|
|
- private void pictureInbound(){
|
|
|
- if (!validate()){
|
|
|
- return;
|
|
|
- }
|
|
|
- //数据检查不通过
|
|
|
-
|
|
|
- if (!checkRepeat(Urls.FXY_PICTURE_INBOUND+(postParam.toString()))){
|
|
|
- Toast.makeText(this, getString(R.string.error_data_processed), Toast.LENGTH_LONG).show();
|
|
|
- return;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_PICTURE_INBOUND).upJson(postParam)
|
|
|
- .execute(new MyDialogCallback(this, true, true) {
|
|
|
- @Override
|
|
|
- public void onSuccess(Response<String> response) {
|
|
|
- super.onSuccess(response);
|
|
|
- try {
|
|
|
- ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
|
|
|
- if(bean.code == 1){
|
|
|
- showSuccessToast(bean.msg);
|
|
|
- pictureSelectorUpload.emptyRemake();//清空图片
|
|
|
- photoList.clear();
|
|
|
- pictureSelectorUpload.authCamera();
|
|
|
- }else{
|
|
|
- showWarningToast(bean.msg);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- XLog.e("添加理货数据结果返回错误",e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
|
|
@@ -393,36 +738,54 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
* 校验必录
|
|
|
*/
|
|
|
private boolean validate(){
|
|
|
- photoList = pictureSelectorUpload.getPhotoList();
|
|
|
- try {
|
|
|
- postParam = new JSONObject();
|
|
|
-
|
|
|
- //检查是否拍照 工单处理时拍照拍照非必传
|
|
|
- if (photoList.size()==0){
|
|
|
- showWarningToast("请拍照上传");
|
|
|
- return false;
|
|
|
- }
|
|
|
- Gson gson = new Gson();
|
|
|
- postParam.put("label_img",gson.toJson(photoList));
|
|
|
-
|
|
|
- } catch (JSONException e) {
|
|
|
- showWarningToast("系统异常"+e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//sIsGoodinfoMatch,sIsBattery,sIsMagnetic,sIsWood,sIsExtra,sIsOther
|
|
|
- @OnClick({R.id.btn_photos})
|
|
|
+ @OnClick({R.id.btn_photos,R.id.tv_abnormal_view})
|
|
|
public void onViewClicked(View view) {
|
|
|
Bundle bundle = new Bundle();
|
|
|
switch (view.getId()) {
|
|
|
case R.id.btn_photos:
|
|
|
- pictureSelectorUpload.authCamera();
|
|
|
+ authCamera();
|
|
|
+ break;
|
|
|
+ case R.id.tv_abnormal_view:
|
|
|
+ List<LocalMedia> selectList = new ArrayList<>();
|
|
|
+ long timestamp = getCurrentDayStartTimestamp();
|
|
|
+ RealmResults<TakePhotosRealm> realmResults = mRealm.where(TakePhotosRealm.class)
|
|
|
+ .equalTo("isDelete",0)
|
|
|
+ .equalTo("pushStatus",2)
|
|
|
+ .greaterThan("createTime", timestamp)
|
|
|
+ .sort("pushStatus").findAll();
|
|
|
+ realmResults.load();
|
|
|
+ if (realmResults.size()>0){
|
|
|
+ for (int i=0;i<realmResults.size();i++){
|
|
|
+ TakePhotosRealm tmpRealm = realmResults.get(i);
|
|
|
+ if (!realmResults.get(i).getLocalPath().isEmpty()){
|
|
|
+ String cutPath = tmpRealm.getLocalPath();
|
|
|
+ LocalMedia media = new LocalMedia(cutPath, 0, false,i, 0, tmpRealm.getMimeType());
|
|
|
+ media.setCut(false);
|
|
|
+ media.setCutPath(cutPath);
|
|
|
+ String imageType = PictureMimeType.createImageType(cutPath);
|
|
|
+ media.setPictureType(imageType);
|
|
|
+ selectList.add(media);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (selectList.size()>0){
|
|
|
+
|
|
|
+
|
|
|
+ PictureSelector.create(PutinPhotosMainActivity.this).externalPicturePreview(0, selectList);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ showErrorToast("暂时无照片");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -431,13 +794,16 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
unbinder.unbind();
|
|
|
- pictureSelectorUpload.removeHandler();
|
|
|
super.onDestroy();
|
|
|
+ //注销
|
|
|
+ unregisterReceiver(networkReceiver);
|
|
|
+
|
|
|
}
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
|
initReceiver();
|
|
|
+
|
|
|
}
|
|
|
@Override
|
|
|
protected void onPause() {
|
|
@@ -455,6 +821,31 @@ public class PutinPhotosMainActivity extends BaseActivity implements StoJNI.Sca
|
|
|
}catch (Exception e){
|
|
|
XLog.e("销毁广播失败:",e.getMessage());
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ // 注册 NetworkChangeReceiver
|
|
|
+ private void registerNetReceiver() {
|
|
|
+ networkReceiver = new NetworkChangeReceiver();
|
|
|
+ registerReceiver(networkReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 自定义的广播接收器类 (重写onReceive)
|
|
|
+ private class NetworkChangeReceiver extends BroadcastReceiver {
|
|
|
+ @Override
|
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
+ if ("android.net.conn.CONNECTIVITY_CHANGE".equals(intent.getAction())) {
|
|
|
+ boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
|
|
|
+ currentNetwork = !noConnectivity;
|
|
|
+ if (currentNetwork){
|
|
|
+ asyncUpload();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|