Commit 292e92e8 authored by YONG-LIN SU's avatar YONG-LIN SU

修正部分錯誤

parent d21d6aae
......@@ -12,6 +12,6 @@
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-08-23T08:32:55.773946400Z" />
<timeTargetWasSelectedWithDropDown value="2022-08-24T09:01:07.838534400Z" />
</component>
</project>
\ No newline at end of file
......@@ -264,6 +264,34 @@ public class Case {
return mCalendar.after(startTime) && mCalendar.before(endTime);
}
public static boolean isWorkTime(Calendar mCalendar, boolean isMorning){
Calendar endTime = Calendar.getInstance();
Calendar startTime = Calendar.getInstance();
if (isMorning) {//08:00-16:30
startTime.set(Calendar.HOUR_OF_DAY, 8);
startTime.set(Calendar.MINUTE, 0);
startTime.set(Calendar.SECOND, 0);
startTime.set(Calendar.MILLISECOND, 0);
endTime.set(Calendar.HOUR_OF_DAY, 16);
endTime.set(Calendar.MINUTE, 30);
endTime.set(Calendar.SECOND, 0);
endTime.set(Calendar.MILLISECOND, 0);
} else {//13:30-22:00
startTime.set(Calendar.HOUR_OF_DAY, 13);
startTime.set(Calendar.MINUTE, 30);
startTime.set(Calendar.SECOND, 0);
startTime.set(Calendar.MILLISECOND, 0);
endTime.set(Calendar.HOUR_OF_DAY, 22);
endTime.set(Calendar.MINUTE, 0);
endTime.set(Calendar.SECOND, 0);
endTime.set(Calendar.MILLISECOND, 0);
}
return mCalendar.after(startTime) && mCalendar.before(endTime);
}
/**
* @return 是否為早班
*/
......@@ -308,10 +336,12 @@ public class Case {
int addMins = 0;
Calendar nowCalendar = Calendar.getInstance();
nowCalendar.set(Calendar.SECOND, 0);
nowCalendar.set(Calendar.MILLISECOND, 0);
Calendar nextCalendar = Calendar.getInstance();
nextCalendar.setTime(this.caseTime);
nextCalendar.set(Calendar.SECOND, 0);
nowCalendar.set(Calendar.MILLISECOND, 0);
nextCalendar.add(Calendar.MINUTE, (int)(this.periodHour * 60));
long diff = nextCalendar.getTime().getTime() - nowCalendar.getTime().getTime();
......
......@@ -125,13 +125,19 @@ public class T02StartActivity extends AppCompatActivity {
resultLauncherRegister();
observeBinding();
// progress alert dialog init
initAlertDialogProgress();
// 判斷是否在工作時間
if (!t02StartViewModel.isWorkTime()){
lockUi();
return;
}
// 搜尋監聽藍芽裝置
hasPermissions.setValue(false);
initBlueTooth();
// progress alert dialog init
initAlertDialogProgress();
}
@Override
......@@ -139,9 +145,30 @@ public class T02StartActivity extends AppCompatActivity {
if (blueToothViewModel != null){
blueToothViewModel.disconnect();
}
if (t02StartViewModel != null){
t02StartViewModel.stopTimer();
}
super.onDestroy();
}
private void lockUi(){
dataBinding.btnGpsSearchMode.setEnabled(false);
dataBinding.btnPrint.setEnabled(false);
dataBinding.btnSearchingParkingSpace.setEnabled(false);
dataBinding.btnTimeNow.setEnabled(false);
dataBinding.btnCumulativeTime.setEnabled(false);
dataBinding.btnNewPage.setEnabled(false);
dataBinding.btnPlateNumber.setEnabled(false);
dataBinding.btnParkingSpace.setEnabled(false);
dataBinding.btnVehicleType.setEnabled(false);
dataBinding.btnPhotograph.setEnabled(false);
dataBinding.btnSelectPrinter.setEnabled(false);
}
private void eventBinding() {
dataBinding.btnVehicleType.setOnClickListener(v -> btnVehicleTypeOnClicked());
......@@ -157,6 +184,7 @@ public class T02StartActivity extends AppCompatActivity {
dataBinding.btnMonthlyReport.setOnClickListener(v -> btnMonthlyReportOnClicked());
dataBinding.btnPrint.setOnClickListener(v -> btnPrintOnClicked());
dataBinding.btnGpsSearchMode.setOnClickListener(v -> btnGpsSearchModeOnClicked());
dataBinding.btnSelectPrinter.setOnClickListener(v -> selectPrinterDialog());
// 搜尋是否有相關車格資料
dataBinding.btnParkingSpace.setOnClickListener(v -> btnParkingSpaceOnClicked());
......@@ -351,6 +379,12 @@ public class T02StartActivity extends AppCompatActivity {
}
});
t02StartViewModel.getHasNeedAddCase().observe(this, hasNeedAddCase -> {
if (hasNeedAddCase){
Toast.makeText(this, "即將有可以加時的案件", Toast.LENGTH_LONG).show();
}
});
}
private void btnParkingSpaceOnClicked() {
......
......@@ -116,11 +116,19 @@ public class T04RenewListActivity extends AppCompatActivity {
});
// 自動檢查通知
timer = new Timer();
timer.schedule(new NotifyNestedReNewTimerTask(),0, timerIntervalMines * 60 * 1000);
//timer = new Timer();
//timer.schedule(new NotifyNestedReNewTimerTask(),0, timerIntervalMines * 60 * 1000);
}//onCreate
@Override
protected void onDestroy() {
if (timer != null){
timer.cancel();
}
super.onDestroy();
}
/**
* 複寫上一頁按鈕事件
*/
......@@ -200,7 +208,7 @@ public class T04RenewListActivity extends AppCompatActivity {
Location location = fusedGpsViewModel.getLocation().getValue();
boolean isNeedNotify = false;
for (Case c: caseList) {
if (c.getNextAddMinsAway() < 5){
if (c.getNextAddMinsAway() <= 5){
if (!alreadyNotifyList.contains(c.billingNumber2))
{
isNeedNotify = true;
......
......@@ -44,7 +44,7 @@ public class T02SelectSpaceViewModel extends AndroidViewModel {
public void searchNearSpace(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
double precision = 0.0002;
double precision = 0.0002;// 63m
currentRoad.setValue(null);
currentSpace.setValue(infoRepository.spaceDao.getAllByLocation(latitude + precision, latitude - precision, longitude + precision, longitude - precision));
}
......
......@@ -5,6 +5,7 @@ import static ecom.android.newparkapp.Common.plateModifyByRule;
import static ecom.android.newparkapp.Common.plateRuleCheck;
import android.app.Application;
import android.database.sqlite.SQLiteConstraintException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
......@@ -19,10 +20,13 @@ import androidx.lifecycle.MutableLiveData;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import ecom.android.newparkapp.Common;
import ecom.android.newparkapp.ModifyPhoto;
......@@ -68,6 +72,14 @@ public class T02StartViewModel extends AndroidViewModel {
private final float threshold = 0.7f;
private final float nms_threshold = 0.3f;
private Timer timer = new Timer();
private final int needAddCaseNotifyMines = 10;
private final int clearAlreadyNotifyCaseInterval = 5;
private int clearAlreadyNotifyCaseCounter = 0;
private List<String> alreadyNotifyCase = new ArrayList<>();
private MutableLiveData<Boolean> hasNeedAddCase = new MutableLiveData<>();
public T02StartViewModel(@NonNull Application application) {
super(application);
infoRepository = new InfoRepository(application);
......@@ -86,6 +98,8 @@ public class T02StartViewModel extends AndroidViewModel {
initALPR();
}
private void initALPR() {
......@@ -101,6 +115,7 @@ public class T02StartViewModel extends AndroidViewModel {
public LiveData<List<Road>> getRoads(){ return roads; }
public LiveData<List<Space>> getSpaces(){ return spaces; }
public LiveData<Integer> getCaseCursor(){return caseCursor;}
public LiveData<Boolean> getHasNeedAddCase(){return hasNeedAddCase;}
public int getCastListSize(){return cases.size();}
public boolean isLastCase(){ return (caseCursor.getValue()+1) >= cases.size();}
public void setCurrentUser(User user){ currentUser.setValue(user);};
......@@ -294,7 +309,12 @@ public class T02StartViewModel extends AndroidViewModel {
// 新增車牌辨識結果
for (int i = 0 ; i < tempCasePhoto.size(); i++){
infoRepository.casePhotoDao.insertAll(tempCasePhoto.get(i));
CasePhoto casePhoto = tempCasePhoto.get(i);
try {
infoRepository.casePhotoDao.insertAll(casePhoto);
}catch (SQLiteConstraintException exception){
exception.printStackTrace();
}
}
tempCasePhoto.clear();
......@@ -321,7 +341,12 @@ public class T02StartViewModel extends AndroidViewModel {
// 新增車牌辨識結果
for (int i = 0 ; i < tempCasePhoto.size(); i++){
infoRepository.casePhotoDao.insertAll(tempCasePhoto.get(i));
CasePhoto casePhoto = tempCasePhoto.get(i);
try {
infoRepository.casePhotoDao.insertAll(casePhoto);
}catch (SQLiteConstraintException exception){
exception.printStackTrace();
}
}
tempCasePhoto.clear();
......@@ -635,6 +660,10 @@ public class T02StartViewModel extends AndroidViewModel {
}
caseCursor.setValue(cases.size());
// 定期60s檢查案件是否需要加時
hasNeedAddCase.setValue(false);
timer.schedule(new NotifyReNewTimerTask(), 0, 1000*60);
}
/**
......@@ -691,4 +720,46 @@ public class T02StartViewModel extends AndroidViewModel {
}
return plateNumber;
}
public boolean isWorkTime(){
Calendar calendar = Calendar.getInstance();
Shift currentShift = shift.getValue();
if (currentShift == null){
return false;
}
return Case.isWorkTime(calendar, currentShift == Shift.MORNING);
}
private class NotifyReNewTimerTask extends TimerTask {
@Override
public void run() {
if (cases != null){
boolean isNeedNotify = false;
hasNeedAddCase.postValue(false);
for (Case c: cases) {
if (c.getNextAddMinsAway() <= needAddCaseNotifyMines){
if (!alreadyNotifyCase.contains(c.billingNumber2)){
alreadyNotifyCase.add(c.billingNumber2);
isNeedNotify = true;
}
}
}
if (isNeedNotify){
hasNeedAddCase.postValue(true);
}
clearAlreadyNotifyCaseCounter++;
if (clearAlreadyNotifyCaseCounter > clearAlreadyNotifyCaseInterval){
clearAlreadyNotifyCaseCounter = 0;
}
}
}
}
public void stopTimer(){
if (timer != null){
timer.cancel();
}
}
}
......@@ -42,15 +42,14 @@ tools:layout_editor_absoluteY="25dp">
android:layout_gravity="center"
>
<TextView
android:id="@+id/textView23"
<Button
android:id="@+id/btn_select_printer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:paddingStart="3dp"
android:layout_weight="0.9"
android:textAlignment="center"
android:text="印表機"
android:gravity="center_vertical"
android:textSize="21sp" />
android:textSize="20sp" />
<TextView
android:id="@+id/textView21"
......@@ -60,7 +59,7 @@ tools:layout_editor_absoluteY="25dp">
android:text="@{blueToothViewModel.bluetoothDevice.name}"
android:textAlignment="center"
android:gravity="center"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/textView24"
......@@ -69,7 +68,7 @@ tools:layout_editor_absoluteY="25dp">
android:layout_weight="0.95"
android:textAlignment="center"
android:textColor="#8BC34A"
android:textSize="20sp"
android:textSize="18sp"
android:gravity="center"
app:blueToothStatus2String="@{blueToothViewModel.blueToothStatus}" />
......
......@@ -7,3 +7,13 @@ N068 N 02 02 23.4895994 120.4303028 01
N070 N 02 02 23.4900085 120.4301186 01
CY001 CY 02 02 24.143980 120.728605 01
CY002 CY 01 01 24.144095 120.728209 01
CY003 CY 01 01 24.145044 120.730499 01
CY004 CY 01 01 24.146152 120.730624 01
CY101 CY 01 01 24.142922 120.729012 01
CY102 CY 01 01 24.143535 120.728891 01
CY103 CY 01 01 24.143514 120.729429 01
CY104 CY 01 01 24.143509 120.728561 01
CY105 CY 01 01 24.143510 120.728581 01
CY106 CY 01 01 24.143710 120.728481 01
CY107 CY 01 01 24.143296 120.728681 01
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment