@ -1,11 +1,13 @@
package com.example.as_trak ;
import androidx.activity.result.contract.ActivityResultContracts ;
import androidx.annotation.Nullable ;
import androidx.databinding.DataBindingUtil ;
import androidx.databinding.ObservableBoolean ;
import androidx.databinding.ObservableInt ;
import android.annotation.SuppressLint ;
import android.app.AlertDialog ;
import android.content.DialogInterface ;
import android.content.Intent ;
import android.os.Bundle ;
import android.util.Log ;
@ -23,13 +25,13 @@ import com.example.as_trak.entity.CargoInfo;
import com.example.as_trak.entity.ContainerType ;
import com.example.as_trak.entity.FlightInfo ;
import com.example.as_trak.entity.LoadOperation ;
import com.example.as_trak.toast.LoadToast ;
import org.litepal.LitePal ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
import java.util.concurrent.atomic.AtomicInteger ;
public class LoadMainActivity extends BaseActivity implements AddFlightDialog . AddFlightDialogCall , CargoInfoAdapter . CargoInfoCall , AdapterView . OnItemClickListener {
private ObservableBoolean visibState ;
@ -40,8 +42,9 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
private CargoInfoAdapter cargoInfoAdapter ;
private List < CargoInfo > cargoInfoList ;
private FlightInfoAdapter adapter ;
private ActivityLoadMainBinding binding ;
private ObservableInt cargoQty ;
private ObservableInt loadQty ;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
@ -53,7 +56,20 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
// 装载器适配
cargoInfoAdapter = new CargoInfoAdapter ( this , this ) ;
binding . setAdapter ( cargoInfoAdapter ) ;
// 航班添加框
initAddFlight ( ) ; // 航班添加框
intent = new Intent ( this , LoadScanActivity . class ) ;
initInputCargo ( ) ;
cargoQty = new ObservableInt ( ) ;
loadQty = new ObservableInt ( ) ;
binding . setQty1 ( cargoQty ) ;
binding . setQty2 ( loadQty ) ;
builder = new AlertDialog . Builder ( this ) ;
builder . setTitle ( "删除确认" ) . setMessage ( "是否确定删除装载单元" ) . setNegativeButton ( "取消" , null ) ;
}
// 初始化航班添加
private void initAddFlight ( ) {
addFlightDialog = new AddFlightDialog ( this ) ;
addFlightDialog . setCall ( this ) ;
// 航班选择框
@ -68,9 +84,10 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
binding . loadMainFlightCode . setOnClickListener ( v - > {
lpw . show ( ) ;
} ) ;
intent = new Intent ( this , LoadScanActivity . class ) ;
}
// 初始化添加货箱
private void initInputCargo ( ) {
List < ContainerType > list = LitePal . findAll ( ContainerType . class ) ;
Log . e ( "TAG" , "onCreate:" + list . toString ( ) ) ;
if ( list ! = null ) {
@ -87,10 +104,8 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
binding . setList1 ( list1 ) ;
binding . setList2 ( list2 ) ;
}
}
// 显示航班添加框
public void loadAddFlight ( View view ) {
addFlightDialog . show ( ) ;
@ -102,15 +117,15 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
}
// 添加货箱
@SuppressLint ( "NotifyDataSetChanged" )
public void loadAddCargo ( View view ) {
if ( flightInfoTag = = null ) {
return ;
}
if ( flightInfoTag = = null ) return ;
String cargoCode = binding . loadMainCargoCode . getText ( ) . toString ( ) ;
if ( cargoCode . isEmpty ( ) ) {
return ;
}
if ( cargoCode . isEmpty ( ) ) return ;
String cargoCode0 = binding . loadMainCargoCode0 . getSelectedItem ( ) . toString ( ) ;
String cargoCode2 = binding . loadMainCargoCode2 . getSelectedItem ( ) . toString ( ) ;
int id = flightInfoTag . getId ( ) ;
cargoCode = cargoCode0 + cargoCode + cargoCode2 ;
int countTag = LitePal . where ( "cargoCode= ? and flightId=?" , cargoCode , String . valueOf ( id ) ) . count ( CargoInfo . class ) ;
if ( countTag > 0 ) {
Toast . makeText ( this , "装载单元已经绑定" , Toast . LENGTH_SHORT ) . show ( ) ;
@ -121,13 +136,18 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
cargoInfo . setCargoCode ( cargoCode ) ;
cargoInfo . setFlightId ( id ) ;
cargoInfo . setState ( "未装载" ) ;
// cargoInfo.setLoadState("C0");
cargoInfo . save ( ) ;
cargoInfoList . add ( cargoInfo ) ;
cargoInfoAdapter . notifyDataSetChanged ( ) ;
cargoQty . set ( cargoInfoList . size ( ) ) ;
binding . loadMainCargoCode . setText ( null ) ;
Toast . makeText ( this , "绑定成功" , Toast . LENGTH_SHORT ) . show ( ) ;
}
public void saveNumber ( View view ) {
flightInfoTag . setJieguiQty ( binding . loadMainJieguiQty . getText ( ) . toString ( ) ) ;
flightInfoTag . update ( flightInfoTag . getId ( ) ) ;
}
// 关闭货箱添加
public void loadCloseEdit ( View view ) {
visibState . set ( true ) ;
@ -156,50 +176,37 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
adapter . notifyDataSetChanged ( ) ;
}
/ *
@Override
public void sanCodeResult ( String code ) {
super . sanCodeResult ( code ) ;
Log . e ( "TAG" , "sanCodeResult:" + code ) ;
} * /
@Override
public void updateCargoInfo ( int index ) {
// CargoInfo cargoInfo = cargoInfoList.get(index);
// cargoInfoAdapter.notifyDataSetChanged();
}
// 长按删除
private AlertDialog . Builder builder ;
@SuppressLint ( "NotifyDataSetChanged" )
@Override
public void delete CargoInfo( int index ) {
public void longClick CargoInfo( int index ) {
CargoInfo cargoInfo = cargoInfoList . get ( index ) ;
if ( ! cargoInfo . getState ( ) . equals ( "待装载" ) ) {
Toast . makeText ( this , "已经装载行李,不能删除" , Toast . LENGTH_SHORT ) . show ( ) ;
return ;
}
builder . setPositiveButton ( "确定" , new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
cargoInfo . delete ( ) ;
cargoInfoList . remove ( index ) ;
cargoInfoAdapter . notifyDataSetChanged ( ) ;
Toast . makeText ( LoadMainActivity . this , "删除完成" , Toast . LENGTH_SHORT ) . show ( ) ;
}
} ) . show ( ) ;
private Intent intent ;
public void clickCargoInfo ( View view ) {
if ( flightInfoTag = = null ) {
Toast . makeText ( this , "没有选择航班" , Toast . LENGTH_SHORT ) . show ( ) ;
return ;
}
if ( cargoInfoList = = null | | cargoInfoList . isEmpty ( ) ) {
Toast . makeText ( this , "没有添加装载单元" , Toast . LENGTH_SHORT ) . show ( ) ;
return ;
}
intent . putExtra ( "id" , flightInfoTag . getId ( ) ) ;
startActivityForResult ( intent , 0 ) ;
}
// 选中航班
@Override
public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) {
flightInfoTag = flightList . get ( position ) ;
binding . loadMainJieguiQty . setText ( flightInfoTag . getJieguiQty ( ) ) ;
// 添加输入框
binding . loadMainFlightCode . setText ( flightInfoTag . getFlightCode ( ) ) ;
// 查询货框
@ -219,15 +226,32 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
private void selectCargo ( ) {
cargoInfoList = LitePal . where ( "flightId = ? " ,
String . valueOf ( flightInfoTag . getId ( ) ) ) . find ( CargoInfo . class ) ;
AtomicInteger tag = new AtomicInteger ( ) ;
if ( ! cargoInfoList . isEmpty ( ) ) {
cargoInfoList . forEach ( cargoInfo - > {
int countNum = LitePal . where ( "cargoId = ? and type ='正常' and (state IS NULL or state = '修改')" , String . valueOf ( cargoInfo . getId ( ) ) ) . count ( LoadOperation . class ) ;
cargoInfo . setCount ( countNum ) ;
tag . addAndGet ( countNum ) ;
} ) ;
}
cargoQty . set ( cargoInfoList . size ( ) ) ;
loadQty . set ( tag . intValue ( ) ) ;
cargoInfoAdapter . setList ( cargoInfoList ) ;
cargoInfoAdapter . notifyDataSetChanged ( ) ;
}
private Intent intent ; // 跳转扫描界面
public void clickCargoInfo ( View view ) {
if ( flightInfoTag = = null ) {
Toast . makeText ( this , "没有选择航班" , Toast . LENGTH_SHORT ) . show ( ) ;
return ;
}
if ( cargoInfoList = = null | | cargoInfoList . isEmpty ( ) ) {
Toast . makeText ( this , "没有添加装载单元" , Toast . LENGTH_SHORT ) . show ( ) ;
return ;
}
intent . putExtra ( "id" , flightInfoTag . getId ( ) ) ;
startActivityForResult ( intent , 0 ) ;
}
}