Commit 20f3f571 authored by YONG-LIN SU's avatar YONG-LIN SU

修正可續單清冊ProgressBar顯示問題

parent ae32c13c
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="577125220043" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-08-23T05:10:09.651008900Z" />
</component>
</project>
\ No newline at end of file
......@@ -96,7 +96,7 @@ public class ReNewListAdapter extends RecyclerView.Adapter<ReNewListAdapter.ReNe
dataBinding.carNumTxt.setText(carNumString);
float percentageReNewCount = renewSpacesNum/totalSpacesNum;
float percentageReNewCount = (float) renewSpacesNum/(float) totalSpacesNum;
int progressTintColor = Color.GREEN;
if (percentageReNewCount>=0.7)
progressTintColor = Color.RED;
......
......@@ -35,6 +35,7 @@ import ecom.android.newparkapp.databinding.ActivityMainBinding;
import ecom.android.newparkapp.entity.Shift;
import ecom.android.newparkapp.entity.User;
import ecom.android.newparkapp.viewModel.FTPUploadViewModel;
import ecom.android.newparkapp.viewModel.NotificationViewModel;
import ecom.android.newparkapp.viewModel.T01SettingViewModel;
public class MainActivity extends AppCompatActivity {
......@@ -43,6 +44,7 @@ public class MainActivity extends AppCompatActivity {
private ViewModelProvider viewModelProvider;
private T01SettingViewModel t01SettingViewModel;
private FTPUploadViewModel ftpUploadViewModel;
private NotificationViewModel notificationViewModel;
private ActivityResultLauncher<String[]> requestPermissionLauncher;
private ActivityResultLauncher requestAllFilesAccessPermissionLauncher; // Android 11 以上需申請較高權限
......@@ -61,6 +63,8 @@ public class MainActivity extends AppCompatActivity {
ftpUploadViewModel = viewModelProvider.get(FTPUploadViewModel.class);
ftpUploadViewModel.setT01SettingViewModel(t01SettingViewModel);
notificationViewModel = viewModelProvider.get(NotificationViewModel.class);
initLayout();
// 註冊權限請求結果處理
......
......@@ -22,6 +22,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import ecom.android.newparkapp.R;
......@@ -33,6 +36,7 @@ import ecom.android.newparkapp.entity.RenewInfoData;
import ecom.android.newparkapp.entity.Shift;
import ecom.android.newparkapp.repository.InfoRepository;
import ecom.android.newparkapp.viewModel.FusedGpsViewModel;
import ecom.android.newparkapp.viewModel.NotificationViewModel;
public class T04RenewListActivity extends AppCompatActivity {
......@@ -45,16 +49,26 @@ public class T04RenewListActivity extends AppCompatActivity {
private ReNewListAdapter reNewListAdapter;
private Map<String, List<Case>> pureCasesGroupByRoad = new HashMap<>();
private ViewModelProvider viewModelProvider;
private FusedGpsViewModel fusedGpsViewModel;
private NotificationViewModel notificationViewModel;
private ReNewNestedItemOnClick reNewNestedItemOnClick = new ReNewNestedItemOnClick();
private final float nearSpaceMaxDistance = 100.0f; // 鄰近車格多少m以內
private final float nearSpaceMaxDistance = 100.0f; // 鄰近車格多少 m 以內
private boolean isNearSpace = false;
private Timer timer;
private int timerIntervalMines = 1;
private List<String> alreadyNotifyList = new ArrayList<>();
private int clearAlreadyNotifyListMines = 5;
private int clearAlreadyNotifyListCounter = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_t04_renew_list);
fusedGpsViewModel = new ViewModelProvider(this).get(FusedGpsViewModel.class);
viewModelProvider = new ViewModelProvider(this);
fusedGpsViewModel = viewModelProvider.get(FusedGpsViewModel.class);
notificationViewModel = viewModelProvider.get(NotificationViewModel.class);
// 顯示上一頁按鈕
ActionBar actionBar = getSupportActionBar();
......@@ -100,6 +114,11 @@ public class T04RenewListActivity extends AppCompatActivity {
}
return true;
});
// 自動檢查通知
timer = new Timer();
timer.schedule(new NotifyNestedReNewTimerTask(),0, timerIntervalMines * 60 * 1000);
}//onCreate
/**
......@@ -173,4 +192,32 @@ public class T04RenewListActivity extends AppCompatActivity {
finish();
}
}
private class NotifyNestedReNewTimerTask extends TimerTask {
@Override
public void run() {
List<Case> caseList = infoRepository.caseDao.getAllByShiftAndUser(shift, userId);
Location location = fusedGpsViewModel.getLocation().getValue();
boolean isNeedNotify = false;
for (Case c: caseList) {
if (c.getNextAddMinsAway() < 5){
if (!alreadyNotifyList.contains(c.billingNumber2))
{
isNeedNotify = true;
alreadyNotifyList.add(c.billingNumber2);
}
}
}
if (isNeedNotify){
notificationViewModel.nearReNewCaseNotify();
}
clearAlreadyNotifyListCounter++;
if (clearAlreadyNotifyListCounter > clearAlreadyNotifyListMines){
alreadyNotifyList.clear();
clearAlreadyNotifyListCounter = 0;
}
}
}
}
\ No newline at end of file
package ecom.android.newparkapp.viewModel;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import ecom.android.newparkapp.R;
public class NotificationViewModel extends AndroidViewModel {
private final String CHANNEL_ID = "ecom.android.newparkapp.notification.channel";
private final CharSequence name = "系統通知";
private final String description = "嘉義路邊停車開單系統通知";
private NotificationChannel channel;
private NotificationManager notificationManager;
public NotificationViewModel(@NonNull Application application) {
super(application);
int importance = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
importance = NotificationManager.IMPORTANCE_HIGH;
}
channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
notificationManager = application.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
public void initNotify(String title, String text){
Notification.Builder builder = new Notification.Builder(getApplication(),CHANNEL_ID);
Notification notification = builder.setSmallIcon(R.drawable.icon)
.setContentTitle(title)
.setContentText(text)
.setAutoCancel(true)
.build();
notificationManager.notify(0, notification);
}
public void nearReNewCaseNotify(){
Notification.Builder builder = new Notification.Builder(getApplication(),CHANNEL_ID);
Notification notification = builder.setSmallIcon(R.drawable.icon)
.setContentTitle("續單提醒")
.setContentText("附近有即將有可以續單的單號")
.setAutoCancel(true)
.build();
notificationManager.notify(1, notification);
}
}
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