@ -1,10 +1,5 @@
package com.example.as_trak ;
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 ;
@ -14,8 +9,14 @@ import android.util.Log;
import android.view.View ;
import android.widget.AdapterView ;
import android.widget.ListPopupWindow ;
import android.widget.Spinner ;
import android.widget.Toast ;
import androidx.annotation.Nullable ;
import androidx.databinding.DataBindingUtil ;
import androidx.databinding.ObservableBoolean ;
import androidx.databinding.ObservableInt ;
import com.example.as_trak.adapter.CargoInfoAdapter ;
import com.example.as_trak.adapter.FlightInfoAdapter ;
import com.example.as_trak.base.BaseActivity ;
@ -47,6 +48,9 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
private ObservableInt loadQty ;
private androidx . appcompat . app . AlertDialog . Builder alertDialog ;
private String [ ] loadStateList ;
private AlertDialog . Builder builder ; // 长按删除
private AlertDialog . Builder selectCargoType ; //
private Intent intent ; // 跳转扫描界面
@Override
protected void onCreate ( Bundle savedInstanceState ) {
@ -60,13 +64,12 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
binding . setAdapter ( cargoInfoAdapter ) ;
initAddFlight ( ) ; // 航班添加框
intent = new Intent ( this , LoadScanActivity . class ) ;
initInputCargo ( ) ;
cargoQty = new ObservableInt ( ) ;
loadQty = new ObservableInt ( ) ;
binding . setQty1 ( cargoQty ) ;
binding . setQty2 ( loadQty ) ;
initAlertDialog ( ) ;
initScan ( ) ;
}
private void initAlertDialog ( ) {
@ -74,8 +77,7 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
builder . setTitle ( "删除确认" ) . setMessage ( "是否确定删除装载单元" ) . setNegativeButton ( "取消" , null ) ;
loadStateList = getResources ( ) . getStringArray ( R . array . loadState ) ;
alertDialog = new androidx . appcompat . app . AlertDialog . Builder ( this ) ;
alertDialog . setTitle ( "选择装载量" )
. setNegativeButton ( "取消" , null ) . create ( ) ;
alertDialog . setTitle ( "选择装载量" ) . setNegativeButton ( "取消" , null ) . create ( ) ;
}
// 初始化航班添加
@ -96,6 +98,12 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
} ) ;
}
@Override
protected void onResume ( ) {
super . onResume ( ) ;
initInputCargo ( ) ;
}
// 初始化添加货箱
private void initInputCargo ( ) {
List < ContainerType > list = LitePal . findAll ( ContainerType . class ) ;
@ -111,8 +119,14 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
list2 . add ( t . getTypeName ( ) ) ;
}
} ) ;
if ( list1 . isEmpty ( ) | | list2 . isEmpty ( ) ) {
Toast . makeText ( this , "基础信息未维护" , Toast . LENGTH_SHORT ) . show ( ) ;
Intent intent1 = new Intent ( this , SettingActivity . class ) ;
startActivity ( intent1 ) ;
}
binding . setList1 ( list1 ) ;
binding . setList2 ( list2 ) ;
}
}
@ -128,14 +142,23 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
// 添加货箱
@SuppressLint ( "NotifyDataSetChanged" )
public void loadAddCargo1 ( View view ) {
if ( flightInfoTag = = null ) return ;
String code0 = binding . loadMainCargoSanCode . getText ( ) . toString ( ) ;
addCargo ( code0 , binding . loadMainSanTypeSpinner . getSelectedItem ( ) . toString ( ) ) ;
}
public void loadAddCargo ( View view ) {
if ( flightInfoTag = = null ) return ;
String cargoCode = binding . loadMainCargoCode . getText ( ) . toString ( ) ;
if ( cargoCode . isEmpty ( ) ) return ;
String cargoCode0 = binding . loadMainCargoCode0 . getSelectedItem ( ) . toString ( ) ;
cargoCode = cargoCode0 + cargoCode ;
addCargo ( cargoCode , binding . loadMainCargoCode2 . getSelectedItem ( ) . toString ( ) ) ;
}
@SuppressLint ( "NotifyDataSetChanged" )
private void addCargo ( String cargoCode , String type ) {
int id = flightInfoTag . getId ( ) ;
cargoCode = cargoCode0 + cargoCode ;
int countTag = LitePal . where ( "cargoCode= ? and flightId=?" , cargoCode , String . valueOf ( id ) ) . count ( CargoInfo . class ) ;
if ( countTag > 0 ) {
Toast . makeText ( this , "装载单元已经绑定" , Toast . LENGTH_SHORT ) . show ( ) ;
@ -146,12 +169,14 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
cargoInfo . setCargoCode ( cargoCode ) ;
cargoInfo . setFlightId ( id ) ;
cargoInfo . setState ( "未装载" ) ;
cargoInfo . setCargoType ( binding. loadMainCargoCode2 . getSelectedItem ( ) . toString ( ) ) ;
cargoInfo . setCargoType ( type ) ;
cargoInfo . save ( ) ;
cargoInfoList . add ( cargoInfo ) ;
cargoInfoAdapter . notifyDataSetChanged ( ) ;
cargoQty . set ( cargoInfoList . size ( ) ) ;
int size = cargoInfoList . size ( ) ;
cargoQty . set ( size ) ;
cargoInfoAdapter . notifyItemInserted ( size - 1 ) ;
binding . loadMainCargoCode . setText ( null ) ;
binding . loadMainCargoSanCode . setText ( null ) ;
Toast . makeText ( this , "绑定成功" , Toast . LENGTH_SHORT ) . show ( ) ;
}
@ -188,11 +213,7 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
flightList . add ( flightInfo ) ;
adapter . notifyDataSetChanged ( ) ;
}
// 长按删除
private AlertDialog . Builder builder ;
// 删除装载单元
@SuppressLint ( "NotifyDataSetChanged" )
@Override
public void longClickCargoInfo ( int index ) {
@ -228,7 +249,6 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
} ) . show ( ) ;
}
// 选中航班
@Override
public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) {
@ -241,14 +261,14 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
Toast . makeText ( this , "查询成功" , Toast . LENGTH_SHORT ) . show ( ) ;
lpw . dismiss ( ) ;
}
// 返回时调
@Override
protected void onActivityResult ( int requestCode , int resultCode , @Nullable Intent data ) {
super . onActivityResult ( requestCode , resultCode , data ) ;
Log . e ( "TAG" , "onActivityResult:重加载" ) ;
selectCargo ( ) ;
}
// 查询装载单元 内 数量
@SuppressLint ( "NotifyDataSetChanged" )
private void selectCargo ( ) {
cargoInfoList = LitePal . where ( "flightId = ? " ,
@ -267,8 +287,6 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
cargoInfoAdapter . notifyDataSetChanged ( ) ;
}
private Intent intent ; // 跳转扫描界面
public void clickCargoInfo ( View view ) {
if ( flightInfoTag = = null ) {
Toast . makeText ( this , "没有选择航班" , Toast . LENGTH_SHORT ) . show ( ) ;
@ -281,4 +299,16 @@ public class LoadMainActivity extends BaseActivity implements AddFlightDialog.Ad
intent . putExtra ( "id" , flightInfoTag . getId ( ) ) ;
startActivityForResult ( intent , 0 ) ;
}
// 扫描装载单元
@Override
public void sanCodeResult ( String code ) {
super . sanCodeResult ( code ) ;
if ( code . length ( ) < 8 ) {
Toast . makeText ( this , "扫描数据:" + code + " 异常" , Toast . LENGTH_SHORT ) . show ( ) ;
return ;
}
String substring = code . substring ( 0 , 8 ) ;
binding . loadMainCargoSanCode . setText ( substring ) ;
}
}