@ -10,6 +10,8 @@ import android.content.DialogInterface;
import android.content.res.Resources ;
import android.content.res.Resources ;
import android.os.Build ;
import android.os.Build ;
import android.os.Bundle ;
import android.os.Bundle ;
import android.os.Handler ;
import android.os.Looper ;
import android.util.Log ;
import android.util.Log ;
import android.view.PixelCopy ;
import android.view.PixelCopy ;
import android.view.View ;
import android.view.View ;
@ -28,6 +30,7 @@ import com.example.as_trak.toast.LoadToast;
import org.litepal.LitePal ;
import org.litepal.LitePal ;
import java.time.LocalDateTime ;
import java.time.LocalTime ;
import java.time.LocalTime ;
import java.time.format.DateTimeFormatter ;
import java.time.format.DateTimeFormatter ;
import java.util.List ;
import java.util.List ;
@ -44,7 +47,7 @@ public class LoadScanActivity extends BaseActivity implements CargoListAdapter.C
private DateTimeFormatter formatter ;
private DateTimeFormatter formatter ;
private UpdataDialog updataDialog ;
private UpdataDialog updataDialog ;
// 装载完成对话框
// 装载完成对话框
private ActivityLoadScanBinding binding ;
private TipDialog tipDialog ;
private TipDialog tipDialog ;
private AlertDialog . Builder alertDialog ;
private AlertDialog . Builder alertDialog ;
@ -52,18 +55,22 @@ public class LoadScanActivity extends BaseActivity implements CargoListAdapter.C
@Override
@Override
protected void onCreate ( Bundle savedInstanceState ) {
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState ) ;
super . onCreate ( savedInstanceState ) ;
ActivityLoadScanBinding binding = DataBindingUtil . setContentView ( this , R . layout . activity_load_scan ) ;
binding = DataBindingUtil . setContentView ( this , R . layout . activity_load_scan ) ;
initScan ( ) ;
initScan ( ) ;
int id = getIntent ( ) . getIntExtra ( "id" , 0 ) ;
int id = getIntent ( ) . getIntExtra ( "id" , 0 ) ;
// 航班显示
flightInfo = LitePal . where ( "id= ?" , String . valueOf ( id ) ) . findFirst ( FlightInfo . class ) ;
flightInfo = LitePal . where ( "id= ?" , String . valueOf ( id ) ) . findFirst ( FlightInfo . class ) ;
binding . setData ( flightInfo ) ;
binding . setData ( flightInfo ) ;
// 货箱显示
cargoInfoList = LitePal . where ( "flightId = ?" , String . valueOf ( id ) ) . find ( CargoInfo . class ) ;
cargoInfoList = LitePal . where ( "flightId = ?" , String . valueOf ( id ) ) . find ( CargoInfo . class ) ;
adapter = new CargoListAdapter ( this , this ) ;
adapter = new CargoListAdapter ( this , this ) ;
adapter . setList ( cargoInfoList ) ;
adapter . setList ( cargoInfoList ) ;
binding . setAdapter1 ( adapter ) ;
binding . setAdapter1 ( adapter ) ;
formatter = DateTimeFormatter . ofPattern ( " HH:mm") ;
formatter = DateTimeFormatter . ofPattern ( " yyyy-MM-dd HH:mm") ;
// loadToast = new LoadToast(this);
// loadToast = new LoadToast(this);
loadInfoAdapter = new LoadInfoAdapter ( this , this ) ;
loadInfoAdapter = new LoadInfoAdapter ( this , this ) ;
loadInfoAdapter . setRecyclerView ( binding . loadInfoRecyclerview ) ;
binding . setAdapter2 ( loadInfoAdapter ) ;
binding . setAdapter2 ( loadInfoAdapter ) ;
binding . loadScanSubmit . setOnLongClickListener ( this ) ;
binding . loadScanSubmit . setOnLongClickListener ( this ) ;
initDialog ( ) ;
initDialog ( ) ;
@ -84,43 +91,69 @@ public class LoadScanActivity extends BaseActivity implements CargoListAdapter.C
updataDialog . dismiss ( ) ;
updataDialog . dismiss ( ) ;
} ) ;
} ) ;
tipDialog = new TipDialog ( this ) ;
tipDialog = new TipDialog ( this ) ;
alertDialog = new AlertDialog . Builder ( this ) ;
alertDialog = new AlertDialog . Builder ( this ) ;
alertDialog . setTitle ( "装载完成提示" )
alertDialog . setTitle ( "装载完成提示" )
. setMessage ( " 是否全部修改状态为 装载完成")
. setMessage ( " 确认 装载完成")
. setNegativeButton ( "取消" , null )
. setNegativeButton ( "取消" , null )
. setPositiveButton ( "确 定 ", new DialogInterface . OnClickListener ( ) {
. setPositiveButton ( "确 认 ", new DialogInterface . OnClickListener ( ) {
@Override
@Override
public void onClick ( DialogInterface dialog , int which ) {
public void onClick ( DialogInterface dialog , int which ) {
cargoInfoList . forEach ( t - > {
if ( cargoInfoTag = = null ) {
t . setState ( "装载完成" ) ;
Toast . makeText ( LoadScanActivity . this , "没有选择装载单元" , Toast . LENGTH_SHORT ) . show ( ) ;
t . update ( t . getId ( ) ) ;
return ;
} ) ;
}
Toast . makeText ( LoadScanActivity . this , "成功" , Toast . LENGTH_SHORT ) . show ( ) ;
cargoInfoTag . setState ( "装载完成" ) ;
finish ( ) ;
cargoInfoTag . update ( cargoInfoTag . getId ( ) ) ;
adapter . notifyDataSetChanged ( ) ;
Toast . makeText ( LoadScanActivity . this , "装载完成" , Toast . LENGTH_SHORT ) . show ( ) ;
}
}
} ) . create ( ) ;
} ) . create ( ) ;
}
}
// 点击装载单元
@Override
public void clickCargoInfo ( int index ) {
cargoInfoTag = cargoInfoList . get ( index ) ;
// Log.e("TAG", "clickCargoInfo:" + cargoInfoTag.toString());
loadOperations = LitePal . where ( "cargoId =? and type = ? and (state IS NULL or state = '修改') " , String . valueOf ( cargoInfoTag . getId ( ) ) , "装载" )
. order ( "id desc" ) . find ( LoadOperation . class ) ;
Log . e ( "TAG" , "clickCargoInfo:" + loadOperations ) ;
loadInfoAdapter . setList ( loadOperations ) ;
loadInfoAdapter . notifyDataSetChanged ( ) ;
}
// 扫码结果
// 扫码结果
@SuppressLint ( "NotifyDataSetChanged" )
@SuppressLint ( "NotifyDataSetChanged" )
@Override
@Override
public void sanCodeResult ( String code ) {
public void sanCodeResult ( String code ) {
super . sanCodeResult ( code ) ;
super . sanCodeResult ( code ) ;
addInfo ( code ) ;
}
// 手动添加扫描结果
public void addSanResult ( View view ) {
String code = binding . loadSanInfoCode . getText ( ) . toString ( ) ;
addInfo ( code ) ;
}
// 添加
private void addInfo ( String code ) {
if ( cargoInfoTag = = null ) {
if ( cargoInfoTag = = null ) {
Toast . makeText ( this , "没有选择装载单元" , Toast . LENGTH_SHORT ) . show ( ) ;
Toast . makeText ( this , "没有选择装载单元" , Toast . LENGTH_SHORT ) . show ( ) ;
return ;
return ;
}
}
if ( cargoInfoTag . getState ( ) . equals ( "装载完成" ) ) {
// if (cargoInfoTag.getState().equals("装载完成")) {
Toast . makeText ( this , "装载单元已经装载完成" , Toast . LENGTH_SHORT ) . show ( ) ;
// Toast.makeText(this, "装载单元已经装载完成", Toast.LENGTH_SHORT).show();
return ;
// return;
}
// }
int count = LitePal . where ( "flightId= ? and luggageCode=? and (state IS NULL or state = '修改') " , String . valueOf ( flightInfo . getId ( ) ) , code ) . count ( LoadOperation . class ) ;
int count = LitePal . where ( "flightId= ? and luggageCode=? and type ='装载' and (state IS NULL or state = '修改') ", String . valueOf ( flightInfo . getId ( ) ) , code ) . count ( LoadOperation . class ) ;
if ( count > 0 ) {
if ( count > 0 ) {
tipDialog . showError ( "行李条码:" + code + "重复" ) ;
tipDialog . showError ( "行李条码:" + code + "重复" ) ;
return ;
return ;
}
}
tipDialog . showSuccess ( "绑定 成功") ;
tipDialog . showSuccess ( code + "\t装载 成功") ;
// 添加行李
LoadOperation loadOperation = new LoadOperation ( ) ;
LoadOperation loadOperation = new LoadOperation ( ) ;
loadOperation . setFlightCode ( flightInfo . getFlightCode ( ) ) ;
loadOperation . setFlightCode ( flightInfo . getFlightCode ( ) ) ;
loadOperation . setFlightId ( flightInfo . getId ( ) ) ;
loadOperation . setFlightId ( flightInfo . getId ( ) ) ;
@ -130,39 +163,37 @@ public class LoadScanActivity extends BaseActivity implements CargoListAdapter.C
loadOperation . setCargoId ( cargoInfoTag . getId ( ) ) ;
loadOperation . setCargoId ( cargoInfoTag . getId ( ) ) ;
loadOperation . setLuggageCode ( code ) ;
loadOperation . setLuggageCode ( code ) ;
// loadOperation.setUser();
// loadOperation.setUser();
String formattedTime = Local Time. now ( ) . format ( formatter ) ; // 格式化当前时间
String formattedTime = Local Date Time. now ( ) . format ( formatter ) ; // 格式化当前时间
loadOperation . setLoadTime ( formattedTime ) ;
loadOperation . setLoadTime ( formattedTime ) ;
loadOperation . setType ( "装载" ) ;
loadOperation . setType ( "装载" ) ;
loadOperation . save ( ) ;
loadOperation . save ( ) ;
loadOperations . add ( 0 , loadOperation ) ;
loadOperations . add ( 0 , loadOperation ) ; //列表
Log . e ( "TAG" , "sanCodeResult:" + loadOperations . toString ( ) ) ;
loadInfoAdapter . notifyItemInserted ( 0 ) ;
loadInfoAdapter . notifyDataSetChanged ( ) ;
binding . loadInfoRecyclerview . scrollToPosition ( 0 ) ;
loadOperation . setBg ( true ) ;
changeBackgroundColorAfterDelay ( loadOperation ) ;
// 更新货箱状态
int size = loadOperations . size ( ) ;
int size = loadOperations . size ( ) ;
Log . e ( "TAG" , "更新的id:" + cargoInfoTag . getId ( ) + "数量:" + size ) ;
Log . e ( "TAG" , "更新的id:" + cargoInfoTag . getId ( ) + "数量:" + size ) ;
cargoInfoTag . setCount ( size ) ;
cargoInfoTag . setCount ( size ) ;
cargoInfoTag . setState ( "装载中" ) ;
cargoInfoTag . setState ( "装载中" ) ;
cargoInfoTag . update ( cargoInfoTag . getId ( ) ) ;
cargoInfoTag . update ( cargoInfoTag . getId ( ) ) ;
}
}
private Handler handler = new Handler ( Looper . getMainLooper ( ) ) ;
// 点击装载单元
private void changeBackgroundColorAfterDelay ( LoadOperation loadOperation ) {
@Override
handler . postDelayed ( ( ) - > {
public void clickCargoInfo ( int index ) {
loadOperation . setBg ( false ) ;
cargoInfoTag = cargoInfoList . get ( index ) ;
loadInfoAdapter . notifyDataSetChanged ( ) ;
// Log.e("TAG", "clickCargoInfo:" + cargoInfoTag.toString());
} , 3000 ) ;
loadOperations = LitePal . where ( "cargoId =? and type = ? and (state IS NULL or state = '修改') " , String . valueOf ( cargoInfoTag . getId ( ) ) , "装载" ) . find ( LoadOperation . class ) ;
loadInfoAdapter . setList ( loadOperations ) ;
loadInfoAdapter . notifyDataSetChanged ( ) ;
}
}
// 修改行李号
// 修改行李号
@SuppressLint ( "NotifyDataSetChanged" )
@SuppressLint ( "NotifyDataSetChanged" )
@Override
@Override
public void updateCargoInfo ( int index ) {
public void updateCargoInfo ( int index ) {
if ( cargoInfoTag . getState ( ) . equals ( "装载完成" ) ) {
// if (cargoInfoTag.getState().equals("装载完成")) {
Toast . makeText ( this , "装载单元已经装载完成" , Toast . LENGTH_SHORT ) . show ( ) ;
// Toast.makeText(this, "装载单元已经装载完成", Toast.LENGTH_SHORT).show();
return ;
// return;
}
// }
LoadOperation loadOperation = loadOperations . get ( index ) ;
LoadOperation loadOperation = loadOperations . get ( index ) ;
updataDialog . setIndex ( index ) ;
updataDialog . setIndex ( index ) ;
updataDialog . setCode ( loadOperation . getLuggageCode ( ) ) ;
updataDialog . setCode ( loadOperation . getLuggageCode ( ) ) ;
@ -173,10 +204,10 @@ public class LoadScanActivity extends BaseActivity implements CargoListAdapter.C
@SuppressLint ( "NotifyDataSetChanged" )
@SuppressLint ( "NotifyDataSetChanged" )
@Override
@Override
public void deleteCargoInfo ( int index ) {
public void deleteCargoInfo ( int index ) {
if ( cargoInfoTag . getState ( ) . equals ( "装载完成" ) ) {
// if (cargoInfoTag.getState().equals("装载完成")) {
Toast . makeText ( this , "装载单元已经装载完成" , Toast . LENGTH_SHORT ) . show ( ) ;
// Toast.makeText(this, "装载单元已经装载完成", Toast.LENGTH_SHORT).show();
return ;
// return;
}
// }
LoadOperation loadOperation = loadOperations . get ( index ) ;
LoadOperation loadOperation = loadOperations . get ( index ) ;
loadOperation . setState ( "删除" ) ;
loadOperation . setState ( "删除" ) ;
loadOperation . update ( loadOperation . getId ( ) ) ;
loadOperation . update ( loadOperation . getId ( ) ) ;